From cb4de2a6a1817af7c9f265073560c3f0b3ee1eff Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Thu, 24 Aug 2017 15:00:11 +0200 Subject: [PATCH] Add discard changes notification to rights/permissions dialog --- .../umbsetdirtyonchange.directive.js | 21 +++- .../content/content.rights.controller.js | 30 ++++- .../src/views/content/rights.html | 110 +++++++++++------- 3 files changed, 111 insertions(+), 50 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/validation/umbsetdirtyonchange.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/validation/umbsetdirtyonchange.directive.js index 37a773ae97..0c2339dd5c 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/validation/umbsetdirtyonchange.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/validation/umbsetdirtyonchange.directive.js @@ -5,13 +5,22 @@ function link(scope, el, attr, ctrl) { - var initValue = attr.umbSetDirtyOnChange; - - attr.$observe("umbSetDirtyOnChange", function (newValue) { - if(newValue !== initValue) { + if(attr.ngModel) { + scope.$watch(attr.ngModel, function(newValue, oldValue) { + if (!newValue) {return;} + if (newValue === oldValue) {return;} ctrl.$setDirty(); - } - }); + }, true); + + } else { + var initValue = attr.umbSetDirtyOnChange; + + attr.$observe("umbSetDirtyOnChange", function (newValue) { + if(newValue !== initValue) { + ctrl.$setDirty(); + } + }); + } } diff --git a/src/Umbraco.Web.UI.Client/src/views/content/content.rights.controller.js b/src/Umbraco.Web.UI.Client/src/views/content/content.rights.controller.js index 2fc0fe39d1..f8eea10c0b 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/content.rights.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/content/content.rights.controller.js @@ -1,29 +1,35 @@ (function () { "use strict"; - function ContentRightsController($scope, contentResource, localizationService) { + function ContentRightsController($scope, contentResource, localizationService, angularHelper) { var vm = this; + var currentForm; vm.availableUserGroups = []; vm.selectedUserGroups = []; vm.removedUserGroups = []; vm.viewState = "manageGroups"; vm.labels = {}; - + vm.showNotification = false; + vm.setViewSate = setViewSate; vm.editPermissions = editPermissions; vm.setPermissions = setPermissions; vm.save = save; vm.removePermissions = removePermissions; vm.cancelManagePermissions = cancelManagePermissions; + vm.closeDialog = closeDialog; + vm.stay = stay; function onInit() { vm.loading = true; contentResource.getDetailedPermissions($scope.currentNode.id).then(function (userGroups) { initData(userGroups); vm.loading = false; + currentForm = angularHelper.getCurrentForm($scope); }); + } /** @@ -139,6 +145,11 @@ //re-assign model from server since it could have changed initData(userGroups); + // clear dirty state on the form so we don't see the discard changes notification + if(currentForm) { + currentForm.$dirty = false; + } + vm.saveState = "success"; vm.saveSuccces = true; }, function(error){ @@ -147,6 +158,21 @@ }); } + function stay() { + vm.showNotification = false; + } + + function closeDialog() { + + // check if form has been changed. If it has show discard changes notification + if (currentForm && currentForm.$dirty) { + vm.showNotification = true; + } else { + $scope.nav.hideDialog(); + } + + } + onInit(); } diff --git a/src/Umbraco.Web.UI.Client/src/views/content/rights.html b/src/Umbraco.Web.UI.Client/src/views/content/rights.html index c83054212f..faec86571f 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/rights.html +++ b/src/Umbraco.Web.UI.Client/src/views/content/rights.html @@ -3,64 +3,90 @@
-
-
-
-
{{vm.saveError.errorMsg}}
-
{{vm.saveError.data.message}}
+ + +
+ +
+ +
+
+
{{vm.saveError.errorMsg}}
+
{{vm.saveError.data.message}}
+
-
-
-
- {{currentNode.name}} +
+
+ {{currentNode.name}} +
-
-
Set permissions for {{ currentNode.name }}
-

+
Set permissions for {{ currentNode.name }}
+

- -
- - -
+
+ + +
+ +
+
+

You have unsaved changes

+

Are you sure you want to navigate away from this dialog? - you have unsaved changes

+ + + + +
+
+ +
+