]> git.proxmox.com Git - extjs.git/blame - extjs/examples/kitchensink/classic/samples/model/Company.js
add extjs 6.0.1 sources
[extjs.git] / extjs / examples / kitchensink / classic / samples / model / Company.js
CommitLineData
6527f429
DM
1Ext.define('KitchenSink.model.Company', {\r
2 extend: 'KitchenSink.model.Base',\r
3 fields: [\r
4 {name: 'name'},\r
5 {name: 'price', type: 'float'},\r
6 {name: 'change', type: 'float'},\r
7 {name: 'pctChange', type: 'float'},\r
8 {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'},\r
9 {name: 'industry'},\r
10 {name: 'desc'},\r
11 // Trend begins with the cerrent price. Changes get pushed onto the end\r
12 {\r
13 name: 'trend',\r
14 convert: function(value, record) {\r
15 // Record creation call with no trend there: start with current price\r
16 if (value === null) {\r
17 return [record.get('price')];\r
18 }\r
19 return Ext.isArray(value) ? value : [ value ];\r
20 } \r
21 },\r
22 // Rating dependent upon performance 0 = best, 2 = worst\r
23 {\r
24 name: 'rating',\r
25 type: 'int',\r
26 convert: function(value, record) {\r
27 var pct = record.get('pctChange');\r
28 if (pct < 0)\r
29 return 2;\r
30 if (pct < 1)\r
31 return 1;\r
32 return 0;\r
33 }\r
34 }\r
35 ],\r
36\r
37 // Override to keep the last 10 prices in the trend field\r
38 set: function(fieldName, value) {\r
39 if (fieldName === 'price') {\r
40 this.callParent([{\r
41 price: value,\r
42 trend: this.addToTrend(fieldName.price)\r
43 }]);\r
44 }\r
45 else {\r
46 if (typeof fieldName !== 'string' && 'price' in fieldName) {\r
47 fieldName.trend = this.addToTrend(fieldName.price);\r
48 }\r
49 this.callParent(arguments);\r
50 }\r
51 },\r
52\r
53 // Override to keep the last 10 prices in the trend field\r
54 addToTrend: function(value) {\r
55 var trend = this.data.trend.concat(value);\r
56\r
57 if (trend.length > 10) {\r
58 Ext.Array.splice(trend, 0, trend.length - 10);\r
59 }\r
60 return trend;\r
61 }\r
62});\r