905d7497d8bb617e291ae2650a72806ed5dc08b0
[roojs1] / Roo / bootstrap / Modal.js
1
2 /*
3 <div class="modal fade">
4   <div class="modal-dialog">
5     <div class="modal-content">
6       <div class="modal-header">
7         <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
8         <h4 class="modal-title">Modal title</h4>
9       </div>
10       <div class="modal-body">
11         <p>One fine body&hellip;</p>
12       </div>
13       <div class="modal-footer">
14         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
15         <button type="button" class="btn btn-primary">Save changes</button>
16       </div>
17     </div><!-- /.modal-content -->
18   </div><!-- /.modal-dialog -->
19 </div><!-- /.modal -->
20 */
21 /*
22  * - LGPL
23  *
24  * page contgainer.
25  * 
26  */
27
28 /**
29  * @class Roo.bootstrap.Modal
30  * @extends Roo.bootstrap.Component
31  * Bootstrap Modal class
32  * @cfg {String} title Title of dialog
33  * @cfg {Array} buttons Array of buttons
34     
35  * @constructor
36  * Create a new Modal Dialog
37  * @param {Object} config The config object
38  */
39
40 Roo.bootstrap.Modal = function(config){
41     Roo.bootstrap.Modal.superclass.constructor.call(this, config);
42 };
43
44 Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component,  {
45     
46     title : 'test dialog',
47    
48         buttons : false,
49     onRender : function(ct, position){
50         Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
51         if(!this.el){
52             var cfg = Roo.apply({},  this.getAutoCreate());
53             cfg.id = Roo.id();
54             //if(!cfg.name){
55             //    cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
56             //}
57             //if (!cfg.name.length) {
58             //    delete cfg.name;
59            // }
60             if (this.cls) {
61                 cfg.cls += ' ' + this.cls;
62             }
63             if (this.style) {
64                 cfg.style = this.style;
65             }
66             this.el = Roo.get(document.body).createChild(cfg, position);
67         }
68         //var type = this.el.dom.type;
69          
70         if(this.tabIndex !== undefined){
71             this.el.dom.setAttribute('tabIndex', this.tabIndex);
72         }
73         this.initEvents();
74         //this.el.addClass([this.fieldClass, this.cls]);
75         
76     },
77     getAutoCreate : function(){
78         
79         return {
80             cls: "modal fade",
81             cn : [
82                 {
83                     cls: "modal-dialog",
84                     cn : [
85                         {
86                             cls : "modal-content",
87                             cn : [
88                                 {
89                                     cls : 'modal-header',
90                                     cn : [
91                                         {
92                                             tag: 'button',
93                                             cls : 'close',
94                                             html : '&times'
95                                         },
96                                         {
97                                             tag: 'h4',
98                                             cls : 'modal-title',
99                                             html : this.title
100                                         }
101                                     
102                                     ]
103                                 },
104                                 {
105                                     cls : 'modal-body'
106                                  
107                                 },
108                                  {
109                                     cls : 'modal-footer'
110                                     /*
111                                     cn : [
112                                         {
113                                             tag: 'button',
114                                             cls : 'btn btn-default',
115                                             html : 'Close'
116                                         },
117                                         {
118                                             tag: 'button',
119                                             cls : 'btn btn-primary',
120                                             html : 'Save'
121                                         }
122                                     
123                                     ]
124                                     */
125                                 }
126                                 
127                                 
128                             ]
129                             
130                         }
131                     ]
132                         
133                 }
134             ]
135             
136             
137         };
138           
139     },
140     getChildContainer : function() {
141          
142          return this.el.select('.modal-body',true).first();
143         
144     },
145     getButtonContainer : function() {
146          return this.el.select('.modal-footer',true).first();
147         
148     },
149     initEvents : function()
150     {
151         this.el.select('.modal-header .close').on('click', this.hide, this);
152     },
153     show : function() {
154         this.el.addClass('on');
155         this.el.removeClass('fade');
156         this.el.setStyle('display', 'block');
157     },
158     hide : function() {
159         this.el.removeClass('on');
160         this.el.addClass('fade');
161         this.el.setStyle('display', 'none');
162     }
163 });
164
165