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',
74 onRender : function(ct, position)
76 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
79 var cfg = Roo.apply({}, this.getAutoCreate());
82 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
84 //if (!cfg.name.length) {
88 cfg.cls += ' ' + this.cls;
91 cfg.style = this.style;
93 this.el = Roo.get(document.body).createChild(cfg, position);
95 //var type = this.el.dom.type;
98 if(this.tabIndex !== undefined){
99 this.el.dom.setAttribute('tabIndex', this.tabIndex);
102 this.dialogEl = this.el.select('.modal-dialog',true).first();
103 this.bodyEl = this.el.select('.modal-body',true).first();
104 this.closeEl = this.el.select('.modal-header .close', true).first();
105 this.footerEl = this.el.select('.modal-footer',true).first();
106 this.titleEl = this.el.select('.modal-title',true).first();
110 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
111 this.maskEl.enableDisplayMode("block");
113 //this.el.addClass("x-dlg-modal");
115 if (this.buttons.length) {
116 Roo.each(this.buttons, function(bb) {
117 var b = Roo.apply({}, bb);
118 b.xns = b.xns || Roo.bootstrap;
119 b.xtype = b.xtype || 'Button';
120 if (typeof(b.listeners) == 'undefined') {
121 b.listeners = { click : this.onButtonClick.createDelegate(this) };
124 var btn = Roo.factory(b);
126 btn.render(this.el.select('.modal-footer div').first());
130 // render the children.
133 if(typeof(this.items) != 'undefined'){
134 var items = this.items;
137 for(var i =0;i < items.length;i++) {
138 nitems.push(this.addxtype(Roo.apply({}, items[i])));
144 // where are these used - they used to be body/close/footer
148 //this.el.addClass([this.fieldClass, this.cls]);
152 getAutoCreate : function(){
157 html : this.html || ''
166 if(this.specificTitle){
172 if (this.allow_close) {
183 style : 'display: none',
189 cls : "modal-content",
192 cls : 'modal-header',
197 cls : 'modal-footer',
201 cls: 'btn-' + this.buttonPosition
218 modal.cls += ' fade';
224 getChildContainer : function() {
229 getButtonContainer : function() {
230 return this.el.select('.modal-footer div',true).first();
233 initEvents : function()
235 if (this.allow_close) {
236 this.closeEl.on('click', this.hide, this);
241 window.addEventListener("resize", function() { _this.resize(); } );
247 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
250 setSize : function(w,h)
257 if (!this.rendered) {
261 this.el.setStyle('display', 'block');
263 if(this.animate){ // element has 'fade' - so stuff happens after .3s ?- not sure why the delay?
266 this.el.addClass('in');
269 this.el.addClass('in');
273 // not sure how we can show data in here..
275 // this.getChildContainer().dom.innerHTML = this.tmpl.applyTemplate(this);
278 Roo.get(document.body).addClass("x-body-masked");
279 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
281 this.el.setStyle('zIndex', '10001');
283 this.fireEvent('show', this);
284 this.items.forEach(function(e) {
285 e.layout ? e.layout() : false;
295 Roo.get(document.body).removeClass("x-body-masked");
296 this.el.removeClass('in');
297 this.el.select('.modal-dialog', true).first().setStyle('transform','');
299 if(this.animate){ // why
301 (function(){ _this.el.setStyle('display', 'none'); }).defer(150);
303 this.el.setStyle('display', 'none');
306 this.fireEvent('hide', this);
309 addButton : function(str, cb)
313 var b = Roo.apply({}, { html : str } );
314 b.xns = b.xns || Roo.bootstrap;
315 b.xtype = b.xtype || 'Button';
316 if (typeof(b.listeners) == 'undefined') {
317 b.listeners = { click : cb.createDelegate(this) };
320 var btn = Roo.factory(b);
322 btn.render(this.el.select('.modal-footer div').first());
328 setDefaultButton : function(btn)
330 //this.el.select('.modal-footer').()
334 resizeTo: function(w,h)
338 this.dialogEl.setWidth(w);
339 if (this.diff === false) {
340 this.diff = this.dialogEl.getHeight() - this.el.select('.modal-body',true).first().getHeight();
343 this.el.select('.modal-body',true).first().setHeight(h-this.diff);
347 setContentSize : function(w, h)
351 onButtonClick: function(btn,e)
354 this.fireEvent('btnclick', btn.name, e);
357 * Set the title of the Dialog
358 * @param {String} str new Title
360 setTitle: function(str) {
361 this.titleEl.dom.innerHTML = str;
364 * Set the body of the Dialog
365 * @param {String} str new Title
367 setBody: function(str) {
368 this.bodyEl.dom.innerHTML = str;
371 * Set the body of the Dialog using the template
372 * @param {Obj} data - apply this data to the template and replace the body contents.
374 applyBody: function(obj)
377 Roo.log("Error - using apply Body without a template");
380 this.tmpl.overwrite(this.bodyEl, obj);
386 Roo.apply(Roo.bootstrap.Modal, {
388 * Button config that displays a single OK button
397 * Button config that displays Yes and No buttons
413 * Button config that displays OK and Cancel buttons
428 * Button config that displays Yes, No and Cancel buttons