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-05-01 19:46:50 +02:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('harbor.project')
|
|
|
|
.directive('addProject', addProject);
|
|
|
|
|
|
|
|
AddProjectController.$inject = ['AddProjectService', '$scope'];
|
|
|
|
|
|
|
|
function AddProjectController(AddProjectService, $scope) {
|
|
|
|
var vm = this;
|
2016-06-25 10:15:50 +02:00
|
|
|
|
|
|
|
$scope.p = {};
|
|
|
|
var vm0 = $scope.p;
|
|
|
|
vm0.projectName = '';
|
2016-05-01 19:46:50 +02:00
|
|
|
vm.isPublic = false;
|
|
|
|
|
|
|
|
vm.addProject = addProject;
|
|
|
|
vm.cancel = cancel;
|
2016-06-28 07:12:25 +02:00
|
|
|
|
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-06-25 10:15:50 +02:00
|
|
|
|
2016-05-14 07:34:54 +02:00
|
|
|
function addProject(p) {
|
|
|
|
if(p && angular.isDefined(p.projectName)) {
|
|
|
|
AddProjectService(p.projectName, vm.isPublic)
|
|
|
|
.success(addProjectSuccess)
|
|
|
|
.error(addProjectFailed);
|
2016-05-01 19:46:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addProjectSuccess(data, status) {
|
|
|
|
$scope.$emit('addedSuccess', true);
|
2016-06-25 10:15:50 +02:00
|
|
|
vm.hasError = false;
|
|
|
|
vm.errorMessage = '';
|
2016-06-29 09:30:13 +02:00
|
|
|
vm.isOpen = false;
|
2016-05-01 19:46:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function addProjectFailed(data, status) {
|
2016-06-17 05:58:24 +02:00
|
|
|
vm.hasError = true;
|
2016-06-25 10:15:50 +02:00
|
|
|
if(status === 400 && vm0.projectName!= '' && vm0.projectName.length < 4) {
|
|
|
|
vm.errorMessage = 'project_name_is_too_short';
|
|
|
|
}
|
|
|
|
if(status === 400 && vm0.projectName.length > 30) {
|
|
|
|
vm.errorMessage = 'project_name_is_too_long';
|
2016-06-17 05:58:24 +02:00
|
|
|
}
|
2016-06-25 10:15:50 +02:00
|
|
|
if(status === 409 && vm0.projectName != '') {
|
2016-05-14 13:28:15 +02:00
|
|
|
vm.errorMessage = 'project_already_exist';
|
|
|
|
}
|
2016-05-01 19:46:50 +02:00
|
|
|
console.log('Failed to add project:' + status);
|
|
|
|
}
|
|
|
|
|
2016-05-14 07:34:54 +02:00
|
|
|
function cancel(form){
|
|
|
|
if(form) {
|
|
|
|
form.$setPristine();
|
2016-06-25 10:15:50 +02:00
|
|
|
form.$setUntouched();
|
2016-05-14 07:34:54 +02:00
|
|
|
}
|
2016-05-01 19:46:50 +02:00
|
|
|
vm.isOpen = false;
|
2016-06-25 10:15:50 +02:00
|
|
|
vm0.projectName = '';
|
2016-05-04 12:42:05 +02:00
|
|
|
vm.isPublic = false;
|
2016-06-25 10:15:50 +02:00
|
|
|
|
2016-06-28 07:12:25 +02:00
|
|
|
vm.hasError = false; vm.close = close;
|
2016-06-25 10:15:50 +02:00
|
|
|
vm.errorMessage = '';
|
|
|
|
}
|
2016-06-28 07:12:25 +02:00
|
|
|
|
2016-06-25 10:15:50 +02:00
|
|
|
function reset() {
|
|
|
|
vm.hasError = false;
|
|
|
|
vm.errorMessage = '';
|
2016-05-01 19:46:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addProject() {
|
|
|
|
var directive = {
|
|
|
|
'restrict': 'E',
|
2016-06-16 08:10:35 +02:00
|
|
|
'templateUrl': '/static/resources/js/components/project/add-project.directive.html',
|
2016-05-01 19:46:50 +02:00
|
|
|
'controller': AddProjectController,
|
|
|
|
'scope' : {
|
|
|
|
'isOpen': '='
|
|
|
|
},
|
2016-05-14 07:34:54 +02:00
|
|
|
'link': link,
|
2016-05-01 19:46:50 +02:00
|
|
|
'controllerAs': 'vm',
|
|
|
|
'bindToController': true
|
|
|
|
};
|
|
|
|
return directive;
|
2016-05-14 07:34:54 +02:00
|
|
|
|
|
|
|
function link(scope, element, attrs, ctrl) {
|
2016-06-25 10:15:50 +02:00
|
|
|
scope.form.$setPristine();
|
|
|
|
scope.form.$setUntouched();
|
2016-05-14 07:34:54 +02:00
|
|
|
}
|
2016-05-01 19:46:50 +02:00
|
|
|
}
|
|
|
|
|
2016-06-29 09:30:13 +02:00
|
|
|
})();
|