From 30d29d9fcf319dca2d9d33da2372ab8c045fcb3e Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 13 Aug 2018 16:45:05 +1000 Subject: [PATCH] initial commit for save dialog --- .../components/content/edit.controller.js | 58 +++++++++- .../content/umbvariantlist.directive.js | 22 ++++ .../common/overlays/publish/publish.html | 7 +- .../components/content/umb-variant-state.html | 6 ++ .../views/content/overlays/save.controller.js | 101 ++++++++++++++++++ .../src/views/content/overlays/save.html | 58 ++++++++++ .../Umbraco/config/lang/en_us.xml | 5 +- 7 files changed, 250 insertions(+), 7 deletions(-) create mode 100644 src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbvariantlist.directive.js create mode 100644 src/Umbraco.Web.UI.Client/src/views/components/content/umb-variant-state.html create mode 100644 src/Umbraco.Web.UI.Client/src/views/content/overlays/save.controller.js create mode 100644 src/Umbraco.Web.UI.Client/src/views/content/overlays/save.html 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 fbe92963ed..3f4ce37f0b 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 @@ -481,7 +481,63 @@ }; $scope.save = function () { - return performSave({ saveMethod: $scope.saveMethod(), action: "save" }).catch(angular.noop); + + // 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) { + //before we launch the dialog we want to execute all client side validations first + if (formHelper.submitForm({ scope: $scope, action: "save" })) { + + var dialog = { + view: "views/content/overlays/save.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: "Save", + submit: function (model) { + model.submitButtonState = "busy"; + + //we need to return this promise so that the dialog can handle the result and wire up the validation response + return performSave({ + saveMethod: $scope.saveMethod(), + action: "save" + }).then(function (data) { + overlayService.close(); + return $q.when(data); + }, + function (err) { + model.submitButtonState = "error"; + //re-map the dialog model since we've re-bound the properties + dialog.variants = $scope.content.variants; + + //check the error list for specific variant errors, if none exist that means that only server side validation + //for the current variant's properties failed, in this case we want to close the publish dialog since the user + //will need to fix validation errors on the properties + if (err.data && err.data.ModelState) { + var keys = _.keys(err.data.ModelState); + var foundVariantError = _.find(keys, + function (k) { + return k.startsWith("publish_variant_"); + }); + if (!foundVariantError) { + //no variant errors, close the dialog + overlayService.close(); + } + } + + return $q.reject(err); + }); + }, + close: function (oldModel) { + overlayService.close(); + } + }; + + overlayService.open(dialog); + } + } + else { + return performSave({ saveMethod: $scope.saveMethod(), action: "save" }).catch(angular.noop); + } + }; $scope.preview = function (content) { 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/umbvariantlist.directive.js new file mode 100644 index 0000000000..1dc2d60450 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbvariantlist.directive.js @@ -0,0 +1,22 @@ +(function () { + 'use strict'; + + function umbVariantStateController($scope, $element) { + + var vm = this; + + } + + var umbVariantStateComponent = { + templateUrl: 'views/components/content/umb-variant-state.html', + bindings: { + variant: "<" + }, + controllerAs: 'vm', + controller: umbVariantStateController + }; + + angular.module("umbraco.directives") + .component('umbVariantState', umbVariantStateComponent); + +})(); 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 c28b22f415..8a3abc3665 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 @@ -26,11 +26,8 @@ {{ variant.language.name }} -
-
-
-
-
+
+
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 new file mode 100644 index 0000000000..94ec40e876 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/views/components/content/umb-variant-state.html @@ -0,0 +1,6 @@ +
+
+
+
+
+
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 new file mode 100644 index 0000000000..711630b75a --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/views/content/overlays/save.controller.js @@ -0,0 +1,101 @@ +(function () { + "use strict"; + + function SaveContentController($scope, localizationService) { + + var vm = this; + vm.variants = $scope.model.variants; + vm.changeSelection = changeSelection; + vm.loading = true; + vm.dirtyVariantFilter = dirtyVariantFilter; + vm.pristineVariantFilter = pristineVariantFilter; + vm.hasPristineVariants = false; + + //watch this model, if it's reset, then re init + $scope.$watch("model.variants", + function (newVal, oldVal) { + vm.variants = newVal; + if (oldVal && oldVal.length) { + //re-bind the selections + for (var i = 0; i < oldVal.length; i++) { + var found = _.find(vm.variants, function (v) { + return v.language.id === oldVal[i].language.id; + }); + if (found) { + found.publish = oldVal[i].publish; + } + } + } + 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 dirtyVariantFilter(variant) { + //determine a variant is 'dirty' (meaning it will show up as publish-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"); + } + + function pristineVariantFilter(variant) { + return !(dirtyVariantFilter(variant)); + } + + function onInit() { + + if(!$scope.model.title) { + localizationService.localize("content_readyToSave").then(function(value){ + $scope.model.title = value; + }); + } + + vm.hasPristineVariants = false; + + _.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; + + //check for pristine variants + if (!vm.hasPristineVariants) { + vm.hasPristineVariants = pristineVariantFilter(variant); + } + }); + + if (vm.variants.length !== 0) { + //now sort it so that the current one is at the top + vm.variants = _.sortBy(vm.variants, function (v) { + return v.active ? 0 : 1; + }); + + var active = _.find(vm.variants, function (v) { + return v.active; + }); + + if (active) { + //ensure that the current one is selected + active.publish = true; + } + + } else { + //disable Publish button if we have nothing to publish + $scope.model.disableSubmitButton = true; + } + + vm.loading = false; + } + } + + angular.module("umbraco").controller("Umbraco.Overlays.SaveContentController", SaveContentController); + +})(); 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 new file mode 100644 index 0000000000..4c3ebca6a6 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/views/content/overlays/save.html @@ -0,0 +1,58 @@ +
+ +
+

+
+ +
+ +
+ +
+ +
+ +
+ +
+ + +
+ +
+ +
+
{{publishVariantSelectorForm.publishVariantSelector.errorMsg}}
+
+ +
+
+ +
+
+
+
+ +
+
+

+
+ +
+
+
{{ variant.language.name }}
+
{{ variant.state }}
+
+
+
+ +
diff --git a/src/Umbraco.Web.UI/Umbraco/config/lang/en_us.xml b/src/Umbraco.Web.UI/Umbraco/config/lang/en_us.xml index e752e2c859..ca5721057d 100644 --- a/src/Umbraco.Web.UI/Umbraco/config/lang/en_us.xml +++ b/src/Umbraco.Web.UI/Umbraco/config/lang/en_us.xml @@ -264,8 +264,11 @@ This value is hidden. If you need access to view this value please contact your website administrator. This value is hidden. What languages would you like to publish? - Published Languages. + What languages would you like to save? + Published Languages + Unmodified Languages Ready to Publish? + Ready to Save? Create a new Content Template from '%0%'