Wires up saving the user group
This commit is contained in:
@@ -174,6 +174,23 @@
|
||||
"Failed to save user");
|
||||
}
|
||||
|
||||
function saveUserGroup(userGroup) {
|
||||
if (!userGroup) {
|
||||
throw "userGroup not specified";
|
||||
}
|
||||
|
||||
//need to convert the user data into the correctly formatted save data - it is *not* the same and we don't want to over-post
|
||||
var formattedSaveData = umbDataFormatter.formatUserGroupPostData(userGroup);
|
||||
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.post(
|
||||
umbRequestHelper.getApiUrl(
|
||||
"userApiBaseUrl",
|
||||
"PostSaveUserGroup"),
|
||||
formattedSaveData),
|
||||
"Failed to save user group");
|
||||
}
|
||||
|
||||
function getUserGroup(id) {
|
||||
|
||||
return umbRequestHelper.resourcePromise(
|
||||
@@ -203,6 +220,7 @@
|
||||
createUser: createUser,
|
||||
inviteUser: inviteUser,
|
||||
saveUser: saveUser,
|
||||
saveUserGroup: saveUserGroup,
|
||||
getUserGroup: getUserGroup,
|
||||
getUserGroups: getUserGroups,
|
||||
clearAvatar: clearAvatar,
|
||||
|
||||
@@ -652,14 +652,14 @@ function umbDataFormatter() {
|
||||
},
|
||||
|
||||
/** formats the display model used to display the user to the model used to save the user */
|
||||
formatUserPostData: function (displayModel, preValues, action) {
|
||||
formatUserPostData: function (displayModel) {
|
||||
|
||||
//create the save model from the display model
|
||||
var saveModel = _.pick(displayModel, 'id', 'parentId', 'name', 'username', 'culture', 'email', 'startContentIds', 'startMediaIds', 'userGroups', 'message');
|
||||
|
||||
var saveModel = _.pick(displayModel, 'id', 'parentId', 'name', 'username', 'culture', 'email', 'startContentIds', 'startMediaIds', 'userGroups', 'message');
|
||||
|
||||
//make sure the userGroups are just a string array
|
||||
var currGroups = saveModel.userGroups;
|
||||
var formattedGroups = [];
|
||||
var formattedGroups = [];
|
||||
for (var i = 0; i < currGroups.length; i++) {
|
||||
if (!angular.isString(currGroups[i])) {
|
||||
formattedGroups.push(currGroups[i].alias);
|
||||
@@ -671,7 +671,7 @@ function umbDataFormatter() {
|
||||
saveModel.userGroups = formattedGroups;
|
||||
|
||||
//make sure the startnodes are just a string array
|
||||
var props = ["startContentIds", "startMediaIds"];
|
||||
var props = ["startContentIds", "startMediaIds"];
|
||||
for (var m = 0; m < props.length; m++) {
|
||||
var startIds = saveModel[props[m]];
|
||||
if (!startIds) {
|
||||
@@ -682,6 +682,59 @@ function umbDataFormatter() {
|
||||
formattedIds.push(startIds[j].id);
|
||||
}
|
||||
saveModel[props[m]] = formattedIds;
|
||||
}
|
||||
|
||||
return saveModel;
|
||||
},
|
||||
|
||||
/** formats the display model used to display the user group to the model used to save the user group*/
|
||||
formatUserGroupPostData: function (displayModel) {
|
||||
|
||||
//create the save model from the display model
|
||||
var saveModel = _.pick(displayModel, 'id', 'alias', 'name', 'sections', 'users', 'startContentId', 'startMediaId');
|
||||
|
||||
//make sure the sections are just a string array
|
||||
var currSections = saveModel.sections;
|
||||
var formattedSections = [];
|
||||
for (var i = 0; i < currSections.length; i++) {
|
||||
if (!angular.isString(currSections[i])) {
|
||||
formattedSections.push(currSections[i].alias);
|
||||
}
|
||||
else {
|
||||
formattedSections.push(currSections[i]);
|
||||
}
|
||||
}
|
||||
saveModel.sections = formattedSections;
|
||||
|
||||
//make sure the user are just an int array
|
||||
var currUsers = saveModel.users;
|
||||
var formattedUsers = [];
|
||||
for (var j = 0; j < currUsers.length; j++) {
|
||||
if (!angular.isNumber(currUsers[j])) {
|
||||
formattedUsers.push(currUsers[j].id);
|
||||
}
|
||||
else {
|
||||
formattedUsers.push(currUsers[j]);
|
||||
}
|
||||
}
|
||||
saveModel.users = formattedUsers;
|
||||
|
||||
//make sure the startnodes are just an int
|
||||
var props = ["startContentId", "startMediaId"];
|
||||
for (var m = 0; m < props.length; m++) {
|
||||
var startId = saveModel[props[m]];
|
||||
if (!startId) {
|
||||
continue;
|
||||
}
|
||||
saveModel[props[m]] = startId.id;
|
||||
}
|
||||
|
||||
saveModel.parentId = -1;
|
||||
if (!saveModel.startContentId) {
|
||||
saveModel.startContentId = -1;
|
||||
}
|
||||
if (!saveModel.startMediaId) {
|
||||
saveModel.startMediaId = -1;
|
||||
}
|
||||
|
||||
return saveModel;
|
||||
|
||||
@@ -1,189 +1,218 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
"use strict";
|
||||
|
||||
function UserGroupEditController($scope, $timeout, $location, $routeParams, usersResource, localizationService) {
|
||||
function UserGroupEditController($scope, $timeout, $location, $routeParams, usersResource, localizationService, contentEditingHelper) {
|
||||
|
||||
var vm = this;
|
||||
var vm = this;
|
||||
var localizeSaving = localizationService.localize("general_saving");
|
||||
|
||||
vm.page = {};
|
||||
vm.userGroup = {};
|
||||
vm.labels = {};
|
||||
vm.page = {};
|
||||
vm.userGroup = {};
|
||||
vm.labels = {};
|
||||
|
||||
vm.goToPage = goToPage;
|
||||
vm.openSectionPicker = openSectionPicker;
|
||||
vm.openContentPicker = openContentPicker;
|
||||
vm.openMediaPicker = openMediaPicker;
|
||||
vm.openUserPicker = openUserPicker;
|
||||
vm.removeSelectedItem = removeSelectedItem;
|
||||
vm.clearStartNode = clearStartNode;
|
||||
vm.getUserStateType = getUserStateType;
|
||||
vm.goToPage = goToPage;
|
||||
vm.openSectionPicker = openSectionPicker;
|
||||
vm.openContentPicker = openContentPicker;
|
||||
vm.openMediaPicker = openMediaPicker;
|
||||
vm.openUserPicker = openUserPicker;
|
||||
vm.removeSelectedItem = removeSelectedItem;
|
||||
vm.clearStartNode = clearStartNode;
|
||||
vm.getUserStateType = getUserStateType;
|
||||
vm.save = save;
|
||||
|
||||
function init() {
|
||||
|
||||
function init() {
|
||||
vm.loading = true;
|
||||
|
||||
vm.loading = true;
|
||||
localizationService.localize("general_cancel").then(function (name) {
|
||||
vm.labels.cancel = name;
|
||||
});
|
||||
|
||||
localizationService.localize("general_cancel").then(function(name){
|
||||
vm.labels.cancel = name;
|
||||
});
|
||||
|
||||
if ($routeParams.create) {
|
||||
// get user group scaffold
|
||||
usersResource.getUserGroupScaffold().then(function (userGroup) {
|
||||
vm.userGroup = userGroup;
|
||||
setSectionIcon(vm.userGroup.sections);
|
||||
makeBreadcrumbs();
|
||||
vm.loading = false;
|
||||
});
|
||||
} else {
|
||||
// get user group
|
||||
usersResource.getUserGroup($routeParams.id).then(function (userGroup) {
|
||||
vm.userGroup = userGroup;
|
||||
setSectionIcon(vm.userGroup.sections);
|
||||
makeBreadcrumbs();
|
||||
vm.loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function goToPage(ancestor) {
|
||||
$location.path(ancestor.path).search("subview", ancestor.subView);
|
||||
}
|
||||
|
||||
function openSectionPicker() {
|
||||
vm.sectionPicker = {
|
||||
title: "Select sections",
|
||||
view: "sectionpicker",
|
||||
selection: vm.userGroup.sections,
|
||||
closeButtonLabel: vm.labels.cancel,
|
||||
show: true,
|
||||
submit: function(model) {
|
||||
vm.sectionPicker.show = false;
|
||||
vm.sectionPicker = null;
|
||||
},
|
||||
close: function(oldModel) {
|
||||
if(oldModel.selection) {
|
||||
vm.userGroup.sections = oldModel.selection;
|
||||
}
|
||||
vm.sectionPicker.show = false;
|
||||
vm.sectionPicker = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function openContentPicker() {
|
||||
vm.contentPicker = {
|
||||
title: "Select content start node",
|
||||
view: "contentpicker",
|
||||
hideSubmitButton: true,
|
||||
show: true,
|
||||
submit: function(model) {
|
||||
if(model.selection) {
|
||||
vm.userGroup.startContentId = model.selection[0];
|
||||
}
|
||||
vm.contentPicker.show = false;
|
||||
vm.contentPicker = null;
|
||||
},
|
||||
close: function(oldModel) {
|
||||
vm.contentPicker.show = false;
|
||||
vm.contentPicker = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function openMediaPicker() {
|
||||
vm.contentPicker = {
|
||||
title: "Select media start node",
|
||||
view: "treepicker",
|
||||
section: "media",
|
||||
treeAlias: "media",
|
||||
entityType: "media",
|
||||
hideSubmitButton: true,
|
||||
show: true,
|
||||
submit: function(model) {
|
||||
if(model.selection) {
|
||||
vm.userGroup.startMediaId = model.selection[0];
|
||||
}
|
||||
vm.contentPicker.show = false;
|
||||
vm.contentPicker = null;
|
||||
},
|
||||
close: function(oldModel) {
|
||||
vm.contentPicker.show = false;
|
||||
vm.contentPicker = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function openUserPicker() {
|
||||
vm.userPicker = {
|
||||
title: "Select users",
|
||||
view: "userpicker",
|
||||
selection: vm.userGroup.users,
|
||||
show: true,
|
||||
submit: function(model) {
|
||||
/*
|
||||
if(model.selection) {
|
||||
vm.userGroup.startNodesMedia = model.selection;
|
||||
}
|
||||
*/
|
||||
vm.userPicker.show = false;
|
||||
vm.userPicker = null;
|
||||
},
|
||||
close: function(oldModel) {
|
||||
vm.userPicker.show = false;
|
||||
vm.userPicker = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function removeSelectedItem(index, selection) {
|
||||
if(selection && selection.length > 0) {
|
||||
selection.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
function clearStartNode(type) {
|
||||
if (type === "content") {
|
||||
vm.userGroup.startContentId = null;
|
||||
} else if (type === "media") {
|
||||
vm.userGroup.startMediaId = null;
|
||||
}
|
||||
}
|
||||
|
||||
function getUserStateType(state) {
|
||||
switch (state) {
|
||||
case "disabled" || "umbracoDisabled":
|
||||
return "danger";
|
||||
case "pending":
|
||||
return "warning";
|
||||
default:
|
||||
return "success";
|
||||
}
|
||||
}
|
||||
|
||||
function makeBreadcrumbs() {
|
||||
vm.breadcrumbs = [
|
||||
{
|
||||
"name": "Groups",
|
||||
"path": "/users/users/overview",
|
||||
"subView": "groups"
|
||||
},
|
||||
{
|
||||
"name": vm.userGroup.name
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
function setSectionIcon(sections) {
|
||||
angular.forEach(sections, function(section) {
|
||||
section.icon = "icon-section " + section.cssclass;
|
||||
});
|
||||
}
|
||||
|
||||
init();
|
||||
if ($routeParams.create) {
|
||||
// get user group scaffold
|
||||
usersResource.getUserGroupScaffold().then(function (userGroup) {
|
||||
vm.userGroup = userGroup;
|
||||
setSectionIcon(vm.userGroup.sections);
|
||||
makeBreadcrumbs();
|
||||
vm.loading = false;
|
||||
});
|
||||
} else {
|
||||
// get user group
|
||||
usersResource.getUserGroup($routeParams.id).then(function (userGroup) {
|
||||
vm.userGroup = userGroup;
|
||||
setSectionIcon(vm.userGroup.sections);
|
||||
makeBreadcrumbs();
|
||||
vm.loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
angular.module("umbraco").controller("Umbraco.Editors.Users.GroupController", UserGroupEditController);
|
||||
function save() {
|
||||
vm.page.saveButtonState = "busy";
|
||||
|
||||
contentEditingHelper.contentEditorPerformSave({
|
||||
statusMessage: localizeSaving,
|
||||
saveMethod: usersResource.saveUserGroup,
|
||||
scope: $scope,
|
||||
content: vm.userGroup,
|
||||
// We do not redirect on failure for users - this is because it is not possible to actually save a user
|
||||
// when server side validation fails - as opposed to content where we are capable of saving the content
|
||||
// item if server side validation fails
|
||||
redirectOnFailure: false,
|
||||
rebindCallback: function (orignal, saved) { }
|
||||
}).then(function (saved) {
|
||||
|
||||
vm.userGroup = saved;
|
||||
setSectionIcon(vm.userGroup.sections);
|
||||
makeBreadcrumbs();
|
||||
vm.page.saveButtonState = "success";
|
||||
|
||||
}, function (err) {
|
||||
|
||||
vm.page.saveButtonState = "error";
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function goToPage(ancestor) {
|
||||
$location.path(ancestor.path).search("subview", ancestor.subView);
|
||||
}
|
||||
|
||||
function openSectionPicker() {
|
||||
vm.sectionPicker = {
|
||||
title: "Select sections",
|
||||
view: "sectionpicker",
|
||||
selection: vm.userGroup.sections,
|
||||
closeButtonLabel: vm.labels.cancel,
|
||||
show: true,
|
||||
submit: function (model) {
|
||||
vm.sectionPicker.show = false;
|
||||
vm.sectionPicker = null;
|
||||
},
|
||||
close: function (oldModel) {
|
||||
if (oldModel.selection) {
|
||||
vm.userGroup.sections = oldModel.selection;
|
||||
}
|
||||
vm.sectionPicker.show = false;
|
||||
vm.sectionPicker = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function openContentPicker() {
|
||||
vm.contentPicker = {
|
||||
title: "Select content start node",
|
||||
view: "contentpicker",
|
||||
hideSubmitButton: true,
|
||||
show: true,
|
||||
submit: function (model) {
|
||||
if (model.selection) {
|
||||
vm.userGroup.startContentId = model.selection[0];
|
||||
}
|
||||
vm.contentPicker.show = false;
|
||||
vm.contentPicker = null;
|
||||
},
|
||||
close: function (oldModel) {
|
||||
vm.contentPicker.show = false;
|
||||
vm.contentPicker = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function openMediaPicker() {
|
||||
vm.contentPicker = {
|
||||
title: "Select media start node",
|
||||
view: "treepicker",
|
||||
section: "media",
|
||||
treeAlias: "media",
|
||||
entityType: "media",
|
||||
hideSubmitButton: true,
|
||||
show: true,
|
||||
submit: function (model) {
|
||||
if (model.selection) {
|
||||
vm.userGroup.startMediaId = model.selection[0];
|
||||
}
|
||||
vm.contentPicker.show = false;
|
||||
vm.contentPicker = null;
|
||||
},
|
||||
close: function (oldModel) {
|
||||
vm.contentPicker.show = false;
|
||||
vm.contentPicker = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function openUserPicker() {
|
||||
vm.userPicker = {
|
||||
title: "Select users",
|
||||
view: "userpicker",
|
||||
selection: vm.userGroup.users,
|
||||
show: true,
|
||||
submit: function (model) {
|
||||
/*
|
||||
if(model.selection) {
|
||||
vm.userGroup.startNodesMedia = model.selection;
|
||||
}
|
||||
*/
|
||||
vm.userPicker.show = false;
|
||||
vm.userPicker = null;
|
||||
},
|
||||
close: function (oldModel) {
|
||||
vm.userPicker.show = false;
|
||||
vm.userPicker = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function removeSelectedItem(index, selection) {
|
||||
if (selection && selection.length > 0) {
|
||||
selection.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
function clearStartNode(type) {
|
||||
if (type === "content") {
|
||||
vm.userGroup.startContentId = null;
|
||||
} else if (type === "media") {
|
||||
vm.userGroup.startMediaId = null;
|
||||
}
|
||||
}
|
||||
|
||||
function getUserStateType(state) {
|
||||
switch (state) {
|
||||
case "disabled" || "umbracoDisabled":
|
||||
return "danger";
|
||||
case "pending":
|
||||
return "warning";
|
||||
default:
|
||||
return "success";
|
||||
}
|
||||
}
|
||||
|
||||
function makeBreadcrumbs() {
|
||||
vm.breadcrumbs = [
|
||||
{
|
||||
"name": "Groups",
|
||||
"path": "/users/users/overview",
|
||||
"subView": "groups"
|
||||
},
|
||||
{
|
||||
"name": vm.userGroup.name
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
function setSectionIcon(sections) {
|
||||
angular.forEach(sections, function (section) {
|
||||
section.icon = "icon-section " + section.cssclass;
|
||||
});
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
}
|
||||
|
||||
angular.module("umbraco").controller("Umbraco.Editors.Users.GroupController", UserGroupEditController);
|
||||
|
||||
})();
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
<umb-editor-header
|
||||
name="vm.userGroup.name"
|
||||
alias="vm.userGroup.alias"
|
||||
icon="vm.userGroup.icon"
|
||||
hide-description="true"
|
||||
hide-alias="true">
|
||||
hide-description="true">
|
||||
</umb-editor-header>
|
||||
|
||||
<umb-editor-container>
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
}
|
||||
|
||||
function goToUserGroup(userGroup) {
|
||||
$location.path('users/users/group/' + userGroup.id);
|
||||
$location.path('users/users/group/' + userGroup.id).search("create", null);
|
||||
}
|
||||
|
||||
onInit();
|
||||
|
||||
Reference in New Issue
Block a user