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;
97 if(this.tabIndex !== undefined){
98 this.el.dom.setAttribute('tabIndex', this.tabIndex);
102 this.bodyEl = this.el.select('.modal-body',true).first();
103 this.closeEl = this.el.select('.modal-header .close', true).first();
104 this.footerEl = this.el.select('.modal-footer',true).first();
105 this.titleEl = this.el.select('.modal-title',true).first();
109 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
110 this.maskEl.enableDisplayMode("block");
112 //this.el.addClass("x-dlg-modal");
114 if (this.buttons.length) {
115 Roo.log('this.button');
116 Roo.log(this.buttons);
117 Roo.each(this.buttons, function(bb) {
118 var b = Roo.apply({}, bb);
119 b.xns = b.xns || Roo.bootstrap;
120 b.xtype = b.xtype || 'Button';
121 if (typeof(b.listeners) == 'undefined') {
122 b.listeners = { click : this.onButtonClick.createDelegate(this) };
125 var btn = Roo.factory(b);
127 btn.onRender(this.el.select('.modal-footer div').first());
131 // render the children.
134 if(typeof(this.items) != 'undefined'){
135 var items = this.items;
138 for(var i =0;i < items.length;i++) {
139 nitems.push(this.addxtype(Roo.apply({}, items[i])));
145 // where are these used - they used to be body/close/footer
149 //this.el.addClass([this.fieldClass, this.cls]);
153 getAutoCreate : function(){
158 html : this.html || ''
167 if(this.specificTitle){
173 if (this.allow_close) {
184 style : 'display: none',
190 cls : "modal-content",
193 cls : 'modal-header',
198 cls : 'modal-footer',
202 cls: 'btn-' + this.buttonPosition
219 modal.cls += ' fade';
225 getChildContainer : function() {
230 getButtonContainer : function() {
231 return this.el.select('.modal-footer div',true).first();
234 initEvents : function()
236 if (this.allow_close) {
237 this.closeEl.on('click', this.hide, this);
242 window.addEventListener("resize", function() { _this.resize(); } );
248 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
253 if (!this.rendered) {
257 this.el.setStyle('display', 'block');
261 (function(){ _this.el.addClass('in'); }).defer(50);
263 this.el.addClass('in');
266 // not sure how we can show data in here..
268 // this.getChildContainer().dom.innerHTML = this.tmpl.applyTemplate(this);
271 Roo.get(document.body).addClass("x-body-masked");
272 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
274 this.el.setStyle('zIndex', '10001');
276 this.fireEvent('show', this);
283 Roo.get(document.body).removeClass("x-body-masked");
284 this.el.removeClass('in');
288 (function(){ _this.el.setStyle('display', 'none'); }).defer(150);
290 this.el.setStyle('display', 'none');
293 this.fireEvent('hide', this);
296 addButton : function(str, cb)
300 var b = Roo.apply({}, { html : str } );
301 b.xns = b.xns || Roo.bootstrap;
302 b.xtype = b.xtype || 'Button';
303 if (typeof(b.listeners) == 'undefined') {
304 b.listeners = { click : cb.createDelegate(this) };
307 var btn = Roo.factory(b);
309 btn.onRender(this.el.select('.modal-footer div').first());
315 setDefaultButton : function(btn)
317 //this.el.select('.modal-footer').()
319 resizeTo: function(w,h)
323 setContentSize : function(w, h)
327 onButtonClick: function(btn,e)
330 this.fireEvent('btnclick', btn.name, e);
333 * Set the title of the Dialog
334 * @param {String} str new Title
336 setTitle: function(str) {
337 this.titleEl.dom.innerHTML = str;
340 * Set the body of the Dialog
341 * @param {String} str new Title
343 setBody: function(str) {
344 this.bodyEl.dom.innerHTML = str;
347 * Set the body of the Dialog using the template
348 * @param {Obj} data - apply this data to the template and replace the body contents.
350 applyBody: function(obj)
353 Roo.log("Error - using apply Body without a template");
356 this.tmpl.overwrite(this.bodyEl, obj);
362 Roo.apply(Roo.bootstrap.Modal, {
364 * Button config that displays a single OK button
373 * Button config that displays Yes and No buttons
389 * Button config that displays OK and Cancel buttons
404 * Button config that displays Yes, No and Cancel buttons