Blame view

js/app/views/CatalogUI.js 14.3 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',
d18b535d   elena   catalog draft + c...
13
14

	isCatalog : true,
f792a3de   elena   catalog ihm
15
	
70aabdee   elena   catalog draft
16
17
18
	constructor: function(config) 
	{
		this.init(config);
d18b535d   elena   catalog draft + c...
19
		this.callParent(arguments);;
70aabdee   elena   catalog draft
20
		if (this.object) this.loadObject();	         
f792a3de   elena   catalog ihm
21
22
	},
	
70aabdee   elena   catalog draft
23
24
	setObject : function (object) 
	{
048b4d77   elena   catalogs +
25
26
27
28
29
30
		// set object
		this.object = object;
		
		// load object into view
		this.loadObject();
	},
f792a3de   elena   catalog ihm
31
	
d18b535d   elena   catalog draft + c...
32
33
34
	/**
	 * set params description into this.object
	 */
70aabdee   elena   catalog draft
35
36
37
38
39
40
41
42
	setParamInfo : function(parameters) 
	{
		var params = [];
		Ext.Array.each(parameters, function(item, index) {
			params[index] = item;	     	  
		}, this);
		
		this.object.set('parameters', params);	  
f792a3de   elena   catalog ihm
43
44
45
46
	},
	
	/**
	 * update this.object from form
d18b535d   elena   catalog draft + c...
47
	 */	
70aabdee   elena   catalog draft
48
49
	updateObject : function()
	{  
d18b535d   elena   catalog draft + c...
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
	// get the basic form	
	  var basicForm = this.formPanel.getForm();        
	  var updateStatus = true;

	  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;	    
	},
f792a3de   elena   catalog ihm
72
	
d18b535d   elena   catalog draft + c...
73
	
70aabdee   elena   catalog draft
74
75
	updateCount : function() 
	{
d18b535d   elena   catalog draft + c...
76
77
78
79
80
81
82
		this.object.set('nbIntervals',this.TTGrid.getStore().getTotalCount());		
		this.formPanel.getForm().findField('nbIntervals').setValue(this.object.get('nbIntervals'));
	},
	
	/**
	 * load object catalog into this view
	 */
70aabdee   elena   catalog draft
83
84
85
86
	loadObject : function()
	{ 	  
		// load object into form
		this.formPanel.getForm().loadRecord(this.object);
d18b535d   elena   catalog draft + c...
87
		
70aabdee   elena   catalog draft
88
89
90
		this.status = null;
			
		var me = this;
d18b535d   elena   catalog draft + c...
91
		
70aabdee   elena   catalog draft
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
		var onAfterInit = function(result, e) 
		{		
			if (!result || !result.success)
			{
				if (result.message)
					myDesktopApp.errorMsg(result.message);
				else
					myDesktopApp.errorMsg('Unknown error during catalog cache initialisation');
				return;
			}
			          	
			var fields = [], columns = [], i = 3, width, index;

			var fieldsConfig =  [{ name : 'start' },{ name : 'stop' },{ name: 'cacheId', type : 'int'},
				{ name: 'isNew', type : 'boolean', defaultValue: false },
			       { name: 'isModified', type : 'boolean', defaultValue: false}
			];
			
			for (var j = 0; j < 5; j++) fields[j] =  Ext.create('Ext.data.Field', fieldsConfig[j]);
				
			columns[0] =  Ext.create('Ext.grid.column.RowNumberer');
d18b535d   elena   catalog draft + c...
113

70aabdee   elena   catalog draft
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
			columns[1] = Ext.create('Ext.grid.column.Column', { text: 'Start Time', sortable : false,  dataIndex: 'start',  
						width : 120, menuDisabled: true });
			columns[2] = Ext.create('Ext.grid.column.Column', { text: 'Stop Time', sortable : false,  dataIndex: 'stop',  
						width : 120, menuDisabled: true });
		
			Ext.Array.each(result.parameters, function(obj) 
			{
				index = 'param'+(i-1).toString();			
				fields[i+2] = Ext.create('Ext.data.Field',{ name : index });
				width = 50. *  parseInt(obj.size);
				columns[i] = Ext.create('Ext.grid.column.Column', { text: obj.name, sortable : false,  dataIndex: index,  
						width : width, menuDisabled: true });
				i++;
			});
			
			
         
			var store = Ext.create('Ext.data.Store', {
				fields: fields,
				autoDestroy: false,
				pageSize : 200,
				buffered : true, 
				purgePageCount: 0,
				remoteSort: true,
				proxy: {
					type: 'direct',
					api :
					{
						read   :  AmdaAction.readTTCacheIntervals
					},
					// 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');
						me.TTGrid.getView().refresh();
						me.TTGrid.getSelectionModel().refresh();
						me.updateCount();
						//Statistical plugin
						//   	this.fireEvent("refresh");
					}
				}
			});
	   
			me.TTGrid.reconfigure(store, columns);
					
			me.TTGrid.getSelectionModel().deselectAll();
	//         	        	
	//         	// clear filters
	//         	me.TTGrid.getStore().clearFilter(true);
	//         
	//     		//clear sort
	//         	me.TTGrid.getStore().sorters.clear();
	//         	//me.TTGrid.getStore().sorters = new Ext.util.MixedCollection();
	//         	
			//set cache token to the Catalog object
			me.object.set('cacheToken', result.token);
			me.setParamInfo(result.parameters);
			
			me.TTGrid.getStore().load();
			
			me.status = result.status;
		};
d18b535d   elena   catalog draft + c...
185
	  
70aabdee   elena   catalog draft
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
		if (this.object.get('fromPlugin'))
		{
			if (this.object.get('objFormat') && this.object.get('objFormat') != '')
			{
				//From uploaded file
				//AmdaAction.initTTCacheFromUploadedFile(this.object.get('objName'), this.object.get('objFormat'), onAfterInit);
			}
			else
			{
				//From tmp object (ie Search result)		    
				AmdaAction.initTTCacheFromTmpObject(this.object.get('folderId'), this.object.get('objName'), this.isCatalog, onAfterInit);
			}
		}
		else
		{
			var typeTT = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id).linkedNode.data.nodeType;
			if (this.object.get('id') == '')
			{
				//Init empty cache
				AmdaAction.initTTCache(this.isCatalog, onAfterInit);
			}	
			else
			{
				//From existing TT file
				AmdaAction.initTTCacheFromTT(this.object.get('id'), 'catalog', onAfterInit);
			}
		}
d18b535d   elena   catalog draft + c...
213
	},
70aabdee   elena   catalog draft
214
	
d18b535d   elena   catalog draft + c...
215
	checkIntervalsStatusForSave : function(onStatusOk) {
70aabdee   elena   catalog draft
216
		onStatusOk();
d18b535d   elena   catalog draft + c...
217
218
219
220
221
	},
	
	/*	    
	 * save method called by Save button
	 */
70aabdee   elena   catalog draft
222
223
224
	saveProcess : function(toRename)
	{
		var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id); 
d18b535d   elena   catalog draft + c...
225
226
	      
            // if the name has been modified this is a creation
70aabdee   elena   catalog draft
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
		if (this.fclose()) 
	      {         
			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;
				} 
				module.linkedNode.create({callback : function() {module.linkedNode.update();}, scope : this});
			} else {
				//update
				module.linkedNode.update();
			}
		}
f792a3de   elena   catalog ihm
252
253
	},
	
d18b535d   elena   catalog draft + c...
254
255
256
257
	/**
	 * Check if changes were made before closing window 
	 * @return true if changes
	 */	
70aabdee   elena   catalog draft
258
259
	fclose : function() 
	{
d18b535d   elena   catalog draft + c...
260
261
262
263
		if (this.status == null)
			return false;
		
		var isDirty = this.formPanel.getForm().isDirty() || (this.status.isModified) || (this.status.nbModified > 0) || (this.status.nbNew > 0);
70aabdee   elena   catalog draft
264
	return isDirty;
d18b535d   elena   catalog draft + c...
265
266
267
	},

		    
70aabdee   elena   catalog draft
268
269
270
	init : function (config) 
	{	  
		this.object =   config.object;
f792a3de   elena   catalog ihm
271
	  
70aabdee   elena   catalog draft
272
273
274
275
276
277
278
279
280
281
282
283
284
		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,
				validator : function() {
					return this.validFlag;
				}
		});
f792a3de   elena   catalog ihm
285
	  
d18b535d   elena   catalog draft + c...
286

70aabdee   elena   catalog draft
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
331
332
333
334
335
336
337
338
339
		this.TTGrid =  Ext.create('Ext.grid.Panel', { 
			height: 530,
			columns: [ ],
			frame: true,
			dockedItems: [{
				xtype: 'toolbar', 
				items: [{
				iconCls: 'icon-add',
				scope: this,
				handler: function(){
				      alert('NOT IMPLEMENTED YET');
	//                         cellEditing.cancelEdit();
	//                         
	//                         var selection = this.TTGrid.getView().getSelectionModel().getSelection()[0];
	//                         var row = 0;
	//                         if (selection)
	//                         	row = store.indexOf(selection) + 1;
	//                         this.TTGrid.getSelectionModel().deselectAll();
	//                         
	//                         var me = this;
	//                         AmdaAction.addTTCacheInterval({'index' : row}, function (result, e) {
	//                         	this.status = result.status;
	//                         	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);	
	//                         		}
	//                         	});
	//                         }, 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');
						console.log(selection);
						this.TTGrid.getSelectionModel().deselectAll();
						AmdaAction.removeTTCacheIntervalFromId(rowId, this.isCatalog, function (result, e) {
							this.status = result.status;
							this.TTGrid.getStore().reload();
						}, this);
					}
				}
				}]
			}]
		});
f792a3de   elena   catalog ihm
340
341
 
	  this.formPanel =  Ext.create('Ext.form.Panel', { 
d18b535d   elena   catalog draft + c...
342
343
344
345
	      region : 'center',
	      layout:  'hbox', 
	      bodyStyle: {background : '#dfe8f6'},
	      defaults: { border : false, align: 'stretch', bodyStyle: {background : '#dfe8f6'},  padding: '3'},
f792a3de   elena   catalog ihm
346
347
348
	      fieldDefaults: { labelWidth: 80, labelAlign : 'top' },
	      items: [ 
		{            
d18b535d   elena   catalog draft + c...
349
		    xtype: 'form',		            
f792a3de   elena   catalog ihm
350
351
		    flex: 1,
		    buttonAlign: 'left',
d18b535d   elena   catalog draft + c...
352
//		    title : 'Information',		   
f792a3de   elena   catalog ihm
353
354
		    layout: {type: 'vbox', pack: 'start', align: 'stretch'},
		    items : [
d18b535d   elena   catalog draft + c...
355
356
		     this.fieldName,
		      {
f792a3de   elena   catalog ihm
357
358
359
360
361
362
363
364
365
366
		      xtype: 'fieldcontainer',
		      layout: 'hbox',		      
		      items: [
			  {
			      xtype:'datefield', fieldLabel:'Creation date',
			      name: 'created', disabled: true, 
			      hideTrigger: true, format: 'Y/m/d H:i:s'
			  },			  
			  { xtype: 'splitter' },			 			 
			  { xtype:'textfield', fieldLabel: 'Intervals', name: 'nbIntervals', disabled: true}
d18b535d   elena   catalog draft + c...
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
			]                                                                       
		      },
		      {
			  xtype: 'textarea',
			  name: 'description',
			  fieldLabel: 'Description',
			  height: 200
		      },
		      {
			  xtype: 'component',
			  height: 180
		      }
		      ],
		      fbar:[
			  {   
			      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);

                            			var me = this;
                            			this.checkIntervalsStatusForSave(function () {
						    //Name validation
						    var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id);	
						    if (!module)
							    return;
						    module.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');
  				              }
                                    }
                           } 
			  },{   
			      type: 'button',
			      text: 'Share',
			      disabled: true 
			  },
			  {   
			      type: 'button',
			      text: 'Visualize' 
			  } 
			]
f792a3de   elena   catalog ihm
457
		}, {
d18b535d   elena   catalog draft + c...
458
		    xtype: 'form',		               
f792a3de   elena   catalog ihm
459
		    bodyStyle: {background : '#dfe8f6'},
d18b535d   elena   catalog draft + c...
460
//		    padding: '3',
f792a3de   elena   catalog ihm
461
462
		    flex: 2,
		    items : [
d18b535d   elena   catalog draft + c...
463
464
		      this.TTGrid
		    ] 
f792a3de   elena   catalog ihm
465
466
		}
	    ]  
70aabdee   elena   catalog draft
467
	}); 
f792a3de   elena   catalog ihm
468
	 
d18b535d   elena   catalog draft + c...
469
	 this.TTGrid.getSelectionModel().on('selectionchange', function(selModel,selections){
70aabdee   elena   catalog draft
470
		this.TTGrid.down('#delete').setDisabled(selections.length === 0); 
d18b535d   elena   catalog draft + c...
471
        }, this); 
f792a3de   elena   catalog ihm
472
473
474
475
476
477
478
479
480
481
482
483
484
	
	var myConf = {
		    layout: 'border',
		    items: [		   
			  this.formPanel, 		     
			  {
			    xtype: 'panel', 
			    region: 'south',
			    title: 'Information',
			    collapsible: true,
			    height: 100,
			    autoHide: false,
			    bodyStyle: 'padding:5px',
70aabdee   elena   catalog draft
485
			    iconCls:  'icon-information',
f792a3de   elena   catalog ihm
486
487
			      loader: {
				autoLoad: true,
38c35fa6   elena   catalog howto tbd
488
				url: helpDir+'catalogHOWTO'
f792a3de   elena   catalog ihm
489
490
491
492
493
			      } 
			  }
		    ] 
	      };
	    
70aabdee   elena   catalog draft
494
	Ext.apply (this, Ext.apply(arguments, myConf));	
f792a3de   elena   catalog ihm
495
496
497
    }
	 
});