b8007c793e772a8249496124c4b6f168e39efe93
[xtuple] / enyo-client / application / source / widgets / number.js
1 /*jshint node:true, indent:2, curly:true, eqeqeq:true, immed:true, latedef:true, newcap:true, noarg:true,
2 regexp:true, undef:true, trailing:true, white:true */
3 /*global XT:true, XV:true, Globalize:true, enyo:true, _:true */
4
5 (function () {
6
7   // ..........................................................
8   // COST
9   //
10
11   enyo.kind({
12     name: "XV.Cost",
13     kind: "XV.Number",
14     scale: XT.COST_SCALE
15   });
16
17   enyo.kind({
18     name: "XV.CostWidget",
19     kind: "XV.NumberWidget",
20     scale: XT.COST_SCALE
21   });
22
23   // ..........................................................
24   // EXTENDED PRICE
25   //
26
27   enyo.kind({
28     name: "XV.ExtendedPrice",
29     kind: "XV.Number",
30     scale: XT.EXTENDED_PRICE_SCALE
31   });
32
33   enyo.kind({
34     name: "XV.ExtendedPriceWidget",
35     kind: "XV.NumberWidget",
36     scale: XT.EXTENDED_PRICE_SCALE
37   });
38
39   // ..........................................................
40   // HOURS
41   //
42
43   enyo.kind({
44     name: "XV.Hours",
45     kind: "XV.Number",
46     maxlength: 12,
47     scale: XT.HOURS_SCALE
48   });
49
50   enyo.kind({
51     name: "XV.HoursWidget",
52     kind: "XV.NumberWidget",
53     maxlength: 12,
54     scale: XT.HOURS_SCALE
55   });
56
57   // ..........................................................
58   // PERCENT
59   //
60
61   enyo.kind({
62     name: "XV.Percent",
63     kind: "XV.Number",
64     scale: XT.PERCENT_SCALE,
65     validate: function (value) {
66       // this takes the string from the input field and parses it (including understanding commas, which isNaN cannot)
67       // if it cannot parse the value, it returns NaN
68       value = Globalize.parseFloat(value);
69       // use isNaN here because parseFloat could return NaN
70       // if you pass NaN into _.isNumber, it will misleadingly return true
71       // only bad string and null/undefined cases do we want to fail validation
72       return !isNaN(value) ? value / 100 : false;
73     },
74     valueChanged: function (value) {
75       // use isNaN here because this value may be a number string and _isNaN requires
76       // a separate falsy check.
77       // In this case, it is ok for 0 to fall to the true case, just not null or a bad string
78       value = !isNaN(value) ? value * 100 : value;
79       XV.Number.prototype.valueChanged.call(this, value);
80     }
81   });
82
83   enyo.kind({
84     name: "XV.PercentWidget",
85     kind: "XV.NumberWidget",
86     scale: XT.PERCENT_SCALE,
87     validate: function (value) {
88       // this takes the string from the input field and parses it (including understanding commas, which isNaN cannot)
89       // if it cannot parse the value, it returns NaN
90       value = Globalize.parseFloat(value);
91       // use isNaN here because parseFloat could return NaN
92       // if you pass NaN into _.isNumber, it will misleadingly return true
93       // only bad string and null/undefined cases do we want to fail validation
94       return !isNaN(value) ? value / 100 : false;
95     },
96     valueChanged: function (value) {
97       // use isNaN here because this value may be a number string and _isNaN requires
98       // a separate falsy check.
99       // In this case, it is ok for 0 to fall to the true case, just not null or a bad string
100       value = !isNaN(value) ? value * 100 : value;
101       XV.NumberWidget.prototype.valueChanged.call(this, value);
102     }
103   });
104
105   // ..........................................................
106   // PURCHASE PRICE
107   //
108
109   enyo.kind({
110     name: "XV.PurchasePrice",
111     kind: "XV.Number",
112     scale: XT.PURCHASE_PRICE_SCALE
113   });
114
115   enyo.kind({
116     name: "XV.PurchasePriceWidget",
117     kind: "XV.NumberWidget",
118     scale: XT.PURCHASE_PRICE_SCALE
119   });
120
121   // ..........................................................
122   // QUANTITY
123   //
124
125   enyo.kind({
126     name: "XV.Quantity",
127     kind: "XV.Number",
128     maxlength: 12,
129     scale: XT.QTY_SCALE
130   });
131
132   enyo.kind({
133     name: "XV.QuantityWidget",
134     kind: "XV.NumberWidget",
135     maxlength: 12,
136     scale: XT.QTY_SCALE
137   });
138
139   // ..........................................................
140   // QUANTITY PER
141   //
142
143   enyo.kind({
144     name: "XV.QuantityPer",
145     kind: "XV.Number",
146     scale: XT.QTY_PER_SCALE
147   });
148
149   enyo.kind({
150     name: "XV.QuantityPerWidget",
151     kind: "XV.NumberWidget",
152     scale: XT.QTY_PER_SCALE
153   });
154
155   // ..........................................................
156   // SALES PRICE
157   //
158
159   enyo.kind({
160     name: "XV.SalesPrice",
161     kind: "XV.Number",
162     scale: XT.SALES_PRICE_SCALE
163   });
164
165   enyo.kind({
166     name: "XV.SalesPriceWidget",
167     kind: "XV.NumberWidget",
168     scale: XT.SALES_PRICE_SCALE
169   });
170
171   // ..........................................................
172   // UNIT RATIO
173   //
174
175   enyo.kind({
176     name: "XV.UnitRatio",
177     kind: "XV.Number",
178     scale: XT.UNIT_RATIO_SCALE
179   });
180
181   enyo.kind({
182     name: "XV.UnitRatioWidget",
183     kind: "XV.NumberWidget",
184     scale: XT.UNIT_RATIO_SCALE
185   });
186
187   // ..........................................................
188   // WEIGHT
189   //
190
191   enyo.kind({
192     name: "XV.Weight",
193     kind: "XV.Number",
194     scale: XT.WEIGHT_SCALE
195   });
196
197   enyo.kind({
198     name: "XV.WeightWidget",
199     kind: "XV.NumberWidget",
200     scale: XT.WEIGHT_SCALE
201   });
202
203 }());