-
Notifications
You must be signed in to change notification settings - Fork 12
/
WineModel.js
153 lines (141 loc) · 3.54 KB
/
WineModel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*globals define*/
define( [
'src/models/BaseModel',
'app/models/CountryCollection',
'src/utils/convert'
], function(
BaseModel,
CountryCollection,
convert
) {
'use strict';
var Model = BaseModel.extend({
idAttribute: 'id',
name: 'Wine',
label: 'Wine',
fields: [
{
name : 'id',
type : 'number',
label : 'Id',
defaults : '(new)',
editable : false,
span : 2,
order : 'id'
},
{
name : 'name',
type : 'string',
label : 'Name',
max : 50,
defaults : '',
span : 3,
order : 'name',
help : 'Enter the name of the wine',
validations: [
{ method: 'required', message: 'The field wine cannot be empty.' },
{ method: 'length' }
]
},
{
name : 'year',
type : 'string',
label : 'Year',
defaults : (new Date().getFullYear()).toString(),
span : 3,
order : 'year',
help : 'Enter the year of the wine',
validations: [
{ method: 'required', message: 'The year of the wine cannot be empty.' },
{ method: 'range',
greater: '1900',
'lessEqual': (new Date().getFullYear()).toString()
}
]
},
{
name : 'grapes',
type : 'string',
label : 'Grapes',
max : 50,
defaults : '',
span : 3,
order : 'grapes',
help : 'Enter the grapes of the wine',
validations: [
{ method: 'length' }
]
},
{
name : 'country',
label : 'Country',
type : 'object',
idAttribute : 'id',
displayAttribute : 'name',
defaults : null,
span : 3,
help : 'Country of the wine',
validations : [
{ method: 'required', message: 'You have to specify the country.' }
],
control : {
type : 'CollectionCombo',
collection : new CountryCollection(),
display : function(attrs) {
return attrs.name + ' (' + attrs.code + ')';
}
}
},
{
name : 'region',
type : 'string',
label : 'Region',
max : 1000,
defaults : '',
span : 6,
order : 'region',
help : 'Nombre de la Provincia',
validations : [
{ method:'required' }, { method: 'length' }
]
},
{
name : 'description',
type : 'string',
label : 'Description',
max : 1000,
defaults : '',
span : 6,
order : 'description',
help : 'Wine\'s description',
validations : [
{ method:'required' }, { method: 'length' }
]
}
],
formFields: [
'id',
'name',
'year',
'grapes',
'country',
'region',
{ name: 'description', control: 'textarea', rows: 4 }
],
headerFields: [
'id',
{ name: 'name', span: 4 },
{ name: 'grapes', span: 7 }
],
queryFields: [
{ name: 'id', defaults: '', editable: true },
'name',
{ name: 'year', defaults: '' },
'grapes',
'region',
{ name: 'description', control: 'textarea', rows: 4 }
],
tableFields: ['id', 'name', 'year', 'country', 'region']
});
return Model;
});