Blame view

js/app/views/TimeTableUI.js 31.6 KB
16035364   Benjamin Renard   First commit
1
2
3
4
/**
 * Project   : AMDA-NG
 * Name      : TimeTableUI.js
 * @class 	 amdaUI.TimeTableUI
70aabdee   elena   catalog draft
5
 * @extends    Ext.container.Container
16035364   Benjamin Renard   First commit
6
7
8
 * @brief	 Time Table Module UI definition (View)
 * @author 	 Myriam
 * @version  $Id: TimeTableUI.js 2075 2014-02-11 11:30:14Z elena $
16035364   Benjamin Renard   First commit
9
10
11
12
13
14
15
 */

Ext.define('amdaUI.TimeTableUI', {
	extend: 'Ext.container.Container',
	alias: 'widget.panelTimeTable',
	
	requires: [
70aabdee   elena   catalog draft
16
17
18
19
20
21
		'Ext.ux.grid.FiltersFeature',
		'Ext.ux.grid.filter.DateFilter',
		'Ext.ux.grid.filter.NumericFilter',
		'amdaUI.OperationsTT',
		'amdaUI.StatisticalPlug',
		'Ext.grid.plugin.BufferedRenderer'
16035364   Benjamin Renard   First commit
22
23
24
	],
	
	statics: {
70aabdee   elena   catalog draft
25
26
		COL_TO_HIDE : 'colToHide'
	},
16035364   Benjamin Renard   First commit
27
       
70aabdee   elena   catalog draft
28
	status: null,
16035364   Benjamin Renard   First commit
29
30
31
32
33
34
35
36
37
38
39
40
    
	constructor: function(config) {          	 
		this.init(config);
	 	this.callParent(arguments);
	 	// load object into view
	 	this.loadObject();
	},

	/**
	 * set the current editing object
	 * this method will be used on timetable edition when this win is already opened
	 */
70aabdee   elena   catalog draft
41
42
	setObject : function (object) 
	{
16035364   Benjamin Renard   First commit
43
44
45
46
47
48
49
		// set object
		this.object = object;
		
		// load object into view
		this.loadObject();
        
		// show the default duration column
901ba3f3   Elena.Budnik   upload catalog
50
51
		this.TTGrid.headerCt.getGridColumns();
		
16035364   Benjamin Renard   First commit
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
		Ext.Array.each(this.TTGrid.headerCt.getGridColumns(), function(item,index,all){
			// if item is the default duration column
			if ( item.id == amdaUI.TimeTableUI.COL_TO_HIDE+'2' ) {
				// show this column
				item.show();
			}
		});    
        // fire the refresh event (to statistical plugin)
        this.fireEvent("refresh");
	// global event
	myDesktopApp.EventManager.fireEvent("refresh");
	},
	
	/**
	 * load object timetable into this view
	 */
	loadObject : function(){    
        // load object into form
        this.formPanel.getForm().loadRecord(this.object);
        
        this.status = null;
        
        //
        var me = this;
        
        var onAfterInit = function(result, e) {
        	if (!result || !result.success)
        	{
        		if (result.message)
        			myDesktopApp.errorMsg(result.message);
        		else
        			myDesktopApp.errorMsg('Unknown error during cache initialisation');
        		return;
        	}
        	
        	me.TTGrid.getSelectionModel().deselectAll();
        	        	
        	// clear filters
        	me.TTGrid.getStore().clearFilter(true);
55da2eac   Benjamin Renard   Fix another bug w...
91
		me.TTGrid.filters.clearFilters();
16035364   Benjamin Renard   First commit
92
93
        
    		//clear sort
5d15649f   Benjamin Renard   Migration to ExtJ...
94
95
        	me.TTGrid.getStore().sorters.clear();
        	//me.TTGrid.getStore().sorters = new Ext.util.MixedCollection();
16035364   Benjamin Renard   First commit
96
97
98
        	
        	//set cache token to the Time Table object
        	me.object.set('cacheToken', result.token);
0d95ceab   Elena.Budnik   redmine #5141, part1
99
      			
5d15649f   Benjamin Renard   Migration to ExtJ...
100
        	me.TTGrid.getStore().load();
16035364   Benjamin Renard   First commit
101
102
103
104
105
106
107
108
109
110
111
112
        	
        	me.status = result.status;
        	
        	//Statistical plugin
        	me.fireEvent("refresh");
        };
        
        if (this.object.get('fromPlugin'))
        {
        	if (this.object.get('objFormat') && this.object.get('objFormat') != '')
        	{
        		//From uploaded file
0364e7a3   Elena.Budnik   bug when call to ...
113
        		AmdaAction.initTTCacheFromUploadedFile(this.object.get('objName'), this.object.get('objFormat'), false, onAfterInit);
16035364   Benjamin Renard   First commit
114
115
116
117
        	}
        	else
        	{
        		//From tmp object (ie Search result)
71a95117   Benjamin Renard   Fix some bugs aro...
118
        		AmdaAction.initTTCacheFromTmpObject(this.object.get('folderId'), this.object.get('objName'), false, onAfterInit);
16035364   Benjamin Renard   First commit
119
120
        	}
        }
d547a559   Hacene SI HADJ MOHAND   rm_6903 ok
121
        else if(this.object.get('relatedCatalogId') != '')
80af0168   Hacene SI HADJ MOHAND   rm_6903 adding na...
122
123
124
125
126
127
128
129
        {  
                              var pathern=this.object.get('relatedCatalogId').split('_')[0] ;
                              catType='';
                               if(pathern=='cat')
                                   catType=' catalog' ;
                               if(pathern=='sharedcatalog')
                                   catType='sharedcatalog' ;
                               AmdaAction.initTTCacheFromCatalog(this.object.get('relatedCatalogId'), catType, onAfterInit);
d547a559   Hacene SI HADJ MOHAND   rm_6903 ok
130
131
        }
       else 
16035364   Benjamin Renard   First commit
132
133
134
135
136
        {
        	var typeTT = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.tt.id).linkedNode.data.nodeType;
        	if (this.object.get('id') == '')
        	{
        		//Init empty cache
71a95117   Benjamin Renard   Fix some bugs aro...
137
        		AmdaAction.initTTCache(false,0,onAfterInit);
16035364   Benjamin Renard   First commit
138
139
140
141
142
143
144
145
146
147
148
149
        	}	
        	else
        	{
        		//From existing TT file
        		AmdaAction.initTTCacheFromTT(this.object.get('id'), typeTT, onAfterInit);
        	}
        }
	},

	/**
	* update this.object from form
	*/
70aabdee   elena   catalog draft
150
151
	updateObject : function()
	{
16035364   Benjamin Renard   First commit
152
153
154
		this.updateCount();
		
		// get the basic form
70aabdee   elena   catalog draft
155
156
		var basicForm = this.formPanel.getForm();        
		var updateStatus = true;
16035364   Benjamin Renard   First commit
157

70aabdee   elena   catalog draft
158
159
160
161
162
163
164
165
166
		var fieldsWithoutName = basicForm.getFields().items;
		Ext.Array.each(fieldsWithoutName, function(item, index,allItems){
			if(item !== this.fieldName) { 		     
				if (!item.isValid()) {
					// set update isn't allowed
					updateStatus = false;    
				}
			}
		}, this);
16035364   Benjamin Renard   First commit
167
		// if the update is allowed
70aabdee   elena   catalog draft
168
169
170
171
172
173
174
		if (updateStatus) {
		/// real object update
		// update TimeTable object with the content of form
			basicForm.updateRecord(this.object);	
		}
		// return the update status
		return updateStatus;	    
16035364   Benjamin Renard   First commit
175
176
	},	

70aabdee   elena   catalog draft
177
178
	updateCount : function() 
	{
16035364   Benjamin Renard   First commit
179
180
181
182
183
184
185
		this.object.set('nbIntervals',this.TTGrid.getStore().getTotalCount());
		this.formPanel.getForm().findField('nbIntervals').setValue(this.object.get('nbIntervals'));
	},
	
	/*	    
	 * save method called by Save button
	 */
70aabdee   elena   catalog draft
186
187
	saveProcess : function(toRename)
	{
0d95ceab   Elena.Budnik   redmine #5141, part1
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
		var timeTableModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.tt.id); 
	
		// if the name has been modified this is a creation
		if (timeTableModule.contextNode &&  (timeTableModule.contextNode.data.id == 'sharedtimeTable-treeRootNode'))
		{ 
			timeTableModule.linkedNode = null;	    		      
			timeTableModule.createLinkedNode();
			timeTableModule.createObject(this.object.getJsonValues());     
			var ttobj = timeTableModule.linkedNode.get('object');                                                    
			// synchronisation of objects
			this.object = ttobj;
			timeTableModule.linkedNode.create();
		}
		else  if (this.fclose()) /*TimeTable object has been modified*/
		{
			if (this.object.isModified('name') || this.object.get('fromPlugin')) 
			{			
				// if object already has an id : it's a 'rename' of an existing TimeTable
				if (this.object.get('id'))
				{
					// the context Node is the parent node of current edited one
					var contextNode = timeTableModule.linkedNode.parentNode;
					// link a new node to the TimeTableModule
					timeTableModule.createLinkedNode();
					// set the contextNode
					timeTableModule.linkedNode.set('contextNode',contextNode);
					// create a new object linked
					timeTableModule.createObject(this.object.getJsonValues());
					
					var ttobj = timeTableModule.linkedNode.get('object');                                                    
					// synchronisation of objects
					this.object = ttobj;
					
					if (toRename) timeTableModule.linkedNode.toRename = true;
				} 
				timeTableModule.linkedNode.create({callback : function ($action) {
					if (timeTableModule.linkedNode.get('object').get('fromPlugin'))
						timeTableModule.linkedNode.get('object').set('fromPlugin',false);
					timeTableModule.linkedNode.update();}, 
					scope : this});
			} else {
				//update
				timeTableModule.linkedNode.update();
			}
		}
16035364   Benjamin Renard   First commit
233
234
235
236
237
	},
	
	/**
	 * overwrite metod called by Save button
	 */
70aabdee   elena   catalog draft
238
239
	overwriteProcess : function(btn)
	{	
16035364   Benjamin Renard   First commit
240
241
		if (btn == 'cancel') return;
           
70aabdee   elena   catalog draft
242
		this.fieldName.clearInvalid();
16035364   Benjamin Renard   First commit
243
244
245
246
		this.saveProcess(true);		
		
	},
	
70aabdee   elena   catalog draft
247
248
	addInterval : function(start, stop) 
	{
a73f0195   Benjamin Renard   Insert interval i...
249
250
		var row = this.TTGrid.getStore().getTotalCount();
		var me = this;
5d15649f   Benjamin Renard   Migration to ExtJ...
251
		this.TTGrid.getSelectionModel().deselectAll();
a73f0195   Benjamin Renard   Insert interval i...
252
253
		AmdaAction.addTTCacheInterval({'start' : start, 'stop' : stop, 'index' : row},function (result, e) {
			this.status = result.status;
55da2eac   Benjamin Renard   Fix another bug w...
254
255
256
257
258
259
260
261
262
		if (!this.TTGrid.getStore().loading) {
        		this.TTGrid.getStore().reload({
        			callback : function(records, options, success) {
        				me.TTGrid.getView().bufferedRenderer.scrollTo(row, false, function() {
        					me.TTGrid.getView().select(row);
        				}, me);
        			}
        		});
		}
70aabdee   elena   catalog draft
263
		}, this);
16035364   Benjamin Renard   First commit
264
265
	},
	
70aabdee   elena   catalog draft
266
267
	init : function(config) 
	{	    
16035364   Benjamin Renard   First commit
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
	    this.object =   config.object;
	     
	    this.fieldName = new Ext.form.field.Text({
                fieldLabel: 'Name*',
                allowBlank : false,
                stripCharsRe: /(^\s+|\s+$)/g,
                emptyText: 'Please no spaces!',
                name: 'name',
                anchor: '100%',
                validateOnChange: false,
                validateOnBlur: false,
                validFlag: false,
	            validator : function() {
	            	return this.validFlag;
	            }
	    });
	    
	    this.formPanel = new Ext.form.Panel({
            bodyStyle: {background : '#dfe8f6'},
            id: 'formTimeTable',
            flex: 4,
            model : 'amdaModel.TimeTable',
            trackResetOnLoad : true, // reset to the last loaded record
            border : false,
            fieldDefaults: { labelWidth: 80 },
            items: [
                this.fieldName,      
                {
                    xtype: 'fieldcontainer',
                    layout: 'hbox',
                    fieldLabel:'Creation date',
                    items: [
                        {
96c5328a   Myriam Bouchemit   augmentation larg...
301
                            xtype:'datefield', width: 180, 
16035364   Benjamin Renard   First commit
302
303
304
305
306
307
                            name: 'created', disabled: true, 
                            hideTrigger: true, format: 'Y/m/d H:i:s'
                        },
                        { xtype:'component', width: 20 },
                        { xtype:'displayfield', value: 'Intervals:', width: 50 },
                        { xtype:'component', width: 8 },
96c5328a   Myriam Bouchemit   augmentation larg...
308
                        { xtype:'textfield', name: 'nbIntervals', disabled: true, width: 70 }
16035364   Benjamin Renard   First commit
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
                    ]                                                                       
                },
                {
                    xtype: 'textarea',
                    name: 'description',
                    fieldLabel: 'Description',
                    anchor: '100% 50%'
                },
                {
                    xtype: 'textarea',
                    name: 'history',
                    fieldLabel: 'Operation log',
                    anchor: '100% 30%'
                }
            ]

        });
	    
	    var store = Ext.create('Ext.data.Store', {
	        model: 'amdaModel.Interval',
	        autoDestroy: false,
	        pageSize : 200,
		  buffered : true,
	      autoLoad: true,
	      purgePageCount: 0,
	 	remoteSort: true,
	        listeners: { 
	            load: function(store,records) {
	            	
 	              //  alert('nb of records in store:'+records.length );          
                        myDesktopApp.EventManager.fireEvent('refresh');
                        this.TTGrid.getView().refresh();
                        this.TTGrid.getSelectionModel().refresh();
                        this.updateCount();
                        //Statistical plugin
             		   	this.fireEvent("refresh");
	            },
	            prefetch : function(store, records, successful, operation, eOpts) {
	            	if (operation && (operation.action == 'read'))
	            	{
	            		if (operation.response && operation.response.result && operation.response.result.success)
	            			this.status = operation.response.result.status;
	            	}
	            },
	            remove: function(store) {
	            	this.updateCount();
	            	//Statistical plugin
         		   	this.fireEvent("refresh");
	            },
	            add:  function(store) {
	            	this.updateCount();
	            	//Statistical plugin
         		   	this.fireEvent("refresh");
	            },
	            datachanged: function(store){
	            	this.updateCount();
	            	//Statistical plugin
         		   	this.fireEvent("refresh");
	    		},
	            scope : this
	        } 
	    });      
     
	    var filters = {
	        ftype: 'filters',
	        encode: true, // json encode the filter query
	        local: false,   // defaults to false (remote filte
	        filters: [
                { type: 'numeric', dataIndex: 'durationHour'},
                { type: 'numeric', dataIndex: 'durationMin'},  
                { type: 'numeric', dataIndex: 'durationSec'},  		     
                { type: 'date', dataIndex: 'start',  dateFormat: 'Y-m-d'},
                { type: 'date', dataIndex: 'stop',  dateFormat: 'Y-m-d' }
            ]
	    };  

	    var cellEditing = Ext.create('Ext.grid.plugin.CellEditing',{
	    		onEditComplete : function(ed, value, startValue) {
	    	        var me = this,
	    	            activeColumn = me.getActiveColumn(),
	    	            context = me.context,
	    	            record;

	    	        if (activeColumn) {
	    	            record = context.record;

	    	            me.setActiveEditor(null);
	    	            me.setActiveColumn(null);
	    	            me.setActiveRecord(null);
	    	    
	    	            context.value = value;
	    	            if (!me.validateEdit()) {
	    	                me.editing = false;
	    	                return;
	    	            }

	    	            // Only update the record if the new value is different than the
	    	            // startValue. When the view refreshes its el will gain focus
	    	            if (!record.isEqual(value, startValue)) {
	    	            	var obj = null;
	    	            	if (activeColumn.dataIndex == 'start')
	    	            		obj = {
	    	            			'cacheId' : record.get('cacheId'),
	    	            			'start'   : value
	    	            		};
	    	            	else if (activeColumn.dataIndex == 'stop')
	    	            		obj = {
	    	            			'cacheId' : record.get('cacheId'),
	    	            			'stop'   : value
	    	            		};
	    	            	else
	    	            	{
	    	            		me.editing = false;
		    	                return;
	    	            	}
	    	            		
	    	            	//context.grid.getSelectionModel().deselectAll();
	    	            	//Interval is modified on the server side
5d15649f   Benjamin Renard   Migration to ExtJ...
427
428
	    	            	me.editing = true;
	    	            	
16035364   Benjamin Renard   First commit
429
	    	            	AmdaAction.modifyTTCacheInterval(obj, function (result, e) {
5d15649f   Benjamin Renard   Migration to ExtJ...
430
	    	            		
16035364   Benjamin Renard   First commit
431
432
433
	    	            		var ttModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.tt.id);
                    			if (ttModule)
                    				ttModule.getUiContent().status = result.status;
55da2eac   Benjamin Renard   Fix another bug w...
434
435
436
437
438
439
440
441
442
443
444
445
446
447
					if (!context.store.loading) {
                    				context.grid.getSelectionModel().deselectAll();
	    	            			context.store.reload({
	                        			callback : function(records, options, success) {
	                        				context.view.bufferedRenderer.scrollTo(context.rowIdx, true, function() {
	                        					me.fireEvent('edit', me, context);
	                        					me.editing = false;
	                        				}, me);	    	            
	                        			}
	                        		});
					}
					else {
						me.editing = false;
					}
16035364   Benjamin Renard   First commit
448
449
	                        }, this);
	    	            }
5d15649f   Benjamin Renard   Migration to ExtJ...
450
451
	    	            else
	    	            	me.editing = false;
16035364   Benjamin Renard   First commit
452
453
454
455
456
457
458
459
460
	    	        }
	    	    }
	    
	    });

	    this.TTGrid =  Ext.create('Ext.grid.Panel', {
	        store : store,
	        features: [filters],
	        columnLines: true,
a061cfac   Benjamin Renard   Fix a bug with TT...
461
		selModel: {pruneRemoved: false},
16035364   Benjamin Renard   First commit
462
463
464
465
466
	        columns: [ 
                {
                	xtype: 'rownumberer',
                	width: 50,
                	renderer: function(value, metaData, record, row, col, store, gridView){
e2acb540   Elena.Budnik   redmine #6397 : ...
467
                		var msg = record.index + 1;
16035364   Benjamin Renard   First commit
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
                		if (record.get('isNew') || record.get('isModified'))
                		{
                			msg += ' *';
                			metaData.style = 'font-weight: bold'
                		}
               	      	return msg;
                    }
                },
                {   
                    header: 'Start Time', dataIndex: 'start',  width: 120,
                    editor: { xtype:'datefield', allowBlank:false, hideTrigger: true,  format : 'Y-m-d\\TH:i:s'},                              
                    renderer: function(value){  
                        if (value != null) {
                            if(Ext.isDate(value)){
                                return Ext.Date.format(value, 'Y-m-d\\TH:i:s');
                            } else {
                                return Ext.Date.format(new Date (value), 'Y-m-d\\TH:i:s');
                            }
                        } else {
                            return value;
                        }
                    }
                },
                {  
                    header: 'Stop Time', dataIndex: 'stop', width: 120, 
                    editor: { xtype: 'datefield', allowBlank: false, hideTrigger: true,  format : 'Y-m-d\\TH:i:s'},
                    renderer: function(value) {
                        if (value != null) {
                            if(Ext.isDate(value)){
                                return Ext.Date.format(value, 'Y-m-d\\TH:i:s');
                            } else {
                                return Ext.Date.format(new Date (value), 'Y-m-d\\TH:i:s');
                            }
                        } else {
                            return value;
                        }
                    }
                },                             
                {
                    header: 'Duration (hour)',  width: 120, dataIndex: 'durationHour',
                    id: amdaUI.TimeTableUI.COL_TO_HIDE+'1',
                    hidden: true,
                    renderer: function(value) {
                        return Ext.util.Format.number(value,'0.00');
                    },
                    listeners: {
                        beforeshow : function(){
                            Ext.Array.each(this.ownerCt.getGridColumns(), function(item,index,all){
                                // if item is a column to hide automatically
                                if ( Ext.util.Format.substr(item.id, 0, amdaUI.TimeTableUI.COL_TO_HIDE.length) == amdaUI.TimeTableUI.COL_TO_HIDE ) {
                                    // if item isn't the column which is being declared and is not hidden
                                    if ( item.id != amdaUI.TimeTableUI.COL_TO_HIDE+'1' && !item.isHidden() ){
                                        // hide this column
                                        item.hide();
                                    }
                                }
                            });
                        }
                    }
                },                             
                {
                	header: 'Duration (min)',  width: 120, dataIndex: 'durationMin',
                	id: amdaUI.TimeTableUI.COL_TO_HIDE+'2',
                	renderer: function(value) {
                		return Ext.util.Format.number(value,'0.00');
                	},
                    listeners: {
                        beforeshow : function(){
                            Ext.Array.each(this.ownerCt.getGridColumns(), function(item,index,all){
                                // if item is a column to hide automatically
                                if ( Ext.util.Format.substr(item.id, 0, amdaUI.TimeTableUI.COL_TO_HIDE.length) == amdaUI.TimeTableUI.COL_TO_HIDE ) {
                                    // if item isn't the column which is being declared and is not hidden
                                    if ( item.id != amdaUI.TimeTableUI.COL_TO_HIDE+'2' && !item.isHidden() ){
                                        // hide this column
                                        item.hide();
                                    }
                                }
                            });
                        }
                    }
                },                             
                {
                    header: 'Duration (sec)',  width: 120, dataIndex: 'durationSec',
                    id: amdaUI.TimeTableUI.COL_TO_HIDE+'3',
                    hidden: true,
                    renderer: function(value) {
                        return Ext.util.Format.number(value,'0.00');
                    },
                    listeners: {
                        beforeshow : function(){
                            Ext.Array.each(this.ownerCt.getGridColumns(), function(item,index,all){
                                // if item is a column to hide automatically
                                if ( Ext.util.Format.substr(item.id, 0, amdaUI.TimeTableUI.COL_TO_HIDE.length) == amdaUI.TimeTableUI.COL_TO_HIDE ) {
                                    // if item isn't the column which is being declared and is not hidden
                                    if ( item.id != amdaUI.TimeTableUI.COL_TO_HIDE+'3' && !item.isHidden() ){
                                        // hide this column
                                        item.hide();
                                    }
                                }
                            });
                        }
                    }
                }
            ], 
            frame: true,
            dockedItems: [{
                xtype: 'toolbar', 
                items: [{
                    iconCls: 'icon-add',
                    scope: this,
                    handler: function(){
                        cellEditing.cancelEdit();
                        
                        var selection = this.TTGrid.getView().getSelectionModel().getSelection()[0];
                        var row = 0;
                        if (selection)
                        	row = store.indexOf(selection) + 1;
5d15649f   Benjamin Renard   Migration to ExtJ...
585
                        this.TTGrid.getSelectionModel().deselectAll();
16035364   Benjamin Renard   First commit
586
587
588
589
                        
                        var me = this;
                        AmdaAction.addTTCacheInterval({'index' : row}, function (result, e) {
                        	this.status = result.status;
55da2eac   Benjamin Renard   Fix another bug w...
590
591
592
593
594
595
596
597
598
599
				if (!this.TTGrid.getStore().loading) {
                        		this.TTGrid.getStore().reload({
                        			callback : function(records, options, success) {
                        				me.TTGrid.getView().bufferedRenderer.scrollTo(row, false, function() {
                        					me.TTGrid.getView().select(row);
                        					cellEditing.startEditByPosition({row: row, column: 1});	
                        				}, me);	
                        			}
                        		});
				}
16035364   Benjamin Renard   First commit
600
601
602
603
604
605
606
607
608
609
610
                        }, this);
                    }
                }, {
                    iconCls: 'icon-delete',
                    disabled: true,
                    itemId: 'delete',
                    scope: this,
                    handler:  function(){
                        var selection = this.TTGrid.getView().getSelectionModel().getSelection()[0];
                        if (selection) {
                        	var rowId = selection.get('cacheId');
5d15649f   Benjamin Renard   Migration to ExtJ...
611
                        	this.TTGrid.getSelectionModel().deselectAll();
6b1de4f1   elena   second arg when d...
612
                        	AmdaAction.removeTTCacheIntervalFromId(rowId, false, function (result, e) {
16035364   Benjamin Renard   First commit
613
                        		this.status = result.status;
55da2eac   Benjamin Renard   Fix another bug w...
614
615
616
				if (!this.TTGrid.getStore().loading) {
                            		this.TTGrid.getStore().reload();
				}
16035364   Benjamin Renard   First commit
617
618
619
620
621
622
623
624
625
626
                            }, this);
                        }
                    }
                },
                '->',
                {
                    text: 'Clear Filters',
                    scope: this,
                    handler: function () {
                    	this.TTGrid.getStore().clearFilter(true);
55da2eac   Benjamin Renard   Fix another bug w...
627
			this.TTGrid.filters.clearFilters();
16035364   Benjamin Renard   First commit
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
                    } 
                }
                ] 
            }],
            plugins: [ cellEditing, {ptype : 'bufferedrenderer'} ],
            listeners : {
                scope : this,
                edit : function(editor,e) { 
                    if (e.record.get('stop') != null && e.record.get('start') != null) {
                        e.record.set('durationHour', (e.record.get('stop') - e.record.get('start'))/3600000.0);
                        e.record.set('durationMin', (e.record.get('stop') - e.record.get('start'))/60000.0);
                        e.record.set('durationSec', (e.record.get('stop') - e.record.get('start'))/1000.0);
                        //  send refresh event to statistical plugin
                        this.fireEvent("refresh");
                    }
                }
            }
	    });

	    this.TTGrid.getSelectionModel().on('selectionchange', function(selModel,selections){
	        this.TTGrid.down('#delete').setDisabled(selections.length === 0); 
        }, this);
    	
	    var myConf = {
	        layout: 'border',
	        defaults: { layout: 'fit', border: false },
	        items : [
                {
                    xtype: 'form',
                    region: 'center',
                    buttonAlign: 'left',
                    bodyStyle: {background : '#dfe8f6'},
                    padding: '5 5 5 5',
                    layout: {type: 'hbox', pack: 'start', align: 'stretch'},	
                    items: [						        	        	        
                        {
                            xtype: 'container',
                            flex: 3.6,
                            layout: {type: 'vbox', pack: 'start', align: 'stretch'},
                            items: [
                                this.formPanel,
                                {
                                    xtype: 'operationsTT',
                                    parent: this,
                                    flex: 2.5,
                                    id: 'operation'
                                }
                            ]      
                        }, 
                        {						        	        	        	
                            xtype: 'container',
                            border: false,
                            padding: '0 0 5 15',
                            flex: 4,					
                            layout: 'fit',
                            items: [ this.TTGrid ] 					        	        
                        }
                    ],
                    fbar:[
                        {   
                            xtype: 'button',
                            text: 'Save',
                            width: 65,
                            scope : this,
                            handler: function () {
                            	if (this.updateObject()){
                            		var basicForm = this.formPanel.getForm();      
                            		// if there's at least one record in the store of TTGrid
                            		if (this.TTGrid.getStore().getTotalCount()>0) {
                            			// update TimeTable object which the content of form
                            			basicForm.updateRecord(this.object);

                            			var me = this;
                            			this.checkIntervalsStatusForSave(function () {
                            				//Name validation
                            				var ttModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.tt.id);	
                            				if (!ttModule)
                            					return;
                            				ttModule.linkedNode.isValidName(me.fieldName.getValue(), function (res) {
        			                    		if (!res)
        			                    		{
        			                    			me.fieldName.validFlag = 'Error during object validation';
        			                    			myDesktopApp.errorMsg(me.fieldName.validFlag);
        			                    			me.fieldName.validate();
        			                    			return;
        			                    		}
        									  
        			                    		if (!res.valid)
        			                    		{
        			                    			if (res.error)
        			                    			{
        			                    				if (res.error.search('subtree') != -1) {  							
        			                    					Ext.MessageBox.show({title:'Warning', 
        			                    						msg: res.error+'<br/>Do you want to overwrite it?',
        			                    						width: 300,
        			                    						buttons: Ext.MessageBox.OKCANCEL, 
        			                    						fn : me.overwriteProcess,
        			                    						icon: Ext.MessageBox.WARNING,
        			                    						scope : me
        			                    					});
        			                    					me.fieldName.validFlag = true;
        			                    				}
        			                    				else
        			                    					me.fieldName.validFlag = res.error;
        			                    			}
        			                    			else
        			                    			{
        			                    				me.fieldName.validFlag = 'Invalid object name';
        			                    				myDesktopApp.errorMsg(me.fieldName.validFlag);
        			                    			}
        			                    			me.fieldName.validate();
        			                    			return;
        			                    		}
        									  
        			                    		me.fieldName.validFlag = true;
        			                    		me.fieldName.validate();
        			                    		me.saveProcess(false);
        			                    	});
                            			});                            
  				              } else {
  				                // warning:
  				                Ext.Msg.alert('No intervals', 'Your time table is invalid, <br>you must have at least one interval');
  				              }
                                        }
                           }                                  
                        },{ 
                            xtype: 'button',
                            text: 'Reset',
                            width: 65,
                            scope: this,
                            handler: function() {
	                        	var ttModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.tt.id);			
	    					    ttModule.createLinkedNode();
	    					    ttModule.createObject();
	    					    this.setObject(ttModule.getLinkedNode().get('object'));
                            }
d7cb6b27   Myriam Bouchemit   delete Share button
764
                        } 
16035364   Benjamin Renard   First commit
765
766
767
768
769
                    ]
                },                              
                {
		  xtype: 'panel', region: 'south',
		  title: 'Information',
42863f42   Elena.Budnik   collapseMode: "he...
770
771
		  collapsible: true, 
		  collapseMode: 'header',
16035364   Benjamin Renard   First commit
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
		  height: 100,
		  autoHide: false,
		  iconCls: 'icon-information',
		  bodyStyle: 'padding:5px',
		  loader: {
		    autoLoad: true,
		    url: helpDir+'timetableHOWTO'
		  }	 		    
                }
            ],
            plugins: [ {ptype: 'statisticalPlugin'} ]                   
	    };
	    
	    Ext.apply (this , Ext.apply (arguments, myConf));	    	    
	},
	
	checkIntervalsStatusForSave : function(onStatusOk) {
		if (this.status == null)
			return;
		
		if (this.status.nbValid <= 0)
		{
			myDesktopApp.errorMsg('Your time table is invalid, <br>you must have at least one valid interval');
			return;
		}
		
		var msg = '';
		if (this.status.nbInvalid > 0)
			msg += 'There are some invalid intervals. Only valid intervals will be saved!<br/>';
		if (this.status.nbFiltered > 0)
			msg += 'There are some filtered intervals. Filtered intervals will not be saved!<br/>';
		if (msg != '')
		{
			msg += 'Do you want to continue?';
			Ext.Msg.show({
				title:'Warning!',
				msg: msg,
				buttons: Ext.Msg.OKCANCEL,
				fn: function(btnId){
					if (btnId==='cancel'){
						// cancel the save action
					} else {
						onStatusOk();
					}
				},
				scope: this,
				icon: Ext.Msg.WARNING
			});
			return;
		}
		
		onStatusOk();
	},
	
	/**
	 * Check if changes were made before closing window 
	 * @return true if changes
	 */	
	fclose : function() {
		if (this.status == null)
			return false;
		
		var isDirty = this.formPanel.getForm().isDirty() || (this.status.isModified) || (this.status.nbModified > 0) || (this.status.nbNew > 0);
		return isDirty;
	}
});