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

82 lines
1.8 KiB
JavaScript
Raw Normal View History

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;
vm.projectName = "";
vm.isPublic = false;
2016-05-14 07:34:54 +02:00
vm.reset = reset;
2016-05-01 19:46:50 +02:00
vm.addProject = addProject;
vm.cancel = cancel;
2016-05-14 07:34:54 +02:00
vm.hasError = false;
vm.errorMessage = '';
function reset() {
vm.hasError = false;
vm.errorMessage = '';
}
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) {
2016-05-04 12:42:05 +02:00
vm.projectName = "";
2016-05-14 07:34:54 +02:00
vm.isPublic = false;
2016-05-01 19:46:50 +02:00
$scope.$emit('addedSuccess', true);
}
function addProjectFailed(data, status) {
vm.hasError = true;
if(status == 400) {
vm.errorMessage = 'project_name_is_invalid';
}
2016-05-14 07:34:54 +02:00
if(status === 409) {
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-05-01 19:46:50 +02:00
vm.isOpen = false;
2016-05-14 07:34:54 +02:00
vm.projectName = '';
2016-05-04 12:42:05 +02:00
vm.isPublic = false;
2016-05-01 19:46:50 +02:00
}
}
function addProject() {
var directive = {
'restrict': 'E',
'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-05-01 19:46:50 +02:00
}
})();