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.each(this.buttons, function(bb) {
116 var b = Roo.apply({}, bb);
117 b.xns = b.xns || Roo.bootstrap;
118 b.xtype = b.xtype || 'Button';
119 if (typeof(b.listeners) == 'undefined') {
120 b.listeners = { click : this.onButtonClick.createDelegate(this) };
123 var btn = Roo.factory(b);
125 btn.onRender(this.el.select('.modal-footer div').first());
129 // render the children.
132 if(typeof(this.items) != 'undefined'){
133 var items = this.items;
136 for(var i =0;i < items.length;i++) {
137 nitems.push(this.addxtype(Roo.apply({}, items[i])));
143 // where are these used - they used to be body/close/footer
147 //this.el.addClass([this.fieldClass, this.cls]);
151 getAutoCreate : function(){
156 html : this.html || ''
165 if(this.specificTitle){
171 if (this.allow_close) {
182 style : 'display: none',
188 cls : "modal-content",
191 cls : 'modal-header',
196 cls : 'modal-footer',
200 cls: 'btn-' + this.buttonPosition
217 modal.cls += ' fade';
223 getChildContainer : function() {
228 getButtonContainer : function() {
229 return this.el.select('.modal-footer div',true).first();
232 initEvents : function()
234 if (this.allow_close) {
235 this.closeEl.on('click', this.hide, this);
240 window.addEventListener("resize", function() { _this.resize(); } );
246 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
251 if (!this.rendered) {
255 this.el.setStyle('display', 'block');
259 (function(){ _this.el.addClass('in'); }).defer(50);
261 this.el.addClass('in');
264 // not sure how we can show data in here..
266 // this.getChildContainer().dom.innerHTML = this.tmpl.applyTemplate(this);
269 Roo.get(document.body).addClass("x-body-masked");
270 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
272 this.el.setStyle('zIndex', '10001');
274 this.fireEvent('show', this);
281 Roo.get(document.body).removeClass("x-body-masked");
282 this.el.removeClass('in');
286 (function(){ _this.el.setStyle('display', 'none'); }).defer(150);
288 this.el.setStyle('display', 'none');
291 this.fireEvent('hide', this);
294 addButton : function(str, cb)
298 var b = Roo.apply({}, { html : str } );
299 b.xns = b.xns || Roo.bootstrap;
300 b.xtype = b.xtype || 'Button';
301 if (typeof(b.listeners) == 'undefined') {
302 b.listeners = { click : cb.createDelegate(this) };
305 var btn = Roo.factory(b);
307 btn.onRender(this.el.select('.modal-footer div').first());
313 setDefaultButton : function(btn)
315 //this.el.select('.modal-footer').()
317 resizeTo: function(w,h)
321 setContentSize : function(w, h)
325 onButtonClick: function(btn,e)
328 this.fireEvent('btnclick', btn.name, e);
331 * Set the title of the Dialog
332 * @param {String} str new Title
334 setTitle: function(str) {
335 this.titleEl.dom.innerHTML = str;
338 * Set the body of the Dialog
339 * @param {String} str new Title
341 setBody: function(str) {
342 this.bodyEl.dom.innerHTML = str;
345 * Set the body of the Dialog using the template
346 * @param {Obj} data - apply this data to the template and replace the body contents.
348 applyBody: function(obj)
351 Roo.log("Error - using apply Body without a template");
354 this.tmpl.overwrite(this.bodyEl, obj);
360 Roo.apply(Roo.bootstrap.Modal, {
362 * Button config that displays a single OK button
371 * Button config that displays Yes and No buttons
387 * Button config that displays OK and Cancel buttons
402 * Button config that displays Yes, No and Cancel buttons