harbor/static/resources/js/layout/project/project.controller.js

83 lines
1.9 KiB
JavaScript
Raw Normal View History

2016-05-01 19:46:50 +02:00
(function() {
'use strict';
angular
.module('harbor.layout.project')
.controller('ProjectController', ProjectController);
ProjectController.$inject = ['$scope', 'ListProjectService', '$timeout', 'currentUser', 'getRole'];
2016-05-01 19:46:50 +02:00
function ProjectController($scope, ListProjectService, $timeout, currentUser, getRole) {
2016-05-02 12:24:58 +02:00
var vm = this;
2016-06-25 21:12:17 +02:00
2016-05-01 19:46:50 +02:00
vm.isOpen = false;
vm.projectName = '';
vm.publicity = 0;
2016-05-04 12:42:05 +02:00
vm.retrieve = retrieve;
vm.showAddProject = showAddProject;
vm.searchProject = searchProject;
2016-05-02 12:24:58 +02:00
vm.showAddButton = showAddButton;
vm.togglePublicity = togglePublicity;
vm.user = currentUser.get();
vm.retrieve();
2016-06-06 09:39:17 +02:00
vm.getProjectRole = getProjectRole;
function retrieve() {
ListProjectService(vm.projectName, vm.publicity)
.success(listProjectSuccess)
.error(listProjectFailed);
}
function listProjectSuccess(data, status) {
vm.projects = data || [];
2016-06-06 09:39:17 +02:00
}
function getProjectRole(roleId) {
if(roleId !== 0) {
var role = getRole({'key': 'roleId', 'value': roleId});
return role.name;
}
return '';
}
function listProjectFailed(e) {
console.log('Failed to list Project:' + e);
}
2016-05-01 19:46:50 +02:00
$scope.$on('addedSuccess', function(e, val) {
vm.retrieve();
2016-05-01 19:46:50 +02:00
});
function showAddProject() {
if(vm.isOpen){
2016-06-25 21:12:17 +02:00
vm.isOpen = false;
2016-05-01 19:46:50 +02:00
}else{
2016-06-25 21:12:17 +02:00
vm.isOpen = true;
2016-05-01 19:46:50 +02:00
}
}
function searchProject() {
vm.retrieve();
2016-05-01 19:46:50 +02:00
}
2016-05-02 12:24:58 +02:00
function showAddButton() {
2016-05-23 12:29:17 +02:00
if(vm.publicity === 0) {
2016-05-02 12:24:58 +02:00
return true;
}else{
return false;
}
}
function togglePublicity(e) {
vm.publicity = e.publicity;
2016-05-14 07:34:54 +02:00
vm.isOpen = false;
vm.retrieve();
console.log('vm.publicity:' + vm.publicity);
2016-05-02 12:24:58 +02:00
}
2016-05-01 19:46:50 +02:00
}
})();