cef63908a64935a48604a54d8cc1e0e196b9e238
[roojs1] / Roo / bootstrap / MoneyField.js
1
2 /**
3  * @class Roo.bootstrap.MoneyField
4  * @extends Roo.bootstrap.TriggerField
5  * Bootstrap MoneyField class
6  * 
7  * @constructor
8  * Create a new MoneyField.
9  * @param {Object} config Configuration options
10  */
11
12 Roo.bootstrap.MoneyField = function(config) {
13     Roo.bootstrap.MoneyField.superclass.constructor.call(this, config);
14 };
15
16 Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.TriggerField, {
17     
18     inputlg : 9,
19     inputmd : 9,
20     inputsm : 9,
21     inputxs : 6,
22     
23     getAutoCreate : function()
24     {
25         var align = this.labelAlign || this.parentLabelAlign();
26         
27         var id = Roo.id();
28
29         var cfg = {
30             cls: 'form-group',
31             cn: []
32         };
33
34         var input =  {
35             tag: 'input',
36             id : id,
37             cls : 'form-control roo-money-amount-input',
38             autocomplete: 'new-password'
39         };
40         
41         if (this.name) {
42             input.name = this.name;
43         }
44
45         if (this.disabled) {
46             input.disabled = true;
47         }
48
49         var clg = 12 - this.inputlg;
50         var cmd = 12 - this.inputmd;
51         var csm = 12 - this.inputsm;
52         var cxs = 12 - this.inputxs;
53         
54         var container = {
55             tag : 'div',
56             cls : 'row roo-money-field',
57             cn : [
58                 {
59                     tag : 'div',
60                     cls : 'column col-lg-' + clg + ' col-md-' + cmd + ' col-sm-' + csm + ' col-xs-' + cxs,
61                     cn : [
62                         {
63                             tag : 'div',
64                             cls: 'roo-select2-container input-group',
65                             cn: [
66                                 {
67                                     tag : 'input',
68                                     cls : 'form-control roo-money-amount-input',
69                                     autocomplete: 'new-password'
70                                 },
71                                 {
72                                     tag :'span',
73                                     cls : 'input-group-addon btn dropdown-toggle',
74                                     cn : [
75                                         {
76                                             tag: 'span',
77                                             cls: 'caret'
78                                         }
79                                     ]
80                                 }
81                             ]
82                         }
83                     ]
84                 },
85                 {
86                     tag : 'div',
87                     cls : 'column col-lg-' + this.inputlg + ' col-md-' + this.inputmd + ' col-sm-' + this.inputsm + ' col-xs-' + this.inputxs,
88                     cn : [
89                         {
90                             tag: 'div',
91                             cls: this.hasFeedback ? 'has-feedback' : '',
92                             cn: [
93                                 input
94                             ]
95                         }
96                     ]
97                 }
98             ]
99             
100         };
101         
102         if (this.fieldLabel.length) {
103             var indicator = {
104                 tag: 'i',
105                 tooltip: 'This field is required'
106             };
107
108             var label = {
109                 tag: 'label',
110                 'for':  id,
111                 cls: 'control-label',
112                 cn: []
113             };
114
115             var label_text = {
116                 tag: 'span',
117                 html: this.fieldLabel
118             };
119
120             indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
121             label.cn = [
122                 indicator,
123                 label_text
124             ];
125
126             if(this.indicatorpos == 'right') {
127                 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
128                 label.cn = [
129                     label_text,
130                     indicator
131                 ];
132             }
133
134             if(align == 'left') {
135                 container = {
136                     tag: 'div',
137                     cn: [
138                         container
139                     ]
140                 };
141
142                 if(this.labelWidth > 12){
143                     label.style = "width: " + this.labelWidth + 'px';
144                 }
145                 if(this.labelWidth < 13 && this.labelmd == 0){
146                     this.labelmd = this.labelWidth;
147                 }
148                 if(this.labellg > 0){
149                     label.cls += ' col-lg-' + this.labellg;
150                     input.cls += ' col-lg-' + (12 - this.labellg);
151                 }
152                 if(this.labelmd > 0){
153                     label.cls += ' col-md-' + this.labelmd;
154                     container.cls += ' col-md-' + (12 - this.labelmd);
155                 }
156                 if(this.labelsm > 0){
157                     label.cls += ' col-sm-' + this.labelsm;
158                     container.cls += ' col-sm-' + (12 - this.labelsm);
159                 }
160                 if(this.labelxs > 0){
161                     label.cls += ' col-xs-' + this.labelxs;
162                     container.cls += ' col-xs-' + (12 - this.labelxs);
163                 }
164             }
165         }
166
167         cfg.cn = [
168             label,
169             container
170         ];
171
172         var settings = this;
173
174         ['xs','sm','md','lg'].map(function(size){
175             if (settings[size]) {
176                 cfg.cls += ' col-' + size + '-' + settings[size];
177             }
178         });
179         
180         return cfg;
181     },
182     
183     initEvents : function()
184     {
185         
186     }
187     
188 });