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
38 this.buttons = this.buttons || [];
41 this.tmpl = Roo.factory(this.tmpl);
46 Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component, {
48 title : 'test dialog',
60 buttonPosition: 'right',
79 onRender : function(ct, position)
81 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
84 var cfg = Roo.apply({}, this.getAutoCreate());
87 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
89 //if (!cfg.name.length) {
93 cfg.cls += ' ' + this.cls;
96 cfg.style = this.style;
98 this.el = Roo.get(document.body).createChild(cfg, position);
100 //var type = this.el.dom.type;
103 if(this.tabIndex !== undefined){
104 this.el.dom.setAttribute('tabIndex', this.tabIndex);
107 this.dialogEl = this.el.select('.modal-dialog',true).first();
108 this.bodyEl = this.el.select('.modal-body',true).first();
109 this.closeEl = this.el.select('.modal-header .close', true).first();
110 this.headerEl = this.el.select('.modal-header',true).first();
111 this.titleEl = this.el.select('.modal-title',true).first();
112 this.footerEl = this.el.select('.modal-footer',true).first();
114 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
115 this.maskEl.enableDisplayMode("block");
117 //this.el.addClass("x-dlg-modal");
119 if (this.buttons.length) {
120 Roo.each(this.buttons, function(bb) {
121 var b = Roo.apply({}, bb);
122 b.xns = b.xns || Roo.bootstrap;
123 b.xtype = b.xtype || 'Button';
124 if (typeof(b.listeners) == 'undefined') {
125 b.listeners = { click : this.onButtonClick.createDelegate(this) };
128 var btn = Roo.factory(b);
130 btn.render(this.el.select('.modal-footer div').first());
134 // render the children.
137 if(typeof(this.items) != 'undefined'){
138 var items = this.items;
141 for(var i =0;i < items.length;i++) {
142 nitems.push(this.addxtype(Roo.apply({}, items[i])));
148 // where are these used - they used to be body/close/footer
152 //this.el.addClass([this.fieldClass, this.cls]);
156 getAutoCreate : function(){
161 html : this.html || ''
170 if(this.specificTitle){
176 if (this.allow_close) {
188 if(this.size.length){
189 size = 'modal-' + this.size;
194 style : 'display: none',
197 cls: "modal-dialog " + size,
200 cls : "modal-content",
203 cls : 'modal-header',
208 cls : 'modal-footer',
212 cls: 'btn-' + this.buttonPosition
229 modal.cls += ' fade';
235 getChildContainer : function() {
240 getButtonContainer : function() {
241 return this.el.select('.modal-footer div',true).first();
244 initEvents : function()
246 if (this.allow_close) {
247 this.closeEl.on('click', this.hide, this);
249 Roo.EventManager.onWindowResize(this.resize, this, true);
256 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
257 if (this.fitwindow) {
258 var w = this.width || Roo.lib.Dom.getViewportWidth(true) - 30;
259 var h = this.height || Roo.lib.Dom.getViewportHeight(true) - 60;
264 setSize : function(w,h)
274 if (!this.rendered) {
278 this.el.setStyle('display', 'block');
280 if(this.animate){ // element has 'fade' - so stuff happens after .3s ?- not sure why the delay?
283 this.el.addClass('in');
286 this.el.addClass('in');
290 // not sure how we can show data in here..
292 // this.getChildContainer().dom.innerHTML = this.tmpl.applyTemplate(this);
295 Roo.get(document.body).addClass("x-body-masked");
297 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
298 this.maskEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
301 this.fireEvent('show', this);
305 this.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
308 this.items.forEach( function(e) {
309 e.layout ? e.layout() : false;
317 if(this.fireEvent("beforehide", this) !== false){
319 Roo.get(document.body).removeClass("x-body-masked");
320 this.el.removeClass('in');
321 this.el.select('.modal-dialog', true).first().setStyle('transform','');
323 if(this.animate){ // why
325 (function(){ _this.el.setStyle('display', 'none'); }).defer(150);
327 this.el.setStyle('display', 'none');
329 this.fireEvent('hide', this);
333 addButton : function(str, cb)
337 var b = Roo.apply({}, { html : str } );
338 b.xns = b.xns || Roo.bootstrap;
339 b.xtype = b.xtype || 'Button';
340 if (typeof(b.listeners) == 'undefined') {
341 b.listeners = { click : cb.createDelegate(this) };
344 var btn = Roo.factory(b);
346 btn.render(this.el.select('.modal-footer div').first());
352 setDefaultButton : function(btn)
354 //this.el.select('.modal-footer').()
358 resizeTo: function(w,h)
362 this.dialogEl.setWidth(w);
363 if (this.diff === false) {
364 this.diff = this.dialogEl.getHeight() - this.bodyEl.getHeight();
367 this.bodyEl.setHeight(h-this.diff);
371 setContentSize : function(w, h)
375 onButtonClick: function(btn,e)
378 this.fireEvent('btnclick', btn.name, e);
381 * Set the title of the Dialog
382 * @param {String} str new Title
384 setTitle: function(str) {
385 this.titleEl.dom.innerHTML = str;
388 * Set the body of the Dialog
389 * @param {String} str new Title
391 setBody: function(str) {
392 this.bodyEl.dom.innerHTML = str;
395 * Set the body of the Dialog using the template
396 * @param {Obj} data - apply this data to the template and replace the body contents.
398 applyBody: function(obj)
401 Roo.log("Error - using apply Body without a template");
404 this.tmpl.overwrite(this.bodyEl, obj);
410 Roo.apply(Roo.bootstrap.Modal, {
412 * Button config that displays a single OK button
421 * Button config that displays Yes and No buttons
437 * Button config that displays OK and Cancel buttons
452 * Button config that displays Yes, No and Cancel buttons