From f7be5a5dec218c3ea4336174a614d26c91fdbcb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rasmus=20S=C3=B6derstr=C3=B6m?= Date: Tue, 23 Nov 2021 03:02:32 +0100 Subject: [PATCH] Add functionality for resetting to the initial state. (#11593) * Add functionality for resetting to the initial state. * Refactoing initData --- .../content/content.rights.controller.js | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) 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 2fb032d301..028f898fd5 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 @@ -11,7 +11,8 @@ vm.removedUserGroups = []; vm.viewState = "manageGroups"; vm.labels = {}; - + vm.initialState = {}; + vm.setViewSate = setViewSate; vm.editPermissions = editPermissions; vm.setPermissions = setPermissions; @@ -24,7 +25,7 @@ function onInit() { vm.loading = true; contentResource.getDetailedPermissions($scope.currentNode.id).then(function (userGroups) { - initData(userGroups); + initData(userGroups); vm.loading = false; currentForm = angularHelper.getCurrentForm($scope); }); @@ -45,6 +46,21 @@ assignGroupPermissions(group); } }); + vm.initialState = angular.copy(userGroups); + } + + function resetData() { + vm.selectedUserGroups = []; + vm.availableUserGroups = angular.copy(vm.initialState); + vm.availableUserGroups.forEach(function (group) { + if (group.permissions) { + //if there's explicit permissions assigned than it's selected + group.selected = false; + assignGroupPermissions(group); + } + }); + currentForm = angularHelper.getCurrentForm($scope); + } function setViewSate(state) { @@ -91,7 +107,7 @@ } function setPermissions(group) { - assignGroupPermissions(group); + assignGroupPermissions(group); setViewSate("manageGroups"); $scope.dialog.confirmDiscardChanges = true; } @@ -114,6 +130,7 @@ function cancelManagePermissions() { setViewSate("manageGroups"); + resetData(); } function formatSaveModel(permissionsSave, groupCollection) { @@ -146,7 +163,7 @@ //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 // we use a timeout here because in some cases the initData reformats the userGroups model and triggers a change after the form state was changed $timeout(function() {