]>
git.proxmox.com Git - extjs.git/blob - 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'],
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();
11 function getRandom(array
) {
12 var index
= Ext
.Number
.randomInt(0, array
.length
- 1);
16 function getName(seen
) {
18 first
: getRandom(firsts
),
19 last
: getRandom(lasts
)
22 if (seen
[name
.first
+ name
.last
]) {
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
);
35 return new Date(y
, m
, d
);
42 for (i
= 0; i
< 5; ++i
) {
43 chars
+= String
.fromCharCode(Ext
.Number
.randomInt(97, 122));
49 return function(options
) {
50 options
= options
|| {};
53 adults
= options
.adults
,
54 children
= options
.children
,
55 total
= options
.total
,
56 includeAccounts
= options
.includeAccounts
,
58 adultsUndef
= adults
=== undefined,
59 childrenUndef
= children
=== undefined,
61 name
, o
, accounts
, j
, len
;
63 if (!adultsUndef
&& !childrenUndef
) {
64 total
= adults
+ children
;
66 // We rely on total now
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
;
74 children
= total
- adults
;
78 for (i
= 0; i
< total
; ++i
) {
79 name
= getName(seenNames
);
82 firstName
: name
.first
,
84 age
: i
>= adults
? Ext
.Number
.randomInt(0, 17) : Ext
.Number
.randomInt(18, 100),
85 favoriteColor
: getRandom(colors
)
88 if (includeAccounts
) {
90 len
= Ext
.Number
.randomInt(1, 5);
91 for (j
= 0; j
< len
; ++j
) {
93 id
: ++accountIdCounter
,
99 o
.accounts
= accounts
;