define(function(require){let DecorillaView=require("DecorillaView");let modalTemplate=require("text!templates/bootstrap-modal-upgraded-ren.html");let vaModalTemplate=require("text!templates/bootstrap-modal-upgraded-va-ren.html");return DecorillaView.extend({$el:null,modalTemplate:null,defaults:{modalId:"myModal",verticalAlign:!1,title:"",subtitle:"",modalClass:"",modalDialogClass:"",modalOverflow:!1,footerPadding:!1,contentId:"",content:"",appendContentToModalInnerCont:!1,buttons:[{id:"okBtn",label:"Ok",className:"ok-btn btn-primary",onClick:function(){this.$el.modal("hide")}},{id:"cancelBtn",label:"Cancel",className:"cancel-btn",onClick:function(){this.$el.modal("hide")}}],remoteUrl:null,footerContent:'',onHidden:null,onShown:null,preventHide:!1,preventHideExceptOnX:!1,showOnCreate:!0,initialiseOnCreate:!1,destroyOnHide:!0},options:null,initialize:function Modal_initialize(options){this.options=$.extend({},this.defaults,options||{});if(this.options.verticalAlign){this.modalTemplate=_.template(vaModalTemplate)}else{this.modalTemplate=_.template(modalTemplate)} if(this.options.footerPadding){this.options.modalClass=this.options.modalClass+' with-footer-padding'} let i,button;for(i=0;i"+button.label+""}else{footerContent=footerContent+button.rawHtml}} this.options.footerContent=footerContent+this.options.footerContent;if(this.options.initialiseOnCreate===!0){this.initialise()} if(this.options.showOnCreate===!0){this.show()}},initialise:function(){let dialogHtml;if(this.options.contentId){let selector='#'+this.options.contentId;if(!$(selector).hasClass('modal-initialised')){dialogHtml=this.modalTemplate({modalId:this.options.modalId,title:this.options.title,subtitle:this.options.subtitle,modalClass:this.options.modalClass,modalDialogClass:this.options.modalDialogClass,modalOverflow:this.options.modalOverflow,footerContent:this.options.footerContent,content:""});let modalClassList=$(dialogHtml).attr('class');$(selector).addClass(modalClassList);let content=$(selector).children().detach();$(selector).append($(dialogHtml).children());if(this.options.appendContentToModalInnerCont){$(selector).find('.modal-body p').hide();$(selector).find('.modal-body .modal-inner-cont').append(content)}else{$(selector).find('.modal-body p').append(content)} $(selector).removeClass('hidden hide').addClass('modal-initialised')} this.$el=$(selector)}else{dialogHtml=this.modalTemplate({modalId:this.options.modalId,title:this.options.title,subtitle:this.options.subtitle,modalClass:this.options.modalClass,modalDialogClass:this.options.modalDialogClass,modalOverflow:this.options.modalOverflow,content:this.options.content,footerContent:this.options.footerContent});this.$el=$(dialogHtml)}},show:function Modal_show(){this.initialise();if(this.options.remoteUrl){this.$el.one("shown.bs.modal",$.proxy(function(){this.$el.find('.modal-body').html("loading...").load(this.options.remoteUrl,$.proxy(function(){this.$el.trigger('loaded');this.$el.trigger('modalContentLoaded')},this))},this))} let modalOptions={};if(this.options.preventHideExceptOnX){modalOptions={backdrop:'static'}} this.$el.modal(modalOptions);for(let i=0;i