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);
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.onRender(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));
249 if (!this.rendered) {
253 this.el.setStyle('display', 'block');
255 if(this.animate){ // element has 'fade' - so stuff happens after .3s ?- not sure why the delay?
258 this.el.addClass('in');
261 this.el.addClass('in');
265 // not sure how we can show data in here..
267 // this.getChildContainer().dom.innerHTML = this.tmpl.applyTemplate(this);
270 Roo.get(document.body).addClass("x-body-masked");
271 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
273 this.el.setStyle('zIndex', '10001');
275 this.fireEvent('show', this);
283 Roo.get(document.body).removeClass("x-body-masked");
284 this.el.removeClass('in');
285 this.el.select('.modal-dialog', true).first().setStyle('transform','');
287 if(this.animate){ // why
289 (function(){ _this.el.setStyle('display', 'none'); }).defer(150);
291 this.el.setStyle('display', 'none');
294 this.fireEvent('hide', this);
297 addButton : function(str, cb)
301 var b = Roo.apply({}, { html : str } );
302 b.xns = b.xns || Roo.bootstrap;
303 b.xtype = b.xtype || 'Button';
304 if (typeof(b.listeners) == 'undefined') {
305 b.listeners = { click : cb.createDelegate(this) };
308 var btn = Roo.factory(b);
310 btn.onRender(this.el.select('.modal-footer div').first());
316 setDefaultButton : function(btn)
318 //this.el.select('.modal-footer').()
322 resizeTo: function(w,h)
326 this.el.select('.modal-dialog',true).first().setWidth(w);
327 if (this.diff === false) {
328 this.diff = this.el.select('.modal-dialog',true).first().getHeight() - this.el.select('.modal-body',true).first().getHeight();
331 this.el.select('.modal-body',true).first().setWidth(h-this.diff);
335 setContentSize : function(w, h)
339 onButtonClick: function(btn,e)
342 this.fireEvent('btnclick', btn.name, e);
345 * Set the title of the Dialog
346 * @param {String} str new Title
348 setTitle: function(str) {
349 this.titleEl.dom.innerHTML = str;
352 * Set the body of the Dialog
353 * @param {String} str new Title
355 setBody: function(str) {
356 this.bodyEl.dom.innerHTML = str;
359 * Set the body of the Dialog using the template
360 * @param {Obj} data - apply this data to the template and replace the body contents.
362 applyBody: function(obj)
365 Roo.log("Error - using apply Body without a template");
368 this.tmpl.overwrite(this.bodyEl, obj);
374 Roo.apply(Roo.bootstrap.Modal, {
376 * Button config that displays a single OK button
385 * Button config that displays Yes and No buttons
401 * Button config that displays OK and Cancel buttons
416 * Button config that displays Yes, No and Cancel buttons