2016-07-07 18:03:32 +02:00
|
|
|
/*
|
|
|
|
Copyright (c) 2016 VMware, Inc. All Rights Reserved.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
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-06-25 10:15:50 +02:00
|
|
|
|
|
|
|
$scope.pm = {};
|
|
|
|
|
|
|
|
var pm = $scope.pm;
|
|
|
|
|
2016-04-22 18:49:52 +02:00
|
|
|
vm.roles = roles();
|
|
|
|
vm.optRole = 1;
|
2016-06-25 10:15:50 +02:00
|
|
|
|
2016-04-22 18:49:52 +02:00
|
|
|
vm.save = save;
|
|
|
|
vm.cancel = cancel;
|
2016-06-25 10:15:50 +02:00
|
|
|
vm.reset = reset;
|
|
|
|
|
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 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)
|
2016-06-25 10:15:50 +02:00
|
|
|
.error(addProjectMemberFailed);
|
2016-05-14 07:34:54 +02:00
|
|
|
}
|
2016-04-22 18:49:52 +02:00
|
|
|
}
|
|
|
|
|
2016-05-14 07:34:54 +02:00
|
|
|
function cancel(form) {
|
2016-06-25 10:15:50 +02:00
|
|
|
|
|
|
|
form.$setPristine();
|
|
|
|
form.$setUntouched();
|
|
|
|
|
2016-04-22 18:49:52 +02:00
|
|
|
vm.isOpen = false;
|
2016-06-25 10:15:50 +02:00
|
|
|
pm.username = '';
|
2016-05-04 12:42:05 +02:00
|
|
|
vm.optRole = 1;
|
2016-06-25 10:15:50 +02:00
|
|
|
|
|
|
|
vm.hasError = false;
|
|
|
|
vm.errorMessage = '';
|
2016-04-22 18:49:52 +02:00
|
|
|
}
|
2016-06-28 07:12:25 +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-06-29 09:33:28 +02:00
|
|
|
vm.isOpen = false;
|
2016-04-27 12:29:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function addProjectMemberFailed(data, status, headers) {
|
2016-06-28 17:42:05 +02:00
|
|
|
if(status === 403) {
|
|
|
|
vm.hasError = true;
|
|
|
|
vm.errorMessage = 'failed_to_add_member';
|
|
|
|
}
|
2016-07-11 12:38:51 +02:00
|
|
|
if(status === 409 && pm.username !== '') {
|
2016-05-14 07:34:54 +02:00
|
|
|
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-06-25 10:15:50 +02:00
|
|
|
function reset() {
|
|
|
|
vm.hasError = false;
|
|
|
|
vm.errorMessage = '';
|
|
|
|
}
|
|
|
|
|
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
|
|
|
},
|
2016-06-25 10:15:50 +02:00
|
|
|
'link': link,
|
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;
|
2016-06-25 10:15:50 +02:00
|
|
|
|
|
|
|
function link(scope, element, attrs, ctrl) {
|
|
|
|
scope.form.$setPristine();
|
|
|
|
scope.form.$setUntouched();
|
|
|
|
}
|
2016-04-22 18:49:52 +02:00
|
|
|
}
|
|
|
|
|
2016-06-29 09:33:28 +02:00
|
|
|
})();
|