Blame view

js/app/models/TimeTable.js 6.23 KB
16035364   Benjamin Renard   First commit
1
2
/**
 * Project      : AMDA-NG
342b20ca   Benjamin Renard   Fix inheritence b...
3
 * Name         : timeTable.js
16035364   Benjamin Renard   First commit
4
5
 * Description  : TimeTable Business Object Definition
 * @class amdaModel.TimeTable
342b20ca   Benjamin Renard   Fix inheritence b...
6
7
 * @extends amdaModel.AmdaObject
 *
16035364   Benjamin Renard   First commit
8
9
10
11
12
13
14
15
16
17
18
 * @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', {
342b20ca   Benjamin Renard   Fix inheritence b...
19
    extend: 'amdaModel.AmdaObject',
16035364   Benjamin Renard   First commit
20
21
22
23
24
25
26
27
28
29
30
31
    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)){
1fe67f2c   Hacene SI HADJ MOHAND   progress
32
                                                return new Date(value);
16035364   Benjamin Renard   First commit
33
34
35
36
37
38
		   }
		   return value;
		   }
	},
        { name: 'stop', type : 'date', defaultValue : new Date(),
	  convert: function(value,rec) {
1fe67f2c   Hacene SI HADJ MOHAND   progress
39
40
		     if (!Ext.isDate(value)){
                                                return new Date(value);
16035364   Benjamin Renard   First commit
41
42
43
44
		   }
		   return value;
		   }
	},
265c5cdf   Hacene SI HADJ MOHAND   ok
45
46
47
48
49
50
51
52
53
54
         {
            name: 'durationDay',
            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/24.0;
                }
            },
            persist: false
        },
16035364   Benjamin Renard   First commit
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
        {
            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}
    ],
342b20ca   Benjamin Renard   Fix inheritence b...
89

16035364   Benjamin Renard   First commit
90
91
92
93
94
95
    getJsonValues : function () {
        var values  = new Object();
        values.start = this.get('start');
        values.stop = this.get('stop');
        return values;
    },
342b20ca   Benjamin Renard   Fix inheritence b...
96

16035364   Benjamin Renard   First commit
97
98
99
100
    proxy: {
        type: 'direct',
        api :
        {
342b20ca   Benjamin Renard   Fix inheritence b...
101
              read   :  AmdaAction.readCacheIntervals
16035364   Benjamin Renard   First commit
102
103
104
105
106
107
108
109
110
        },
        extraParams : {'typeTT' : ''},
        reader:
        {
          type: 'json',
          root: 'intervals',
          totalProperty : 'totalCount'
        }
    }
342b20ca   Benjamin Renard   Fix inheritence b...
111
112

 /*
16035364   Benjamin Renard   First commit
113
114
115
116
117
118
119
120
    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}/}
    ],
*/
342b20ca   Benjamin Renard   Fix inheritence b...
121

16035364   Benjamin Renard   First commit
122
123
124
125
});


Ext.define('amdaModel.TimeTable', {
342b20ca   Benjamin Renard   Fix inheritence b...
126

16035364   Benjamin Renard   First commit
127
    extend: 'amdaModel.AmdaObject',
342b20ca   Benjamin Renard   Fix inheritence b...
128

16035364   Benjamin Renard   First commit
129
    fields : [
d547a559   Hacene SI HADJ MOHAND   rm_6903 ok
130
            {name: 'fromPlugin', type: 'boolean', defaultValue: false},
16035364   Benjamin Renard   First commit
131
132
            {name: 'created', type: 'date'},
            {name: 'description', type: 'string'},
709a2d2e   Hacene SI HADJ MOHAND   il reste auto sta...
133
            {name: 'contact', type: 'string', defaultValue:sessionID},
a4acaf46   Hacene SI HADJ MOHAND   IHM progess
134
135
            {name: 'surveyStart', type: 'date'},
             {name: 'surveyStop', type: 'date'},
342b20ca   Benjamin Renard   Fix inheritence b...
136
            {name: 'history', type: 'string'},
16035364   Benjamin Renard   First commit
137
138
139
            {name: 'nbIntervals', type: 'int'},
            {name: 'objName', type: 'string', defaultValue: ""},
            {name: 'objFormat', type: 'string', defaultValue: ""},
d547a559   Hacene SI HADJ MOHAND   rm_6903 ok
140
141
142
            {name: 'folderId', type: 'string', defaultValue: ""},
            {name: 'cacheToken', type: 'string', defaultValue: ""},
            {name: 'relatedCatalogId', type: 'string', defaultValue: ""}
342b20ca   Benjamin Renard   Fix inheritence b...
143
144
	],

16035364   Benjamin Renard   First commit
145
146
	/*commit: function(){
	    this.callParent(arguments);
342b20ca   Benjamin Renard   Fix inheritence b...
147

16035364   Benjamin Renard   First commit
148
	    // fix the modifications for its intervals
342b20ca   Benjamin Renard   Fix inheritence b...
149
150
151
	    Ext.Array.each(this.get('intervals'), function(item, index, all) {
//TODO check if JSON object should be processed
	       if (item.$className) {
16035364   Benjamin Renard   First commit
152
	                   item.commit();
342b20ca   Benjamin Renard   Fix inheritence b...
153
	       }
16035364   Benjamin Renard   First commit
154
        });
342b20ca   Benjamin Renard   Fix inheritence b...
155

16035364   Benjamin Renard   First commit
156
	},*/
342b20ca   Benjamin Renard   Fix inheritence b...
157

16035364   Benjamin Renard   First commit
158
//	hasMany: {model: 'amdaModel.Interval', name: 'intervals'},
342b20ca   Benjamin Renard   Fix inheritence b...
159

16035364   Benjamin Renard   First commit
160
161
162
163
164
165
    /**
     * get TimeTable values to sent to Server
     * @return object
     */
	//TODO utf8_encode() and Ext.urlEncode() ???
    getJsonValues : function (hasId) {
342b20ca   Benjamin Renard   Fix inheritence b...
166
    	var values  = new Object();
16035364   Benjamin Renard   First commit
167
168
169
170
171
172
173
174
175
176
177
178
179
    	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');
709a2d2e   Hacene SI HADJ MOHAND   il reste auto sta...
180
                    values.folderId = this.get('folderId');
16035364   Benjamin Renard   First commit
181
182
    	values.nbIntervals = this.get('nbIntervals');
    	values.cacheToken = this.get('cacheToken');
342b20ca   Benjamin Renard   Fix inheritence b...
183

16035364   Benjamin Renard   First commit
184
185
    	values.leaf = true;
    	values.nodeType = amdaModel.TimeTableNode.nodeType;
a4acaf46   Hacene SI HADJ MOHAND   IHM progess
186
187
188
189
190
191
        
                   if (this.get('contact').match(/[a-z,0-9]/gi) != null) {
    		values.contact = this.get('contact');
    	}
                    values.surveyStart = this.get('surveyStart');
                    values.surveyStop = this.get('surveyStop');                
16035364   Benjamin Renard   First commit
192
193
194
195
    	return values;
    }

});