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('publicityButton', publicityButton);
|
|
|
|
|
2016-07-06 06:56:44 +02:00
|
|
|
PublicityButtonController.$inject = ['$scope', 'ToggleProjectPublicityService', '$filter', 'trFilter'];
|
2016-05-01 19:46:50 +02:00
|
|
|
|
2016-07-06 06:56:44 +02:00
|
|
|
function PublicityButtonController($scope, ToggleProjectPublicityService, $filter, trFilter) {
|
2016-05-01 19:46:50 +02:00
|
|
|
var vm = this;
|
|
|
|
vm.toggle = toggle;
|
|
|
|
|
2016-07-06 06:56:44 +02:00
|
|
|
function toggle() {
|
2016-05-01 19:46:50 +02:00
|
|
|
if(vm.isPublic) {
|
|
|
|
vm.isPublic = false;
|
|
|
|
}else{
|
|
|
|
vm.isPublic = true;
|
|
|
|
}
|
2016-06-15 12:31:02 +02:00
|
|
|
ToggleProjectPublicityService(vm.projectId, vm.isPublic)
|
|
|
|
.success(toggleProjectPublicitySuccess)
|
|
|
|
.error(toggleProjectPublicityFailed);
|
2016-05-01 19:46:50 +02:00
|
|
|
}
|
|
|
|
|
2016-06-15 12:31:02 +02:00
|
|
|
function toggleProjectPublicitySuccess(data, status) {
|
2016-07-06 06:56:44 +02:00
|
|
|
|
2016-06-15 12:31:02 +02:00
|
|
|
console.log('Successful toggle project publicity.');
|
2016-05-01 19:46:50 +02:00
|
|
|
}
|
|
|
|
|
2016-07-06 06:56:44 +02:00
|
|
|
function toggleProjectPublicityFailed(e, status) {
|
|
|
|
$scope.$emit('modalTitle', $filter('tr')('error'));
|
|
|
|
var message;
|
|
|
|
if(status === 403) {
|
|
|
|
message = $filter('tr')('failed_to_toggle_publicity_insuffient_permissions');
|
|
|
|
}else{
|
|
|
|
message = $filter('tr')('failed_to_toggle_publicity');
|
|
|
|
}
|
|
|
|
$scope.$emit('modalMessage', message);
|
|
|
|
$scope.$emit('raiseError', true);
|
|
|
|
|
|
|
|
if(vm.isPublic) {
|
|
|
|
vm.isPublic = false;
|
|
|
|
}else{
|
|
|
|
vm.isPublic = true;
|
|
|
|
}
|
|
|
|
|
2016-07-04 06:34:34 +02:00
|
|
|
console.log('Failed to toggle project publicity:' + e);
|
2016-05-01 19:46:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function publicityButton() {
|
|
|
|
var directive = {
|
|
|
|
'restrict': 'E',
|
2016-06-16 08:10:35 +02:00
|
|
|
'templateUrl': '/static/resources/js/components/project/publicity-button.directive.html',
|
2016-05-01 19:46:50 +02:00
|
|
|
'scope': {
|
|
|
|
'isPublic': '=',
|
|
|
|
'owned': '=',
|
|
|
|
'projectId': '='
|
|
|
|
},
|
|
|
|
'link': link,
|
|
|
|
'controller': PublicityButtonController,
|
|
|
|
'controllerAs': 'vm',
|
|
|
|
'bindToController': true
|
|
|
|
};
|
|
|
|
return directive;
|
|
|
|
|
|
|
|
function link(scope, element, attr, ctrl) {
|
2016-07-06 06:56:44 +02:00
|
|
|
scope.$watch('vm.isPublic', function(current, origin) {
|
|
|
|
if(current) {
|
|
|
|
ctrl.isPublic = current;
|
|
|
|
}
|
|
|
|
});
|
2016-05-01 19:46:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
})();
|