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

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

@ -9,7 +9,7 @@ async function alert2(msg){
return await dialog2(msg, "alert");
}
async function dialog2(msg, type){
async function dialog2(msg, type, buttons){
var dlgId = "dlg-" + uuid();
var resp = await fetch(wctx.url("/resources/html/dialog.html"));
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("btn-primary","btn-primary btn-ok");
var dlg = $(tmpl).appendTo("body");
if(type == "confirm" || type == "alert"){
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-body").html(content).fadeIn();
dlg.on("hidden.bs.modal", function() {
@ -40,6 +53,7 @@ async function dialog2(msg, type){
setDialogZindex();
return new Promise(resolve => {
if(type == "confirm" || type == "alert"){
dlg[0].querySelector(".btn-ok").addEventListener("click", () => {
dlg.modal("hide");
resolve(true);
@ -50,6 +64,15 @@ async function dialog2(msg, type){
resolve(false);
});
}
} else {
dlg.find(".btn-custom").each(function(){
this.addEventListener("click", () => {
dlg.modal("hide");
resolve(this.dataset.key);
});
});
}
});
}

Loading…
Cancel
Save