From 09b0d61ab8ff8af00e7f201b1c94238dd26f70e7 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 10 Apr 2018 12:26:19 +1000 Subject: [PATCH] Ensures current variant is at the top of the publish list and is selected, disable the publish button if there are none selected --- .../components/content/edit.controller.js | 1 - .../overlays/publish/publish.controller.js | 17 ++++++++++++++--- .../views/common/overlays/publish/publish.html | 1 + .../Models/Mapping/VariationResolver.cs | 15 +++++++++++++-- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js index 992ae9a2e4..794b61accc 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js @@ -293,7 +293,6 @@ $scope.saveAndPublish = function () { - // TODO: we only want to open the bulk publish dialog if there are more than one variant to publish // TODO: Add "..." to publish button label if there are more than one variant to publish - currently it just adds the elipses if there's more than 1 variant if ($scope.content.variants.length > 1) { var dialog = { diff --git a/src/Umbraco.Web.UI.Client/src/views/common/overlays/publish/publish.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/overlays/publish/publish.controller.js index e4b224a5f5..a489e9927d 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/overlays/publish/publish.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/overlays/publish/publish.controller.js @@ -5,6 +5,7 @@ var vm = this; vm.variants = $scope.model.variants; + vm.changeSelection = changeSelection; //watch this model, if it's reset, then re init $scope.$watch(function() { @@ -26,16 +27,26 @@ onInit(); }); + function changeSelection(variant) { + var firstSelected = _.find(vm.variants, function(v) { + return v.publish; + }); + $scope.model.disableSubmitButton = !firstSelected; //disable submit button if there is none selected + } + function onInit() { _.each(vm.variants, function (v) { v.compositeId = v.language.id + "_" + (v.segment ? v.segment : ""); v.htmlId = "publish_variant_" + v.compositeId; }); + //now sort it so that the current one is at the top + vm.variants = _.sortBy(vm.variants, function(v) { + return v.current ? 0 : 1; + }); + //ensure that the current one is selected + vm.variants[0].publish = true; } - - onInit(); - } angular.module("umbraco").controller("Umbraco.Overlays.PublishController", PublishController); diff --git a/src/Umbraco.Web.UI.Client/src/views/common/overlays/publish/publish.html b/src/Umbraco.Web.UI.Client/src/views/common/overlays/publish/publish.html index 70cfe83a53..ed7f32fc25 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/overlays/publish/publish.html +++ b/src/Umbraco.Web.UI.Client/src/views/common/overlays/publish/publish.html @@ -17,6 +17,7 @@ name="publishVariantSelector" type="checkbox" ng-model="variant.publish" + ng-change="vm.changeSelection(variant)" ng-disabled="variant.validationError" style="margin-right: 8px;" val-server-field="{{variant.htmlId}}"/> diff --git a/src/Umbraco.Web/Models/Mapping/VariationResolver.cs b/src/Umbraco.Web/Models/Mapping/VariationResolver.cs index 1ced557b91..84bd79133a 100644 --- a/src/Umbraco.Web/Models/Mapping/VariationResolver.cs +++ b/src/Umbraco.Web/Models/Mapping/VariationResolver.cs @@ -38,8 +38,19 @@ namespace Umbraco.Web.Models.Mapping var langId = context.GetLanguageId(); - //set the current variant being edited to the one found in the context or the default, whichever matches - variants.First(x => (langId.HasValue && langId.Value == x.Language.Id) || x.Language.IsDefaultVariantLanguage).IsCurrent = true; + //set the current variant being edited to the one found in the context or the default if nothing matches + var foundCurrent = false; + foreach (var variant in variants) + { + if (langId.HasValue && langId.Value == variant.Language.Id) + { + variant.IsCurrent = true; + foundCurrent = true; + break; + } + } + if (!foundCurrent) + variants.First(x => x.Language.IsDefaultVariantLanguage).IsCurrent = true; return variants; }