2016-04-02 14:40:07 +02:00
|
|
|
define(function () {
|
2016-06-17 22:16:46 +02:00
|
|
|
app.registerController('ProjectKeysCtrl', ['$scope', '$http', '$uibModal', 'Project', '$rootScope', function ($scope, $http, $modal, Project, $rootScope) {
|
2016-04-04 01:10:12 +02:00
|
|
|
$scope.reload = function () {
|
|
|
|
$http.get(Project.getURL() + '/keys').success(function (keys) {
|
|
|
|
$scope.keys = keys;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.remove = function (key) {
|
|
|
|
$http.delete(Project.getURL() + '/keys/' + key.id).success(function () {
|
|
|
|
$scope.reload();
|
2016-06-17 22:16:46 +02:00
|
|
|
}).error(function (d) {
|
|
|
|
if (!(d && d.inUse)) {
|
|
|
|
swal('error', 'could not delete key..', 'error');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
swal({
|
|
|
|
title: 'Key in use',
|
|
|
|
text: d.error,
|
|
|
|
type: 'error',
|
|
|
|
showCancelButton: true,
|
|
|
|
confirmButtonColor: "#DD6B55",
|
|
|
|
confirmButtonText: 'Mark as removed'
|
|
|
|
}, function () {
|
|
|
|
$http.delete(Project.getURL() + '/keys/' + key.id + '?setRemoved=1').success(function () {
|
|
|
|
$scope.reload();
|
|
|
|
}).error(function () {
|
|
|
|
swal('error', 'could not remove key..', 'error');
|
|
|
|
});
|
|
|
|
});
|
2016-04-04 01:10:12 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.add = function () {
|
|
|
|
$modal.open({
|
2016-04-10 20:03:12 +02:00
|
|
|
templateUrl: '/tpl/projects/keys/add.html'
|
2016-06-25 22:19:47 +02:00
|
|
|
}).result.then(function (opts) {
|
|
|
|
$http.post(Project.getURL() + '/keys', opts.key).success(function () {
|
2016-04-04 15:44:34 +02:00
|
|
|
$scope.reload();
|
|
|
|
}).error(function (_, status) {
|
|
|
|
swal('error', 'could not add key:' + status, 'error');
|
|
|
|
});
|
2016-04-04 01:10:12 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-06-17 22:16:46 +02:00
|
|
|
$scope.update = function (key) {
|
|
|
|
var scope = $rootScope.$new();
|
|
|
|
scope.key = key;
|
|
|
|
|
|
|
|
$modal.open({
|
|
|
|
templateUrl: '/tpl/projects/keys/add.html',
|
|
|
|
scope: scope
|
|
|
|
}).result.then(function (opts) {
|
|
|
|
if (opts.delete) {
|
|
|
|
$scope.remove(key);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$http.put(Project.getURL() + '/keys/' + key.id, opts.key)
|
|
|
|
.success(function () {
|
|
|
|
$scope.reload();
|
|
|
|
}).error(function (_, status) {
|
|
|
|
swal('Error', 'could not update key:' + status, 'error');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-04-04 01:10:12 +02:00
|
|
|
$scope.reload();
|
2016-04-02 14:40:07 +02:00
|
|
|
}]);
|
2016-06-25 11:39:55 +02:00
|
|
|
});
|