TimeTable.js
5.56 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/**
* Project : AMDA-NG
* Name : timeTable.js
* Description : TimeTable Business Object Definition
* @class amdaModel.TimeTable
* @extends amdaModel.AmdaObject
*
* @author cdarmon
* @version $Id: TimeTable.js 1907 2013-11-25 15:59:42Z myriam $
******************************************************************************
* FT Id : Date : Name - Description
******************************************************************************
* : :24/03/2011: CDA – creation
* : :22/06/2011: elena - extends generic class AmdaObject
*/
Ext.define('amdaModel.Interval', {
extend: 'amdaModel.AmdaObject',
fields: [
{
name: 'id',
convert: function(value, rec){
// generate id only if start and stop fields exists
return rec.get('start')&rec.get('stop')?Ext.id():null;
},
persist: false
},
{ name: 'start', type : 'date', defaultValue : new Date(),
convert: function(value,rec) {
if (!Ext.isDate(value)){
var valueString = new String(value);
var date = new Date(valueString.replace(/\-/g,'\/').replace(/[T|Z]/g,' '));
return date;
}
return value;
}
},
{ name: 'stop', type : 'date', defaultValue : new Date(),
convert: function(value,rec) {
if (!Ext.isDate(value)){
var valueString = new String(value);
var date = new Date(valueString.replace(/\-/g,'\/').replace(/[T|Z]/g,' '));
return date;
}
return value;
}
},
{
name: 'durationHour',
type: 'float',
convert: function(value, rec){
if (rec.get('stop') && rec.get('start') && (rec.get('stop')-rec.get('start'))>=0) {
return (rec.get('stop') - rec.get('start'))/3600000.0;
}
},
persist: false
},
{
name: 'durationMin',
type: 'float',
convert: function(value, rec){
if (rec.get('stop') && rec.get('start') && (rec.get('stop')-rec.get('start'))>=0) {
return (rec.get('stop') - rec.get('start'))/60000.0;
}
},
persist: false
},
{
name: 'durationSec',
type: 'float',
convert: function(value, rec){
if (rec.get('stop') && rec.get('start') && (rec.get('stop')-rec.get('start'))>=0) {
return (rec.get('stop') - rec.get('start'))/1000.0;
}
},
persist: false
},
{ name: 'cacheId', type : 'int'},
{ name: 'isNew', type : 'boolean', defaultValue: false},
{ name: 'isModified', type : 'boolean', defaultValue: false}
],
getJsonValues : function () {
var values = new Object();
values.start = this.get('start');
values.stop = this.get('stop');
return values;
},
proxy: {
type: 'direct',
api :
{
read : AmdaAction.readTTCacheIntervals
},
extraParams : {'typeTT' : ''},
reader:
{
type: 'json',
root: 'intervals',
totalProperty : 'totalCount'
}
}
/*
validations: [
{type: 'presence', field: 'age'},
{type: 'length', field: 'name', min: 2},
{type: 'inclusion', field: 'gender', list: ['Male', 'Female']},
{type: 'exclusion', field: 'username', list: ['Admin', 'Operator']},
{type: 'format', field: 'username', matcher: /([a-z]+)[0-9]{2,3}/}
],
*/
});
Ext.define('amdaModel.TimeTable', {
extend: 'amdaModel.AmdaObject',
fields : [
{name: 'fromPlugin', type: 'boolean', defaultValue: false},
{name: 'created', type: 'date'},
{name: 'description', type: 'string'},
{name: 'history', type: 'string'},
{name: 'nbIntervals', type: 'int'},
{name: 'objName', type: 'string', defaultValue: ""},
{name: 'objFormat', type: 'string', defaultValue: ""},
{name: 'folderId', type: 'string', defaultValue: ""},
{name: 'cacheToken', type: 'string', defaultValue: ""}
],
/*commit: function(){
this.callParent(arguments);
// fix the modifications for its intervals
Ext.Array.each(this.get('intervals'), function(item, index, all) {
//TODO check if JSON object should be processed
if (item.$className) {
item.commit();
}
});
},*/
// hasMany: {model: 'amdaModel.Interval', name: 'intervals'},
/**
* get TimeTable values to sent to Server
* @return object
*/
//TODO utf8_encode() and Ext.urlEncode() ???
getJsonValues : function (hasId) {
var values = new Object();
if (hasId) {
values.id = this.get('id');
}
values.name = this.get('name');
values.created = this.get('created');
if (this.get('description').match(/[a-z,0-9]/gi) != null) {
values.description = this.get('description');
}
if (this.get('history').match(/[a-z,0-9]/gi) != null) {
values.history = this.get('history');
}
values.objName = this.get('objName');
values.objFormat = this.get('objFormat');
values.folderId = this.get('folderId');
values.nbIntervals = this.get('nbIntervals');
values.cacheToken = this.get('cacheToken');
values.leaf = true;
values.nodeType = amdaModel.TimeTableNode.nodeType;
return values;
}
});