OperationsTT.js
5.71 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
183
184
185
186
187
188
189
190
/**
* Project : AMDA-NG
* Name : OperationsTT.js
* @class amdaUI.OperationsTT
* @extends Ext.form.FieldSet
* @brief Operations in Time Table Module UI (View)
* @author Myriam
* @version $Id: OperationsTT.js 1855 2013-11-19 13:23:55Z elena $
********************************************************************************
* FT Id : Date : Name - Description
*******************************************************************************
* 08/06/2011: Myriam - Migration extjs4
*/
Ext.define('amdaUI.OperationsTT', {
extend: 'Ext.form.FieldSet',
alias: 'widget.operationsTT',
// Translate Extend or Shift in seconds
TranslateSec: function(valueForm, valueUnit) {
if (valueForm == "") var value = 0;
else switch (valueUnit) {
case "sec":
var value = valueForm;
break;
case "min":
var value = valueForm * 60;
break;
case "hour":
var value = valueForm * 3600;
break;
case "day":
var value = valueForm * 86400;
break;
default:
break;
}
return value;
},
// Extend and shift intervals
ExtendTT: function(dir){
var extendForm = this.formExtend.getForm().findField('extend').getValue();
var extendUnit = this.formExtend.getForm().findField('extendUnit').getValue();
var shiftForm = this.formExtend.getForm().findField('shift').getValue();
var shiftUnit = this.formExtend.getForm().findField('shiftUnit').getValue();
if ((extendForm == null) && (shiftForm == null))return;
// Translate Extend and Shift in milliseconds
var extend = dir * this.TranslateSec(extendForm, extendUnit);
var shift = dir * this.TranslateSec(shiftForm, shiftUnit);
this.cntApply += dir;
if (this.cntApply < 0) {
this.cntApply = 0;
alert("Nothing to Undo");
return;
}
var me = this;
AmdaAction.operationTTCacheIntervals(extend,shift, function () {
me.parent.TTGrid.getStore().reload();
// Update historic field
var history = me.parent.formPanel.getForm().findField('history').getValue();
if (extend != 0) {
history += " \n Extended by "+ dir*extendForm + " " + extendUnit;
}
if (shift != 0) {
history += " \n Shifted by "+ dir*shiftForm + " " + shiftUnit;
}
me.parent.formPanel.getForm().findField('history').setValue(history);
});
},
// Merge intervals
MergeTT: function(){
var me = this;
AmdaAction.mergeTTCacheIntervals(function () {
me.parent.TTGrid.getStore().reload({
callback : function(records, options, success) {
me.parent.updateCount();
},
me
});
});
},
initComponent : function (){
this.cntApply = 0;
this.formExtend = new Ext.form.Panel({
xtype: 'form', frame: true, buttonAlign: 'center', height: 75,
trackResetOnLoad : true, // reset to the last loaded record
fieldDefaults: {
labelWidth: 40, labelSeparator: ''
},
items: [
{
xtype: 'fieldcontainer',
layout: 'hbox',
fieldLabel:'Extend',
items: [
{xtype:'numberfield', name: 'extend', hideTrigger: true, width: 60},
{xtype: 'splitter', width: 5},
{
xtype:'combo', name: 'extendUnit', store:['sec', 'min', 'hour', 'day'],
editable: false, width: 60, value: 'min', triggerAction: 'all'
},
{xtype: 'splitter', width: 20},
{xtype:'displayfield', value: 'Shift', width: 30},
{xtype:'numberfield', name: 'shift', hideTrigger: true, width: 60},
{xtype: 'splitter', width: 5},
{
xtype:'combo', name: 'shiftUnit', store:['sec', 'min', 'hour', 'day'],
editable: false, width: 60, value: 'min', triggerAction: 'all'
}
]
}
],
fbar: [{
text: 'Apply',
scope: this,
handler: function () {
this.ExtendTT(1);
this.parent.fireEvent('refresh');
}
},{
text: 'Undo',
scope: this,
handler: function () {
this.ExtendTT(-1);
this.parent.fireEvent('refresh');
}
}]
});
var config = {
title:'Operations on Intervals',
style: { borderWidth: '2px' },
items: [
{xtype: 'splitter', width: 5},
this.formExtend,
{
xtype: 'form', frame: true,
border: 1,
height: 60,
layout: {
type: 'hbox',
pack: 'center',
align: 'middle'
},
items: [
{
xtype: 'button',
text: 'Merge intervals',
minWidth: 105,
scope : this,
handler: function () {
this.MergeTT();
this.parent.fireEvent('refresh');
}
},
{
xtype: 'container',
width: 5
},
{
xtype: 'button',
text: 'Statistical info',
minWidth: 105,
scope: this,
handler: function() {
this.parent.fireEvent('info');
}
}
]
}
]
};
Ext.apply (this , Ext.apply (this.initialConfig, config));
this.callParent(arguments);
}
});