Blame view

js/app/views/OperationsTT.js 6.83 KB
16035364   Benjamin Renard   First commit
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
/**
  * 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;
5d15649f   Benjamin Renard   Migration to ExtJ...
65
	    me.parent.TTGrid.getSelectionModel().deselectAll();
f3e15e49   Erdogan Furkan   #10700 - Done
66
	    AmdaAction.operationTTCacheIntervals(extend,shift, me.isCat, function () {
16035364   Benjamin Renard   First commit
67
68
69
	    	me.parent.TTGrid.getStore().reload();
	    	
			// Update historic field
2da2119e   Benjamin Renard   Minor fix
70
			if(!me.isCat){
f3e15e49   Erdogan Furkan   #10700 - Done
71
72
73
74
75
76
77
78
				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);
16035364   Benjamin Renard   First commit
79
			}
16035364   Benjamin Renard   First commit
80
81
82
83
84
85
86
87
88
89
90
91
	    });
	
	},
	
	// Merge intervals
	MergeTT: function(){
		var me = this;
		AmdaAction.mergeTTCacheIntervals(function () {
	    	me.parent.TTGrid.getStore().reload({
        		callback : function(records, options, success) {
        			me.parent.updateCount();	
        		},
71a95117   Benjamin Renard   Fix some bugs aro...
92
        		scope : me
16035364   Benjamin Renard   First commit
93
94
95
96
97
98
99
	    	});	
	    });   
	},
		
    initComponent : function (){
		this.cntApply = 0;
		this.formExtend = new Ext.form.Panel({
f3e15e49   Erdogan Furkan   #10700 - Done
100
			xtype: 'form', frame: true, buttonAlign: 'center', height: (this.isCat) ? 90 : 75,
16035364   Benjamin Renard   First commit
101
102
103
104
			trackResetOnLoad : true, // reset to the last loaded record
        	fieldDefaults: {
                labelWidth: 40, labelSeparator: ''
            },
f3e15e49   Erdogan Furkan   #10700 - Done
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
			items: (this.isCat) ? 
				[ 	        	        
					{
						xtype: 'fieldcontainer',
						layout:'hbox',
						defaults: {
							flex: 1,
						},
						items: [
							{ xtype: 'label',text: 'Extend',margin: '3 0 0 0' },
							{xtype:'numberfield',  name: 'extend', hideTrigger: true, width: 50},
							{
								xtype:'combo',name: 'extendUnit', store:['sec', 'min', 'hour', 'day'], 
								editable: false, width: 50, value: 'min',	triggerAction: 'all'
							},
						]
					},
					{
						xtype: 'fieldcontainer',
						layout:'hbox',
						defaults: {
							flex: 1,
							//hideLabel: true
						},
						items: [
							{ xtype: 'label', text: 'Shift', margin: '3 0 0 0' },
							{xtype:'numberfield',  name: 'shift', hideTrigger: true, width: 50},
							{
								xtype:'combo',name: 'shiftUnit', store:['sec', 'min', 'hour', 'day'], 
								editable: false, width: 50, value: 'min',	triggerAction: 'all'
							},
						]
					}
				]
				:
				[{
16035364   Benjamin Renard   First commit
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
    	        	  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',
d1dd574b   Furkan   Done, in a way
182
183
           style: this.isCat ? '' :{ borderWidth: '2px' },
		   border: this.isCat ? false:'',            
16035364   Benjamin Renard   First commit
184
185
186
           items: [
               {xtype: 'splitter', width: 5},   
               this.formExtend,
f3e15e49   Erdogan Furkan   #10700 - Done
187
			   (this.isCat) ? {} :
16035364   Benjamin Renard   First commit
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
               {
		        	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() {
0318dbe6   Hacene SI HADJ MOHAND   rm_6998 ok
218
	    						this.parent.fireEvent('info','timeTableUi');
16035364   Benjamin Renard   First commit
219
220
221
222
223
224
225
226
227
	    					}
	    				} 
	              	]
		        } 
           ]
        };
        Ext.apply (this , Ext.apply (this.initialConfig, config));
        this.callParent(arguments);
  }
2da2119e   Benjamin Renard   Minor fix
228
 });