##// END OF EJS Templates
Added tag 0.9.1 for changeset feca18f6ff09
Added tag 0.9.1 for changeset feca18f6ff09

File last commit:

r85:d384ac58
r109:5b6ca9a3
Show More
admin-groups-create-view.js
147 lines | 5.1 KiB | application/javascript | JavascriptLexer
project: initial commit
r0 // # Copyright (C) 2010-2016 RhodeCode GmbH
// #
// # This program is free software: you can redistribute it and/or modify
// # it under the terms of the GNU Affero General Public License, version 3
// # (only), as published by the Free Software Foundation.
// #
// # This program is distributed in the hope that it will be useful,
// # but WITHOUT ANY WARRANTY; without even the implied warranty of
// # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// # GNU General Public License for more details.
// #
// # You should have received a copy of the GNU Affero General Public License
// # along with this program. If not, see <http://www.gnu.org/licenses/>.
// #
// # This program is dual-licensed. If you wish to learn more about the
refactor: fix inconsistent naming
r28 // # AppEnlight Enterprise Edition, including its added features, Support
project: initial commit
r0 // # services, and proprietary license terms, please see
// # https://rhodecode.com/licenses/
components: admin panel componentized
r85 angular.module('appenlight.components.adminGroupsCreateView', [])
.component('adminGroupsCreateView', {
templateUrl: 'components/views/admin-groups-create-view/admin-groups-create-view.html',
controller: AdminGroupsCreateViewController
});
project: initial commit
r0
components: admin panel componentized
r85 AdminGroupsCreateViewController.$inject = ['$state', 'groupsResource', 'groupsPropertyResource', 'sectionViewResource'];
project: initial commit
r0
components: admin panel componentized
r85 function AdminGroupsCreateViewController($state, groupsResource, groupsPropertyResource, sectionViewResource) {
project: initial commit
r0 console.debug('AdminGroupsCreateController');
var vm = this;
components: admin panel componentized
r85 vm.$state = $state;
project: initial commit
r0 vm.loading = {
group: false,
resource_permissions: false,
users: false
};
vm.form = {
autocompleteUser: '',
}
if (typeof $state.params.groupId !== 'undefined') {
vm.loading.group = true;
var groupId = $state.params.groupId;
vm.group = groupsResource.get({groupId: groupId}, function (data) {
vm.loading.group = false;
});
vm.resource_permissions = groupsPropertyResource.query(
{groupId: groupId, key: 'resource_permissions'}, function (data) {
vm.loading.resource_permissions = false;
var tmpObj = {
'group': {
'application': {},
'dashboard': {}
}
};
_.each(data, function (item) {
console.log(item);
var section = tmpObj[item.type][item.resource_type];
if (typeof section[item.resource_id] == 'undefined') {
section[item.resource_id] = {
self: item,
permissions: []
}
}
section[item.resource_id].permissions.push(item.perm_name);
});
console.log(tmpObj)
vm.resourcePermissions = tmpObj;
});
vm.users = groupsPropertyResource.query(
{groupId: groupId, key: 'users'}, function (data) {
vm.loading.users = false;
}, function () {
vm.loading.users = false;
});
}
else {
var groupId = null;
}
var formResponse = function (response) {
if (response.status === 422) {
setServerValidation(vm.groupForm, response.data);
}
vm.loading.group = false;
};
vm.createGroup = function () {
vm.loading.group = true;
if (groupId) {
groupsResource.update({groupId: vm.group.id}, vm.group, function (data) {
setServerValidation(vm.groupForm);
vm.loading.group = false;
}, formResponse);
}
else {
groupsResource.save(vm.group, function (data) {
$state.go('admin.group.update', {groupId: data.id});
}, formResponse);
}
};
vm.removeUser = function (user) {
groupsPropertyResource.delete(
{groupId: groupId, key: 'users', user_name: user.user_name},
function (data) {
vm.loading.users = false;
vm.users = _.filter(vm.users, function (item) {
return item != user;
});
}, function () {
vm.loading.users = false;
});
};
vm.addUser = function () {
groupsPropertyResource.save(
{groupId: groupId, key: 'users'},
{user_name: vm.form.autocompleteUser},
function (data) {
vm.loading.users = false;
vm.users.push(data);
vm.form.autocompleteUser = '';
}, function () {
vm.loading.users = false;
});
}
vm.searchUsers = function (searchPhrase) {
console.log(searchPhrase);
return sectionViewResource.query({
section: 'users_section',
view: 'search_users',
'user_name': searchPhrase
}).$promise.then(function (data) {
return _.map(data, function (item) {
return item.user;
});
});
}
};