2016-04-22 18:49:52 +02:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('harbor.project.member')
|
|
|
|
.directive('addProjectMember', addProjectMember);
|
|
|
|
|
2016-05-10 12:43:52 +02:00
|
|
|
AddProjectMemberController.$inject = ['$scope', 'roles', 'AddProjectMemberService'];
|
2016-04-22 18:49:52 +02:00
|
|
|
|
2016-05-10 12:43:52 +02:00
|
|
|
function AddProjectMemberController($scope, roles, AddProjectMemberService) {
|
2016-04-22 18:49:52 +02:00
|
|
|
var vm = this;
|
2016-05-14 19:43:05 +02:00
|
|
|
vm.username = '';
|
2016-04-22 18:49:52 +02:00
|
|
|
vm.roles = roles();
|
|
|
|
vm.optRole = 1;
|
2016-05-14 07:34:54 +02:00
|
|
|
|
|
|
|
vm.reset = reset;
|
2016-04-22 18:49:52 +02:00
|
|
|
vm.save = save;
|
|
|
|
vm.cancel = cancel;
|
2016-05-14 07:34:54 +02:00
|
|
|
|
|
|
|
vm.hasError = false;
|
|
|
|
vm.errorMessage = '';
|
2016-04-22 18:49:52 +02:00
|
|
|
|
2016-05-14 07:34:54 +02:00
|
|
|
function reset() {
|
|
|
|
vm.hasError = false;
|
|
|
|
vm.errorMessage = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
function save(pm) {
|
|
|
|
if(pm && angular.isDefined(pm.username)) {
|
2016-05-14 13:28:15 +02:00
|
|
|
AddProjectMemberService(vm.projectId, vm.optRole, pm.username)
|
2016-05-14 07:34:54 +02:00
|
|
|
.success(addProjectMemberComplete)
|
|
|
|
.error(addProjectMemberFailed);
|
|
|
|
}
|
2016-04-22 18:49:52 +02:00
|
|
|
}
|
|
|
|
|
2016-05-14 07:34:54 +02:00
|
|
|
function cancel(form) {
|
|
|
|
if(form) {
|
|
|
|
form.$setPristine();
|
|
|
|
}
|
2016-04-22 18:49:52 +02:00
|
|
|
vm.isOpen = false;
|
2016-05-14 19:43:05 +02:00
|
|
|
vm.username = '';
|
2016-05-04 12:42:05 +02:00
|
|
|
vm.optRole = 1;
|
2016-04-22 18:49:52 +02:00
|
|
|
}
|
|
|
|
|
2016-04-27 12:29:55 +02:00
|
|
|
function addProjectMemberComplete(data, status, header) {
|
|
|
|
console.log('addProjectMemberComplete: status:' + status + ', data:' + data);
|
2016-05-25 06:13:07 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-04-22 18:49:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function addProjectMember() {
|
|
|
|
var directive = {
|
|
|
|
'restrict': 'E',
|
2016-06-16 08:10:35 +02:00
|
|
|
'templateUrl': '/static/resources/js/components/project-member/add-project-member.directive.html',
|
2016-04-22 18:49:52 +02:00
|
|
|
'scope': {
|
2016-05-10 12:43:52 +02:00
|
|
|
'projectId': '@',
|
2016-04-28 19:36:39 +02:00
|
|
|
'isOpen': '=',
|
|
|
|
'reload': '&'
|
2016-04-22 18:49:52 +02:00
|
|
|
},
|
|
|
|
'controller': AddProjectMemberController,
|
|
|
|
'controllerAs': 'vm',
|
|
|
|
'bindToController': true
|
2016-05-23 12:29:17 +02:00
|
|
|
};
|
|
|
|
|
2016-04-22 18:49:52 +02:00
|
|
|
return directive;
|
|
|
|
}
|
|
|
|
|
|
|
|
})();
|