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 false
19 * @cfg {String} size (sm|lg) default empty
23 * Create a new Modal Dialog
24 * @param {Object} config The config object
27 Roo.bootstrap.Modal = function(config){
28 Roo.bootstrap.Modal.superclass.constructor.call(this, config);
33 * The raw btnclick event for the button
34 * @param {Roo.EventObject} e
39 * Fire when dialog resize
40 * @param {Roo.bootstrap.Modal} this
41 * @param {Roo.EventObject} e
45 this.buttons = this.buttons || [];
48 this.tmpl = Roo.factory(this.tmpl);
53 Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component, {
55 title : 'test dialog',
67 buttonPosition: 'right',
86 onRender : function(ct, position)
88 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
91 var cfg = Roo.apply({}, this.getAutoCreate());
94 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
96 //if (!cfg.name.length) {
100 cfg.cls += ' ' + this.cls;
103 cfg.style = this.style;
105 this.el = Roo.get(document.body).createChild(cfg, position);
107 //var type = this.el.dom.type;
110 if(this.tabIndex !== undefined){
111 this.el.dom.setAttribute('tabIndex', this.tabIndex);
114 this.dialogEl = this.el.select('.modal-dialog',true).first();
115 this.bodyEl = this.el.select('.modal-body',true).first();
116 this.closeEl = this.el.select('.modal-header .close', true).first();
117 this.headerEl = this.el.select('.modal-header',true).first();
118 this.titleEl = this.el.select('.modal-title',true).first();
119 this.footerEl = this.el.select('.modal-footer',true).first();
121 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
123 //this.el.addClass("x-dlg-modal");
125 if (this.buttons.length) {
126 Roo.each(this.buttons, function(bb) {
127 var b = Roo.apply({}, bb);
128 b.xns = b.xns || Roo.bootstrap;
129 b.xtype = b.xtype || 'Button';
130 if (typeof(b.listeners) == 'undefined') {
131 b.listeners = { click : this.onButtonClick.createDelegate(this) };
134 var btn = Roo.factory(b);
136 btn.render(this.el.select('.modal-footer div').first());
140 // render the children.
143 if(typeof(this.items) != 'undefined'){
144 var items = this.items;
147 for(var i =0;i < items.length;i++) {
148 nitems.push(this.addxtype(Roo.apply({}, items[i])));
154 // where are these used - they used to be body/close/footer
158 //this.el.addClass([this.fieldClass, this.cls]);
162 getAutoCreate : function()
166 html : this.html || ''
175 if(this.specificTitle){
181 if (this.allow_close) {
193 if(this.size.length){
194 size = 'modal-' + this.size;
201 cls: "modal-dialog " + size,
204 cls : "modal-content",
207 cls : 'modal-header',
212 cls : 'modal-footer',
216 cls: 'btn-' + this.buttonPosition
233 modal.cls += ' fade';
239 getChildContainer : function() {
244 getButtonContainer : function() {
245 return this.el.select('.modal-footer div',true).first();
248 initEvents : function()
250 if (this.allow_close) {
251 this.closeEl.on('click', this.hide, this);
253 Roo.EventManager.onWindowResize(this.resize, this, true);
260 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
262 if (this.fitwindow) {
263 var w = this.width || Roo.lib.Dom.getViewportWidth(true) - 30;
264 var h = this.height || Roo.lib.Dom.getViewportHeight(true) - 60;
271 setSize : function(w,h)
281 if (!this.rendered) {
285 //this.el.setStyle('display', 'block');
286 this.el.removeClass('hideing');
287 this.el.addClass('show');
289 if(this.animate){ // element has 'fade' - so stuff happens after .3s ?- not sure why the delay?
292 this.el.addClass('in');
295 this.el.addClass('in');
298 // not sure how we can show data in here..
300 // this.getChildContainer().dom.innerHTML = this.tmpl.applyTemplate(this);
303 Roo.get(document.body).addClass("x-body-masked");
305 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
306 this.maskEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
307 this.maskEl.addClass('show');
311 this.fireEvent('show', this);
313 // set zindex here - otherwise it appears to be ignored...
314 this.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
317 this.items.forEach( function(e) {
318 e.layout ? e.layout() : false;
326 if(this.fireEvent("beforehide", this) !== false){
327 this.maskEl.removeClass('show');
328 Roo.get(document.body).removeClass("x-body-masked");
329 this.el.removeClass('in');
330 this.el.select('.modal-dialog', true).first().setStyle('transform','');
332 if(this.animate){ // why
333 this.el.addClass('hideing');
335 if (!this.el.hasClass('hideing')) {
336 return; // it's been shown again...
338 this.el.removeClass('show');
339 this.el.removeClass('hideing');
343 this.el.removeClass('show');
345 this.fireEvent('hide', this);
348 isVisible : function()
351 return this.el.hasClass('show') && !this.el.hasClass('hideing');
355 addButton : function(str, cb)
359 var b = Roo.apply({}, { html : str } );
360 b.xns = b.xns || Roo.bootstrap;
361 b.xtype = b.xtype || 'Button';
362 if (typeof(b.listeners) == 'undefined') {
363 b.listeners = { click : cb.createDelegate(this) };
366 var btn = Roo.factory(b);
368 btn.render(this.el.select('.modal-footer div').first());
374 setDefaultButton : function(btn)
376 //this.el.select('.modal-footer').()
380 resizeTo: function(w,h)
384 this.dialogEl.setWidth(w);
385 if (this.diff === false) {
386 this.diff = this.dialogEl.getHeight() - this.bodyEl.getHeight();
389 this.bodyEl.setHeight(h-this.diff);
391 this.fireEvent('resize', this);
394 setContentSize : function(w, h)
398 onButtonClick: function(btn,e)
401 this.fireEvent('btnclick', btn.name, e);
404 * Set the title of the Dialog
405 * @param {String} str new Title
407 setTitle: function(str) {
408 this.titleEl.dom.innerHTML = str;
411 * Set the body of the Dialog
412 * @param {String} str new Title
414 setBody: function(str) {
415 this.bodyEl.dom.innerHTML = str;
418 * Set the body of the Dialog using the template
419 * @param {Obj} data - apply this data to the template and replace the body contents.
421 applyBody: function(obj)
424 Roo.log("Error - using apply Body without a template");
427 this.tmpl.overwrite(this.bodyEl, obj);
433 Roo.apply(Roo.bootstrap.Modal, {
435 * Button config that displays a single OK button
444 * Button config that displays Yes and No buttons
460 * Button config that displays OK and Cancel buttons
475 * Button config that displays Yes, No and Cancel buttons