2023-08-03 10:55:53 +00:00
|
|
|
/**
|
|
|
|
* BSDialog
|
2023-08-03 10:56:18 +00:00
|
|
|
* @version v0.1.0.024 (2019/07/05 2210)
|
2023-08-03 10:55:53 +00:00
|
|
|
*/
|
|
|
|
var BSDialog = {
|
2023-08-03 10:56:18 +00:00
|
|
|
Create: function(id, title, url, is_big, update_body) {
|
|
|
|
var a = this;
|
|
|
|
var isBig = ((typeof(is_big) == "undefined") ? false : (is_big == true) ? true : false);
|
|
|
|
var updateBody = ((typeof(update_body) == "undefined") ? false : (update_body == true) ? true : false);
|
2023-08-03 10:55:53 +00:00
|
|
|
|
2023-08-03 10:56:18 +00:00
|
|
|
if (!a.hasDialog(id)) {
|
|
|
|
var html = a.generateModalHtml(id, title, null, isBig);
|
2023-08-03 10:55:53 +00:00
|
|
|
|
2023-08-03 10:56:18 +00:00
|
|
|
$("body").append(html);
|
|
|
|
}
|
2023-08-03 10:55:53 +00:00
|
|
|
|
2023-08-03 10:56:18 +00:00
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
cache: false,
|
|
|
|
timeout: 10000,
|
|
|
|
success: function(result, status, xhr){
|
|
|
|
if ((xhr.status == 200) || (xhr.status == 302) || (xhr.status == 301))
|
|
|
|
{
|
|
|
|
if (updateBody)
|
|
|
|
{
|
|
|
|
a.updateContentBody(id, result);
|
|
|
|
} else {
|
|
|
|
$("#dlg" + id).find(".modal-content").html(result);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
a.updateContentBody(id, xhr.statusText + " (" + xhr.status + ")");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function(xhr){
|
|
|
|
a.updateContentBody(id, xhr.statusText + " (" + xhr.status + ")");
|
|
|
|
},
|
|
|
|
complete: function(xhr, status){
|
|
|
|
// do nothing yet
|
2023-08-03 10:55:53 +00:00
|
|
|
}
|
2023-08-03 10:56:18 +00:00
|
|
|
});
|
2023-08-03 10:55:53 +00:00
|
|
|
|
2023-08-03 10:56:18 +00:00
|
|
|
a.show(id);
|
|
|
|
},
|
|
|
|
Close: function(id) {
|
|
|
|
if (!this.hasDialog(id)) return;
|
|
|
|
|
|
|
|
$("#dlg" + id).modal('hide');
|
2023-08-03 10:55:53 +00:00
|
|
|
},
|
2023-08-03 10:56:18 +00:00
|
|
|
Clear: function() {
|
2023-08-03 10:55:53 +00:00
|
|
|
$("body > div[class~='modal'][role='dialog']").remove();
|
|
|
|
$("body > div[class~='modal-backdrop']").remove();
|
|
|
|
$("body").removeClass("modal-open");
|
|
|
|
},
|
2023-08-03 10:56:18 +00:00
|
|
|
ShowToast: function(id, title, message, is_big) {
|
|
|
|
if (this.hasDialog(id)) return;
|
|
|
|
|
|
|
|
var html = this.generateModalHtml(id, title, message, is_big);
|
|
|
|
$("body").append(html);
|
|
|
|
|
|
|
|
this.show(id);
|
|
|
|
},
|
|
|
|
hasDialog: function(id) {
|
|
|
|
return ($("body > div[id='dlg" + id + "']").length > 0);
|
|
|
|
},
|
|
|
|
generateModalHtml: function(id, title, message, is_big) {
|
|
|
|
var size = ((typeof(is_big) == "undefined") ? "sm" : (is_big == true ? "lg" : "sm"));
|
|
|
|
|
2023-08-03 10:55:53 +00:00
|
|
|
var html = "";
|
2023-08-03 10:56:18 +00:00
|
|
|
html += "<div class=\"modal fade\" id=\"dlg" + id + "\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"dlg" + id + "Label\" aria-hidden=\"true\">";
|
|
|
|
html += " <div class=\"modal-dialog modal-" + size + "\">";
|
2023-08-03 10:55:53 +00:00
|
|
|
html += " <div class=\"modal-content\">";
|
|
|
|
html += " <div class=\"modal-header\">";
|
|
|
|
html += " <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"true\">×</button>";
|
2023-08-03 10:56:18 +00:00
|
|
|
html += " <strong class=\"modal-title\">" + title + "</strong>";
|
2023-08-03 10:55:53 +00:00
|
|
|
html += " </div>";
|
2023-08-03 10:56:18 +00:00
|
|
|
|
|
|
|
if ($.trim(message).length <= 0)
|
|
|
|
{
|
|
|
|
html += " <div class=\"modal-body custom-loading\"></div>";
|
|
|
|
} else {
|
|
|
|
html += " <div class=\"modal-body\">" + message + "</div>";
|
|
|
|
}
|
|
|
|
|
2023-08-03 10:55:53 +00:00
|
|
|
html += " <div class=\"modal-footer\">";
|
|
|
|
html += " <button type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\">Close</button>";
|
|
|
|
html += " </div>";
|
|
|
|
html += " </div>";
|
|
|
|
html += " </div>";
|
|
|
|
html += "</div>";
|
2023-08-03 10:56:18 +00:00
|
|
|
|
|
|
|
return html;
|
|
|
|
},
|
|
|
|
show: function(id) {
|
|
|
|
$("#dlg" + id).modal('show');
|
|
|
|
$("#dlg" + id).off('hide.bs.modal');
|
|
|
|
$("#dlg" + id).on('hide.bs.modal', function() {
|
|
|
|
if ($("body > div[id='dlg" + id + "']").next().is("div[class~='modal-backdrop']")) {
|
|
|
|
$("body > div[id='dlg" + id + "']").next().remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
$("body > div[id='dlg" + id + "']").remove();
|
|
|
|
|
2023-08-03 10:55:53 +00:00
|
|
|
});
|
2023-08-03 10:56:18 +00:00
|
|
|
},
|
|
|
|
updateContentBody: function(id, text) {
|
|
|
|
var body = $("#dlg" + id).find(".modal-body");
|
|
|
|
|
|
|
|
if ($(body).hasClass("custom-loading")) $(body).removeClass("custom-loading");
|
|
|
|
|
|
|
|
$(body).html(text);
|
2023-08-03 10:55:53 +00:00
|
|
|
}
|
2023-08-03 10:56:18 +00:00
|
|
|
};
|