Add functionality for resetting to the initial state. (#11593)

* Add functionality for resetting to the initial state.

* Refactoing initData
This commit is contained in:
Rasmus Söderström
2021-11-23 03:02:32 +01:00
committed by GitHub
parent 16c1359a90
commit f7be5a5dec

View File

@@ -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() {