Blame view

js/app/views/TimeTableUI.js 33.8 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
 */

Ext.define('amdaUI.TimeTableUI', {
	extend: 'Ext.container.Container',
	alias: 'widget.panelTimeTable',
0fea5567   Benjamin Renard   First step for re...
14

16035364   Benjamin Renard   First commit
15
	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
	],
0fea5567   Benjamin Renard   First step for re...
23

16035364   Benjamin Renard   First commit
24
	statics: {
70aabdee   elena   catalog draft
25
26
		COL_TO_HIDE : 'colToHide'
	},
0fea5567   Benjamin Renard   First step for re...
27

70aabdee   elena   catalog draft
28
	status: null,
0fea5567   Benjamin Renard   First step for re...
29
30

	constructor: function(config) {
16035364   Benjamin Renard   First commit
31
32
33
34
35
36
37
38
39
40
		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
	 */
0fea5567   Benjamin Renard   First step for re...
41
	setObject : function (object)
70aabdee   elena   catalog draft
42
	{
16035364   Benjamin Renard   First commit
43
44
		// set object
		this.object = object;
0fea5567   Benjamin Renard   First step for re...
45

16035364   Benjamin Renard   First commit
46
47
		// load object into view
		this.loadObject();
0fea5567   Benjamin Renard   First step for re...
48

16035364   Benjamin Renard   First commit
49
		// show the default duration column
901ba3f3   Elena.Budnik   upload catalog
50
		this.TTGrid.headerCt.getGridColumns();
0fea5567   Benjamin Renard   First step for re...
51

16035364   Benjamin Renard   First commit
52
53
54
55
56
57
		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();
			}
0fea5567   Benjamin Renard   First step for re...
58
		});
16035364   Benjamin Renard   First commit
59
60
61
62
63
        // fire the refresh event (to statistical plugin)
        this.fireEvent("refresh");
	// global event
	myDesktopApp.EventManager.fireEvent("refresh");
	},
0fea5567   Benjamin Renard   First step for re...
64

16035364   Benjamin Renard   First commit
65
66
67
	/**
	 * load object timetable into this view
	 */
0fea5567   Benjamin Renard   First step for re...
68
	loadObject : function(){
16035364   Benjamin Renard   First commit
69
70
        // load object into form
        this.formPanel.getForm().loadRecord(this.object);
0fea5567   Benjamin Renard   First step for re...
71

16035364   Benjamin Renard   First commit
72
        this.status = null;
0fea5567   Benjamin Renard   First step for re...
73

16035364   Benjamin Renard   First commit
74
75
        //
        var me = this;
0fea5567   Benjamin Renard   First step for re...
76

16035364   Benjamin Renard   First commit
77
78
79
80
81
82
83
84
85
        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;
        	}
0fea5567   Benjamin Renard   First step for re...
86

16035364   Benjamin Renard   First commit
87
        	me.TTGrid.getSelectionModel().deselectAll();
0fea5567   Benjamin Renard   First step for re...
88

16035364   Benjamin Renard   First commit
89
90
        	// clear filters
        	me.TTGrid.getStore().clearFilter(true);
55da2eac   Benjamin Renard   Fix another bug w...
91
		me.TTGrid.filters.clearFilters();
0fea5567   Benjamin Renard   First step for re...
92

16035364   Benjamin Renard   First commit
93
    		//clear sort
5d15649f   Benjamin Renard   Migration to ExtJ...
94
95
        	me.TTGrid.getStore().sorters.clear();
        	//me.TTGrid.getStore().sorters = new Ext.util.MixedCollection();
0fea5567   Benjamin Renard   First step for re...
96

16035364   Benjamin Renard   First commit
97
98
        	//set cache token to the Time Table object
        	me.object.set('cacheToken', result.token);
0fea5567   Benjamin Renard   First step for re...
99

5d15649f   Benjamin Renard   Migration to ExtJ...
100
        	me.TTGrid.getStore().load();
0fea5567   Benjamin Renard   First step for re...
101

16035364   Benjamin Renard   First commit
102
        	me.status = result.status;
0fea5567   Benjamin Renard   First step for re...
103

16035364   Benjamin Renard   First commit
104
105
106
        	//Statistical plugin
        	me.fireEvent("refresh");
        };
0fea5567   Benjamin Renard   First step for re...
107

16035364   Benjamin Renard   First commit
108
109
110
111
112
        if (this.object.get('fromPlugin'))
        {
        	if (this.object.get('objFormat') && this.object.get('objFormat') != '')
        	{
        		//From uploaded file
0fea5567   Benjamin Renard   First step for re...
113
        		AmdaAction.initObjectCacheFromUploadedFile(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)
0fea5567   Benjamin Renard   First step for re...
118
        		AmdaAction.initObjectCacheFromTmpObject(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') != '')
0fea5567   Benjamin Renard   First step for re...
122
        {
80af0168   Hacene SI HADJ MOHAND   rm_6903 adding na...
123
124
125
126
127
128
                              var pathern=this.object.get('relatedCatalogId').split('_')[0] ;
                              catType='';
                               if(pathern=='cat')
                                   catType=' catalog' ;
                               if(pathern=='sharedcatalog')
                                   catType='sharedcatalog' ;
0fea5567   Benjamin Renard   First step for re...
129
                               AmdaAction.initObjectCacheFromCatalog(this.object.get('relatedCatalogId'), catType, onAfterInit);
d547a559   Hacene SI HADJ MOHAND   rm_6903 ok
130
        }
0fea5567   Benjamin Renard   First step for re...
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
0fea5567   Benjamin Renard   First step for re...
137
138
        		AmdaAction.initObjectCache(false,0,onAfterInit);
        	}
16035364   Benjamin Renard   First commit
139
140
141
        	else
        	{
        		//From existing TT file
342b20ca   Benjamin Renard   Fix inheritence b...
142
        		AmdaAction.initObjectCacheFromObject(this.object.get('id'), typeTT, onAfterInit);
16035364   Benjamin Renard   First commit
143
144
145
146
147
148
149
        	}
        }
	},

	/**
	* update this.object from form
	*/
70aabdee   elena   catalog draft
150
151
	updateObject : function()
	{
16035364   Benjamin Renard   First commit
152
		this.updateCount();
0fea5567   Benjamin Renard   First step for re...
153

16035364   Benjamin Renard   First commit
154
		// get the basic form
0fea5567   Benjamin Renard   First step for re...
155
		var basicForm = this.formPanel.getForm();
70aabdee   elena   catalog draft
156
		var updateStatus = true;
16035364   Benjamin Renard   First commit
157

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

0fea5567   Benjamin Renard   First step for re...
177
	updateCount : function()
70aabdee   elena   catalog draft
178
	{
16035364   Benjamin Renard   First commit
179
180
181
		this.object.set('nbIntervals',this.TTGrid.getStore().getTotalCount());
		this.formPanel.getForm().findField('nbIntervals').setValue(this.object.get('nbIntervals'));
	},
0fea5567   Benjamin Renard   First step for re...
182
183

	/*
16035364   Benjamin Renard   First commit
184
185
	 * save method called by Save button
	 */
e1fdab74   Hacene SI HADJ MOHAND   starting
186
	saveProcess : function(toRename,onAfterSave, notDisplayMsg)
70aabdee   elena   catalog draft
187
	{
0fea5567   Benjamin Renard   First step for re...
188
189
		var timeTableModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.tt.id);

0d95ceab   Elena.Budnik   redmine #5141, part1
190
191
		// if the name has been modified this is a creation
		if (timeTableModule.contextNode &&  (timeTableModule.contextNode.data.id == 'sharedtimeTable-treeRootNode'))
0fea5567   Benjamin Renard   First step for re...
192
193
		{
			timeTableModule.linkedNode = null;
0d95ceab   Elena.Budnik   redmine #5141, part1
194
			timeTableModule.createLinkedNode();
0fea5567   Benjamin Renard   First step for re...
195
196
			timeTableModule.createObject(this.object.getJsonValues());
			var ttobj = timeTableModule.linkedNode.get('object');
0d95ceab   Elena.Budnik   redmine #5141, part1
197
198
199
200
201
202
			// synchronisation of objects
			this.object = ttobj;
			timeTableModule.linkedNode.create();
		}
		else  if (this.fclose()) /*TimeTable object has been modified*/
		{
0fea5567   Benjamin Renard   First step for re...
203
204
			if (this.object.isModified('name') || this.object.get('fromPlugin'))
			{
0d95ceab   Elena.Budnik   redmine #5141, part1
205
206
207
208
209
210
211
212
213
214
215
				// 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());
0fea5567   Benjamin Renard   First step for re...
216
217

					var ttobj = timeTableModule.linkedNode.get('object');
0d95ceab   Elena.Budnik   redmine #5141, part1
218
219
					// synchronisation of objects
					this.object = ttobj;
0fea5567   Benjamin Renard   First step for re...
220

0d95ceab   Elena.Budnik   redmine #5141, part1
221
					if (toRename) timeTableModule.linkedNode.toRename = true;
0fea5567   Benjamin Renard   First step for re...
222
				}
0d95ceab   Elena.Budnik   redmine #5141, part1
223
224
225
				timeTableModule.linkedNode.create({callback : function ($action) {
					if (timeTableModule.linkedNode.get('object').get('fromPlugin'))
						timeTableModule.linkedNode.get('object').set('fromPlugin',false);
0fea5567   Benjamin Renard   First step for re...
226
					timeTableModule.linkedNode.update();},
0d95ceab   Elena.Budnik   redmine #5141, part1
227
228
229
230
231
232
					scope : this});
			} else {
				//update
				timeTableModule.linkedNode.update();
			}
		}
16035364   Benjamin Renard   First commit
233
	},
0fea5567   Benjamin Renard   First step for re...
234

16035364   Benjamin Renard   First commit
235
236
237
	/**
	 * overwrite metod called by Save button
	 */
70aabdee   elena   catalog draft
238
	overwriteProcess : function(btn)
0fea5567   Benjamin Renard   First step for re...
239
	{
16035364   Benjamin Renard   First commit
240
		if (btn == 'cancel') return;
0fea5567   Benjamin Renard   First step for re...
241

70aabdee   elena   catalog draft
242
		this.fieldName.clearInvalid();
0fea5567   Benjamin Renard   First step for re...
243
244
		this.saveProcess(true);

16035364   Benjamin Renard   First commit
245
	},
0fea5567   Benjamin Renard   First step for re...
246
247

	addInterval : function(start, stop)
70aabdee   elena   catalog draft
248
	{
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();
342b20ca   Benjamin Renard   Fix inheritence b...
252
		AmdaAction.addCacheInterval({'start' : start, 'stop' : stop, 'index' : row},function (result, e) {
a73f0195   Benjamin Renard   Insert interval i...
253
			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
	},
e1fdab74   Hacene SI HADJ MOHAND   starting
265
266
267
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
                     generateCAT : function(id)
                     {
                      if(this.fclose()){
                        Ext.Msg.confirm('Generate CAT', 'Current Time Table has been modified.\nDo you want to save it to include these changes in the generated Catalog ?' ,
                        function (btn, text){
                         if (btn == 'yes'){
                          // mark this.closed as true before the call to close() as that will fire the beforeclose event again
                          if(this.object.get('id') ==""){
                              // case of creation of catalog
                          this.saveTT();
                      }else{
                          // case existing catalog
                          this.saveProcess(false);
                      }
                          return;
                          }
                           }, this);

                     }else{
                         this.createCAT(this.object.get('id'));
                         return;
                     }   
                     },
                     createCAT : function(id)
                     {
                         Ext.Msg.prompt('Create catalog', 'Enter the number of columns:', function(btn, text){
                                        if (btn == 'ok'){
                                                var catObj=Ext.create('amdaModel.Catalog');
                                                var catNode=Ext.create('amdaModel.CatalogNode',{leaf : true});
                                                catObj.set('relatedTimeTable',  id);
                                                creatDate=new Date(this.object.get('created'));
                                                date=Ext.Date.format(creatDate,'Y-m-d\\TH:i:s');
                                                descr='Generated by CDPP/Amda Time Table Module \n'+ 'From Time Table: '+this.object.get('name')+'\nOn: '+date+'\n';
                                                catObj.set('description', descr+this.object.get('description'));
                                                var nbParam = parseInt(text);
                                                if ((nbParam <= 0) || (nbParam > 100)) {
                                                        nbParam = 1;
                                                }
                                                catObj.set('nbParameters', nbParam);
                                                catNode.set('object',catObj);
                                                var explorerTree = Ext.getCmp(amdaUI.ExplorerUI.RESRC_TAB.TREE_ID);
                                                var catRootNode = explorerTree.getRootNode().findChild('id', 'catalog-treeRootNode', true);
                                                 amdaModel.InteractiveNode.preloadNodes(catRootNode.getRootNode(),
			function()
			{
				// edit newNode into Parameter Module with node as contextNode
				catNode.editInModule();
			});
                                        }
                                }, this);
                     },
                     saveTT  : 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);
0fea5567   Benjamin Renard   First step for re...
324

e1fdab74   Hacene SI HADJ MOHAND   starting
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
                            			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');
  				              }
                                        }
                     },
                     
0fea5567   Benjamin Renard   First step for re...
379
380
	init : function(config)
	{
16035364   Benjamin Renard   First commit
381
	    this.object =   config.object;
0fea5567   Benjamin Renard   First step for re...
382

16035364   Benjamin Renard   First commit
383
384
385
386
387
388
389
390
391
392
393
394
395
396
	    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;
	            }
	    });
0fea5567   Benjamin Renard   First step for re...
397

16035364   Benjamin Renard   First commit
398
399
400
401
402
403
404
405
406
	    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: [
0fea5567   Benjamin Renard   First step for re...
407
                this.fieldName,
16035364   Benjamin Renard   First commit
408
409
410
411
412
413
                {
                    xtype: 'fieldcontainer',
                    layout: 'hbox',
                    fieldLabel:'Creation date',
                    items: [
                        {
0fea5567   Benjamin Renard   First step for re...
414
415
                            xtype:'datefield', width: 180,
                            name: 'created', disabled: true,
16035364   Benjamin Renard   First commit
416
417
418
419
420
                            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...
421
                        { xtype:'textfield', name: 'nbIntervals', disabled: true, width: 70 }
0fea5567   Benjamin Renard   First step for re...
422
                    ]
16035364   Benjamin Renard   First commit
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
                },
                {
                    xtype: 'textarea',
                    name: 'description',
                    fieldLabel: 'Description',
                    anchor: '100% 50%'
                },
                {
                    xtype: 'textarea',
                    name: 'history',
                    fieldLabel: 'Operation log',
                    anchor: '100% 30%'
                }
            ]

        });
0fea5567   Benjamin Renard   First step for re...
439

16035364   Benjamin Renard   First commit
440
441
442
443
444
445
446
447
	    var store = Ext.create('Ext.data.Store', {
	        model: 'amdaModel.Interval',
	        autoDestroy: false,
	        pageSize : 200,
		  buffered : true,
	      autoLoad: true,
	      purgePageCount: 0,
	 	remoteSort: true,
0fea5567   Benjamin Renard   First step for re...
448
	        listeners: {
16035364   Benjamin Renard   First commit
449
	            load: function(store,records) {
0fea5567   Benjamin Renard   First step for re...
450
451

 	              //  alert('nb of records in store:'+records.length );
16035364   Benjamin Renard   First commit
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
                        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
0fea5567   Benjamin Renard   First step for re...
482
483
484
	        }
	    });

16035364   Benjamin Renard   First commit
485
486
487
488
489
490
	    var filters = {
	        ftype: 'filters',
	        encode: true, // json encode the filter query
	        local: false,   // defaults to false (remote filte
	        filters: [
                { type: 'numeric', dataIndex: 'durationHour'},
0fea5567   Benjamin Renard   First step for re...
491
492
                { type: 'numeric', dataIndex: 'durationMin'},
                { type: 'numeric', dataIndex: 'durationSec'},
16035364   Benjamin Renard   First commit
493
494
495
                { type: 'date', dataIndex: 'start',  dateFormat: 'Y-m-d'},
                { type: 'date', dataIndex: 'stop',  dateFormat: 'Y-m-d' }
            ]
0fea5567   Benjamin Renard   First step for re...
496
	    };
16035364   Benjamin Renard   First commit
497
498
499
500
501
502
503
504
505
506
507
508
509
510

	    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);
0fea5567   Benjamin Renard   First step for re...
511

16035364   Benjamin Renard   First commit
512
513
514
515
516
517
518
519
520
	    	            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)) {
342b20ca   Benjamin Renard   Fix inheritence b...
521
522
523
524
525
526
	    	            	var obj = {
                        'cacheId' : record.get('cacheId'),
                        'isCatalog' : false,
                        'data' : {}
                      };
                      obj['data'][activeColumn.dataIndex] = value;
0fea5567   Benjamin Renard   First step for re...
527

16035364   Benjamin Renard   First commit
528
529
	    	            	//context.grid.getSelectionModel().deselectAll();
	    	            	//Interval is modified on the server side
5d15649f   Benjamin Renard   Migration to ExtJ...
530
	    	            	me.editing = true;
0fea5567   Benjamin Renard   First step for re...
531

342b20ca   Benjamin Renard   Fix inheritence b...
532
	    	            	AmdaAction.modifyCacheInterval(obj, function (result, e) {
0fea5567   Benjamin Renard   First step for re...
533

16035364   Benjamin Renard   First commit
534
535
536
	    	            		var ttModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.tt.id);
                    			if (ttModule)
                    				ttModule.getUiContent().status = result.status;
55da2eac   Benjamin Renard   Fix another bug w...
537
538
539
540
541
542
543
					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;
0fea5567   Benjamin Renard   First step for re...
544
	                        				}, me);
55da2eac   Benjamin Renard   Fix another bug w...
545
546
547
548
549
550
	                        			}
	                        		});
					}
					else {
						me.editing = false;
					}
16035364   Benjamin Renard   First commit
551
552
	                        }, this);
	    	            }
5d15649f   Benjamin Renard   Migration to ExtJ...
553
554
	    	            else
	    	            	me.editing = false;
16035364   Benjamin Renard   First commit
555
556
	    	        }
	    	    }
0fea5567   Benjamin Renard   First step for re...
557

16035364   Benjamin Renard   First commit
558
559
560
561
562
563
	    });

	    this.TTGrid =  Ext.create('Ext.grid.Panel', {
	        store : store,
	        features: [filters],
	        columnLines: true,
a061cfac   Benjamin Renard   Fix a bug with TT...
564
		selModel: {pruneRemoved: false},
0fea5567   Benjamin Renard   First step for re...
565
	        columns: [
16035364   Benjamin Renard   First commit
566
567
568
569
                {
                	xtype: 'rownumberer',
                	width: 50,
                	renderer: function(value, metaData, record, row, col, store, gridView){
e2acb540   Elena.Budnik   redmine #6397 : ...
570
                		var msg = record.index + 1;
16035364   Benjamin Renard   First commit
571
572
573
574
575
576
577
578
                		if (record.get('isNew') || record.get('isModified'))
                		{
                			msg += ' *';
                			metaData.style = 'font-weight: bold'
                		}
               	      	return msg;
                    }
                },
0fea5567   Benjamin Renard   First step for re...
579
                {
16035364   Benjamin Renard   First commit
580
                    header: 'Start Time', dataIndex: 'start',  width: 120,
0fea5567   Benjamin Renard   First step for re...
581
582
                    editor: { xtype:'datefield', allowBlank:false, hideTrigger: true,  format : 'Y-m-d\\TH:i:s'},
                    renderer: function(value){
16035364   Benjamin Renard   First commit
583
584
585
586
587
588
589
590
591
592
593
                        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;
                        }
                    }
                },
0fea5567   Benjamin Renard   First step for re...
594
595
                {
                    header: 'Stop Time', dataIndex: 'stop', width: 120,
16035364   Benjamin Renard   First commit
596
597
598
599
600
601
602
603
604
605
606
607
                    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;
                        }
                    }
0fea5567   Benjamin Renard   First step for re...
608
                },
16035364   Benjamin Renard   First commit
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
                {
                    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();
                                    }
                                }
                            });
                        }
                    }
0fea5567   Benjamin Renard   First step for re...
630
                },
16035364   Benjamin Renard   First commit
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
                {
                	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();
                                    }
                                }
                            });
                        }
                    }
0fea5567   Benjamin Renard   First step for re...
651
                },
16035364   Benjamin Renard   First commit
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
                {
                    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();
                                    }
                                }
                            });
                        }
                    }
                }
0fea5567   Benjamin Renard   First step for re...
674
            ],
16035364   Benjamin Renard   First commit
675
676
            frame: true,
            dockedItems: [{
0fea5567   Benjamin Renard   First step for re...
677
                xtype: 'toolbar',
16035364   Benjamin Renard   First commit
678
679
680
681
682
                items: [{
                    iconCls: 'icon-add',
                    scope: this,
                    handler: function(){
                        cellEditing.cancelEdit();
0fea5567   Benjamin Renard   First step for re...
683

16035364   Benjamin Renard   First commit
684
685
686
687
                        var selection = this.TTGrid.getView().getSelectionModel().getSelection()[0];
                        var row = 0;
                        if (selection)
                        	row = store.indexOf(selection) + 1;
5d15649f   Benjamin Renard   Migration to ExtJ...
688
                        this.TTGrid.getSelectionModel().deselectAll();
0fea5567   Benjamin Renard   First step for re...
689

16035364   Benjamin Renard   First commit
690
                        var me = this;
342b20ca   Benjamin Renard   Fix inheritence b...
691
                        AmdaAction.addCacheInterval({'index' : row}, function (result, e) {
16035364   Benjamin Renard   First commit
692
                        	this.status = result.status;
55da2eac   Benjamin Renard   Fix another bug w...
693
694
695
696
697
				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);
0fea5567   Benjamin Renard   First step for re...
698
699
                        					cellEditing.startEditByPosition({row: row, column: 1});
                        				}, me);
55da2eac   Benjamin Renard   Fix another bug w...
700
701
702
                        			}
                        		});
				}
16035364   Benjamin Renard   First commit
703
704
705
706
707
708
709
710
711
712
713
                        }, 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...
714
                        	this.TTGrid.getSelectionModel().deselectAll();
6b1de4f1   elena   second arg when d...
715
                        	AmdaAction.removeTTCacheIntervalFromId(rowId, false, function (result, e) {
16035364   Benjamin Renard   First commit
716
                        		this.status = result.status;
55da2eac   Benjamin Renard   Fix another bug w...
717
718
719
				if (!this.TTGrid.getStore().loading) {
                            		this.TTGrid.getStore().reload();
				}
16035364   Benjamin Renard   First commit
720
721
722
723
724
725
726
727
728
729
                            }, this);
                        }
                    }
                },
                '->',
                {
                    text: 'Clear Filters',
                    scope: this,
                    handler: function () {
                    	this.TTGrid.getStore().clearFilter(true);
55da2eac   Benjamin Renard   Fix another bug w...
730
			this.TTGrid.filters.clearFilters();
0fea5567   Benjamin Renard   First step for re...
731
                    }
16035364   Benjamin Renard   First commit
732
                }
0fea5567   Benjamin Renard   First step for re...
733
                ]
16035364   Benjamin Renard   First commit
734
735
736
737
            }],
            plugins: [ cellEditing, {ptype : 'bufferedrenderer'} ],
            listeners : {
                scope : this,
0fea5567   Benjamin Renard   First step for re...
738
                edit : function(editor,e) {
16035364   Benjamin Renard   First commit
739
740
741
742
743
744
745
746
747
748
749
750
                    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){
0fea5567   Benjamin Renard   First step for re...
751
	        this.TTGrid.down('#delete').setDisabled(selections.length === 0);
16035364   Benjamin Renard   First commit
752
        }, this);
0fea5567   Benjamin Renard   First step for re...
753

16035364   Benjamin Renard   First commit
754
755
756
757
758
759
760
761
762
763
	    var myConf = {
	        layout: 'border',
	        defaults: { layout: 'fit', border: false },
	        items : [
                {
                    xtype: 'form',
                    region: 'center',
                    buttonAlign: 'left',
                    bodyStyle: {background : '#dfe8f6'},
                    padding: '5 5 5 5',
0fea5567   Benjamin Renard   First step for re...
764
765
                    layout: {type: 'hbox', pack: 'start', align: 'stretch'},
                    items: [
16035364   Benjamin Renard   First commit
766
767
768
769
770
771
772
773
774
775
776
777
                        {
                            xtype: 'container',
                            flex: 3.6,
                            layout: {type: 'vbox', pack: 'start', align: 'stretch'},
                            items: [
                                this.formPanel,
                                {
                                    xtype: 'operationsTT',
                                    parent: this,
                                    flex: 2.5,
                                    id: 'operation'
                                }
0fea5567   Benjamin Renard   First step for re...
778
779
780
                            ]
                        },
                        {
16035364   Benjamin Renard   First commit
781
782
783
                            xtype: 'container',
                            border: false,
                            padding: '0 0 5 15',
0fea5567   Benjamin Renard   First step for re...
784
                            flex: 4,
16035364   Benjamin Renard   First commit
785
                            layout: 'fit',
0fea5567   Benjamin Renard   First step for re...
786
                            items: [ this.TTGrid ]
16035364   Benjamin Renard   First commit
787
788
789
                        }
                    ],
                    fbar:[
0fea5567   Benjamin Renard   First step for re...
790
                        {
16035364   Benjamin Renard   First commit
791
792
793
794
795
                            xtype: 'button',
                            text: 'Save',
                            width: 65,
                            scope : this,
                            handler: function () {
e1fdab74   Hacene SI HADJ MOHAND   starting
796
                            	this.saveTT();
0fea5567   Benjamin Renard   First step for re...
797
798
                           }
                        },{
16035364   Benjamin Renard   First commit
799
800
801
802
803
                            xtype: 'button',
                            text: 'Reset',
                            width: 65,
                            scope: this,
                            handler: function() {
0fea5567   Benjamin Renard   First step for re...
804
	                        	var ttModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.tt.id);
16035364   Benjamin Renard   First commit
805
806
807
808
	    					    ttModule.createLinkedNode();
	    					    ttModule.createObject();
	    					    this.setObject(ttModule.getLinkedNode().get('object'));
                            }
e1fdab74   Hacene SI HADJ MOHAND   starting
809
810
811
812
813
814
815
816
                        },{
                            xtype: 'button',
                            text: 'Generate Catalog',
                            width: 120,
                            scope: this,
                            handler: function() {
                                this.generateCAT(this.object.get('id'));						
                            }
0fea5567   Benjamin Renard   First step for re...
817
                        }
16035364   Benjamin Renard   First commit
818
                    ]
0fea5567   Benjamin Renard   First step for re...
819
                },
16035364   Benjamin Renard   First commit
820
821
822
                {
		  xtype: 'panel', region: 'south',
		  title: 'Information',
0fea5567   Benjamin Renard   First step for re...
823
		  collapsible: true,
42863f42   Elena.Budnik   collapseMode: "he...
824
		  collapseMode: 'header',
16035364   Benjamin Renard   First commit
825
826
827
828
829
830
831
		  height: 100,
		  autoHide: false,
		  iconCls: 'icon-information',
		  bodyStyle: 'padding:5px',
		  loader: {
		    autoLoad: true,
		    url: helpDir+'timetableHOWTO'
0fea5567   Benjamin Renard   First step for re...
832
		  }
16035364   Benjamin Renard   First commit
833
834
                }
            ],
0fea5567   Benjamin Renard   First step for re...
835
            plugins: [ {ptype: 'statisticalPlugin'} ]
16035364   Benjamin Renard   First commit
836
	    };
0fea5567   Benjamin Renard   First step for re...
837
838

	    Ext.apply (this , Ext.apply (arguments, myConf));
16035364   Benjamin Renard   First commit
839
	},
0fea5567   Benjamin Renard   First step for re...
840

16035364   Benjamin Renard   First commit
841
842
843
	checkIntervalsStatusForSave : function(onStatusOk) {
		if (this.status == null)
			return;
0fea5567   Benjamin Renard   First step for re...
844

16035364   Benjamin Renard   First commit
845
846
847
848
849
		if (this.status.nbValid <= 0)
		{
			myDesktopApp.errorMsg('Your time table is invalid, <br>you must have at least one valid interval');
			return;
		}
0fea5567   Benjamin Renard   First step for re...
850

16035364   Benjamin Renard   First commit
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
		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;
		}
0fea5567   Benjamin Renard   First step for re...
875

16035364   Benjamin Renard   First commit
876
877
		onStatusOk();
	},
0fea5567   Benjamin Renard   First step for re...
878

16035364   Benjamin Renard   First commit
879
	/**
0fea5567   Benjamin Renard   First step for re...
880
	 * Check if changes were made before closing window
16035364   Benjamin Renard   First commit
881
	 * @return true if changes
0fea5567   Benjamin Renard   First step for re...
882
	 */
16035364   Benjamin Renard   First commit
883
884
885
	fclose : function() {
		if (this.status == null)
			return false;
0fea5567   Benjamin Renard   First step for re...
886

16035364   Benjamin Renard   First commit
887
888
889
		var isDirty = this.formPanel.getForm().isDirty() || (this.status.isModified) || (this.status.nbModified > 0) || (this.status.nbNew > 0);
		return isDirty;
	}
0fea5567   Benjamin Renard   First step for re...
890
});