]> git.proxmox.com Git - extjs.git/blob - extjs/build/examples/kitchensink/modern/src/model/Person.js
add extjs 6.0.1 sources
[extjs.git] / extjs / build / examples / kitchensink / modern / src / model / Person.js
1 Ext.define('KitchenSink.model.Person', {
2 extend: 'KitchenSink.model.Base',
3 fields: ['firstName', 'lastName', 'age', 'favoriteColor'],
4 statics: {
5 generateData: (function() {
6 var lasts = ['Jones', 'Smith', 'Lee', 'Wilson', 'Black', 'Williams', 'Lewis', 'Johnson', 'Foot', 'Little', 'Vee', 'Train', 'Hot', 'Mutt'],
7 firsts = ['Fred', 'Julie', 'Bill', 'Ted', 'Jack', 'John', 'Mark', 'Mike', 'Chris', 'Bob', 'Travis', 'Kelly', 'Sara'],
8 colors = ['Red', 'Green', 'Blue'],
9 currentYear = (new Date()).getFullYear();
10
11 function getRandom(array) {
12 var index = Ext.Number.randomInt(0, array.length - 1);
13 return array[index];
14 }
15
16 function getName(seen) {
17 var name = {
18 first: getRandom(firsts),
19 last: getRandom(lasts)
20 };
21
22 if (seen[name.first + name.last]) {
23 return getName(seen);
24 } else {
25 return name;
26 }
27 }
28
29 function getDate() {
30 var y = Ext.Number.randomInt(currentYear - 5, currentYear),
31 m = Ext.Number.randomInt(0, 11),
32 maxDays = Ext.Date.getDaysInMonth(new Date(y, m, 1));
33 d = Ext.Number.randomInt(1, maxDays);
34
35 return new Date(y, m, d);
36 }
37
38 function getKey() {
39 var chars = '',
40 i;
41
42 for (i = 0; i < 5; ++i) {
43 chars += String.fromCharCode(Ext.Number.randomInt(97, 122));
44 }
45
46 return chars;
47 }
48
49 return function(options) {
50 options = options || {};
51 var out = [],
52
53 adults = options.adults,
54 children = options.children,
55 total = options.total,
56 includeAccounts = options.includeAccounts,
57 seenNames = {},
58 adultsUndef = adults === undefined,
59 childrenUndef = children === undefined,
60 accountIdCounter = 0,
61 name, o, accounts, j, len;
62
63 if (!adultsUndef && !childrenUndef) {
64 total = adults + children;
65 } else {
66 // We rely on total now
67 total = total || 15;
68 if (adultsUndef && childrenUndef) {
69 adults = Ext.Number.randomInt(Math.floor(total * 0.25), Math.floor(total * 0.75));
70 children = total - adults;
71 } else if (adultsUndef) {
72 adults = total - children;
73 } else {
74 children = total - adults;
75 }
76 }
77
78 for (i = 0; i < total; ++i) {
79 name = getName(seenNames);
80 o = {
81 id: i + 1,
82 firstName: name.first,
83 lastName: name.last,
84 age: i >= adults ? Ext.Number.randomInt(0, 17) : Ext.Number.randomInt(18, 100),
85 favoriteColor: getRandom(colors)
86 };
87
88 if (includeAccounts) {
89 accounts = [];
90 len = Ext.Number.randomInt(1, 5);
91 for (j = 0; j < len; ++j) {
92 accounts.push({
93 id: ++accountIdCounter,
94 created: getDate(),
95 accountKey: getKey(),
96 personId: o.id
97 });
98 }
99 o.accounts = accounts;
100 }
101
102 out.push(o);
103 }
104
105 return out;
106 };
107 })()
108 }
109 });