2016-05-12 12:30:01 +02:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('harbor.user')
|
|
|
|
.directive('toggleAdmin', toggleAdmin);
|
|
|
|
|
|
|
|
ToggleAdminController.$inject = ['$scope', 'ToggleAdminService'];
|
|
|
|
|
|
|
|
function ToggleAdminController($scope, ToggleAdminService) {
|
|
|
|
var vm = this;
|
|
|
|
|
2016-05-31 12:49:16 +02:00
|
|
|
vm.isAdmin = (vm.hasAdminRole == 1) ? true : false;
|
2016-06-17 09:22:58 +02:00
|
|
|
vm.enabled = vm.isAdmin ? 0 : 1;
|
2016-05-12 12:30:01 +02:00
|
|
|
vm.toggle = toggle;
|
|
|
|
|
|
|
|
function toggle() {
|
2016-06-17 09:22:58 +02:00
|
|
|
ToggleAdminService(vm.userId, vm.enabled)
|
2016-05-12 12:30:01 +02:00
|
|
|
.success(toggleAdminSuccess)
|
|
|
|
.error(toggleAdminFailed);
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleAdminSuccess(data, status) {
|
|
|
|
if(vm.isAdmin) {
|
|
|
|
vm.isAdmin = false;
|
|
|
|
}else{
|
|
|
|
vm.isAdmin = true;
|
|
|
|
}
|
|
|
|
console.log('Toggled userId:' + vm.userId + ' to admin:' + vm.isAdmin);
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleAdminFailed(data, status) {
|
|
|
|
console.log('Failed toggle admin:' + data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleAdmin() {
|
|
|
|
var directive = {
|
|
|
|
'restrict': 'E',
|
2016-06-16 08:10:35 +02:00
|
|
|
'templateUrl': '/static/resources/js/components/user/toggle-admin.directive.html',
|
2016-05-12 12:30:01 +02:00
|
|
|
'scope': {
|
|
|
|
'hasAdminRole': '=',
|
|
|
|
'userId': '@'
|
|
|
|
},
|
|
|
|
'link': link,
|
|
|
|
'controller': ToggleAdminController,
|
|
|
|
'controllerAs': 'vm',
|
|
|
|
'bindToController': true
|
|
|
|
};
|
|
|
|
return directive;
|
|
|
|
|
|
|
|
function link(scope, element, attrs, ctrl) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
})();
|