Blame view

js/app/views/CatalogUI.js 31 KB
f792a3de   elena   catalog ihm
1
2
3
4
5
6
7
8
9
10
11
12
/**
 * Project       AMDA-NG
 * Name          CatalogUI.js
 * @class 	 amdaUI.catalogUI
 * @extends      Ext.container.Container
 * @brief	 Catalog Module UI definition (View)
 * @author 	 elena
 */

Ext.define('amdaUI.CatalogUI', {
	extend: 'Ext.container.Container',
	alias: 'widget.panelCatalog',
f9c8b272   elena   edit catalog
13
14
	
	requires: [
0318dbe6   Hacene SI HADJ MOHAND   rm_6998 ok
15
16
		'Ext.grid.plugin.BufferedRenderer',
                                        'amdaUI.StatisticalPlug'
f9c8b272   elena   edit catalog
17
18
	],
	
d18b535d   elena   catalog draft + c...
19
	isCatalog : true,
fdf0b4cc   Hacene SI HADJ MOHAND   ok
20
                   statics: {
b5342f56   Hacene SI HADJ MOHAND   corecting bugs again
21
		COL_TO_HIDE_DURATION : 'colToHideDuration'
fdf0b4cc   Hacene SI HADJ MOHAND   ok
22
	},
f792a3de   elena   catalog ihm
23
	
1340621c   Elena.Budnik   error msg when up...
24
	constructor: function(config) {
70aabdee   elena   catalog draft
25
		this.init(config);
f9c8b272   elena   edit catalog
26
27
		this.callParent(arguments);
		this.toReconfigure = true;
07650d8e   Elena.Budnik   create empty catalog
28
29
30
31
		
		if (this.object) {
			this.loadObject();
		}
f792a3de   elena   catalog ihm
32
33
	},
	
1340621c   Elena.Budnik   error msg when up...
34
	setObject : function (object, toReconfigure) {	
f9c8b272   elena   edit catalog
35
36
37
38
		if (toReconfigure) 
			this.toReconfigure = true;
		// set object	        
		this.object = object;		 
048b4d77   elena   catalogs +
39
40
		// load object into view
		this.loadObject();
fdf0b4cc   Hacene SI HADJ MOHAND   ok
41
42
43
44
45
                                         // show the default duration column
		this.TTGrid.headerCt.getGridColumns();
		
		Ext.Array.each(this.TTGrid.headerCt.getGridColumns(), function(item,index,all){
			// if item is the default duration column
b5342f56   Hacene SI HADJ MOHAND   corecting bugs again
46
			if ( item.id == amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'2' ) {
fdf0b4cc   Hacene SI HADJ MOHAND   ok
47
48
49
				// show this column
				item.show();
			}
0318dbe6   Hacene SI HADJ MOHAND   rm_6998 ok
50
51
52
53
54
		});  
                                         // fire the refresh event (to statistical plugin)
                                         this.fireEvent("refresh");
                                        // global event
                                        myDesktopApp.EventManager.fireEvent("refresh");
048b4d77   elena   catalogs +
55
	},
f792a3de   elena   catalog ihm
56
	
d18b535d   elena   catalog draft + c...
57
58
59
	/**
	 * set params description into this.object
	 */
1340621c   Elena.Budnik   error msg when up...
60
	setParamInfo : function(parameters) {
70aabdee   elena   catalog draft
61
62
63
64
65
		var params = [];
		Ext.Array.each(parameters, function(item, index) {
			params[index] = item;	     	  
		}, this);
		
8b11b1af   Benjamin Renard   Insert intervals ...
66
67
		this.object.set('parameters', params);
		this.object.set('nbParameters', params.length); 
f792a3de   elena   catalog ihm
68
69
70
71
	},
	
	/**
	 * update this.object from form
1340621c   Elena.Budnik   error msg when up...
72
73
	 */	 
	updateObject : function(){  
d18b535d   elena   catalog draft + c...
74
	// get the basic form	
1340621c   Elena.Budnik   error msg when up...
75
76
		var basicForm = this.formPanel.getForm();        
		var updateStatus = true;
d18b535d   elena   catalog draft + c...
77

1340621c   Elena.Budnik   error msg when up...
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
		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);
			// if the update is allowed
		if (updateStatus) {
		/// real object update
		// update TimeTable object with the content of form
			basicForm.updateRecord(this.object);	
		}
		// return the update status  
		return updateStatus;	    
d18b535d   elena   catalog draft + c...
95
	},
8b11b1af   Benjamin Renard   Insert intervals ...
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

	addInterval : function(start, stop) {
		var row = this.TTGrid.getStore().getTotalCount();
		var me = this;
		this.TTGrid.getSelectionModel().deselectAll();
                AmdaAction.addTTCacheInterval({'start' : start, 'stop' : stop, 'index' : row, 'isCatalog' : true},function (result, e) {
			this.status = result.status;
			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);
				}
			});
                }
                }, this);
	},
f792a3de   elena   catalog ihm
114
	
1340621c   Elena.Budnik   error msg when up...
115
	updateCount : function() {
d18b535d   elena   catalog draft + c...
116
117
		this.object.set('nbIntervals',this.TTGrid.getStore().getTotalCount());		
		this.formPanel.getForm().findField('nbIntervals').setValue(this.object.get('nbIntervals'));
1340621c   Elena.Budnik   error msg when up...
118
	}, 
80af0168   Hacene SI HADJ MOHAND   rm_6903 adding na...
119
	generateTT : function(catId){   
d547a559   Hacene SI HADJ MOHAND   rm_6903 ok
120
121
122
                              var catObj = Ext.create('amdaModel.TimeTable');
                              var timeTabNode = Ext.create('amdaModel.TimeTableNode',{leaf : true});
                              catObj.set('relatedCatalogId', catId)
80af0168   Hacene SI HADJ MOHAND   rm_6903 adding na...
123
124
125
126
                              creatDate=new Date(this.object.get('created'));
                              date=Ext.Date.format(creatDate,'Y-m-d\\TH:i:s');
                              descr='Generated by CDPP/Amda Catalog Module \n'+ 'From Catalog: '+this.object.get('name')+'\nOn: '+date+'\n';
                              catObj.set('description', descr+this.object.get('description'));
d547a559   Hacene SI HADJ MOHAND   rm_6903 ok
127
128
129
130
131
132
133
134
135
136
137
138
139
                              timeTabNode.set('object',catObj);
                              var explorerTree = Ext.getCmp(amdaUI.ExplorerUI.RESRC_TAB.TREE_ID);
                                        var ttRootNode = explorerTree.getRootNode().findChild('id', 'timeTable-treeRootNode', true);
                                        amdaModel.InteractiveNode.preloadNodes(ttRootNode.getRootNode(),
			function()
			{
				// edit newNode into Parameter Module with node as contextNode
				timeTabNode.editInModule();
			});
                                       
  
                                        
                    },
1340621c   Elena.Budnik   error msg when up...
140
141
	onAfterInit:  function(result, e) 
	{
70aabdee   elena   catalog draft
142
		var me = this;
1340621c   Elena.Budnik   error msg when up...
143
144
145
146
		if (!result) {			
			myDesktopApp.errorMsg(e.message);
			Ext.defer(function(){Ext.Msg.toFront()},10);
			 
3768c8a8   Elena.Budnik   RowNumberer catalofs
147
			return;
1340621c   Elena.Budnik   error msg when up...
148
149
		}
		else if (!result.success)
f9c8b272   elena   edit catalog
150
151
152
153
154
		{
			if (result.message)
				myDesktopApp.errorMsg(result.message);
			else
				myDesktopApp.errorMsg('Unknown error during catalog cache initialisation');
1340621c   Elena.Budnik   error msg when up...
155
156

			Ext.defer(function(){Ext.Msg.toFront()},10);
f9c8b272   elena   edit catalog
157
158
			return;
		}
1340621c   Elena.Budnik   error msg when up...
159
		
f9c8b272   elena   edit catalog
160
161
		if (me.toReconfigure) 
		{          	
fdf0b4cc   Hacene SI HADJ MOHAND   ok
162
			var fieldsConfig =  [
6ab359f0   Benjamin Renard   Cleanup model fie...
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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
				{
					name : 'start',
					type : 'date',
					dateFormat: 'Y-m-d\\TH:i:s',
					convert: function(value,rec) {
						if (!Ext.isDate(value)){
							var valueString = new String(value);
							return new Date(valueString.replace(/\-/g,'\/').replace(/[T|Z]/g,' '));
						}
						return value;
					}
				},
				{
					name : 'stop',
					type : 'date',
					dateFormat: 'Y-m-d\\TH:i:s',
					convert: function(value,rec) {
						if (!Ext.isDate(value)){
							var valueString = new String(value);
							return new Date(valueString.replace(/\-/g,'\/').replace(/[T|Z]/g,' '));
						}
						return value;
					}
				},
				{
					name:'durationHour',
					type: 'float',
					convert: function(value, rec){
						if (rec.get('stop') && rec.get('start') && (rec.get('stop')-rec.get('start'))>=0) {
							return (rec.get('stop') - rec.get('start'))/3600000.0;
						}
					},
					persist: false
				},
				{
					name: 'durationMin',
					type: 'float',
					convert: function(value, rec){
						if (rec.get('stop') && rec.get('start') && (rec.get('stop')-rec.get('start'))>=0) {
							return (rec.get('stop') - rec.get('start'))/60000.0;
						}
					},
					persist: false
				},
				{
					name: 'durationSec',
					type: 'float',
					convert: function(value, rec){
						if (rec.get('stop') && rec.get('start') && (rec.get('stop')-rec.get('start'))>=0) {
							return (rec.get('stop') - rec.get('start'))/1000.0;
						}
					},
					persist: false
				},
				{ name: 'cacheId', type : 'int'},
				{ name: 'isNew', type : 'boolean', defaultValue: false },
				{ name: 'isModified', type : 'boolean', defaultValue: false}
			];
fdf0b4cc   Hacene SI HADJ MOHAND   ok
221

6ab359f0   Benjamin Renard   Cleanup model fie...
222
223
224
225
226
227
228
229
230
231
232
233
                        var updateDurationColumnsVisibility = function(columns, visibleId) {
				Ext.Array.each(columns, function(item,index){
					// if item is a column to hide automatically
					if ( Ext.util.Format.substr(item.id, 0, amdaUI.CatalogUI.COL_TO_HIDE_DURATION.length) == amdaUI.CatalogUI.COL_TO_HIDE_DURATION ) {
						// if item isn't the column which is being declared and is not hidden
						if ( item.id != visibleId && !item.isHidden() ){
							// hide this column
							item.hide();
						}
					}
				});
			};
3768c8a8   Elena.Budnik   RowNumberer catalofs
234

6ab359f0   Benjamin Renard   Cleanup model fie...
235
			var columnsConfig = [
c865df36   Elena.Budnik   dateTime datatype...
236
				{
6ab359f0   Benjamin Renard   Cleanup model fie...
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
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
324
325
326
327
328
329
330
					xtype: 'rownumberer',
					width: 50,
					renderer: function(value, metaData, record){
						var msg = record.index + 1;
						if (record.get('isNew') || record.get('isModified')) {
							msg += ' *';
							metaData.style = 'font-weight: bold'
						}
						return msg;
					}
				},
				{
					xtype: 'datecolumn',
					text: 'Start Time',
					format: 'Y-m-d\\TH:i:s',
					sortable : true,
					dataIndex: 'start',  
					width : 120,
					menuDisabled: false,
					editor : {
						xtype:'datefield',
						allowBlank:false,
						hideTrigger: true,
						format : 'Y-m-d\\TH:i:s'
					}
				},
				{
					xtype: 'datecolumn',
					text: 'Stop Time',
					format: 'Y-m-d\\TH:i:s',
					sortable : true, 
					dataIndex: 'stop',
					width : 120,
					menuDisabled: false,
					editor : {
						xtype:'datefield',
						allowBlank:false,
						hideTrigger: true,
						format : 'Y-m-d\\TH:i:s'
					}
				},
				{
					xtype: 'gridcolumn',
					text: 'Duration (hour)',
					sortable : true,
					dataIndex: 'durationHour',  
					width : 120,
					menuDisabled: false, 
					hidden:true,
					id: amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'1',
					renderer: function(value) {
						return Ext.util.Format.number(value,'0.00');
					},
					listeners: {
						beforeshow : function(){
							updateDurationColumnsVisibility(this.ownerCt.getGridColumns(), amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'1');
						}
					}
				},
				{
					xtype: 'gridcolumn',
					text: 'Duration (Min)',
					sortable : true,
					dataIndex: 'durationMin',  
					width : 120,
					menuDisabled: false, 
					hidden:false,
					id: amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'2',
					renderer: function(value) {
						return Ext.util.Format.number(value,'0.00');
					},
					listeners: {
						beforeshow : function(){
							updateDurationColumnsVisibility(this.ownerCt.getGridColumns(), amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'2');
						}
					}
				},
				{
					xtype: 'gridcolumn',
					text: 'Duration (Sec)',
					sortable : true,
					dataIndex: 'durationSec',  
					width : 120,
					menuDisabled: false,
					hidden:true,
					id: amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'3',
					renderer: function(value) {
						return Ext.util.Format.number(value,'0.00');
					},
					listeners: {
						beforeshow : function(){
							updateDurationColumnsVisibility(this.ownerCt.getGridColumns(), amdaUI.CatalogUI.COL_TO_HIDE_DURATION+'3');
						}
					}                    
c865df36   Elena.Budnik   dateTime datatype...
331
				}
6ab359f0   Benjamin Renard   Cleanup model fie...
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
			];

			Ext.Array.each(result.parameters, function(obj, index) {
				var field = {
					name: 'param'+(index+2)
				};
				var column = {
					text: obj.name,
					sortable : true,
					dataIndex: 'param'+(index+2),
					menuDisabled: false
				};
				switch (obj.type) {
					case 1: //dateTime
						field = Ext.apply({}, field, {
							type : 'date',
							dateFormat: 'Y-m-d\\TH:i:s',
							convert: function(value,rec) {
								if (!Ext.isDate(value)){
									var valueString = new String(value);
									return new Date(valueString.replace(/\-/g,'\/').replace(/[T|Z]/g,' '));
								}
								return value;
							}
							
						});
						column = Ext.apply({}, column, {
							xtype: 'datecolumn',
							width : 120,
							editor : {
								xtype:'datefield',
								allowBlank:false,
								hideTrigger: true,
								format : 'Y-m-d\\TH:i:s'
							}
						});
						break;
					default:
						field = Ext.apply({}, field, {
							type: 'string'
						});
						column = Ext.apply({}, column, {
							width : 50. *  parseInt(obj.size),
							editor: 'textfield'
						});
c865df36   Elena.Budnik   dateTime datatype...
377
				}
6ab359f0   Benjamin Renard   Cleanup model fie...
378
379
				fieldsConfig.push(field);
				columnsConfig.push(column);
70aabdee   elena   catalog draft
380
			});
6ab359f0   Benjamin Renard   Cleanup model fie...
381

70aabdee   elena   catalog draft
382
			var store = Ext.create('Ext.data.Store', {
6ab359f0   Benjamin Renard   Cleanup model fie...
383
				fields: fieldsConfig,
70aabdee   elena   catalog draft
384
385
386
387
388
389
390
				autoDestroy: false,
				pageSize : 200,
				buffered : true, 
				purgePageCount: 0,
				remoteSort: true,
				proxy: {
					type: 'direct',
1340621c   Elena.Budnik   error msg when up...
391
					api : { read   :  AmdaAction.readTTCacheIntervals },
70aabdee   elena   catalog draft
392
393
394
395
396
397
398
399
400
401
402
403
404
					// remplir automatiquement tt, sharedtt , catalog, shared catalog
					extraParams : {'typeTT' : 'catalog'},
					reader:
					{
						type: 'json',
						root: 'intervals',
						totalProperty : 'totalCount'
					}
				},
				listeners: {
					scope : me,
					load: function(store,records) {        
						// myDesktopApp.EventManager.fireEvent('refresh');
1340621c   Elena.Budnik   error msg when up...
405
406
407
							me.TTGrid.getView().refresh();
							me.TTGrid.getSelectionModel().refresh();
							me.updateCount();
0318dbe6   Hacene SI HADJ MOHAND   rm_6998 ok
408
409
						                   //Statistical plugin
						 	this.fireEvent("refresh");
dc702c6d   Elena.Budnik   sort without save
410
					} 
70aabdee   elena   catalog draft
411
				}
dc702c6d   Elena.Budnik   sort without save
412
			});
f9c8b272   elena   edit catalog
413
			
6ab359f0   Benjamin Renard   Cleanup model fie...
414
			me.TTGrid.reconfigure(store, columnsConfig);
dc702c6d   Elena.Budnik   sort without save
415
		}
f9c8b272   elena   edit catalog
416
		me.TTGrid.getSelectionModel().deselectAll();
70aabdee   elena   catalog draft
417
418
419
420
	//         	        	
	//         	// clear filters
	//         	me.TTGrid.getStore().clearFilter(true);
	//         
dc702c6d   Elena.Budnik   sort without save
421
422
423
424
		// clear sort
		me.TTGrid.getStore().sorters.clear();
		// me.TTGrid.getStore().sorters = new Ext.util.MixedCollection();
			
1340621c   Elena.Budnik   error msg when up...
425
		//set cache token to the Catalog object
f9c8b272   elena   edit catalog
426
		me.object.set('cacheToken', result.token);
e1fd05b4   Elena.Budnik   visu from cacheCat
427
		me.setParamInfo(result.parameters);	
f9c8b272   elena   edit catalog
428
		me.TTGrid.getStore().load();
70aabdee   elena   catalog draft
429
			
f9c8b272   elena   edit catalog
430
		me.status = result.status;
0318dbe6   Hacene SI HADJ MOHAND   rm_6998 ok
431
432
                                        //Statistical plugin
                                        me.fireEvent("refresh");
f9c8b272   elena   edit catalog
433
434
435
436
437
	},
	
	/**
	 * load object catalog into this view
	 */
1340621c   Elena.Budnik   error msg when up...
438
	loadObject : function(){ 	  
f9c8b272   elena   edit catalog
439
440
441
442
443
		// load object into form
		this.formPanel.getForm().loadRecord(this.object);
	
		this.status = null;
		
8b11b1af   Benjamin Renard   Insert intervals ...
444
		if (this.object.get('fromPlugin') && (this.object.get('objName') != '')){			
1340621c   Elena.Budnik   error msg when up...
445
			if (this.object.get('objFormat') && this.object.get('objFormat') != ''){
70aabdee   elena   catalog draft
446
				//From uploaded file
901ba3f3   Elena.Budnik   upload catalog
447
				AmdaAction.initTTCacheFromUploadedFile(this.object.get('objName'), this.object.get('objFormat'), this.isCatalog, this.onAfterInit, this);
70aabdee   elena   catalog draft
448
			}
1340621c   Elena.Budnik   error msg when up...
449
			else {
f9c8b272   elena   edit catalog
450
451
				//From tmp object (ie Statistics result)		    
				AmdaAction.initTTCacheFromTmpObject(this.object.get('folderId'), this.object.get('objName'), this.isCatalog, this.onAfterInit, this);
70aabdee   elena   catalog draft
452
453
			}
		}
1340621c   Elena.Budnik   error msg when up...
454
		else {
169f14d2   Benjamin Renard   Add shared object...
455
			var typeTT = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id).linkedNode.data.nodeType;
07650d8e   Elena.Budnik   create empty catalog
456
457
			
			if (this.object.get('id') == '') {
8b11b1af   Benjamin Renard   Insert intervals ...
458
				AmdaAction.initTTCache(this.isCatalog, this.object.get('nbParameters'), this.onAfterInit,this); 
70aabdee   elena   catalog draft
459
			}	
1340621c   Elena.Budnik   error msg when up...
460
			else {
70aabdee   elena   catalog draft
461
				//From existing TT file
169f14d2   Benjamin Renard   Add shared object...
462
				AmdaAction.initTTCacheFromTT(this.object.get('id'), typeTT, this.onAfterInit, this);
70aabdee   elena   catalog draft
463
464
			}
		}
0318dbe6   Hacene SI HADJ MOHAND   rm_6998 ok
465
466
                    //Statistical plugin
        	this.fireEvent("refresh");
d18b535d   elena   catalog draft + c...
467
	},
70aabdee   elena   catalog draft
468
	
d18b535d   elena   catalog draft + c...
469
	checkIntervalsStatusForSave : function(onStatusOk) {
70aabdee   elena   catalog draft
470
		onStatusOk();
d18b535d   elena   catalog draft + c...
471
472
473
474
475
	},
	
	/*	    
	 * save method called by Save button
	 */
70aabdee   elena   catalog draft
476
477
	saveProcess : function(toRename)
	{
f9c8b272   elena   edit catalog
478
479
480
		var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id);
		//  store / columns are the same - not needed to reconfigure grid
		this.toReconfigure = false;
efdeca25   Elena.Budnik   Anomalie #6181 : ...
481
482
483
484
485
486
487
488
489
490
491
492
493
494
		
		// if save shared catalog
		if (module.contextNode &&  (module.contextNode.get('id') == 'sharedcatalog-treeRootNode'))
		{ 
			module.linkedNode = null;	    		      
			module.createLinkedNode();
			module.createObject(this.object.getJsonValues());     
			var obj = module.linkedNode.get('object');                                                    
			// synchronisation of objects
			this.object = obj;
			module.linkedNode.create();
		}
		// if the name has been modified this is a creation
		else if (this.fclose()) {         
70aabdee   elena   catalog draft
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
			if (this.object.isModified('name') || this.object.get('fromPlugin')) {				
				// if object already has an id : it's a 'rename' of an existing  
				if (this.object.get('id')){
					// the context Node is the parent node of current edited one
					var contextNode = module.linkedNode.parentNode;
					// link a new node to the TimeTableModule
					module.createLinkedNode();
					// set the contextNode
					module.linkedNode.set('contextNode',contextNode);
					// create a new object linked
					module.createObject(this.object.getJsonValues());
					
					var obj = module.linkedNode.get('object');                                                    
					// synchronisation of objects
					this.object = obj;
					if (toRename) module.linkedNode.toRename = true;
				} 
6ab359f0   Benjamin Renard   Cleanup model fie...
512
				module.linkedNode.create({callback : function() {module.linkedNode.update();}, scope : this});
70aabdee   elena   catalog draft
513
			} else {
f9c8b272   elena   edit catalog
514
				//update				
70aabdee   elena   catalog draft
515
				module.linkedNode.update();
1340621c   Elena.Budnik   error msg when up...
516
			}	
70aabdee   elena   catalog draft
517
		}
f792a3de   elena   catalog ihm
518
519
	},
	
d18b535d   elena   catalog draft + c...
520
	/**
f9c8b272   elena   edit catalog
521
522
	 * overwrite metod called by Save button
	 */
1340621c   Elena.Budnik   error msg when up...
523
	overwriteProcess : function(btn) {	
f9c8b272   elena   edit catalog
524
525
526
		if (btn == 'cancel') return;
               
		this.fieldName.clearInvalid();
07650d8e   Elena.Budnik   create empty catalog
527
		this.saveProcess(true);
f9c8b272   elena   edit catalog
528
529
530
	},
	
	/**
d18b535d   elena   catalog draft + c...
531
532
533
	 * Check if changes were made before closing window 
	 * @return true if changes
	 */	
1340621c   Elena.Budnik   error msg when up...
534
	fclose : function() {
d18b535d   elena   catalog draft + c...
535
536
537
538
		if (this.status == null)
			return false;
		
		var isDirty = this.formPanel.getForm().isDirty() || (this.status.isModified) || (this.status.nbModified > 0) || (this.status.nbNew > 0);
1340621c   Elena.Budnik   error msg when up...
539
		return isDirty;
d18b535d   elena   catalog draft + c...
540
	},
f9c8b272   elena   edit catalog
541
 	    
70aabdee   elena   catalog draft
542
543
544
	init : function (config) 
	{	  
		this.object =   config.object;
f792a3de   elena   catalog ihm
545
	  
70aabdee   elena   catalog draft
546
547
548
549
550
551
552
553
554
		this.fieldName = new Ext.form.field.Text({
			fieldLabel: 'Name',
			allowBlank : false,
			stripCharsRe: /(^\s+|\s+$)/g,
			emptyText: 'Please no spaces!',
			name: 'name',
			validateOnChange: false,
			validateOnBlur: false,
			validFlag: false,
1340621c   Elena.Budnik   error msg when up...
555
556
557
			validator : function() {
				return this.validFlag;
			}
70aabdee   elena   catalog draft
558
		});
f9c8b272   elena   edit catalog
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
		
		var cellEditing = Ext.create('Ext.grid.plugin.CellEditing',{
//			clicksToEdit: 2,
			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)) {
dc702c6d   Elena.Budnik   sort without save
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
						var obj = {};					
						
						obj['cacheId']  = record.get('cacheId');
						obj['isCatalog'] = true;
						obj[activeColumn.dataIndex] = value;								  
						
						//Interval is modified on the server side
						me.editing = true;
						
						AmdaAction.modifyTTCacheInterval(obj, function (result, e) {						
							var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id);
							if (module)
								module.getUiContent().status = result.status;
							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;
f9c8b272   elena   edit catalog
610
							}
f9c8b272   elena   edit catalog
611
612
613
						}, this);
					}
					else
1340621c   Elena.Budnik   error msg when up...
614
						me.editing = false;
dc702c6d   Elena.Budnik   sort without save
615
					}
f9c8b272   elena   edit catalog
616
617
			}	
		});
d18b535d   elena   catalog draft + c...
618

70aabdee   elena   catalog draft
619
620
621
622
		this.TTGrid =  Ext.create('Ext.grid.Panel', { 
			height: 530,
			columns: [ ],
			frame: true,
dc702c6d   Elena.Budnik   sort without save
623
624
			columnLines: true,	
			selModel: {pruneRemoved: false},
1340621c   Elena.Budnik   error msg when up...
625
			//	selType: 'cellmodel',
f9c8b272   elena   edit catalog
626
			plugins: [ cellEditing, { ptype : 'bufferedrenderer'} ],
70aabdee   elena   catalog draft
627
628
629
			dockedItems: [{
				xtype: 'toolbar', 
				items: [{
1340621c   Elena.Budnik   error msg when up...
630
631
632
633
634
635
636
637
638
639
					iconCls: 'icon-add',
					scope: this,
					handler: function(){ 
						cellEditing.cancelEdit();
						var store = this.TTGrid.getStore();
							
						var selection = this.TTGrid.getView().getSelectionModel().getSelection()[0];
						var row = 0;
						if (selection)
							row = store.indexOf(selection) + 1;
70aabdee   elena   catalog draft
640
						this.TTGrid.getSelectionModel().deselectAll();
1340621c   Elena.Budnik   error msg when up...
641
642
643
									
						var me = this;
						AmdaAction.addTTCacheInterval({'index' : row, 'isCatalog' : true}, function (result, e) {
70aabdee   elena   catalog draft
644
							this.status = result.status;
dc702c6d   Elena.Budnik   sort without save
645
646
647
648
649
650
651
652
653
654
							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);
									}
								});
							}
70aabdee   elena   catalog draft
655
656
						}, this);
					}
1340621c   Elena.Budnik   error msg when up...
657
658
659
660
661
662
663
664
665
666
667
668
669
				},{
					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');						
							this.TTGrid.getSelectionModel().deselectAll();
							AmdaAction.removeTTCacheIntervalFromId(rowId, this.isCatalog, function (result, e) {
								this.status = result.status;
dc702c6d   Elena.Budnik   sort without save
670
671
672
								if (!this.TTGrid.getStore().loading) {
									this.TTGrid.getStore().reload();
								}
1340621c   Elena.Budnik   error msg when up...
673
674
675
							}, this);
						}
					}
70aabdee   elena   catalog draft
676
677
678
				}]
			}]
		});
f792a3de   elena   catalog ihm
679
 
1340621c   Elena.Budnik   error msg when up...
680
		this.formPanel =  Ext.create('Ext.form.Panel', { 
f13f0bd4   Elena.Budnik   New Catalog creation
681
			region : 'center',
cf70da13   Benjamin Renard   Fix modif detecti...
682
683
684
			layout:  'hbox',
			model : 'amdaModel.Catalog',
			trackResetOnLoad : true, // reset to the last loaded record 
f13f0bd4   Elena.Budnik   New Catalog creation
685
686
687
			bodyStyle: {background : '#dfe8f6'},
			defaults: { border : false, align: 'stretch', bodyStyle: {background : '#dfe8f6'},  padding: '3'},
			fieldDefaults: { labelWidth: 80, labelAlign : 'top' },
1340621c   Elena.Budnik   error msg when up...
688
			items: [{            
f13f0bd4   Elena.Budnik   New Catalog creation
689
690
691
				xtype: 'form',		            
				flex: 1,
				buttonAlign: 'left',
1340621c   Elena.Budnik   error msg when up...
692
				// title : 'Information',		   
f13f0bd4   Elena.Budnik   New Catalog creation
693
694
695
696
697
698
				layout: {type: 'vbox', pack: 'start', align: 'stretch'},
				items : [
					this.fieldName,
					{
						xtype: 'fieldcontainer',
						layout: 'hbox',		      
1340621c   Elena.Budnik   error msg when up...
699
						items: [{
f13f0bd4   Elena.Budnik   New Catalog creation
700
701
702
703
704
								xtype:'datefield', fieldLabel:'Creation date',
								name: 'created', disabled: true, 
								hideTrigger: true, format: 'Y/m/d H:i:s'
							},			  
							{ xtype: 'splitter' },			 			 
1340621c   Elena.Budnik   error msg when up...
705
							{ xtype:'textfield', fieldLabel: 'Intervals', name: 'nbIntervals', disabled: true }
f13f0bd4   Elena.Budnik   New Catalog creation
706
707
708
709
710
711
712
713
714
715
						]                                                                       
					},
					{
						xtype: 'textarea',
						name: 'description',
						fieldLabel: 'Description',
						height: 200
					},
					{
						xtype: 'component',
3c57b165   Benjamin Renard   Reduce space betw...
716
						height: 90
f13f0bd4   Elena.Budnik   New Catalog creation
717
					}], 
1340621c   Elena.Budnik   error msg when up...
718
					dockedItems:[{
f13f0bd4   Elena.Budnik   New Catalog creation
719
720
721
						xtype: 'toolbar',
						dock: 'bottom', 
						ui: 'footer',
1340621c   Elena.Budnik   error msg when up...
722
						items: [{
f13f0bd4   Elena.Budnik   New Catalog creation
723
724
725
726
727
728
729
730
							type: 'button',
							text: 'Create New Catalog',
							scope : this,
							handler: function () 
							{ 											
								var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id);	
										
								if (!module) return;
07650d8e   Elena.Budnik   create empty catalog
731
732
733
734
											  
								module.createLinkedNode();
 								module.createObject();
								
f13f0bd4   Elena.Budnik   New Catalog creation
735
736
								var obj = module.linkedNode.get('object');
								
1340621c   Elena.Budnik   error msg when up...
737
738
									var me = this;
									
f13f0bd4   Elena.Budnik   New Catalog creation
739
740
									Ext.Msg.prompt('Define Parameters', 'Please enter parameters number:', function(btn, text){
										if (btn == 'ok'){
2190f380   Benjamin Renard   Fix cancel action...
741
742
743
744
											module.createLinkedNode();
											module.createObject();
											var obj = module.linkedNode.get('object');

6ab359f0   Benjamin Renard   Cleanup model fie...
745
746
747
748
749
											var nbParam = parseInt(text);
											if ((nbParam <= 0) || (nbParam > 100)) {
												nbParam = 1;
											}

2190f380   Benjamin Renard   Fix cancel action...
750
751
											obj.set('nbParameters', nbParam);
											me.setObject(obj,true);
07650d8e   Elena.Budnik   create empty catalog
752
										}
f13f0bd4   Elena.Budnik   New Catalog creation
753
									}, this);
07650d8e   Elena.Budnik   create empty catalog
754
									
f13f0bd4   Elena.Budnik   New Catalog creation
755
756
757
							}
						}]
					},
0318dbe6   Hacene SI HADJ MOHAND   rm_6998 ok
758
                                                                                                               
f13f0bd4   Elena.Budnik   New Catalog creation
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
					{  
						xtype: 'toolbar',
						dock: 'bottom', 
						ui: 'footer',
						items: [
						{
							type: 'button',
							text: 'Save',
							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);
d18b535d   elena   catalog draft + c...
778

f13f0bd4   Elena.Budnik   New Catalog creation
779
										var me = this;
1340621c   Elena.Budnik   error msg when up...
780
										this.checkIntervalsStatusForSave(function () {
f13f0bd4   Elena.Budnik   New Catalog creation
781
782
783
784
785
786
											//Name validation
											var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id);	
											
											if (!module) return;
											module.linkedNode.isValidName(me.fieldName.getValue(), function (res) 
											{
1340621c   Elena.Budnik   error msg when up...
787
												if (!res) {
f13f0bd4   Elena.Budnik   New Catalog creation
788
789
790
791
792
793
													me.fieldName.validFlag = 'Error during object validation';
													myDesktopApp.errorMsg(me.fieldName.validFlag);
													me.fieldName.validate();
													return;
												}
												
1340621c   Elena.Budnik   error msg when up...
794
795
796
												if (!res.valid) {
													if (res.error) {
														if (res.error.search('subtree') != -1) {  							
f13f0bd4   Elena.Budnik   New Catalog creation
797
798
799
800
801
802
803
804
805
806
807
808
809
															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;
													}
1340621c   Elena.Budnik   error msg when up...
810
													else {
f13f0bd4   Elena.Budnik   New Catalog creation
811
812
813
814
815
816
817
818
819
820
821
822
823
														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);
											});
										});                            
									} 
1340621c   Elena.Budnik   error msg when up...
824
									else {
d547a559   Hacene SI HADJ MOHAND   rm_6903 ok
825
										Ext.Msg.alert('No intervals', 'Your catalog is invalid, <br>you must have at least one interval');
f13f0bd4   Elena.Budnik   New Catalog creation
826
827
828
									}
								}
							} 
1340621c   Elena.Budnik   error msg when up...
829
						},{
f13f0bd4   Elena.Budnik   New Catalog creation
830
							type: 'button',
08eee02f   Elena.Budnik   reset catalogUI
831
832
							text: 'Reset',
							scope : this,
1340621c   Elena.Budnik   error msg when up...
833
							handler: function() {
398e3bf2   Elena.Budnik   redmine 6507 : ca...
834
								var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id);			
08eee02f   Elena.Budnik   reset catalogUI
835
836
// 								module.createLinkedNode();
// 								module.createObject();
398e3bf2   Elena.Budnik   redmine 6507 : ca...
837
								this.setObject(module.getLinkedNode().get('object'), true);                           
08eee02f   Elena.Budnik   reset catalogUI
838
							} 
f13f0bd4   Elena.Budnik   New Catalog creation
839
						},	
398e3bf2   Elena.Budnik   redmine 6507 : ca...
840
841
842
843
844
845
846
847
848
849
850
851
// 						{   
// 							type: 'button',
// 							text: 'Share',
// 							scope : this,
// 							handler: function() {	
// 								var me = this;	
// 								myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id, true, function (module) {
// 									var catalog = module.getLinkedNode().get('object');
// 									module.shareCatalog({'name' : catalog.get('text'), 'id' : catalog.get('id')});
// 								});
// 							}
// 						},
0318dbe6   Hacene SI HADJ MOHAND   rm_6998 ok
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870

                                                                                                                        ]
					},
                                                                                                     //statistical info 
                                                                                                                       {
                                                                                                                         xtype: 'toolbar',
						dock: 'bottom', 
						ui: 'footer',
                                                                                                                        items:[{ 
                                                                                                                                            xtype: 'button',
                                                                                                                                             text: 'Statistical info',
                                                                                                                                             scope: this,
                                                                                                                                             //dock: 'bottom', 
                                                                                                                                             //ui: 'footer',
                                                                                                                                             handler: function() {
                                                                                                                                                                   this.fireEvent('info','catalogUI');
                                                                                                                                                                }
                                                                                                                                             },
                                                        			                                        {   
f13f0bd4   Elena.Budnik   New Catalog creation
871
872
873
							type: 'button',
							text: 'Visualize',
							scope: this,
1340621c   Elena.Budnik   error msg when up...
874
							handler: function() {
f13f0bd4   Elena.Budnik   New Catalog creation
875
								var me = this;
1340621c   Elena.Budnik   error msg when up...
876
								myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.visu.id, true, function (module) {	 	 							
f13f0bd4   Elena.Budnik   New Catalog creation
877
									//temporary linked node - as  Visu module is 'pseudo' interactive - no 'save', no 'execute'
e1fd05b4   Elena.Budnik   visu from cacheCat
878
									var temporaryNode = Ext.create('amdaModel.CatalogNode', { leaf : true });
f13f0bd4   Elena.Budnik   New Catalog creation
879
880
881
									if (temporaryNode) temporaryNode.set('object',me.object); 
									module.setLinkedNode(temporaryNode);
									
1340621c   Elena.Budnik   error msg when up...
882
									module.createWindow(); 
f13f0bd4   Elena.Budnik   New Catalog creation
883
884
								});     
							}
0318dbe6   Hacene SI HADJ MOHAND   rm_6998 ok
885
886
						}
                                                                                                                        ]
d547a559   Hacene SI HADJ MOHAND   rm_6903 ok
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
                                                                                                                        },
                                                                                                                         {
                                                                                                                         xtype: 'toolbar',
						dock: 'bottom', 
						ui: 'footer',
                                                                                                                        items:[{ 
                                                                                                                                            xtype: 'button',
                                                                                                                                             text: 'Generate Time Table',
                                                                                                                                             scope: this,
                                                                                                                                             //dock: 'bottom', 
                                                                                                                                             //ui: 'footer',
                                                                                                                                             handler: function() {
                                                                                                                                                                   this.generateTT(this.object.get('id'));
                                                                                                                                                                }
                                                                                                                                             }]},
                                                                                            ]
f13f0bd4   Elena.Budnik   New Catalog creation
903
904
905
906
907
908
				},
				{
					xtype: 'form',               
					bodyStyle: {background : '#dfe8f6'},
					//padding: '3',
					flex: 2,
1340621c   Elena.Budnik   error msg when up...
909
					items : [ this.TTGrid ] 
f13f0bd4   Elena.Budnik   New Catalog creation
910
911
				}]  
			}); 
f792a3de   elena   catalog ihm
912
	 
1340621c   Elena.Budnik   error msg when up...
913
		this.TTGrid.getSelectionModel().on('selectionchange', function(selModel,selections) {
f13f0bd4   Elena.Budnik   New Catalog creation
914
915
			this.TTGrid.down('#delete').setDisabled(selections.length === 0); 
		}, this); 
f792a3de   elena   catalog ihm
916
	
1340621c   Elena.Budnik   error msg when up...
917
		var myConf = {
f13f0bd4   Elena.Budnik   New Catalog creation
918
919
920
921
922
923
924
925
			layout: 'border',
			items: [		   
				this.formPanel, 		     
				{
					xtype: 'panel', 
					region: 'south',
					title: 'Information',
					collapsible: true,
42863f42   Elena.Budnik   collapseMode: "he...
926
					collapseMode: 'header',
f13f0bd4   Elena.Budnik   New Catalog creation
927
928
929
930
931
932
933
934
935
936
					height: 100,
					autoHide: false,
					bodyStyle: 'padding:5px',
					iconCls:  'icon-information',
					loader: 
					{
						autoLoad: true,
						url: helpDir+'catalogHOWTO'
					} 
				}
0318dbe6   Hacene SI HADJ MOHAND   rm_6998 ok
937
938
			] ,
                        plugins: [ {ptype: 'statisticalPlugin'} ]  
1340621c   Elena.Budnik   error msg when up...
939
		};	    
f13f0bd4   Elena.Budnik   New Catalog creation
940
		Ext.apply (this, Ext.apply(arguments, myConf));	
0318dbe6   Hacene SI HADJ MOHAND   rm_6998 ok
941
942
	}
        
f792a3de   elena   catalog ihm
943
});