define(function(require){var DecorillaApp=require("DecorillaApp");var DecorillaView=require("DecorillaView");var modalTemplate=require("text!templates/bootstrap-modal.html");var Modal=DecorillaView.extend({$el:null,modalTemplate:null,defaults:{modalId:"myModal",title:"",subtitle:"",modalClass:"",modalOverflow:!1,contentId:"",content:"",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:null,onHidden:null,onShown:null,preventHide:!1,preventHideExceptOnX:!1,destroyOnHide:!0},options:null,initialize:function Modal_initialize(options){this.options=$.extend({},this.defaults,options||{});this.modalTemplate=_.template(modalTemplate);var i;for(i=0;i"+button.label+""}else{footerContent=footerContent+button.rawHtml}} this.options.footerContent=footerContent;this.show()},show:function Modal_show(){var dialogHtml;if(this.options.contentId){var 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,modalOverflow:this.options.modalOverflow,footerContent:this.options.footerContent,content:""});var modalClassList=$(dialogHtml).attr('class');$(selector).addClass(modalClassList);var content=$(selector).children().detach();$(selector).append($(dialogHtml).children());$(selector).find('.modal-body p').append(content);$(selector).removeClass('hidden').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,modalOverflow:this.options.modalOverflow,content:this.options.content,footerContent:this.options.footerContent});this.$el=$(dialogHtml)} if(this.options.remoteUrl){this.$el.one("shown",$.proxy(function(){this.$el.find('.modal-body').html("loading...").load(this.options.remoteUrl,$.proxy(function(){this.$el.trigger('loaded')},this))},this))} var modalOptions={};if(this.options.preventHideExceptOnX){modalOptions={backdrop:'static',}} this.$el.modal(modalOptions);for(var i=0;i