2023-08-30 13:26:40 +00:00
|
|
|
var BSDialog={Show:async function(t){const e=this,o=Object.assign(e.Default().ShowOptions,t);if(e.id=o.ID,e.pfx="bsdia4_",e.body=document.getElementsByTagName("body")[0],e.addBackdrop(),e.addModal(o.ID,o.Title,o.Size,!0,o.Colour),null==o.URL)await e.Update({ID:o.ID,Body:o.Message});else if(e.isNullOrWhitespace(o.URL))await e.Update({ID:o.ID,Body:o.URL});else if(o.URL.startsWith("http://")||o.URL.startsWith("https://")||o.URL.startsWith("/")){let t=await e.retrieveURL(o.URL);await e.Update({ID:o.ID,Body:t})}else await e.Update({ID:o.ID,Body:o.URL})},Prompt:async function(t){const e=this;let o=Math.floor(1e4*Math.random())+1e3;const l=Object.assign(e.Default().PromptOptions,t);return"textbox"===l.Type?await e.showTextboxPrompt(o,l):await e.showButtonPrompt(o,l)},Clear:function(){this.body.querySelectorAll(".modal").forEach((function(t){t.parentNode.removeChild(t)})),this.removeBackdrop()},Close:function(t){let e=this.Find(t);null!==e&&(e.Modal.forEach((function(t){t.parentNode.removeChild(t)})),e=this.Find(t),null===e&&this.removeBackdrop())},Update:async function(t){const e=this;let o=Object.assign(e.Default().UpdateOptions,t);const l=e.Find(o.ID);if(null!==l){if(this.isNullOrWhitespace(o.Title)||l.Title.forEach((function(t){t.innerHTML=o.Title})),this.isNullOrWhitespace(o.Body)||l.Body.forEach((function(t){e.html(t,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 t=await e.retrieveURL(o.BodyURL);await e.Update({ID:o.ID,Body:t})}this.isNullOrWhitespace(o.Footer)||l.Footer.forEach((function(t){e.html(t,o.Footer)})),this.isNullOrWhitespace(o.Size)||l.Modal[0].querySelectorAll(".modal-dialog").forEach((function(t){t.classList.forEach((function(e){"modal-dialog"!=e&&e.startsWith("modal-")&&t.classList.remove(e)})),t.classList.add("modal-"+o.Size)}))}},Exists:function(t){return null!==this.Find(t)},Find:function(t){const e=this.body.querySelectorAll("#"+this.pfx+t+".modal");return e?e.length<=0?null:{Title:e[0].querySelectorAll(".modal-title"),Body:e[0].querySelectorAll(".modal-body"),Footer:e[0].querySelectorAll(".modal-footer"),Close:e[0].querySelectorAll("[data-dismiss='modal']"),Modal:e}:null},Default:function(){return{ShowOptions:{ID:null,Title:"",Message:"",URL:null,Size:"md",Colour:"secondary",ShowFooter:!0},PromptOptions:{Type:"button",Title:"",Message:"",Size:"md",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}},ToastOptions:{ID:null,Title:"",Message:"",Size:"md"},UpdateOptions:{ID:null,Title:null,Body:null,BodyURL:null,Footer:null,Size:null}}},addBackdrop:function(){let t=this;t.body.querySelectorAll(".modal-backdrop").length>0||(t.appendHtml(t.body,'<div class="modal-backdrop fade show"></div>'),t.body.classList.add("modal-open"),t.body.style.overflow="hidden",t.body.querySelectorAll(".modal-backdrop")[0].addEventListener("click",(function(e){e.stopPropagation(),e.preventDefault(),t.Clear()})))},addModal:function(t,e,o,l,a){var i=this;let n=i.Find(t);if(null!==n)return;let s="";s+='<div class="modal fade show d-block" id="'+i.pfx+t+'" tabindex="-1">',s+=' <div class="modal-dialog modal-'+o+'">',s+=' <div class="modal-content">',s+=' <div class="modal-header">',s+=' <span class="modal-title font-weight-bold">'+e+"</span>",s+=' <button type="button" class="close" data-dismiss="modal" aria-label="Close">',s+=' <span aria-hidden="true">×</span>',s+=" </button>",s+=" </div>",s+=' <div class="modal-body">',s+='<div class="row mt-3 pb-3">',s+=' <div class="col-12 text-center">',s+=' <div class="spinner-border" role="status">',s+='\t <span class="sr-only">Loading...</span>',s+=" </div>",s+=" </div>",s+="</div>",s+=" </div>",!0===l&&(s+=' <div class="modal-footer">',s+=' <button type="button" class="btn btn-'+a+'" data-dismiss="modal
|