From 758d09cd5c557d39d8da8a3f213c7275e6957d79 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 14 Aug 2018 16:29:14 +1000 Subject: [PATCH] More work on save and publish overlays --- .../components/content/edit.controller.js | 48 +++++++++++++++---- ...ective.js => umbvariantstate.directive.js} | 0 .../components/content/umb-variant-state.html | 2 +- .../overlays}/publish.controller.js | 8 ++-- .../publish => content/overlays}/publish.html | 8 ++-- .../views/content/overlays/save.controller.js | 17 +++---- .../src/views/content/overlays/save.html | 18 +++---- src/Umbraco.Web/Editors/ContentController.cs | 14 +++--- 8 files changed, 71 insertions(+), 44 deletions(-) rename src/Umbraco.Web.UI.Client/src/common/directives/components/content/{umbvariantlist.directive.js => umbvariantstate.directive.js} (100%) rename src/Umbraco.Web.UI.Client/src/views/{common/overlays/publish => content/overlays}/publish.controller.js (93%) rename src/Umbraco.Web.UI.Client/src/views/{common/overlays/publish => content/overlays}/publish.html (85%) 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 3f4ce37f0b..f0936bf7fb 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 @@ -27,11 +27,6 @@ // add all editors to an editors array to support split view $scope.editors = []; - $scope.splitView = { - "leftIsOpen": true, - "rightIsOpen": false - }; - $scope.initVariant = initVariant; $scope.splitViewChanged = splitViewChanged; @@ -70,6 +65,41 @@ $scope.$broadcast("editors.content.splitViewChanged", { editors: $scope.editors }); } + function countDirtyVariants() { + var count = 0; + for (var i = 0; i < $scope.content.variants.length; i++) { + var v = $scope.content.variants[i]; + if (v.isDirty) { + count++; + } + } + return count; + } + + /** Returns true if the save dialog should be shown when pressing save */ + function showSaveDialog() { + + //show the dialog if split view is open + if ($scope.editors.length > 1) { + return true; + } + + //if there are more than one dirty variants + if (countDirtyVariants() > 1) { + return true; + } + + //if there is a dirty variant that is not the currently selected variant + for (var i = 0; i < $scope.content.variants.length; i++) { + var v = $scope.content.variants[i]; + if (v.isDirty && v.language.culture !== $scope.editors[0].content.language.culture) { + return true; + } + } + + return false; + } + /** * The content item(s) are loaded into an array and this will set the active content item based on the current culture (query string). * If the content item is invariant, then only one item exists in the array. @@ -429,7 +459,7 @@ if (formHelper.submitForm({ scope: $scope, action: "publish" })) { var dialog = { - view: "publish", + view: "views/content/overlays/publish.html", variants: $scope.content.variants, //set a model property for the dialog skipFormValidation: true, //when submitting the overlay form, skip any client side validation submitButtonLabel: "Publish", @@ -456,7 +486,7 @@ var keys = _.keys(err.data.ModelState); var foundVariantError = _.find(keys, function (k) { - return k.startsWith("publish_variant_"); + return k.startsWith("_content_variant_"); }); if (!foundVariantError) { //no variant errors, close the dialog @@ -483,7 +513,7 @@ $scope.save = function () { // TODO: Add "..." to save 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) { + if (showSaveDialog()) { //before we launch the dialog we want to execute all client side validations first if (formHelper.submitForm({ scope: $scope, action: "save" })) { @@ -515,7 +545,7 @@ var keys = _.keys(err.data.ModelState); var foundVariantError = _.find(keys, function (k) { - return k.startsWith("publish_variant_"); + return k.startsWith("_content_variant_"); }); if (!foundVariantError) { //no variant errors, close the dialog diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbvariantlist.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbvariantstate.directive.js similarity index 100% rename from src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbvariantlist.directive.js rename to src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbvariantstate.directive.js diff --git a/src/Umbraco.Web.UI.Client/src/views/components/content/umb-variant-state.html b/src/Umbraco.Web.UI.Client/src/views/components/content/umb-variant-state.html index 94ec40e876..3a41f0623d 100644 --- a/src/Umbraco.Web.UI.Client/src/views/components/content/umb-variant-state.html +++ b/src/Umbraco.Web.UI.Client/src/views/components/content/umb-variant-state.html @@ -1,4 +1,4 @@ -
+
diff --git a/src/Umbraco.Web.UI.Client/src/views/common/overlays/publish/publish.controller.js b/src/Umbraco.Web.UI.Client/src/views/content/overlays/publish.controller.js similarity index 93% rename from src/Umbraco.Web.UI.Client/src/views/common/overlays/publish/publish.controller.js rename to src/Umbraco.Web.UI.Client/src/views/content/overlays/publish.controller.js index 446ed78ec1..6102530619 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/overlays/publish/publish.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/content/overlays/publish.controller.js @@ -22,7 +22,7 @@ return v.language.id === oldVal[i].language.id; }); if (found) { - found.publish = oldVal[i].publish; + found.selected = oldVal[i].selected; } } } @@ -31,7 +31,7 @@ function changeSelection(variant) { var firstSelected = _.find(vm.variants, function (v) { - return v.publish; + return v.selected; }); $scope.model.disableSubmitButton = !firstSelected; //disable submit button if there is none selected } @@ -63,7 +63,7 @@ _.each(vm.variants, function (variant) { variant.compositeId = variant.language.culture + "_" + (variant.segment ? variant.segment : ""); - variant.htmlId = "publish_variant_" + variant.compositeId; + variant.htmlId = "_content_variant_" + variant.compositeId; //check for pristine variants if (!vm.hasPristineVariants) { @@ -83,7 +83,7 @@ if (active) { //ensure that the current one is selected - active.publish = true; + active.selected = true; } } else { diff --git a/src/Umbraco.Web.UI.Client/src/views/common/overlays/publish/publish.html b/src/Umbraco.Web.UI.Client/src/views/content/overlays/publish.html similarity index 85% rename from src/Umbraco.Web.UI.Client/src/views/common/overlays/publish/publish.html rename to src/Umbraco.Web.UI.Client/src/views/content/overlays/publish.html index 8a3abc3665..324a05fdad 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/overlays/publish/publish.html +++ b/src/Umbraco.Web.UI.Client/src/views/content/overlays/publish.html @@ -16,14 +16,14 @@
@@ -49,8 +49,8 @@
-
{{ variant.language.name }}
-
{{ variant.state }}
+
{{ variant.language.name }}
+
diff --git a/src/Umbraco.Web.UI.Client/src/views/content/overlays/save.controller.js b/src/Umbraco.Web.UI.Client/src/views/content/overlays/save.controller.js index 711630b75a..0a2bf8621b 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/overlays/save.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/content/overlays/save.controller.js @@ -22,7 +22,7 @@ return v.language.id === oldVal[i].language.id; }); if (found) { - found.publish = oldVal[i].publish; + found.selected = oldVal[i].selected; } } } @@ -31,19 +31,17 @@ function changeSelection(variant) { var firstSelected = _.find(vm.variants, function (v) { - return v.publish; + return v.selected; }); $scope.model.disableSubmitButton = !firstSelected; //disable submit button if there is none selected } function dirtyVariantFilter(variant) { - //determine a variant is 'dirty' (meaning it will show up as publish-able) if it's + //determine a variant is 'dirty' (meaning it will show up as save-able) if it's // * the active one // * it's editor is in a $dirty state - // * it has pending saves - // * it is unpublished // * it is in NotCreated state - return (variant.active || variant.isDirty || variant.state === "Draft" || variant.state === "PublishedPendingChanges" || variant.state === "NotCreated"); + return (variant.active || variant.isDirty || variant.state === "NotCreated"); } function pristineVariantFilter(variant) { @@ -63,8 +61,7 @@ _.each(vm.variants, function (variant) { variant.compositeId = variant.language.culture + "_" + (variant.segment ? variant.segment : ""); - //TODO: Change this prefix on both this and the publish dialog - variant.htmlId = "publish_variant_" + variant.compositeId; + variant.htmlId = "_content_variant_" + variant.compositeId; //check for pristine variants if (!vm.hasPristineVariants) { @@ -84,11 +81,11 @@ if (active) { //ensure that the current one is selected - active.publish = true; + active.selected = true; } } else { - //disable Publish button if we have nothing to publish + //disable save button if we have nothing to save $scope.model.disableSubmitButton = true; } diff --git a/src/Umbraco.Web.UI.Client/src/views/content/overlays/save.html b/src/Umbraco.Web.UI.Client/src/views/content/overlays/save.html index 4c3ebca6a6..34bd5f294b 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/overlays/save.html +++ b/src/Umbraco.Web.UI.Client/src/views/content/overlays/save.html @@ -11,27 +11,27 @@
- +
-
+
-
-
{{publishVariantSelectorForm.publishVariantSelector.errorMsg}}
+
+
{{saveVariantSelectorForm.saveVariantSelector.errorMsg}}
@@ -49,8 +49,8 @@
-
{{ variant.language.name }}
-
{{ variant.state }}
+
{{ variant.language.name }}
+
diff --git a/src/Umbraco.Web/Editors/ContentController.cs b/src/Umbraco.Web/Editors/ContentController.cs index ac6048bee2..5d1c9e50c9 100644 --- a/src/Umbraco.Web/Editors/ContentController.cs +++ b/src/Umbraco.Web/Editors/ContentController.cs @@ -779,8 +779,7 @@ namespace Umbraco.Web.Editors //cannot continue publishing since a required language that is not currently being published isn't published if (!contentItem.PersistedContent.IsCulturePublished(lang.IsoCode)) { - var errMsg = Services.TextService.Localize("speechBubbles/contentReqCulturePublishError", new[] { allLangs[lang.IsoCode].CultureName }); - ModelState.AddModelError("publish_variant_" + lang.IsoCode + "_", errMsg); + AddCultureValidationError(lang.IsoCode, allLangs, "speechBubbles/contentReqCulturePublishError"); canPublish = false; } } @@ -823,7 +822,7 @@ namespace Umbraco.Web.Editors var valid = persistentContent.PublishCulture(variant.Culture); if (!valid) { - AddCultureValidationError(variant.Culture, allLangs); + AddCultureValidationError(variant.Culture, allLangs, "speechBubbles/contentCultureValidationError"); return false; } } @@ -836,11 +835,12 @@ namespace Umbraco.Web.Editors /// /// /// - private void AddCultureValidationError(string culture, IDictionary allLangs) + /// + private void AddCultureValidationError(string culture, IDictionary allLangs, string localizationKey) { - var key = "publish_variant_" + culture + "_"; + var key = "_content_variant_" + culture + "_"; if (ModelState.ContainsKey(key)) return; - var errMsg = Services.TextService.Localize("speechBubbles/contentCultureValidationError", new[] { allLangs[culture].CultureName }); + var errMsg = Services.TextService.Localize(localizationKey, new[] { allLangs[culture].CultureName }); ModelState.AddModelError(key, errMsg); } @@ -1235,7 +1235,7 @@ namespace Umbraco.Web.Editors foreach (var cultureError in cultureErrors) { - AddCultureValidationError(cultureError, allLangs); + AddCultureValidationError(cultureError, allLangs, "speechBubbles/contentCultureValidationError"); } }