Statistic.js
3.17 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
/**
* Project : AMDA-NG
* Name : Statistic.js
* Description : Statistics Object Definition
* @class amdaModel.Statistic
* @extends amdaModel.AmdaTimeObject
* @author elena
*/
Ext.define('amdaModel.Statistic', {
extend: 'amdaModel.AmdaTimeObject',
requires: [
"amdaModel.StatisticParam"
],
fields : [
{name: 'type', type: 'string', defaultValue: 'Statistic'},
{name: 'description', type: 'string'},
{name: 'last_update', type: 'int', defaultValue: 0}
],
associations : [
{
type : 'hasMany',
model : 'amdaModel.StatisticParam',
name : 'params'
}
],
constructor: function(){
var me = this;
me.callParent(arguments);
if ((arguments.length > 0) && arguments[0])
{
if (arguments[0].parameter)
me.loadParams(arguments[0].parameter);
}
this.dirty = false;
},
loadParams: function(params)
{
/* Compatability mode */
Ext.each(params, function(param, index) {
if (param.hasOwnProperty('is-init')) {
return;
}
params[index]['dim1-sum-type'] = param['dim1-is-range'] ? 1 : 0;
params[index]['dim1-min-value'] = param['dim1-min-range'];
params[index]['dim1-max-value'] = param['dim1-max-range'];
params[index]['dim2-sum-type'] = param['dim2-is-range'] ? 1 : 0;
params[index]['dim2-min-value'] = param['dim2-min-range'];
params[index]['dim2-max-value'] = param['dim2-max-range'];
params[index]['is-init'] = true;
});
this.params().loadData(params);
},
isDirty : function() {
if (this.dirty)
return true;
var d = false;
this.params().each(function (param, index) {
if (param.dirty)
d = true;
});
return d;
},
getJsonValues : function ()
{
var values = new Object();
values.nodeType = 'statistic';
values.type = this.get('type');
values.name = this.get('name');
values.timesrc = this.get('timesrc');
values.description = this.get('description');
// if there's at least one parameter
values.parameter = [];
this.params().each(function (param, index) {
values.parameter[index] = param.getJsonValues();
});
if (values.timesrc == amdaModel.AmdaTimeObject.inputTimeSrc[0])
{
// get complete timeTables collection
var timeTables = this.get('timeTables');
// init an empty array for timeTables
values.timeTables=[];
// for each interval record
Ext.Array.each(timeTables, function(item, index, all)
{
if (!item.$className) {
values.timeTables[index] = {timeTableName : item.timeTableName, id : item.id};
}
// get Json simplified value
else {
values.timeTables[index] = item.getJsonValues();
}
});
} else
{
values.startDate = Ext.Date.format(this.get('startDate'), 'Y-m-d\\TH:i:s.u');
values.stopDate = Ext.Date.format(this.get('stopDate'), 'Y-m-d\\TH:i:s.u');
values.durationDay = this.get('durationDay');
values.durationHour = this.get('durationHour');
values.durationMin = this.get('durationMin');
values.durationSec = this.get('durationSec');
values.durationMs = this.get('durationMs');
}
values.leaf = true;
return values;
}
});