2023-11-04 02:46:04 +00:00
|
|
|
var BSDialog={Show:async function(options){const a=this,_options=Object.assign(a.Options.ShowModal,options);if(a.id=_options.ID,a.pfx="bsdia4_",a.body=document.getElementsByTagName("body")[0],a.addBackdrop(),a.addModal(_options.ID,_options.Title,_options.Size,_options.ShowFooter,_options.EasyClose,_options.Colour),null==_options.URL)await a.Update({ID:_options.ID,Body:_options.Message});else if(a.isNullOrWhitespace(_options.URL))await a.Update({ID:_options.ID,Body:_options.URL});else if(_options.URL.startsWith("http://")||_options.URL.startsWith("https://")||_options.URL.startsWith("/")){let response=await a.retrieveURL(_options.URL);await a.Update({ID:_options.ID,Body:response})}else await a.Update({ID:_options.ID,Body:_options.URL})},Prompt:async function(options){const a=this;let id=Math.floor(1e4*Math.random())+1e3;const _options=Object.assign(a.Options.ShowPrompt,options);switch(_options.Type){case"textbox":return await a.showTextboxPrompt(id,_options);case"button":default:return await a.showButtonPrompt(id,_options)}},Clear:function(){this.body.querySelectorAll(".modal").forEach((function(e){e.parentNode.removeChild(e)})),this.removeBackdrop()},Close:function(id){let modal=this.Find(id);null!==modal&&(modal.Modal.parentNode.removeChild(modal.Modal),modal=this.Find(id),null===modal&&this.removeBackdrop())},Update:async function(options){const a=this;let _options=Object.assign(a.Options.UpdateModal,options);const modal=a.Find(_options.ID);if(null!==modal){if(this.isNullOrWhitespace(_options.Title)||(modal.Title.innerHTML=_options.Title),this.isNullOrWhitespace(_options.Body)||a.html(modal.Body,_options.Body),this.isNullOrWhitespace(_options.BodyURL)||_options.BodyURL.startsWith("http://")||_options.BodyURL.startsWith("https://")||_options.BodyURL.startsWith("/")||(_options.BodyURL=null),!this.isNullOrWhitespace(_options.BodyURL)){let response=await a.retrieveURL(_options.BodyURL);await a.Update({ID:_options.ID,Body:response})}this.isNullOrWhitespace(_options.Footer)||a.html(modal.Footer,_options.Footer),this.isNullOrWhitespace(_options.Size)||modal.Modal.querySelectorAll(".modal-dialog").forEach((function(e){e.classList.forEach((function(e2){"modal-dialog"!=e2&&e2.startsWith("modal-")&&e.classList.remove(e2)})),e.classList.add("modal-"+_options.Size)}))}},Exists:function(id){return null!==this.Find(id)},Find:function(id){const a=this,modal=a.body.querySelectorAll("#"+a.pfx+id+".modal");return modal?modal.length<=0?null:{Title:modal[0].querySelectorAll(".modal-title")[0],Header:modal[0].querySelectorAll(".modal-header")[0],Body:modal[0].querySelectorAll(".modal-body")[0],Footer:modal[0].querySelectorAll(".modal-footer")[0],Close:modal[0].querySelectorAll("[data-dismiss='modal']"),Modal:modal[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},ShowToast:{ID:null,Title:"",Message:"",Size:"md"}},addBackdrop:function(){const a=this;a.body.querySelectorAll(".modal-backdrop").length>0||(a.appendHtml(a.body,'<div class="modal-backdrop fade show"></div>'),a.body.classList.add("modal-open"),a.body.style.overflow="hidden")},addModal:function(id,title,size,showFooter,easyClose,closeColour){const a=this;let modal=a.Find(id);if(null!==modal)return;let html="";if(html+='<div class="modal fade show d-block" id="'+a.pfx+id+'" tabindex="-1">',html+=' <div class="modal-dialog modal-'+size+'">',html+=' <div class="modal-content">',html+=' <div class="modal-header">',html+=' <span class="modal-title font-weight-bold" style="cursor: default; user-select: none;" aria-label="Title">'+title+"</span>",html+=' <button type="button" class="close" data-dismiss="modal" aria-label="Close" style="user
|