/** * BSDialog4 * @version v0.1.5.006 (2023/11/14 17:40) */ var BSDialog={Show:async function(e){const t=this,o=Object.assign(t.Options.ShowModal,e);if(t.id=o.ID,t.pfx="bsdia4_",t.body=document.getElementsByTagName("body")[0],t.addModal(o.ID,o.Title,o.Size,o.ShowFooter,o.Colour),$("#"+t.pfx+o.ID).modal({backdrop:o.EasyClose,show:!0}),null==o.URL)await t.Update({ID:o.ID,Body:o.Message});else if(t.isNullOrWhitespace(o.URL))await t.Update({ID:o.ID,Body:o.URL});else if(o.URL.startsWith("http://")||o.URL.startsWith("https://")||o.URL.startsWith("/")){let e=await t.retrieveURL(o.URL);await t.Update({ID:o.ID,Body:e})}else await t.Update({ID:o.ID,Body:o.URL})},Prompt:async function(e){const t=this;let o=Math.floor(1e4*Math.random())+1e3;const l=Object.assign(t.Options.ShowPrompt,e);return"textbox"===l.Type?await t.showTextboxPrompt(o,l):await t.showButtonPrompt(o,l)},Clear:function(){this.body.querySelectorAll(".modal").forEach((function(e){e.parentNode.removeChild(e)})),this.removeBackdrop()},Close:function(e){let t=this.Find(e);null!==t&&(t.Modal.parentNode.removeChild(t.Modal),t=this.Find(e),null===t&&this.removeBackdrop())},Update:async function(e){const t=this;let o=Object.assign(t.Options.UpdateModal,e);const l=t.Find(o.ID);if(null!==l){if(this.isNullOrWhitespace(o.Title)||(l.Title.innerHTML=o.Title),this.isNullOrWhitespace(o.Body)||t.html(l.Body,o.Body),this.isNullOrWhitespace(o.BodyURL)||o.BodyURL.startsWith("http://")||o.BodyURL.startsWith("https://")||o.BodyURL.startsWith("/")||(o.BodyURL=null),!this.isNullOrWhitespace(o.BodyURL)){let e=await t.retrieveURL(o.BodyURL);await t.Update({ID:o.ID,Body:e})}this.isNullOrWhitespace(o.Footer)||t.html(l.Footer,o.Footer),this.isNullOrWhitespace(o.Size)||l.Modal.querySelectorAll(".modal-dialog").forEach((function(e){e.classList.forEach((function(t){"modal-dialog"!=t&&t.startsWith("modal-")&&e.classList.remove(t)})),e.classList.add("modal-"+o.Size)}))}},Exists:function(e){return null!==this.Find(e)},Find:function(e){const t=this.body.querySelectorAll("#"+this.pfx+e+".modal");return t?t.length<=0?null:{Title:t[0].querySelectorAll(".modal-title")[0],Header:t[0].querySelectorAll(".modal-header")[0],Body:t[0].querySelectorAll(".modal-body")[0],Footer:t[0].querySelectorAll(".modal-footer")[0],Close:t[0].querySelectorAll("[data-dismiss='modal']"),Modal:t[0]}:null},Options:{ShowModal:{ID:null,Title:"",Message:"",URL:null,Size:"md",Colour:"secondary",ShowFooter:!0,EasyClose:!0},ShowPrompt:{Type:"button",Title:"",Message:"",Size:"md",EasyClose:!0,Buttons:[{Label:"Yes",Value:"Yes",Colour:"primary"},{Label:"No",Value:"No",Colour:"secondary"},{Label:"Cancel",Value:"Cancel",Colour:"secondary"}],Textbox:{Label:"",LabelSize:4,Placeholder:"",Value:"",BoxSize:8}},UpdateModal:{ID:null,Title:null,Body:null,BodyURL:null,Footer:null,Size:null}},addModal:function(e,t,o,l,a){const s=this;let i=s.Find(e);if(null!==i)return;let n="";n+='
",s.appendHtml(s.body,n),i=s.Find(e),null!==i&&($("#"+s.pfx+e).on("hidden.bs.modal",(function(t){s.Close(e)})),i.Title.addEventListener("dblclick",(function(e){e.stopPropagation(),e.preventDefault(),s.toggleSize()})))},showButtonPrompt:async function(e,t){const o=this;return await new Promise((async(l,a)=>{await o.Show({ID:e,Title:t.Title,Message:t.Message,Size:t.Size,EasyClose:t.EasyClose});let s="";t.Buttons.forEach((function(e){s+='"})),o.Update({ID:e,Footer:s});const i=o.Find(e);i.Footer.querySelectorAll("button").forEach((function(t){t.addEventListener("click",(function(a){a.stopPropagation(),a.preventDefault();const s=t.getAttribute("data-prompt-value");o.Close(e),l(s)}))})),i.Close.forEach((function(t){t.addEventListener("click",(function(t){t.stopPropagation(),t.preventDefault(),o.Close(e),l("")}))}))}))},showTextboxPrompt:async function(e,t){const o=this;return await new Promise((async(l,a)=>{t.Buttons=[{Label:"OK",Value:"",Colour:"primary"},{Label:"Cancel",Value:"",Colour:"secondary"}],await o.Show({ID:e,Title:t.Title,Message:t.Message,Size:t.Size,EasyClose:t.EasyClose});let s="";o.isNullOrWhitespace(t.Message)||(s+=""+t.Message+"
"),s+='