2024-01-23 19:23:10 +01:00
|
|
|
var myconfirm = function (opts) {
|
2022-04-24 16:52:44 +02:00
|
|
|
var confirm = false;
|
2023-03-06 03:55:35 +01:00
|
|
|
var dialog = BootstrapDialog.show({
|
2024-01-23 19:23:10 +01:00
|
|
|
title: opts.title || _("Confirmation"),
|
|
|
|
message: opts.question || _("Do you confirm?"),
|
2022-04-24 16:52:44 +02:00
|
|
|
autodestroy: true,
|
2023-03-06 03:55:35 +01:00
|
|
|
cssClass: opts.css_class || null,
|
|
|
|
type: opts.type || BootstrapDialog.TYPE_LIGHT,
|
|
|
|
draggable: opts.draggable || false,
|
|
|
|
data: {
|
|
|
|
oncancel: opts.oncancel,
|
|
|
|
onconfirm: opts.onconfirm,
|
|
|
|
data: opts.data,
|
|
|
|
confirm: false,
|
|
|
|
},
|
2022-04-24 16:52:44 +02:00
|
|
|
buttons: [
|
|
|
|
{
|
2024-01-23 19:23:10 +01:00
|
|
|
label: opts.cancel_label || _("Cancel"),
|
|
|
|
action: function (dialog) {
|
2023-03-06 03:55:35 +01:00
|
|
|
dialog.close();
|
2024-01-23 19:23:10 +01:00
|
|
|
},
|
2022-04-24 16:52:44 +02:00
|
|
|
},
|
|
|
|
{
|
2024-01-23 19:23:10 +01:00
|
|
|
label: opts.confirm_label || _("Validate"),
|
|
|
|
cssClass: "btn-danger",
|
|
|
|
action: function (dialog) {
|
|
|
|
dialog.setData("confirm", true);
|
2023-03-06 03:55:35 +01:00
|
|
|
dialog.close();
|
2024-01-23 19:23:10 +01:00
|
|
|
},
|
|
|
|
},
|
2022-04-24 16:52:44 +02:00
|
|
|
],
|
2024-01-23 19:23:10 +01:00
|
|
|
onhidden: function (dialog) {
|
|
|
|
if (dialog.getData("confirm")) {
|
|
|
|
if (jQuery.type(dialog.getData("onconfirm")) == "function") {
|
|
|
|
dialog.getData("onconfirm")(dialog.getData("data"));
|
2022-04-24 16:52:44 +02:00
|
|
|
}
|
2024-01-23 19:23:10 +01:00
|
|
|
} else {
|
|
|
|
if (jQuery.type(dialog.getData("oncancel")) == "function") {
|
|
|
|
dialog.getData("oncancel")(dialog.getData("data"));
|
2022-04-24 16:52:44 +02:00
|
|
|
}
|
|
|
|
}
|
2024-01-23 19:23:10 +01:00
|
|
|
},
|
2022-04-24 16:52:44 +02:00
|
|
|
});
|
|
|
|
return dialog;
|
|
|
|
};
|
|
|
|
|
2024-01-23 19:23:10 +01:00
|
|
|
var myalert = function (msg, title, opts) {
|
|
|
|
if (!opts) opts = {};
|
2023-03-06 03:55:35 +01:00
|
|
|
var dialog = BootstrapDialog.show({
|
2024-01-23 19:23:10 +01:00
|
|
|
title: title || opts.title || _("Error"),
|
2022-04-24 16:52:44 +02:00
|
|
|
message: msg,
|
|
|
|
autodestroy: true,
|
2024-01-23 19:23:10 +01:00
|
|
|
type: opts.type || BootstrapDialog.TYPE_DANGER,
|
|
|
|
size: opts.size || BootstrapDialog.SIZE_MEDIUM,
|
2023-03-06 03:55:35 +01:00
|
|
|
draggable: opts.draggable || false,
|
|
|
|
cssClass: opts.css_class || null,
|
|
|
|
data: {
|
|
|
|
onclose: opts.onclose,
|
|
|
|
data: opts.data,
|
|
|
|
},
|
2022-04-24 16:52:44 +02:00
|
|
|
buttons: [
|
|
|
|
{
|
2024-01-23 19:23:10 +01:00
|
|
|
label: opts.btnLabel || _("OK"),
|
|
|
|
cssClass: opts.btnCssClass || "btn-primary",
|
|
|
|
action: function (dialog) {
|
2023-03-06 03:55:35 +01:00
|
|
|
dialog.close();
|
2024-01-23 19:23:10 +01:00
|
|
|
},
|
2022-04-24 16:52:44 +02:00
|
|
|
},
|
|
|
|
],
|
2024-01-23 19:23:10 +01:00
|
|
|
onhidden: function (dialog) {
|
|
|
|
if (jQuery.type(dialog.getData("onclose")) == "function") {
|
|
|
|
dialog.getData("onclose")(dialog.getData("data"));
|
2022-04-24 16:52:44 +02:00
|
|
|
}
|
2024-01-23 19:23:10 +01:00
|
|
|
},
|
2022-04-24 16:52:44 +02:00
|
|
|
});
|
|
|
|
return dialog;
|
|
|
|
};
|
|
|
|
|
2024-01-23 19:23:10 +01:00
|
|
|
var myprompt = function (opts) {
|
2022-04-24 16:52:44 +02:00
|
|
|
if ($.type(opts) != "object") {
|
2024-01-23 19:23:10 +01:00
|
|
|
opts = {};
|
2022-04-24 16:52:44 +02:00
|
|
|
}
|
2024-01-23 19:23:10 +01:00
|
|
|
var submitted = false;
|
2022-04-24 16:52:44 +02:00
|
|
|
|
2024-01-23 19:23:10 +01:00
|
|
|
var onSubmitBtnClick = function (dialog) {
|
|
|
|
submitted = true;
|
|
|
|
var val = dialog.getModalBody().find("input").val();
|
|
|
|
if (jQuery.type(dialog.getData("onsubmit")) == "function") {
|
|
|
|
if (!dialog.getData("onsubmit")(val, dialog.getData("data"))) {
|
|
|
|
if (jQuery.type(dialog.getData("onerror")) == "function") {
|
|
|
|
dialog.getData("onerror")(val, dialog.getData("data"));
|
2022-04-24 16:52:44 +02:00
|
|
|
}
|
2024-01-23 19:23:10 +01:00
|
|
|
if (!dialog.getData("closeonerror")) {
|
2022-04-24 16:52:44 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-06 03:55:35 +01:00
|
|
|
dialog.close();
|
2022-04-24 16:52:44 +02:00
|
|
|
};
|
|
|
|
|
2023-03-06 03:55:35 +01:00
|
|
|
var dialog = BootstrapDialog.show({
|
2024-01-23 19:23:10 +01:00
|
|
|
title: opts.title || _("Question"),
|
|
|
|
message:
|
|
|
|
"<label for='myprompt_input'>" +
|
|
|
|
(opts.label || _("Please enter your answer below:")) +
|
|
|
|
"</label><input type='text' class='form-control' id='myprompt_input'/>",
|
2022-04-24 16:52:44 +02:00
|
|
|
autodestroy: true,
|
2024-01-23 19:23:10 +01:00
|
|
|
type: opts.type || BootstrapDialog.TYPE_INFO,
|
|
|
|
size: opts.size || BootstrapDialog.SIZE_MEDIUM,
|
2023-03-06 03:55:35 +01:00
|
|
|
cssClass: opts.css_class || null,
|
|
|
|
draggable: opts.draggable || false,
|
2022-04-24 16:52:44 +02:00
|
|
|
data: {
|
|
|
|
oncancel: opts.oncancel,
|
|
|
|
onsubmit: opts.onsubmit,
|
|
|
|
onerror: opts.onerror,
|
|
|
|
closeonerror: opts.closeonerror || false,
|
|
|
|
default_answer: opts.default_answer,
|
|
|
|
onSubmitBtnClick: onSubmitBtnClick,
|
|
|
|
data: opts.data,
|
2024-01-23 19:23:10 +01:00
|
|
|
submitted: false,
|
2022-04-24 16:52:44 +02:00
|
|
|
},
|
|
|
|
buttons: [
|
|
|
|
{
|
2024-01-23 19:23:10 +01:00
|
|
|
label: opts.cancel_label || _("Cancel"),
|
|
|
|
action: function (dialog) {
|
2023-03-06 03:55:35 +01:00
|
|
|
dialog.close();
|
2024-01-23 19:23:10 +01:00
|
|
|
},
|
2022-04-24 16:52:44 +02:00
|
|
|
},
|
|
|
|
{
|
2024-01-23 19:23:10 +01:00
|
|
|
label: opts.submit_label || _("Validate"),
|
|
|
|
cssClass: "btn-danger",
|
|
|
|
action: onSubmitBtnClick,
|
|
|
|
},
|
2022-04-24 16:52:44 +02:00
|
|
|
],
|
2024-01-23 19:23:10 +01:00
|
|
|
onshown: function (dialog) {
|
|
|
|
var input = dialog.getModalBody().find("input");
|
|
|
|
input.on("keyup", function (e) {
|
2022-04-24 16:52:44 +02:00
|
|
|
if (e.keyCode == 13) {
|
2024-01-23 19:23:10 +01:00
|
|
|
dialog.getData("onSubmitBtnClick")(dialog);
|
2022-04-24 16:52:44 +02:00
|
|
|
}
|
|
|
|
});
|
2024-01-23 19:23:10 +01:00
|
|
|
if (dialog.getData("default_answer")) {
|
|
|
|
input.val(dialog.getData("default_answer"));
|
2022-04-24 16:52:44 +02:00
|
|
|
}
|
|
|
|
},
|
2024-01-23 19:23:10 +01:00
|
|
|
onhidden: function (dialog) {
|
|
|
|
if (!submitted && jQuery.type(dialog.getData("oncancel")) == "function") {
|
|
|
|
dialog.getData("oncancel")(dialog.getData("data"));
|
2022-04-24 16:52:44 +02:00
|
|
|
}
|
2024-01-23 19:23:10 +01:00
|
|
|
},
|
2022-04-24 16:52:44 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2024-01-23 19:23:10 +01:00
|
|
|
var myloadingalert = function (opts) {
|
|
|
|
if (!opts) opts = {};
|
2022-04-24 16:52:44 +02:00
|
|
|
var opened = false;
|
|
|
|
var closed = false;
|
2023-03-06 03:55:35 +01:00
|
|
|
var dialog = BootstrapDialog.show({
|
2024-01-23 19:23:10 +01:00
|
|
|
title: opts.title || _("Please wait"),
|
|
|
|
message:
|
|
|
|
opts.message || _("Please wait while your request is being processed."),
|
2022-04-24 16:52:44 +02:00
|
|
|
autodestroy: true,
|
2024-01-23 19:23:10 +01:00
|
|
|
type: opts.type || BootstrapDialog.TYPE_INFO,
|
|
|
|
size: opts.size || BootstrapDialog.SIZE_NORMAL,
|
2023-03-06 03:55:35 +01:00
|
|
|
cssClass: opts.css_class || null,
|
2022-04-24 16:52:44 +02:00
|
|
|
centered: opts.centered || true,
|
|
|
|
closable: opts.closable || false,
|
2023-03-06 03:55:35 +01:00
|
|
|
draggable: opts.draggable || false,
|
|
|
|
onshown: function (dialog) {
|
2024-01-23 19:23:10 +01:00
|
|
|
if (closed) dialog.close();
|
2022-04-24 16:52:44 +02:00
|
|
|
opened = true;
|
2024-01-23 19:23:10 +01:00
|
|
|
},
|
2022-04-24 16:52:44 +02:00
|
|
|
});
|
|
|
|
return {
|
2024-01-23 19:23:10 +01:00
|
|
|
modal: dialog,
|
|
|
|
close: function () {
|
|
|
|
if (opened) dialog.close();
|
2022-04-24 16:52:44 +02:00
|
|
|
closed = true;
|
2024-01-23 19:23:10 +01:00
|
|
|
},
|
2022-04-24 16:52:44 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-01-23 19:23:10 +01:00
|
|
|
$(document).ready(function () {
|
2022-04-24 16:52:44 +02:00
|
|
|
// Manage .myconfirm-link
|
2024-01-23 19:23:10 +01:00
|
|
|
$(".myconfirm-link").click(function (event) {
|
2022-04-24 16:52:44 +02:00
|
|
|
event.preventDefault();
|
|
|
|
myconfirm({
|
|
|
|
title: $(this).data("myconfirm-title") || _("Confirmation"),
|
2024-01-23 19:23:10 +01:00
|
|
|
question:
|
|
|
|
"<p><strong>" +
|
|
|
|
($(this).data("myconfirm-question") || _("Are you sure?")) +
|
|
|
|
"</strong></p>",
|
|
|
|
onconfirm: function (data) {
|
2022-04-24 16:52:44 +02:00
|
|
|
window.location = data.confirm_url;
|
|
|
|
},
|
|
|
|
data: {
|
2024-01-23 19:23:10 +01:00
|
|
|
confirm_url: $(this).data("myconfirm-url"),
|
|
|
|
},
|
2022-04-24 16:52:44 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Manage .myloading-link
|
2024-01-23 19:23:10 +01:00
|
|
|
$(".myloading-link").click(function (event) {
|
2022-04-24 16:52:44 +02:00
|
|
|
event.preventDefault();
|
|
|
|
myloadingalert({
|
|
|
|
title: $(this).data("myloading-title"),
|
|
|
|
message: $(this).data("myloading-message"),
|
|
|
|
});
|
2024-01-23 19:23:10 +01:00
|
|
|
window.location = $(this).data("myloading-url");
|
2022-04-24 16:52:44 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Manage .myconfirm-btn
|
2024-01-23 19:23:10 +01:00
|
|
|
$(".myconfirm-btn").click(function (event) {
|
|
|
|
if ($(this).data("myconfirm-btn-confirmed") == "1") {
|
|
|
|
$(this).data("myconfirm-btn-confirmed", "");
|
2022-04-24 16:52:44 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
event.preventDefault();
|
|
|
|
myconfirm({
|
|
|
|
title: $(this).data("myconfirm-title") || _("Confirmation"),
|
2024-01-23 19:23:10 +01:00
|
|
|
question:
|
|
|
|
"<p><strong>" +
|
|
|
|
($(this).data("myconfirm-question") || _("Are you sure?")) +
|
|
|
|
"</strong></p>",
|
|
|
|
onconfirm: function (data) {
|
|
|
|
data.btn.data("myconfirm-btn-confirmed", 1);
|
2022-04-24 16:52:44 +02:00
|
|
|
data.btn.click();
|
|
|
|
},
|
|
|
|
data: {
|
2024-01-23 19:23:10 +01:00
|
|
|
btn: $(this),
|
|
|
|
},
|
2022-04-24 16:52:44 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Manage .myloading-btn
|
2024-01-23 19:23:10 +01:00
|
|
|
$(".myloading-btn").click(function (event) {
|
2022-04-24 16:52:44 +02:00
|
|
|
myloadingalert({
|
|
|
|
title: $(this).data("myloading-title"),
|
|
|
|
message: $(this).data("myloading-message"),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|