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',
76 onRender : function(ct, position)
78 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
81 var cfg = Roo.apply({}, this.getAutoCreate());
84 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
86 //if (!cfg.name.length) {
90 cfg.cls += ' ' + this.cls;
93 cfg.style = this.style;
95 this.el = Roo.get(document.body).createChild(cfg, position);
97 //var type = this.el.dom.type;
100 if(this.tabIndex !== undefined){
101 this.el.dom.setAttribute('tabIndex', this.tabIndex);
104 this.dialogEl = this.el.select('.modal-dialog',true).first();
105 this.bodyEl = this.el.select('.modal-body',true).first();
106 this.closeEl = this.el.select('.modal-header .close', true).first();
107 this.footerEl = this.el.select('.modal-footer',true).first();
108 this.titleEl = this.el.select('.modal-title',true).first();
112 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
113 this.maskEl.enableDisplayMode("block");
115 //this.el.addClass("x-dlg-modal");
117 if (this.buttons.length) {
118 Roo.each(this.buttons, function(bb) {
119 var b = Roo.apply({}, bb);
120 b.xns = b.xns || Roo.bootstrap;
121 b.xtype = b.xtype || 'Button';
122 if (typeof(b.listeners) == 'undefined') {
123 b.listeners = { click : this.onButtonClick.createDelegate(this) };
126 var btn = Roo.factory(b);
128 btn.render(this.el.select('.modal-footer div').first());
132 // render the children.
135 if(typeof(this.items) != 'undefined'){
136 var items = this.items;
139 for(var i =0;i < items.length;i++) {
140 nitems.push(this.addxtype(Roo.apply({}, items[i])));
146 // where are these used - they used to be body/close/footer
150 //this.el.addClass([this.fieldClass, this.cls]);
154 getAutoCreate : function(){
159 html : this.html || ''
168 if(this.specificTitle){
174 if (this.allow_close) {
185 style : 'display: none',
191 cls : "modal-content",
194 cls : 'modal-header',
199 cls : 'modal-footer',
203 cls: 'btn-' + this.buttonPosition
220 modal.cls += ' fade';
226 getChildContainer : function() {
231 getButtonContainer : function() {
232 return this.el.select('.modal-footer div',true).first();
235 initEvents : function()
237 if (this.allow_close) {
238 this.closeEl.on('click', this.hide, this);
242 window.addEventListener("resize", this.resize , this );
248 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
249 if (this.fitwindow) {
250 var w = this.width || Roo.lib.Dom.getViewWidth(true) - 10;
251 var h = this.height || Roo.lib.Dom.getViewHeight(true) - 10;
256 setSize : function(w,h)
263 if (!this.rendered) {
267 this.el.setStyle('display', 'block');
269 if(this.animate){ // element has 'fade' - so stuff happens after .3s ?- not sure why the delay?
272 this.el.addClass('in');
275 this.el.addClass('in');
279 // not sure how we can show data in here..
281 // this.getChildContainer().dom.innerHTML = this.tmpl.applyTemplate(this);
284 Roo.get(document.body).addClass("x-body-masked");
285 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
287 this.el.setStyle('zIndex', '10001');
289 this.fireEvent('show', this);
290 this.items.forEach(function(e) {
291 e.layout ? e.layout() : false;
302 Roo.get(document.body).removeClass("x-body-masked");
303 this.el.removeClass('in');
304 this.el.select('.modal-dialog', true).first().setStyle('transform','');
306 if(this.animate){ // why
308 (function(){ _this.el.setStyle('display', 'none'); }).defer(150);
310 this.el.setStyle('display', 'none');
313 this.fireEvent('hide', this);
316 addButton : function(str, cb)
320 var b = Roo.apply({}, { html : str } );
321 b.xns = b.xns || Roo.bootstrap;
322 b.xtype = b.xtype || 'Button';
323 if (typeof(b.listeners) == 'undefined') {
324 b.listeners = { click : cb.createDelegate(this) };
327 var btn = Roo.factory(b);
329 btn.render(this.el.select('.modal-footer div').first());
335 setDefaultButton : function(btn)
337 //this.el.select('.modal-footer').()
341 resizeTo: function(w,h)
345 this.dialogEl.setWidth(w);
346 if (this.diff === false) {
347 this.diff = this.dialogEl.getHeight() - this.el.select('.modal-body',true).first().getHeight();
350 this.el.select('.modal-body',true).first().setHeight(h-this.diff);
354 setContentSize : function(w, h)
358 onButtonClick: function(btn,e)
361 this.fireEvent('btnclick', btn.name, e);
364 * Set the title of the Dialog
365 * @param {String} str new Title
367 setTitle: function(str) {
368 this.titleEl.dom.innerHTML = str;
371 * Set the body of the Dialog
372 * @param {String} str new Title
374 setBody: function(str) {
375 this.bodyEl.dom.innerHTML = str;
378 * Set the body of the Dialog using the template
379 * @param {Obj} data - apply this data to the template and replace the body contents.
381 applyBody: function(obj)
384 Roo.log("Error - using apply Body without a template");
387 this.tmpl.overwrite(this.bodyEl, obj);
393 Roo.apply(Roo.bootstrap.Modal, {
395 * Button config that displays a single OK button
404 * Button config that displays Yes and No buttons
420 * Button config that displays OK and Cancel buttons
435 * Button config that displays Yes, No and Cancel buttons