2017-02-15 22:14:56 +00:00
|
|
|
angular.module('portainer.services')
|
|
|
|
.factory('ModalService', [function ModalServiceFactory() {
|
|
|
|
'use strict';
|
|
|
|
var service = {};
|
2017-03-12 16:24:15 +00:00
|
|
|
|
2017-05-01 10:18:06 +00:00
|
|
|
var applyBoxCSS = function(box) {
|
|
|
|
box.css({
|
|
|
|
'top': '50%',
|
|
|
|
'margin-top': function () {
|
|
|
|
return -(box.height() / 2);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var confirmButtons = function(options) {
|
|
|
|
var buttons = {
|
|
|
|
confirm: {
|
|
|
|
label: options.buttons.confirm.label,
|
|
|
|
className: options.buttons.confirm.className
|
|
|
|
},
|
|
|
|
cancel: {
|
|
|
|
label: options.buttons.cancel && options.buttons.cancel.label ? options.buttons.cancel.label : 'Cancel'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return buttons;
|
|
|
|
};
|
|
|
|
|
2017-02-15 22:14:56 +00:00
|
|
|
service.confirm = function(options){
|
|
|
|
var box = bootbox.confirm({
|
|
|
|
title: options.title,
|
|
|
|
message: options.message,
|
2017-05-01 10:18:06 +00:00
|
|
|
buttons: confirmButtons(options),
|
2017-02-15 22:14:56 +00:00
|
|
|
callback: options.callback
|
|
|
|
});
|
2017-05-01 10:18:06 +00:00
|
|
|
applyBoxCSS(box);
|
|
|
|
};
|
|
|
|
|
|
|
|
service.prompt = function(options){
|
|
|
|
var box = bootbox.prompt({
|
|
|
|
title: options.title,
|
|
|
|
inputType: options.inputType,
|
|
|
|
inputOptions: options.inputOptions,
|
|
|
|
buttons: confirmButtons(options),
|
|
|
|
callback: options.callback
|
2017-02-15 22:14:56 +00:00
|
|
|
});
|
2017-05-01 10:18:06 +00:00
|
|
|
applyBoxCSS(box);
|
2017-02-15 22:23:43 +00:00
|
|
|
};
|
2017-03-12 16:24:15 +00:00
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
service.confirmAccessControlUpdate = function(callback, msg) {
|
2017-03-12 16:24:15 +00:00
|
|
|
service.confirm({
|
|
|
|
title: 'Are you sure ?',
|
2017-05-23 18:56:10 +00:00
|
|
|
message: 'Changing the ownership of this resource will potentially restrict its management to some users.',
|
2017-03-12 16:24:15 +00:00
|
|
|
buttons: {
|
|
|
|
confirm: {
|
|
|
|
label: 'Change ownership',
|
|
|
|
className: 'btn-primary'
|
|
|
|
}
|
|
|
|
},
|
2017-05-23 18:56:10 +00:00
|
|
|
callback: callback
|
2017-03-12 16:24:15 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
service.confirmImageForceRemoval = function(callback) {
|
|
|
|
service.confirm({
|
2017-05-23 18:56:10 +00:00
|
|
|
title: 'Are you sure?',
|
|
|
|
message: 'Forcing the removal of the image will remove the image even if it has multiple tags or if it is used by stopped containers.',
|
2017-03-12 16:24:15 +00:00
|
|
|
buttons: {
|
|
|
|
confirm: {
|
|
|
|
label: 'Remove the image',
|
|
|
|
className: 'btn-danger'
|
|
|
|
}
|
|
|
|
},
|
2017-05-23 18:56:10 +00:00
|
|
|
callback: callback
|
2017-03-12 16:24:15 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
service.confirmDeletion = function(message, callback) {
|
|
|
|
service.confirm({
|
|
|
|
title: 'Are you sure ?',
|
|
|
|
message: message,
|
|
|
|
buttons: {
|
|
|
|
confirm: {
|
2017-04-25 08:20:57 +00:00
|
|
|
label: 'Remove',
|
2017-03-12 16:24:15 +00:00
|
|
|
className: 'btn-danger'
|
|
|
|
}
|
|
|
|
},
|
2017-05-23 18:56:10 +00:00
|
|
|
callback: callback
|
2017-03-12 16:24:15 +00:00
|
|
|
});
|
|
|
|
};
|
2017-05-01 10:18:06 +00:00
|
|
|
|
|
|
|
service.confirmContainerDeletion = function(title, callback) {
|
|
|
|
service.prompt({
|
|
|
|
title: title,
|
|
|
|
inputType: 'checkbox',
|
|
|
|
inputOptions: [
|
|
|
|
{
|
|
|
|
text: 'Automatically remove non-persistent volumes<i></i>',
|
|
|
|
value: '1'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
buttons: {
|
|
|
|
confirm: {
|
|
|
|
label: 'Remove',
|
|
|
|
className: 'btn-danger'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
callback: callback
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-02-15 22:14:56 +00:00
|
|
|
return service;
|
|
|
|
}]);
|