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);
122 this.maskEl.enableDisplayMode("block");
124 //this.el.addClass("x-dlg-modal");
126 if (this.buttons.length) {
127 Roo.each(this.buttons, function(bb) {
128 var b = Roo.apply({}, bb);
129 b.xns = b.xns || Roo.bootstrap;
130 b.xtype = b.xtype || 'Button';
131 if (typeof(b.listeners) == 'undefined') {
132 b.listeners = { click : this.onButtonClick.createDelegate(this) };
135 var btn = Roo.factory(b);
137 btn.render(this.el.select('.modal-footer div').first());
141 // render the children.
144 if(typeof(this.items) != 'undefined'){
145 var items = this.items;
148 for(var i =0;i < items.length;i++) {
149 nitems.push(this.addxtype(Roo.apply({}, items[i])));
155 // where are these used - they used to be body/close/footer
159 //this.el.addClass([this.fieldClass, this.cls]);
163 getAutoCreate : function(){
168 html : this.html || ''
177 if(this.specificTitle){
183 if (this.allow_close) {
195 if(this.size.length){
196 size = 'modal-' + this.size;
201 style : 'display: none',
204 cls: "modal-dialog " + size,
207 cls : "modal-content",
210 cls : 'modal-header',
215 cls : 'modal-footer',
219 cls: 'btn-' + this.buttonPosition
236 modal.cls += ' fade';
242 getChildContainer : function() {
247 getButtonContainer : function() {
248 return this.el.select('.modal-footer div',true).first();
251 initEvents : function()
253 if (this.allow_close) {
254 this.closeEl.on('click', this.hide, this);
256 Roo.EventManager.onWindowResize(this.resize, this, true);
263 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
264 if (this.fitwindow) {
265 var w = this.width || Roo.lib.Dom.getViewportWidth(true) - 30;
266 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('hidden');
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');
299 // not sure how we can show data in here..
301 // this.getChildContainer().dom.innerHTML = this.tmpl.applyTemplate(this);
304 Roo.get(document.body).addClass("x-body-masked");
306 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
307 this.maskEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
312 this.fireEvent('show', this);
314 // set zindex here - otherwise it appears to be ignored...
315 this.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
318 this.items.forEach( function(e) {
319 e.layout ? e.layout() : false;
327 if(this.fireEvent("beforehide", this) !== false){
329 Roo.get(document.body).removeClass("x-body-masked");
330 this.el.removeClass('in');
331 this.el.select('.modal-dialog', true).first().setStyle('transform','');
333 if(this.animate){ // why
335 this.el.removeClass('show');
336 this.el.addClass('hidden');
339 this.el.removeClass('show');
340 this.el.addClass('hidden');
342 this.fireEvent('hide', this);
345 isVisible : function()
348 return this.el.hasClass('show');
352 addButton : function(str, cb)
356 var b = Roo.apply({}, { html : str } );
357 b.xns = b.xns || Roo.bootstrap;
358 b.xtype = b.xtype || 'Button';
359 if (typeof(b.listeners) == 'undefined') {
360 b.listeners = { click : cb.createDelegate(this) };
363 var btn = Roo.factory(b);
365 btn.render(this.el.select('.modal-footer div').first());
371 setDefaultButton : function(btn)
373 //this.el.select('.modal-footer').()
377 resizeTo: function(w,h)
381 this.dialogEl.setWidth(w);
382 if (this.diff === false) {
383 this.diff = this.dialogEl.getHeight() - this.bodyEl.getHeight();
386 this.bodyEl.setHeight(h-this.diff);
388 this.fireEvent('resize', this);
391 setContentSize : function(w, h)
395 onButtonClick: function(btn,e)
398 this.fireEvent('btnclick', btn.name, e);
401 * Set the title of the Dialog
402 * @param {String} str new Title
404 setTitle: function(str) {
405 this.titleEl.dom.innerHTML = str;
408 * Set the body of the Dialog
409 * @param {String} str new Title
411 setBody: function(str) {
412 this.bodyEl.dom.innerHTML = str;
415 * Set the body of the Dialog using the template
416 * @param {Obj} data - apply this data to the template and replace the body contents.
418 applyBody: function(obj)
421 Roo.log("Error - using apply Body without a template");
424 this.tmpl.overwrite(this.bodyEl, obj);
430 Roo.apply(Roo.bootstrap.Modal, {
432 * Button config that displays a single OK button
441 * Button config that displays Yes and No buttons
457 * Button config that displays OK and Cancel buttons
472 * Button config that displays Yes, No and Cancel buttons