커스텀 버튼 다이얼로그 추가

main
이범준 8 months ago
parent 5a487640ce
commit 7e35b56842

@ -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();
@ -21,9 +21,22 @@ async function dialog2(msg, type){
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" || type == "alert"){
if(type == "confirm"){ if(type == "confirm"){
dlg.find(".modal-footer").append('<button type="button" class="btn btn-primary btn-cancel">취소</button>'); 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,6 +53,7 @@ async function dialog2(msg, type){
setDialogZindex(); setDialogZindex();
return new Promise(resolve => { return new Promise(resolve => {
if(type == "confirm" || type == "alert"){
dlg[0].querySelector(".btn-ok").addEventListener("click", () => { dlg[0].querySelector(".btn-ok").addEventListener("click", () => {
dlg.modal("hide"); dlg.modal("hide");
resolve(true); resolve(true);
@ -50,6 +64,15 @@ async function dialog2(msg, type){
resolve(false); resolve(false);
}); });
} }
} else {
dlg.find(".btn-custom").each(function(){
this.addEventListener("click", () => {
dlg.modal("hide");
resolve(this.dataset.key);
});
});
}
}); });
} }

Loading…
Cancel
Save