Blame view

js/app/models/TimeTable.js 6.37 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
    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;
		   }
	},
265c5cdf   Hacene SI HADJ MOHAND   ok
49
50
51
52
53
54
55
56
57
58
         {
            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
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
        {
            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...
93

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

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

 /*
16035364   Benjamin Renard   First commit
117
118
119
120
121
122
123
124
    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...
125

16035364   Benjamin Renard   First commit
126
127
128
129
});


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

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

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

16035364   Benjamin Renard   First commit
149
150
	/*commit: function(){
	    this.callParent(arguments);
342b20ca   Benjamin Renard   Fix inheritence b...
151

16035364   Benjamin Renard   First commit
152
	    // fix the modifications for its intervals
342b20ca   Benjamin Renard   Fix inheritence b...
153
154
155
	    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
156
	                   item.commit();
342b20ca   Benjamin Renard   Fix inheritence b...
157
	       }
16035364   Benjamin Renard   First commit
158
        });
342b20ca   Benjamin Renard   Fix inheritence b...
159

16035364   Benjamin Renard   First commit
160
	},*/
342b20ca   Benjamin Renard   Fix inheritence b...
161

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

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

16035364   Benjamin Renard   First commit
188
189
    	values.leaf = true;
    	values.nodeType = amdaModel.TimeTableNode.nodeType;
a4acaf46   Hacene SI HADJ MOHAND   IHM progess
190
191
192
193
194
195
        
                   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
196
197
198
199
    	return values;
    }

});