2020-01-21 08:37:30 +01:00
|
|
|
/* global $ uniqId*/
|
2019-11-21 16:42:39 +01:00
|
|
|
/* exported load_modal */
|
2019-11-27 11:43:50 +01:00
|
|
|
/*JS to Show user modals :
|
|
|
|
- Confirm dialogs.
|
|
|
|
- Display dialogs.
|
|
|
|
- Load modal windows.
|
|
|
|
- Logo Previews.
|
|
|
|
- General show messages.
|
|
|
|
*/
|
2019-11-21 16:42:39 +01:00
|
|
|
|
|
|
|
var ENTERPRISE_DIR = "enterprise";
|
|
|
|
|
|
|
|
/**
|
2019-11-28 18:27:05 +01:00
|
|
|
* Display a dialog with an image
|
2019-11-21 16:42:39 +01:00
|
|
|
*
|
2019-11-28 18:27:05 +01:00
|
|
|
* @param {string} icon_name The name of the icon you will display
|
|
|
|
* @param {string} icon_path The path to the icon
|
|
|
|
* @param {Object} incoming_options All options
|
|
|
|
* grayed: {bool} True to display the background black
|
|
|
|
* title {string} 'Logo preview' by default
|
2019-11-21 16:42:39 +01:00
|
|
|
*/
|
2019-11-28 18:27:05 +01:00
|
|
|
function logo_preview(icon_name, icon_path, incoming_options) {
|
|
|
|
// Get the options
|
|
|
|
options = {
|
|
|
|
grayed: false,
|
|
|
|
title: "Logo preview"
|
2019-11-21 16:42:39 +01:00
|
|
|
};
|
2019-11-28 18:27:05 +01:00
|
|
|
$.extend(options, incoming_options);
|
2019-11-21 16:42:39 +01:00
|
|
|
|
2019-11-28 18:27:05 +01:00
|
|
|
if (icon_name == "") return;
|
2019-11-21 16:42:39 +01:00
|
|
|
|
2019-11-28 18:27:05 +01:00
|
|
|
$dialog = $("<div></div>");
|
|
|
|
$image = $('<img src="' + icon_path + '">');
|
|
|
|
$image.css("max-width", "500px").css("max-height", "500px");
|
2019-11-21 16:42:39 +01:00
|
|
|
|
2019-11-28 18:27:05 +01:00
|
|
|
try {
|
|
|
|
$dialog
|
|
|
|
.hide()
|
|
|
|
.html($image)
|
|
|
|
.dialog({
|
|
|
|
title: options.title,
|
|
|
|
resizable: true,
|
|
|
|
draggable: true,
|
|
|
|
modal: true,
|
|
|
|
dialogClass: options.grayed ? "dialog-grayed" : "",
|
|
|
|
overlay: {
|
|
|
|
opacity: 0.5,
|
|
|
|
background: "black"
|
|
|
|
},
|
|
|
|
minHeight: 1,
|
|
|
|
width: $image.width,
|
|
|
|
close: function() {
|
|
|
|
$dialog.empty().remove();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.show();
|
|
|
|
} catch (err) {
|
|
|
|
// console.log(err);
|
|
|
|
}
|
2019-11-21 16:42:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Advanced Form control.
|
2020-01-21 08:37:30 +01:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
2019-11-21 16:42:39 +01:00
|
|
|
function load_modal(settings) {
|
|
|
|
var AJAX_RUNNING = 0;
|
|
|
|
var data = new FormData();
|
|
|
|
if (settings.extradata) {
|
|
|
|
settings.extradata.forEach(function(item) {
|
2020-01-21 08:37:30 +01:00
|
|
|
if (item.value != undefined) {
|
|
|
|
if (item.value instanceof Object || item.value instanceof Array) {
|
|
|
|
data.append(item.name, JSON.stringify(item.value));
|
|
|
|
} else {
|
|
|
|
data.append(item.name, item.value);
|
|
|
|
}
|
|
|
|
}
|
2019-11-21 16:42:39 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
data.append("page", settings.onshow.page);
|
|
|
|
data.append("method", settings.onshow.method);
|
2019-11-28 18:27:05 +01:00
|
|
|
if (settings.onshow.extradata != undefined) {
|
|
|
|
data.append("extradata", JSON.stringify(settings.onshow.extradata));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (settings.target == undefined) {
|
|
|
|
var uniq = uniqId();
|
|
|
|
var div = document.createElement("div");
|
|
|
|
div.id = "div-modal-" + uniq;
|
|
|
|
div.style.display = "none";
|
|
|
|
|
2021-02-03 12:53:05 +01:00
|
|
|
if (document.getElementById("main") == null) {
|
|
|
|
// MC env.
|
|
|
|
document.getElementById("page").append(div);
|
|
|
|
} else {
|
|
|
|
document.getElementById("main").append(div);
|
|
|
|
}
|
2019-11-28 18:27:05 +01:00
|
|
|
|
|
|
|
var id_modal_target = "#div-modal-" + uniq;
|
|
|
|
|
|
|
|
settings.target = $(id_modal_target);
|
|
|
|
}
|
2019-11-21 16:42:39 +01:00
|
|
|
|
|
|
|
var width = 630;
|
|
|
|
if (settings.onshow.width) {
|
|
|
|
width = settings.onshow.width;
|
|
|
|
}
|
|
|
|
|
2019-11-28 18:27:05 +01:00
|
|
|
if (settings.modal.overlay == undefined) {
|
|
|
|
settings.modal.overlay = {
|
|
|
|
opacity: 0.5,
|
|
|
|
background: "black"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-01-21 08:37:30 +01:00
|
|
|
if (settings.beforeClose == undefined) {
|
|
|
|
settings.beforeClose = function() {};
|
|
|
|
}
|
|
|
|
|
2019-11-21 16:42:39 +01:00
|
|
|
settings.target.html("Loading modal...");
|
|
|
|
settings.target
|
|
|
|
.dialog({
|
|
|
|
title: "Loading",
|
|
|
|
close: false,
|
|
|
|
width: 200,
|
|
|
|
buttons: []
|
|
|
|
})
|
|
|
|
.show();
|
|
|
|
var required_buttons = [];
|
|
|
|
if (settings.modal.cancel != undefined) {
|
|
|
|
//The variable contains a function
|
|
|
|
// that is responsible for executing the method it receives from settings
|
|
|
|
// which confirms the closure of a modal
|
|
|
|
var cancelModal = function() {
|
|
|
|
settings.target.dialog("close");
|
|
|
|
if (AJAX_RUNNING) return;
|
|
|
|
AJAX_RUNNING = 1;
|
|
|
|
var formdata = new FormData();
|
|
|
|
|
|
|
|
formdata.append("page", settings.oncancel.page);
|
|
|
|
formdata.append("method", settings.oncancel.method);
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
method: "post",
|
|
|
|
url: settings.url,
|
|
|
|
processData: false,
|
|
|
|
contentType: false,
|
|
|
|
data: formdata,
|
|
|
|
success: function(data) {
|
|
|
|
if (typeof settings.oncancel.callback == "function") {
|
|
|
|
settings.oncancel.callback(data);
|
|
|
|
settings.target.dialog("close");
|
|
|
|
}
|
|
|
|
AJAX_RUNNING = 0;
|
|
|
|
},
|
|
|
|
error: function(data) {
|
|
|
|
// console.log(data);
|
|
|
|
AJAX_RUNNING = 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
required_buttons.push({
|
|
|
|
class:
|
|
|
|
"ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd submit-cancel",
|
2021-11-23 20:31:04 +01:00
|
|
|
id: settings.modal.cancel_button_id,
|
2019-11-21 16:42:39 +01:00
|
|
|
text: settings.modal.cancel,
|
|
|
|
click: function() {
|
|
|
|
if (settings.oncancel != undefined) {
|
|
|
|
if (typeof settings.oncancel.confirm == "function") {
|
|
|
|
//receive function
|
|
|
|
settings.oncancel.confirm(cancelModal);
|
|
|
|
} else if (settings.oncancel != undefined) {
|
|
|
|
cancelModal();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$(this).dialog("close");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (settings.modal.ok != undefined) {
|
2021-01-15 13:52:31 +01:00
|
|
|
var btnClickHandler = function(d) {
|
|
|
|
if (AJAX_RUNNING) return;
|
|
|
|
if (settings.onsubmit != undefined) {
|
|
|
|
if (settings.onsubmit.preaction != undefined) {
|
|
|
|
settings.onsubmit.preaction();
|
|
|
|
}
|
|
|
|
AJAX_RUNNING = 1;
|
|
|
|
if (settings.onsubmit.dataType == undefined) {
|
|
|
|
settings.onsubmit.dataType = "html";
|
|
|
|
}
|
2019-11-21 16:42:39 +01:00
|
|
|
|
2021-01-15 13:52:31 +01:00
|
|
|
var formdata = new FormData();
|
|
|
|
if (settings.extradata) {
|
|
|
|
settings.extradata.forEach(function(item) {
|
2021-01-25 13:36:12 +01:00
|
|
|
if (item.value != undefined) formdata.append(item.name, item.value);
|
2021-01-15 13:52:31 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
formdata.append("page", settings.onsubmit.page);
|
|
|
|
formdata.append("method", settings.onsubmit.method);
|
2019-11-21 16:42:39 +01:00
|
|
|
|
2021-01-15 13:52:31 +01:00
|
|
|
var flagError = false;
|
|
|
|
if (Array.isArray(settings.form) === false) {
|
|
|
|
$("#" + settings.form + " :input").each(function() {
|
|
|
|
if (this.checkValidity() === false) {
|
2021-03-24 12:43:51 +01:00
|
|
|
var select2 = $(this).attr("data-select2-id");
|
|
|
|
if (typeof select2 !== typeof undefined && select2 !== false) {
|
|
|
|
$(this)
|
|
|
|
.next()
|
|
|
|
.attr("title", this.validationMessage);
|
|
|
|
$(this)
|
|
|
|
.next()
|
|
|
|
.tooltip({
|
|
|
|
tooltipClass: "uitooltip",
|
|
|
|
position: {
|
|
|
|
my: "right bottom",
|
|
|
|
at: "right top",
|
|
|
|
using: function(position, feedback) {
|
|
|
|
$(this).css(position);
|
|
|
|
$("<div>")
|
|
|
|
.addClass("arrow")
|
|
|
|
.addClass(feedback.vertical)
|
|
|
|
.addClass(feedback.horizontal)
|
|
|
|
.appendTo(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$(this)
|
|
|
|
.next()
|
|
|
|
.tooltip("open");
|
|
|
|
|
|
|
|
var element = $(this).next();
|
|
|
|
setTimeout(
|
|
|
|
function(element) {
|
|
|
|
element.tooltip("destroy");
|
|
|
|
element.removeAttr("title");
|
|
|
|
},
|
|
|
|
3000,
|
|
|
|
element
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$(this).attr("title", this.validationMessage);
|
|
|
|
$(this).tooltip({
|
|
|
|
tooltipClass: "uitooltip",
|
|
|
|
position: {
|
|
|
|
my: "right bottom",
|
|
|
|
at: "right top",
|
|
|
|
using: function(position, feedback) {
|
|
|
|
$(this).css(position);
|
|
|
|
$("<div>")
|
|
|
|
.addClass("arrow")
|
|
|
|
.addClass(feedback.vertical)
|
|
|
|
.addClass(feedback.horizontal)
|
|
|
|
.appendTo(this);
|
|
|
|
}
|
2019-11-21 16:42:39 +01:00
|
|
|
}
|
2021-03-24 12:43:51 +01:00
|
|
|
});
|
|
|
|
$(this).tooltip("open");
|
|
|
|
|
|
|
|
var element = $(this);
|
|
|
|
setTimeout(
|
|
|
|
function(element) {
|
|
|
|
element.tooltip("destroy");
|
|
|
|
element.removeAttr("title");
|
|
|
|
},
|
|
|
|
3000,
|
|
|
|
element
|
|
|
|
);
|
|
|
|
}
|
2019-11-21 16:42:39 +01:00
|
|
|
|
2021-01-15 13:52:31 +01:00
|
|
|
flagError = true;
|
|
|
|
}
|
2020-01-21 08:37:30 +01:00
|
|
|
|
2021-01-15 13:52:31 +01:00
|
|
|
if (this.type == "file") {
|
|
|
|
if ($(this).prop("files")[0]) {
|
|
|
|
formdata.append(this.name, $(this).prop("files")[0]);
|
2019-11-21 16:42:39 +01:00
|
|
|
}
|
2021-01-15 13:52:31 +01:00
|
|
|
} else {
|
|
|
|
if ($(this).attr("type") == "checkbox") {
|
|
|
|
if (this.checked) {
|
|
|
|
formdata.append(this.name, "on");
|
2019-11-21 16:42:39 +01:00
|
|
|
}
|
|
|
|
} else {
|
2021-01-15 13:52:31 +01:00
|
|
|
formdata.append(this.name, $(this).val());
|
2019-11-21 16:42:39 +01:00
|
|
|
}
|
2021-01-15 13:52:31 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
settings.form.forEach(function(element) {
|
|
|
|
$("#" + element + " :input, #" + element + " textarea").each(
|
|
|
|
function() {
|
2020-01-21 08:37:30 +01:00
|
|
|
// TODO VALIDATE ALL INPUTS.
|
|
|
|
if (this.type == "file") {
|
|
|
|
if ($(this).prop("files")[0]) {
|
|
|
|
formdata.append(this.name, $(this).prop("files")[0]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($(this).attr("type") == "checkbox") {
|
|
|
|
if (this.checked) {
|
|
|
|
formdata.append(this.name, "on");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
formdata.append(this.name, $(this).val());
|
|
|
|
}
|
|
|
|
}
|
2021-01-15 13:52:31 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2019-11-21 16:42:39 +01:00
|
|
|
|
2021-01-15 13:52:31 +01:00
|
|
|
if (flagError === false) {
|
|
|
|
if (
|
|
|
|
settings.onsubmitClose != undefined &&
|
|
|
|
settings.onsubmitClose == 1
|
|
|
|
) {
|
|
|
|
d.dialog("close");
|
|
|
|
}
|
2020-01-21 08:37:30 +01:00
|
|
|
|
2021-01-15 13:52:31 +01:00
|
|
|
$.ajax({
|
|
|
|
method: "post",
|
|
|
|
url: settings.url,
|
|
|
|
processData: false,
|
|
|
|
contentType: false,
|
|
|
|
data: formdata,
|
|
|
|
dataType: settings.onsubmit.dataType,
|
|
|
|
success: function(data) {
|
|
|
|
if (settings.ajax_callback != undefined) {
|
|
|
|
if (settings.idMsgCallback != undefined) {
|
|
|
|
settings.ajax_callback(data, settings.idMsgCallback);
|
|
|
|
} else {
|
|
|
|
settings.ajax_callback(data);
|
2019-11-21 16:42:39 +01:00
|
|
|
}
|
2021-11-18 19:49:57 +01:00
|
|
|
} else {
|
|
|
|
generalShowMsg(data, null);
|
2019-11-21 16:42:39 +01:00
|
|
|
}
|
2021-11-18 19:49:57 +01:00
|
|
|
|
|
|
|
AJAX_RUNNING = 0;
|
|
|
|
},
|
|
|
|
error: function(response) {
|
|
|
|
generalShowMsg(
|
|
|
|
{
|
|
|
|
title: "Failed",
|
|
|
|
text: response.responseText
|
|
|
|
},
|
|
|
|
null
|
|
|
|
);
|
2021-01-15 13:52:31 +01:00
|
|
|
AJAX_RUNNING = 0;
|
|
|
|
}
|
|
|
|
});
|
2019-11-21 16:42:39 +01:00
|
|
|
} else {
|
2021-01-15 13:52:31 +01:00
|
|
|
AJAX_RUNNING = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// No onsumbit configured. Directly close.
|
|
|
|
d.dialog("close");
|
|
|
|
if (document.getElementById(settings.form) != undefined) {
|
|
|
|
document.getElementById(settings.form).submit();
|
|
|
|
}
|
|
|
|
}
|
2021-01-25 13:36:12 +01:00
|
|
|
};
|
2021-01-15 13:52:31 +01:00
|
|
|
|
|
|
|
required_buttons.push({
|
|
|
|
class:
|
|
|
|
"ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next",
|
|
|
|
text: settings.modal.ok,
|
2021-11-23 20:31:04 +01:00
|
|
|
id: settings.modal.ok_button_id,
|
2021-01-15 13:52:31 +01:00
|
|
|
click: function() {
|
2021-01-25 13:36:12 +01:00
|
|
|
if (
|
|
|
|
settings.onsubmit != undefined &&
|
|
|
|
settings.onsubmit.onConfirmSubmit != undefined
|
|
|
|
) {
|
|
|
|
settings.onsubmit.onConfirmSubmit(btnClickHandler, $(this));
|
2021-01-15 13:52:31 +01:00
|
|
|
} else {
|
2021-01-25 13:36:12 +01:00
|
|
|
btnClickHandler($(this));
|
2019-11-21 16:42:39 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function(data) {
|
|
|
|
// console.log(data);
|
|
|
|
AJAX_RUNNING = 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
method: "post",
|
|
|
|
url: settings.url,
|
|
|
|
processData: false,
|
|
|
|
contentType: false,
|
|
|
|
data: data,
|
|
|
|
success: function(data) {
|
2020-03-27 11:41:56 +01:00
|
|
|
if (settings.onshow.parser) {
|
|
|
|
data = settings.onshow.parser(data);
|
|
|
|
} else {
|
|
|
|
data = (function(d) {
|
|
|
|
try {
|
|
|
|
d = JSON.parse(d);
|
|
|
|
} catch (e) {
|
|
|
|
// Not JSON
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
if (d.error) return d.error;
|
|
|
|
|
|
|
|
if (d.result) return d.result;
|
|
|
|
})(data);
|
|
|
|
}
|
2019-11-21 16:42:39 +01:00
|
|
|
settings.target.html(data);
|
|
|
|
if (settings.onload != undefined) {
|
|
|
|
settings.onload(data);
|
|
|
|
}
|
|
|
|
settings.target.dialog({
|
|
|
|
resizable: true,
|
|
|
|
draggable: true,
|
|
|
|
modal: true,
|
|
|
|
title: settings.modal.title,
|
|
|
|
width: width,
|
2020-01-21 08:37:30 +01:00
|
|
|
minHeight:
|
|
|
|
settings.onshow.minHeight != undefined
|
|
|
|
? settings.onshow.minHeight
|
|
|
|
: "auto",
|
|
|
|
maxHeight:
|
|
|
|
settings.onshow.maxHeight != undefined
|
|
|
|
? settings.onshow.maxHeight
|
|
|
|
: "auto",
|
2019-11-28 18:27:05 +01:00
|
|
|
overlay: settings.modal.overlay,
|
2020-03-17 18:34:30 +01:00
|
|
|
position: {
|
|
|
|
my: "top+20%",
|
|
|
|
at: "top",
|
|
|
|
of: window,
|
|
|
|
collision: "fit"
|
|
|
|
},
|
2019-11-21 16:42:39 +01:00
|
|
|
buttons: required_buttons,
|
2020-01-21 08:37:30 +01:00
|
|
|
closeOnEscape: true,
|
2019-11-21 16:42:39 +01:00
|
|
|
open: function() {
|
2020-01-21 08:37:30 +01:00
|
|
|
//$(".ui-dialog-titlebar-close").hide();
|
2019-11-28 18:27:05 +01:00
|
|
|
},
|
|
|
|
close: function() {
|
2020-11-06 20:37:37 +01:00
|
|
|
$(this).dialog("destroy");
|
|
|
|
|
2019-11-28 18:27:05 +01:00
|
|
|
if (id_modal_target != undefined) {
|
|
|
|
$(id_modal_target).remove();
|
|
|
|
}
|
2020-01-21 08:37:30 +01:00
|
|
|
|
|
|
|
if (settings.cleanup != undefined) {
|
|
|
|
settings.cleanup();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeClose: settings.beforeClose()
|
2019-11-21 16:42:39 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
error: function(data) {
|
2020-11-06 20:37:37 +01:00
|
|
|
console.error(data);
|
2019-11-21 16:42:39 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-21 08:37:30 +01:00
|
|
|
// Function that shows a dialog box to confirm closures of generic manners.
|
|
|
|
// The modal id is random.
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
2019-11-21 16:42:39 +01:00
|
|
|
function confirmDialog(settings) {
|
2019-11-28 18:27:05 +01:00
|
|
|
var randomStr = uniqId();
|
2021-02-16 13:43:10 +01:00
|
|
|
var hideOkButton = "";
|
2021-04-26 17:20:00 +02:00
|
|
|
var hideCancelButton = "";
|
2019-11-21 16:42:39 +01:00
|
|
|
|
2020-06-30 12:16:51 +02:00
|
|
|
if (settings.size == undefined) {
|
|
|
|
settings.size = 350;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (settings.maxHeight == undefined) {
|
|
|
|
settings.maxHeight = 1000;
|
|
|
|
}
|
2021-02-16 13:43:10 +01:00
|
|
|
// You can hide the OK button.
|
|
|
|
if (settings.hideOkButton != undefined) {
|
|
|
|
hideOkButton = "invisible_important ";
|
|
|
|
}
|
2021-04-26 17:20:00 +02:00
|
|
|
// You can hide the Cancel button.
|
|
|
|
if (settings.hideCancelButton != undefined) {
|
|
|
|
hideCancelButton = "invisible_important ";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (settings.strOKButton == undefined) {
|
|
|
|
settings.strOKButton = "Ok";
|
|
|
|
}
|
2020-06-30 12:16:51 +02:00
|
|
|
|
2021-04-29 15:59:12 +02:00
|
|
|
if (settings.strCancelButton == undefined) {
|
|
|
|
settings.strCancelButton = "Cancel";
|
|
|
|
}
|
|
|
|
|
2020-06-30 12:16:51 +02:00
|
|
|
if (typeof settings.message == "function") {
|
|
|
|
$("body").append(
|
|
|
|
'<div id="confirm_' + randomStr + '">' + settings.message() + "</div>"
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$("body").append(
|
|
|
|
'<div id="confirm_' + randomStr + '">' + settings.message + "</div>"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-01-31 13:45:44 +01:00
|
|
|
var buttons = [
|
|
|
|
{
|
|
|
|
id: "cancel_btn_dialog",
|
|
|
|
text: settings.cancelText
|
|
|
|
? settings.cancelText
|
|
|
|
: settings.strCancelButton,
|
|
|
|
class:
|
|
|
|
hideCancelButton +
|
|
|
|
"ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd submit-cancel",
|
|
|
|
click: function() {
|
|
|
|
if (typeof settings.notCloseOnDeny == "undefined") {
|
|
|
|
$(this).dialog("close");
|
|
|
|
$(this).remove();
|
|
|
|
}
|
|
|
|
if (typeof settings.onDeny == "function") settings.onDeny();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: settings.strOKButton,
|
|
|
|
class:
|
|
|
|
hideOkButton +
|
|
|
|
"ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next",
|
|
|
|
click: function() {
|
|
|
|
$(this).dialog("close");
|
|
|
|
if (typeof settings.onAccept == "function") settings.onAccept();
|
|
|
|
$(this).remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
if (settings.newButton != undefined) {
|
|
|
|
var newButton = {
|
|
|
|
text: settings.newButton.text,
|
|
|
|
class:
|
|
|
|
settings.newButton.class +
|
|
|
|
"ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-warning",
|
|
|
|
click: function() {
|
|
|
|
$(this).dialog("close");
|
|
|
|
if (typeof settings.newButton.onFunction == "function")
|
|
|
|
settings.newButton.onFunction();
|
|
|
|
$(this).remove();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
buttons.unshift(newButton);
|
|
|
|
}
|
|
|
|
|
2019-11-21 16:42:39 +01:00
|
|
|
$("#confirm_" + randomStr);
|
|
|
|
$("#confirm_" + randomStr)
|
|
|
|
.dialog({
|
2021-11-16 14:05:02 +01:00
|
|
|
open: settings.open,
|
2019-11-21 16:42:39 +01:00
|
|
|
title: settings.title,
|
|
|
|
close: false,
|
2020-06-30 12:16:51 +02:00
|
|
|
width: settings.size,
|
|
|
|
maxHeight: settings.maxHeight,
|
2019-11-21 16:42:39 +01:00
|
|
|
modal: true,
|
2022-01-31 13:45:44 +01:00
|
|
|
buttons: buttons
|
2019-11-21 16:42:39 +01:00
|
|
|
})
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to show modal with message Validation.
|
|
|
|
*
|
|
|
|
* @param {json} data Json example:
|
|
|
|
* $return = [
|
|
|
|
* 'error' => 0 or 1,
|
|
|
|
* 'title' => [
|
|
|
|
* Failed,
|
|
|
|
* Success,
|
|
|
|
* ],
|
|
|
|
* 'text' => [
|
|
|
|
* Failed,
|
|
|
|
* Success,
|
|
|
|
* ],
|
|
|
|
*];
|
|
|
|
* @param {string} idMsg ID div charge modal.
|
|
|
|
*
|
|
|
|
* @return {void}
|
|
|
|
*/
|
2020-01-21 08:37:30 +01:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
2019-11-21 16:42:39 +01:00
|
|
|
function generalShowMsg(data, idMsg) {
|
2022-02-22 17:29:17 +01:00
|
|
|
var title = data.title[data.error];
|
|
|
|
var text = data.text[data.error];
|
|
|
|
var failed = !data.error;
|
|
|
|
|
|
|
|
if (typeof data.error != "number") {
|
|
|
|
title = "Response";
|
|
|
|
text = data;
|
|
|
|
failed = false;
|
|
|
|
|
|
|
|
if (typeof data == "object") {
|
|
|
|
title = data.title || "Response";
|
|
|
|
text = data.text || data.error || data.result;
|
|
|
|
failed = data.failed || data.error;
|
|
|
|
}
|
2021-11-18 19:49:57 +01:00
|
|
|
|
2022-02-22 17:29:17 +01:00
|
|
|
if (failed) {
|
|
|
|
title = "Error";
|
|
|
|
text = data.error;
|
|
|
|
}
|
2021-11-18 19:49:57 +01:00
|
|
|
|
2022-02-22 17:29:17 +01:00
|
|
|
if (idMsg == null) {
|
|
|
|
idMsg = uniqId();
|
|
|
|
}
|
2021-11-18 19:49:57 +01:00
|
|
|
|
2022-02-22 17:29:17 +01:00
|
|
|
if ($("#" + idMsg).length === 0) {
|
|
|
|
$("body").append('<div title="' + title + '" id="' + idMsg + '"></div>');
|
|
|
|
$("#" + idMsg).empty();
|
|
|
|
}
|
2021-11-18 19:49:57 +01:00
|
|
|
}
|
2019-11-21 16:42:39 +01:00
|
|
|
|
|
|
|
$("#" + idMsg).empty();
|
|
|
|
$("#" + idMsg).html(text);
|
|
|
|
$("#" + idMsg).dialog({
|
|
|
|
width: 450,
|
|
|
|
position: {
|
|
|
|
my: "center",
|
|
|
|
at: "center",
|
|
|
|
of: window,
|
|
|
|
collision: "fit"
|
|
|
|
},
|
|
|
|
title: title,
|
|
|
|
buttons: [
|
|
|
|
{
|
|
|
|
class:
|
|
|
|
"ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next",
|
|
|
|
text: "OK",
|
2021-11-26 18:11:34 +01:00
|
|
|
id: "general_message_ok",
|
2019-11-21 16:42:39 +01:00
|
|
|
click: function(e) {
|
|
|
|
if (!failed) {
|
|
|
|
$(".ui-dialog-content").dialog("close");
|
|
|
|
} else {
|
|
|
|
$(this).dialog("close");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
2020-06-18 20:41:14 +02:00
|
|
|
|
|
|
|
function infoMessage(data, idMsg) {
|
|
|
|
var title = data.title;
|
2020-06-19 23:03:37 +02:00
|
|
|
var err_messge = data.text;
|
2021-07-05 20:56:40 +02:00
|
|
|
// False or null: Show all buttons and classic behaviour,
|
|
|
|
// if true, show an OK button and message from data.text.
|
|
|
|
var simple = data.simple;
|
2020-06-18 20:41:14 +02:00
|
|
|
|
|
|
|
if (idMsg == null) {
|
|
|
|
idMsg = uniqId();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($("#" + idMsg).length === 0) {
|
2020-06-19 23:03:37 +02:00
|
|
|
$("body").append('<div title="' + title + '" id="' + idMsg + '"></div>');
|
|
|
|
$("#" + idMsg).empty();
|
2020-06-18 20:41:14 +02:00
|
|
|
}
|
|
|
|
|
2020-06-19 23:03:37 +02:00
|
|
|
$("#err_msg").empty();
|
|
|
|
$("#err_msg").html("\n\n" + err_messge);
|
|
|
|
|
2021-07-05 20:56:40 +02:00
|
|
|
var buttons = [];
|
|
|
|
|
|
|
|
if (simple == null || simple == false) {
|
|
|
|
buttons = [
|
|
|
|
{
|
|
|
|
class:
|
|
|
|
"ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next",
|
|
|
|
text: "Retry",
|
|
|
|
click: function(e) {
|
|
|
|
handleConnection();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
class:
|
|
|
|
"ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-cancel",
|
|
|
|
text: "Close",
|
|
|
|
click: function() {
|
|
|
|
$(this).dialog("close");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
$("#" + idMsg).append($("#err_msg"));
|
|
|
|
buttons = [
|
|
|
|
{
|
|
|
|
class:
|
|
|
|
"ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next",
|
|
|
|
text: "Ok",
|
|
|
|
click: function(e) {
|
|
|
|
$("#" + idMsg).dialog("close");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-06-18 20:41:14 +02:00
|
|
|
$("#" + idMsg)
|
|
|
|
.dialog({
|
2020-06-19 23:03:37 +02:00
|
|
|
height: 250,
|
|
|
|
width: 528,
|
2020-06-18 20:41:14 +02:00
|
|
|
opacity: 1,
|
|
|
|
modal: true,
|
|
|
|
position: {
|
|
|
|
my: "center",
|
|
|
|
at: "center",
|
|
|
|
of: window,
|
|
|
|
collision: "fit"
|
|
|
|
},
|
|
|
|
title: data.title,
|
2021-07-05 20:56:40 +02:00
|
|
|
buttons: buttons,
|
2020-06-19 23:03:37 +02:00
|
|
|
|
2020-06-18 20:41:14 +02:00
|
|
|
open: function(event, ui) {
|
2020-06-19 23:03:37 +02:00
|
|
|
$(".ui-widget-overlay").addClass("error-modal-opened");
|
2020-06-18 20:41:14 +02:00
|
|
|
},
|
|
|
|
close: function(event, ui) {
|
2020-06-19 23:03:37 +02:00
|
|
|
$(".ui-widget-overlay").removeClass("error-modal-opened");
|
2020-06-18 20:41:14 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.show();
|
|
|
|
}
|
2020-09-29 09:44:20 +02:00
|
|
|
|
|
|
|
function reveal_password(name) {
|
|
|
|
var passwordElement = $("#password-" + name);
|
|
|
|
var revealElement = $("#reveal_password_" + name);
|
2020-09-29 12:21:52 +02:00
|
|
|
var imagesPath = "";
|
|
|
|
|
|
|
|
if ($("#hidden-metaconsole_activated").val() == 1) {
|
|
|
|
imagesPath = "../../images/";
|
|
|
|
} else {
|
|
|
|
imagesPath = "images/";
|
|
|
|
}
|
2020-09-29 09:44:20 +02:00
|
|
|
|
|
|
|
if (passwordElement.attr("type") == "password") {
|
|
|
|
passwordElement.attr("type", "text");
|
2020-09-29 12:21:52 +02:00
|
|
|
revealElement.attr("src", imagesPath + "eye_hide.png");
|
2020-09-29 09:44:20 +02:00
|
|
|
} else {
|
|
|
|
passwordElement.attr("type", "password");
|
2020-09-29 12:21:52 +02:00
|
|
|
revealElement.attr("src", imagesPath + "eye_show.png");
|
2020-09-29 09:44:20 +02:00
|
|
|
}
|
|
|
|
}
|