7 * @class Roo.bootstrap.Modal
8 * @extends Roo.bootstrap.Component
9 * Bootstrap Modal class
10 * @cfg {String} title Title of dialog
11 * @cfg {String} html - the body of the dialog (for simple ones) - you can also use template..
12 * @cfg {Roo.Template} tmpl - a template with variables. to use it, add a handler in show:method adn
13 * @cfg {Boolean} specificTitle default false
14 * @cfg {Array} buttons Array of buttons or standard button set..
15 * @cfg {String} buttonPosition (left|right|center) default right
16 * @cfg {Boolean} animate default true
17 * @cfg {Boolean} allow_close default true
18 * @cfg {Boolean} fitwindow default true
22 * Create a new Modal Dialog
23 * @param {Object} config The config object
26 Roo.bootstrap.Modal = function(config){
27 Roo.bootstrap.Modal.superclass.constructor.call(this, config);
32 * The raw btnclick event for the button
33 * @param {Roo.EventObject} e
37 this.buttons = this.buttons || [];
40 this.tmpl = Roo.factory(this.tmpl);
45 Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component, {
47 title : 'test dialog',
59 buttonPosition: 'right',
76 onRender : function(ct, position)
78 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
81 var cfg = Roo.apply({}, this.getAutoCreate());
84 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
86 //if (!cfg.name.length) {
90 cfg.cls += ' ' + this.cls;
93 cfg.style = this.style;
95 this.el = Roo.get(document.body).createChild(cfg, position);
97 //var type = this.el.dom.type;
100 if(this.tabIndex !== undefined){
101 this.el.dom.setAttribute('tabIndex', this.tabIndex);
104 this.dialogEl = this.el.select('.modal-dialog',true).first();
105 this.bodyEl = this.el.select('.modal-body',true).first();
106 this.closeEl = this.el.select('.modal-header .close', true).first();
107 this.footerEl = this.el.select('.modal-footer',true).first();
108 this.titleEl = this.el.select('.modal-title',true).first();
112 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
113 this.maskEl.enableDisplayMode("block");
115 //this.el.addClass("x-dlg-modal");
117 if (this.buttons.length) {
118 Roo.each(this.buttons, function(bb) {
119 var b = Roo.apply({}, bb);
120 b.xns = b.xns || Roo.bootstrap;
121 b.xtype = b.xtype || 'Button';
122 if (typeof(b.listeners) == 'undefined') {
123 b.listeners = { click : this.onButtonClick.createDelegate(this) };
126 var btn = Roo.factory(b);
128 btn.render(this.el.select('.modal-footer div').first());
132 // render the children.
135 if(typeof(this.items) != 'undefined'){
136 var items = this.items;
139 for(var i =0;i < items.length;i++) {
140 nitems.push(this.addxtype(Roo.apply({}, items[i])));
146 // where are these used - they used to be body/close/footer
150 //this.el.addClass([this.fieldClass, this.cls]);
154 getAutoCreate : function(){
159 html : this.html || ''
168 if(this.specificTitle){
174 if (this.allow_close) {
185 style : 'display: none',
191 cls : "modal-content",
194 cls : 'modal-header',
199 cls : 'modal-footer',
203 cls: 'btn-' + this.buttonPosition
220 modal.cls += ' fade';
226 getChildContainer : function() {
231 getButtonContainer : function() {
232 return this.el.select('.modal-footer div',true).first();
235 initEvents : function()
237 if (this.allow_close) {
238 this.closeEl.on('click', this.hide, this);
242 window.addEventListener("resize", this.resize , this );
248 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
251 setSize : function(w,h)
258 if (!this.rendered) {
262 this.el.setStyle('display', 'block');
264 if(this.animate){ // element has 'fade' - so stuff happens after .3s ?- not sure why the delay?
267 this.el.addClass('in');
270 this.el.addClass('in');
274 // not sure how we can show data in here..
276 // this.getChildContainer().dom.innerHTML = this.tmpl.applyTemplate(this);
279 Roo.get(document.body).addClass("x-body-masked");
280 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
282 this.el.setStyle('zIndex', '10001');
284 this.fireEvent('show', this);
285 this.items.forEach(function(e) {
286 e.layout ? e.layout() : false;
296 Roo.get(document.body).removeClass("x-body-masked");
297 this.el.removeClass('in');
298 this.el.select('.modal-dialog', true).first().setStyle('transform','');
300 if(this.animate){ // why
302 (function(){ _this.el.setStyle('display', 'none'); }).defer(150);
304 this.el.setStyle('display', 'none');
307 this.fireEvent('hide', this);
310 addButton : function(str, cb)
314 var b = Roo.apply({}, { html : str } );
315 b.xns = b.xns || Roo.bootstrap;
316 b.xtype = b.xtype || 'Button';
317 if (typeof(b.listeners) == 'undefined') {
318 b.listeners = { click : cb.createDelegate(this) };
321 var btn = Roo.factory(b);
323 btn.render(this.el.select('.modal-footer div').first());
329 setDefaultButton : function(btn)
331 //this.el.select('.modal-footer').()
335 resizeTo: function(w,h)
339 this.dialogEl.setWidth(w);
340 if (this.diff === false) {
341 this.diff = this.dialogEl.getHeight() - this.el.select('.modal-body',true).first().getHeight();
344 this.el.select('.modal-body',true).first().setHeight(h-this.diff);
348 setContentSize : function(w, h)
352 onButtonClick: function(btn,e)
355 this.fireEvent('btnclick', btn.name, e);
358 * Set the title of the Dialog
359 * @param {String} str new Title
361 setTitle: function(str) {
362 this.titleEl.dom.innerHTML = str;
365 * Set the body of the Dialog
366 * @param {String} str new Title
368 setBody: function(str) {
369 this.bodyEl.dom.innerHTML = str;
372 * Set the body of the Dialog using the template
373 * @param {Obj} data - apply this data to the template and replace the body contents.
375 applyBody: function(obj)
378 Roo.log("Error - using apply Body without a template");
381 this.tmpl.overwrite(this.bodyEl, obj);
387 Roo.apply(Roo.bootstrap.Modal, {
389 * Button config that displays a single OK button
398 * Button config that displays Yes and No buttons
414 * Button config that displays OK and Cancel buttons
429 * Button config that displays Yes, No and Cancel buttons