|
|
@ -9,7 +9,7 @@ async function alert2(msg){
|
|
|
|
return await dialog2(msg, "alert");
|
|
|
|
return await dialog2(msg, "alert");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function dialog2(msg, type){
|
|
|
|
async function dialog2(msg, type, buttons){
|
|
|
|
var dlgId = "dlg-" + uuid();
|
|
|
|
var dlgId = "dlg-" + uuid();
|
|
|
|
var resp = await fetch(wctx.url("/resources/html/dialog.html"));
|
|
|
|
var resp = await fetch(wctx.url("/resources/html/dialog.html"));
|
|
|
|
var template = await resp.text();
|
|
|
|
var template = await resp.text();
|
|
|
@ -18,12 +18,25 @@ async function dialog2(msg, type){
|
|
|
|
var backdropID = dlgId + "-backdrop";
|
|
|
|
var backdropID = dlgId + "-backdrop";
|
|
|
|
var tmpl = template.replace(/{id}/g, dlgId).replace(/{title}/g, "").replace(/{size}/, "").replace("","");
|
|
|
|
var tmpl = template.replace(/{id}/g, dlgId).replace(/{title}/g, "").replace(/{size}/, "").replace("","");
|
|
|
|
tmpl = tmpl.replace("data-bs-backdrop=\"static\"", "data-bs-backdrop=\"static\" data-bs-keyboard=\"false\"");
|
|
|
|
tmpl = tmpl.replace("data-bs-backdrop=\"static\"", "data-bs-backdrop=\"static\" data-bs-keyboard=\"false\"");
|
|
|
|
tmpl = tmpl.replace("text-end hidden","text-end");
|
|
|
|
tmpl = tmpl.replace("text-end hidden","text-end");
|
|
|
|
tmpl = tmpl.replace("btn-primary","btn-primary btn-ok");
|
|
|
|
tmpl = tmpl.replace("btn-primary","btn-primary btn-ok");
|
|
|
|
var dlg = $(tmpl).appendTo("body");
|
|
|
|
var dlg = $(tmpl).appendTo("body");
|
|
|
|
if(type == "confirm"){
|
|
|
|
if(type == "confirm" || type == "alert"){
|
|
|
|
dlg.find(".modal-footer").append('<button type="button" class="btn btn-primary btn-cancel">취소</button>');
|
|
|
|
if(type == "confirm"){
|
|
|
|
|
|
|
|
dlg.find(".modal-footer").append('<button type="button" class="btn btn-primary btn-cancel">취소</button>');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
dlg.find(".modal-footer").find(".btn-ok").remove();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(var i=0; i < buttons.length; i++){
|
|
|
|
|
|
|
|
dlg.find(".modal-footer").append(
|
|
|
|
|
|
|
|
'<button type="button" class="btn btn-primary btn-custom" data-key="'+buttons[i].key+'" >'
|
|
|
|
|
|
|
|
+buttons[i].value
|
|
|
|
|
|
|
|
+'</button>');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
dlg.find(".modal-header").remove();
|
|
|
|
dlg.find(".modal-header").remove();
|
|
|
|
dlg.find(".modal-body").html(content).fadeIn();
|
|
|
|
dlg.find(".modal-body").html(content).fadeIn();
|
|
|
|
dlg.on("hidden.bs.modal", function() {
|
|
|
|
dlg.on("hidden.bs.modal", function() {
|
|
|
@ -40,16 +53,26 @@ async function dialog2(msg, type){
|
|
|
|
setDialogZindex();
|
|
|
|
setDialogZindex();
|
|
|
|
|
|
|
|
|
|
|
|
return new Promise(resolve => {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
dlg[0].querySelector(".btn-ok").addEventListener("click", () => {
|
|
|
|
if(type == "confirm" || type == "alert"){
|
|
|
|
dlg.modal("hide");
|
|
|
|
dlg[0].querySelector(".btn-ok").addEventListener("click", () => {
|
|
|
|
resolve(true);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
if(type == "confirm"){
|
|
|
|
|
|
|
|
dlg[0].querySelector(".btn-cancel").addEventListener("click", () => {
|
|
|
|
|
|
|
|
dlg.modal("hide");
|
|
|
|
dlg.modal("hide");
|
|
|
|
resolve(false);
|
|
|
|
resolve(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
if(type == "confirm"){
|
|
|
|
|
|
|
|
dlg[0].querySelector(".btn-cancel").addEventListener("click", () => {
|
|
|
|
|
|
|
|
dlg.modal("hide");
|
|
|
|
|
|
|
|
resolve(false);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
dlg.find(".btn-custom").each(function(){
|
|
|
|
|
|
|
|
this.addEventListener("click", () => {
|
|
|
|
|
|
|
|
dlg.modal("hide");
|
|
|
|
|
|
|
|
resolve(this.dataset.key);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|