harbor/static/resources/js/components/project-member/add-project-member.directive.js

82 lines
2.0 KiB
JavaScript
Raw Normal View History

(function() {
'use strict';
angular
.module('harbor.project.member')
.directive('addProjectMember', addProjectMember);
AddProjectMemberController.$inject = ['$scope', 'roles', 'AddProjectMemberService'];
function AddProjectMemberController($scope, roles, AddProjectMemberService) {
var vm = this;
vm.username = '';
vm.roles = roles();
vm.optRole = 1;
2016-05-14 07:34:54 +02:00
vm.reset = reset;
vm.save = save;
vm.cancel = cancel;
2016-05-14 07:34:54 +02:00
vm.hasError = false;
vm.errorMessage = '';
2016-05-14 07:34:54 +02:00
function reset() {
vm.hasError = false;
vm.errorMessage = '';
}
function save(pm) {
if(pm && angular.isDefined(pm.username)) {
AddProjectMemberService(vm.projectId, vm.optRole, pm.username)
2016-05-14 07:34:54 +02:00
.success(addProjectMemberComplete)
.error(addProjectMemberFailed);
}
}
2016-05-14 07:34:54 +02:00
function cancel(form) {
if(form) {
form.$setPristine();
}
vm.isOpen = false;
vm.username = '';
2016-05-04 12:42:05 +02:00
vm.optRole = 1;
}
2016-04-27 12:29:55 +02:00
function addProjectMemberComplete(data, status, header) {
console.log('addProjectMemberComplete: status:' + status + ', data:' + data);
vm.reload();
2016-04-27 12:29:55 +02:00
}
function addProjectMemberFailed(data, status, headers) {
2016-05-14 07:34:54 +02:00
if(status === 409) {
vm.hasError = true;
vm.errorMessage = 'username_already_exist';
}
2016-05-23 12:29:17 +02:00
if(status === 404) {
2016-05-14 07:34:54 +02:00
vm.hasError = true;
vm.errorMessage = 'username_does_not_exist';
}
2016-04-27 12:29:55 +02:00
console.log('addProjectMemberFailed: status:' + status + ', data:' + data);
}
}
function addProjectMember() {
var directive = {
'restrict': 'E',
'templateUrl': '/static/resources/js/components/project-member/add-project-member.directive.html',
'scope': {
'projectId': '@',
2016-04-28 19:36:39 +02:00
'isOpen': '=',
'reload': '&'
},
'controller': AddProjectMemberController,
'controllerAs': 'vm',
'bindToController': true
2016-05-23 12:29:17 +02:00
};
return directive;
}
})();