mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-03 23:54:00 +01:00
78 lines
1.7 KiB
JavaScript
78 lines
1.7 KiB
JavaScript
|
(function() {
|
||
|
|
||
|
'use strict';
|
||
|
|
||
|
angular
|
||
|
.module('harbor.project')
|
||
|
.directive('publicityButton', publicityButton);
|
||
|
|
||
|
PublicityButtonController.$inject = ['EditProjectService'];
|
||
|
|
||
|
function PublicityButtonController(EditProjectService) {
|
||
|
var vm = this;
|
||
|
vm.toggle = toggle;
|
||
|
|
||
|
if(vm.isPublic == 1) {
|
||
|
vm.isPublic = true;
|
||
|
}else{
|
||
|
vm.isPublic = false;
|
||
|
}
|
||
|
|
||
|
var publicClass = 'btn btn-success';
|
||
|
var privateClass = 'btn btn-danger';
|
||
|
|
||
|
function setBtnClass() {
|
||
|
if(vm.isPublic) {
|
||
|
vm.btnClass = publicClass;
|
||
|
}else{
|
||
|
vm.btnClass = privateClass;
|
||
|
}
|
||
|
}
|
||
|
vm.setBtnClass = setBtnClass;
|
||
|
vm.setBtnClass();
|
||
|
|
||
|
function toggle() {
|
||
|
|
||
|
if(vm.isPublic) {
|
||
|
vm.isPublic = false;
|
||
|
}else{
|
||
|
vm.isPublic = true;
|
||
|
}
|
||
|
|
||
|
EditProjectService(vm.projectId, vm.isPublic)
|
||
|
.success(editProjectSuccess)
|
||
|
.error(editProjectFailed);
|
||
|
}
|
||
|
|
||
|
function editProjectSuccess(data, status) {
|
||
|
setBtnClass();
|
||
|
console.log('edit project successfully:' + status);
|
||
|
}
|
||
|
|
||
|
function editProjectFailed(e) {
|
||
|
console.log('edit project failed:' + e);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function publicityButton() {
|
||
|
var directive = {
|
||
|
'restrict': 'E',
|
||
|
'templateUrl': '/static/ng/resources/js/components/project/publicity-button.directive.html',
|
||
|
'scope': {
|
||
|
'isPublic': '=',
|
||
|
'owned': '=',
|
||
|
'projectId': '='
|
||
|
},
|
||
|
'link': link,
|
||
|
'controller': PublicityButtonController,
|
||
|
'controllerAs': 'vm',
|
||
|
'bindToController': true
|
||
|
};
|
||
|
return directive;
|
||
|
|
||
|
function link(scope, element, attr, ctrl) {
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
})();
|