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
20 * Create a new Modal Dialog
21 * @param {Object} config The config object
24 Roo.bootstrap.Modal = function(config){
25 Roo.bootstrap.Modal.superclass.constructor.call(this, config);
30 * The raw btnclick event for the button
31 * @param {Roo.EventObject} e
35 this.buttons = this.buttons || [];
38 this.tmpl = Roo.factory(this.tmpl);
43 Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component, {
45 title : 'test dialog',
57 buttonPosition: 'right',
71 onRender : function(ct, position)
73 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
76 var cfg = Roo.apply({}, this.getAutoCreate());
79 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
81 //if (!cfg.name.length) {
85 cfg.cls += ' ' + this.cls;
88 cfg.style = this.style;
90 this.el = Roo.get(document.body).createChild(cfg, position);
92 //var type = this.el.dom.type;
95 if(this.tabIndex !== undefined){
96 this.el.dom.setAttribute('tabIndex', this.tabIndex);
99 this.dialgEl = this.el.select('.modal-dialog',true).first();
100 this.bodyEl = this.el.select('.modal-body',true).first();
101 this.closeEl = this.el.select('.modal-header .close', true).first();
102 this.footerEl = this.el.select('.modal-footer',true).first();
103 this.titleEl = this.el.select('.modal-title',true).first();
107 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
108 this.maskEl.enableDisplayMode("block");
110 //this.el.addClass("x-dlg-modal");
112 if (this.buttons.length) {
113 Roo.each(this.buttons, function(bb) {
114 var b = Roo.apply({}, bb);
115 b.xns = b.xns || Roo.bootstrap;
116 b.xtype = b.xtype || 'Button';
117 if (typeof(b.listeners) == 'undefined') {
118 b.listeners = { click : this.onButtonClick.createDelegate(this) };
121 var btn = Roo.factory(b);
123 btn.render(this.el.select('.modal-footer div').first());
127 // render the children.
130 if(typeof(this.items) != 'undefined'){
131 var items = this.items;
134 for(var i =0;i < items.length;i++) {
135 nitems.push(this.addxtype(Roo.apply({}, items[i])));
141 // where are these used - they used to be body/close/footer
145 //this.el.addClass([this.fieldClass, this.cls]);
149 getAutoCreate : function(){
154 html : this.html || ''
163 if(this.specificTitle){
169 if (this.allow_close) {
180 style : 'display: none',
186 cls : "modal-content",
189 cls : 'modal-header',
194 cls : 'modal-footer',
198 cls: 'btn-' + this.buttonPosition
215 modal.cls += ' fade';
221 getChildContainer : function() {
226 getButtonContainer : function() {
227 return this.el.select('.modal-footer div',true).first();
230 initEvents : function()
232 if (this.allow_close) {
233 this.closeEl.on('click', this.hide, this);
238 window.addEventListener("resize", function() { _this.resize(); } );
244 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
247 setSize : function(w,h)
254 if (!this.rendered) {
258 this.el.setStyle('display', 'block');
260 if(this.animate){ // element has 'fade' - so stuff happens after .3s ?- not sure why the delay?
263 this.el.addClass('in');
266 this.el.addClass('in');
270 // not sure how we can show data in here..
272 // this.getChildContainer().dom.innerHTML = this.tmpl.applyTemplate(this);
275 Roo.get(document.body).addClass("x-body-masked");
276 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
278 this.el.setStyle('zIndex', '10001');
280 this.fireEvent('show', this);
281 this.items.forEach(function(e) {
282 e.layout ? e.layout() : false;
292 Roo.get(document.body).removeClass("x-body-masked");
293 this.el.removeClass('in');
294 this.el.select('.modal-dialog', true).first().setStyle('transform','');
296 if(this.animate){ // why
298 (function(){ _this.el.setStyle('display', 'none'); }).defer(150);
300 this.el.setStyle('display', 'none');
303 this.fireEvent('hide', this);
306 addButton : function(str, cb)
310 var b = Roo.apply({}, { html : str } );
311 b.xns = b.xns || Roo.bootstrap;
312 b.xtype = b.xtype || 'Button';
313 if (typeof(b.listeners) == 'undefined') {
314 b.listeners = { click : cb.createDelegate(this) };
317 var btn = Roo.factory(b);
319 btn.render(this.el.select('.modal-footer div').first());
325 setDefaultButton : function(btn)
327 //this.el.select('.modal-footer').()
331 resizeTo: function(w,h)
335 this.el.select('.modal-dialog',true).first().setWidth(w);
336 if (this.diff === false) {
337 this.diff = this.el.select('.modal-dialog',true).first().getHeight() - this.el.select('.modal-body',true).first().getHeight();
340 this.el.select('.modal-body',true).first().setHeight(h-this.diff);
344 setContentSize : function(w, h)
348 onButtonClick: function(btn,e)
351 this.fireEvent('btnclick', btn.name, e);
354 * Set the title of the Dialog
355 * @param {String} str new Title
357 setTitle: function(str) {
358 this.titleEl.dom.innerHTML = str;
361 * Set the body of the Dialog
362 * @param {String} str new Title
364 setBody: function(str) {
365 this.bodyEl.dom.innerHTML = str;
368 * Set the body of the Dialog using the template
369 * @param {Obj} data - apply this data to the template and replace the body contents.
371 applyBody: function(obj)
374 Roo.log("Error - using apply Body without a template");
377 this.tmpl.overwrite(this.bodyEl, obj);
383 Roo.apply(Roo.bootstrap.Modal, {
385 * Button config that displays a single OK button
394 * Button config that displays Yes and No buttons
410 * Button config that displays OK and Cancel buttons
425 * Button config that displays Yes, No and Cancel buttons