Blame view

js/app/views/PlotUI.js 11.1 KB
16035364   Benjamin Renard   First commit
1
2
3
4
5
/**
 * Project   : AMDA-NG
 * Name      : PlotUI.js
 * @class   amdaUI.PlotUI
 * @extends Ext.container.Container
18d4a11e   Benjamin Renard   Save and load plo...
6
7
8
 * @brief   New Plot Module UI definition (View)
 * @author  Benjamin Renard
 * @version $Id: PlotUI.js benjamin $
16035364   Benjamin Renard   First commit
9
10
11
12
 */


Ext.define('amdaUI.PlotUI', {
18d4a11e   Benjamin Renard   Save and load plo...
13
14
	extend: 'Ext.container.Container',
	alias: 'widget.newPanelPlot',
16035364   Benjamin Renard   First commit
15
	
18d4a11e   Benjamin Renard   Save and load plo...
16
17
18
19
20
21
22
23
24
25
26
	requires: [
	           'amdaModel.DownloadNode',
	           'amdaModel.Download',
	           'amdaUI.TimeSelectorUI',
	           'amdaPlotComp.PlotTabPanel',
	           'amdaPlotComp.PlotOutputForm',
	           'amdaPlotComp.PlotElementPanel'
    ],
	
	formPanel: null,
	
27b2a53e   Benjamin Renard   Link tab plot to ...
27
28
	multiPlotIntervalPanel : null,
	
18d4a11e   Benjamin Renard   Save and load plo...
29
30
31
32
33
34
	plotOutput: null,
	
	plotTabs : null,
	
	plotElement : null,
	
18d4a11e   Benjamin Renard   Save and load plo...
35
36
37
38
39
	constructor: function(config) {
		this.init(config);	    
		this.callParent(arguments);
		if (this.object)
			this.setObject(this.object);
16035364   Benjamin Renard   First commit
40
41
	},
	
18d4a11e   Benjamin Renard   Save and load plo...
42
43
44
45
46
	setObject : function(object) {
		this.object = object;
		this.plotOutput.setObject(this.object);
		this.plotTabs.setRequestObject(this.object);
		this.timeSelector.intervalSel.setInterval(this.object.get('startDate'), this.object.get('stopDate'));
e27eecbd   Benjamin Renard   Save and load TT ...
47
		this.addTTs(this.object.get('timeTables'));
a971060f   Benjamin Renard   Fix some bugs
48
	},
e6065c11   Elena.Budnik   overwrite request...
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
	
	/**
	 * overwrite metod called by Save button
	 */
	overwriteProcess : function(btn)
	{	
		if (btn == 'cancel') return;	
  
		this.saveProcess(true);		
	},
	
	
	/**
	 * save method called by Save button to launch the save process
	 */
	saveProcess : function(toRename) { 
e6065c11   Elena.Budnik   overwrite request...
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
		var plotModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id);
		if (!plotModule)
							return;
			           
			if (toRename) {
				plotModule.linkedNode.set('object',this.object);
				plotModule.linkedNode.update();
			}
			else {
				//Save
				if (this.object.get('id') != '') {
					//Duplicate request
					plotModule.createLinkedNode();
					plotModule.linkedNode.set('object',this.object);
				}
				plotModule.linkedNode.create();
			}
	}, 
16035364   Benjamin Renard   First commit
83
    
e6065c11   Elena.Budnik   overwrite request...
84
85
	resetProcess : function(){
		var plotModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id);			
18d4a11e   Benjamin Renard   Save and load plo...
86
		plotModule.createLinkedNode();
d648a5c0   Benjamin Renard   Insert plot tab i...
87
88
89
90
91
		var obj = null;
		if ((arguments.length > 0) && (arguments[0] != null)) {
			obj = arguments[0];
		}
		plotModule.createObject(obj);					  
18d4a11e   Benjamin Renard   Save and load plo...
92
		this.setObject(plotModule.linkedNode.get('object'));
e6065c11   Elena.Budnik   overwrite request...
93
	},
16035364   Benjamin Renard   First commit
94
	
e6065c11   Elena.Budnik   overwrite request...
95
	getDataProcess : function(){
27504b3e   Elena.Budnik   redmine 5080
96
97
		this.updateObject(); 
		// plot was not called - form only		
e6065c11   Elena.Budnik   overwrite request...
98
		if (this.object.get('last-plotted-tab') == 0) {
27504b3e   Elena.Budnik   redmine 5080
99
100
			this.object.set('last-plotted-tab', this.plotTabs.getSelectedTabId());
		}
f85f44e4   Benjamin Renard   us okkkkkkkkkk
101
102
103
		var downObject = amdaModel.DownloadNode.decodeObject(this.object);
		amdaModel.DownloadNode.set('object',Ext.create('amdaModel.Download',downObject));
               
e6065c11   Elena.Budnik   overwrite request...
104
105
		amdaModel.DownloadNode.editInModule(); 
	},
18d4a11e   Benjamin Renard   Save and load plo...
106
    
e6065c11   Elena.Budnik   overwrite request...
107
108
109
110
	addParameter : function(node){
		var crtTree = this.plotTabs.getTreeFromPlotTab(this.plotTabs.getActiveTab());
		crtTree.dropRecord(node,null,'append');
	},
16035364   Benjamin Renard   First commit
111
    
18d4a11e   Benjamin Renard   Save and load plo...
112
	/**
16035364   Benjamin Renard   First commit
113
114
     * plot method called by 'Do Plot' button to launch the plot process
     */
e6065c11   Elena.Budnik   overwrite request...
115
	doPlot : function(){
a56f041d   Elena.Budnik   bug whne multi pa...
116
		
e6065c11   Elena.Budnik   overwrite request...
117
		this.updateObject();
e6065c11   Elena.Budnik   overwrite request...
118
119
120
121
122
		this.object.set('last-plotted-tab', this.plotTabs.getSelectedTabId());
		var plotModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id);
		if (plotModule)
			plotModule.linkedNode.execute();
	},  
16035364   Benjamin Renard   First commit
123
	
18d4a11e   Benjamin Renard   Save and load plo...
124
125
126
127
128
	/**
	 * Check if changes were made before closing window 
	 * @return false
	 */	
	fclose : function() {
a971060f   Benjamin Renard   Fix some bugs
129
130
		var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id);
		if (module)
18d4a11e   Benjamin Renard   Save and load plo...
131
			module.closeInteractiveSession();
18d4a11e   Benjamin Renard   Save and load plo...
132
		
a971060f   Benjamin Renard   Fix some bugs
133
		return this.object.isDirty();
18d4a11e   Benjamin Renard   Save and load plo...
134
	},
16035364   Benjamin Renard   First commit
135
	
e6065c11   Elena.Budnik   overwrite request...
136
137
138
139
140
141
	/**
	* update time selector of this.object from form
	*/
	updateObject : function(){
		var timeSource = this.timeSelector.getActiveTimeSource();

d341347d   Elena.Budnik   Plot Mgr ameliora...
142
		var multiPlotForm = this.timeSelector.getForm();
e6065c11   Elena.Budnik   overwrite request...
143
144
145
146
147
148
		multiPlotForm.updateRecord(this.object);
		this.object.set('timesrc', timeSource);
		if (timeSource === amdaModel.AmdaTimeObject.inputTimeSrc[0])
			this.object.set('timeTables',this.timeSelector.TTGrid.getStore().data.items);
		this.plotTabs.updateTimeObject();
	},
a971060f   Benjamin Renard   Fix some bugs
149
	
a0f13ed1   Elena.Budnik   small format + ti...
150
	addTT : function(newTTName,newTTid,timeSelectorId) {
c94de8e9   Benjamin Renard   Fix Multi plot ti...
151
152
153
		var crtTimeSelector = Ext.getCmp(timeSelectorId);
		if (crtTimeSelector)
			crtTimeSelector.addTT(newTTName,newTTid);
18d4a11e   Benjamin Renard   Save and load plo...
154
	},
e27eecbd   Benjamin Renard   Save and load TT ...
155
156
157
158
159
	
	addTTs : function(TTarray) {
		// set TTTab	    
		this.timeSelector.setTTTab(TTarray);
	},
16035364   Benjamin Renard   First commit
160

a0f13ed1   Elena.Budnik   small format + ti...
161
162
163
164
165
166
167
168
	/**
	* Set Start-Stop from parameter info (Local & MyData)
	*/ 
	setTimeFromData : function(obj) {                                                               
		if (!obj.start || !obj.stop)
			return;
		var dateStart = new Date(obj.start.replace(/[T|Z]/g,' ').replace(/\-/g,'\/')); 
		var dateStop = new Date(obj.stop.replace(/[T|Z]/g,' ').replace(/\-/g,'\/')); 
2e8be1ae   Elena.Budnik   Set Start-Stop fr...
169

a0f13ed1   Elena.Budnik   small format + ti...
170
171
172
173
174
175
176
177
		for (var i = 0; i < this.plotTabs.items.getCount(); ++i) {
			var plotTab = this.plotTabs.items.getAt(i).items.getAt(0);  
			plotTab.items.getAt(1).intervalSel.setInterval(dateStart, dateStop);
			//TBD  plotTab.updateTimeObject();		 
		}
		
		this.timeSelector.intervalSel.setInterval(dateStart, dateStop);        
	},
ebbb3638   Benjamin Renard   Edit plot tab on ...
178
179
180
181
182
183
184
185
186
187

	forceActiveTab : function(tabId) {
		for (var i = 0; i < this.plotTabs.items.getCount(); ++i) {
			var plotTab = this.plotTabs.items.getAt(i).items.getAt(0);
			if (plotTab.tabId == tabId) {
				this.plotTabs.setActiveTab(i);
				return;
			}
		}
	},
d648a5c0   Benjamin Renard   Insert plot tab i...
188

efca00de   Benjamin Renard   Update tab name i...
189
190
191
192
193
194
195
196
197
198
	updatePlotTabName: function(tabId, name) {
		var me = this;
		this.object.tabs().each(function (tabObject) {
			if (tabId == tabObject.getId()) {
				tabObject.set('tab-name', name);
				me.plotTabs.updatePlotTabs();
			}
		});
	},

d648a5c0   Benjamin Renard   Insert plot tab i...
199
200
201
202
	insertPlotTab : function(tabData) {
		var newTab = this.object.createNewTab(tabData);
		this.plotTabs.addPlotTab(newTab,true);
	},
18d4a11e   Benjamin Renard   Save and load plo...
203
	
e6065c11   Elena.Budnik   overwrite request...
204
	updateLinkedToMultiPlotMode : function(isLinkedToMultiPlotMode) {
d341347d   Elena.Budnik   Plot Mgr ameliora...
205
		this.timeSelector.setVisible(isLinkedToMultiPlotMode); 
27b2a53e   Benjamin Renard   Link tab plot to ...
206
	},
0ead0129   Benjamin Renard   Modify save plot ...
207

6e2fdb1f   Benjamin Renard   Implments save cu...
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
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
	keepOnlySelectedTabInObject: function(showWarning, onSuccess) {
		if (this.object.tabs().count() == 1) {
			if (onSuccess) {
				onSuccess();
			}
			return;
		}

		var me = this;
		var removeFunc = function() {
			var tabsToRemove = [];
			var selectedTabFound = false;
			me.object.tabs().each(function(tab) {
				if (tab.get('id') != me.object.get('active-tab-id')) {
					tabsToRemove.push(tab);
				}
				else {
					selectedTabFound = true;
				}
			});
			if (!selectedTabFound) {
				myDesktopApp.errorMsg('Cannot retrieve selected tab');
				return false;
			}
			if (tabsToRemove.length > 0) {
				me.object.tabs().remove(tabsToRemove);
			}
			return true;
		};

		if (!showWarning) {
			if (removeFunc()) {
				if (onSuccess) {
					onSuccess();
				}
			}
			return;
		}


		Ext.Msg.show( { title : 'Warning',
			msg: 'Active plot will be saved, but other ones will be lost.<br/>Do you want to continue?',
			width: 300,
			buttons: Ext.Msg.OKCANCEL,
			fn: function(btn) {
				if (btn == 'cancel') return;

				if (removeFunc()) {
					if (onSuccess) {
						onSuccess();
					}
				}
				return;
			},
			scope: me
		});
	},

d575ea1d   Benjamin Renard   Fix bug in PlotUI
266
	savePlotRequest : function(allTabs) {
0ead0129   Benjamin Renard   Modify save plot ...
267
268
269
270
271
		var plotModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id);
		if (!plotModule)
			return;
		this.updateObject();
		this.object.set('active-tab-id', this.plotTabs.getSelectedTabId());
6e2fdb1f   Benjamin Renard   Implments save cu...
272
		var me = this;
0ead0129   Benjamin Renard   Modify save plot ...
273
274
275

		if ((this.object.get('id') != '') && (plotModule.linkedNode.get('text') == this.object.get('name'))) {
			//update existing request
6e2fdb1f   Benjamin Renard   Implments save cu...
276
277
278
279
280
281
282
283
			if (!allTabs) {
				this.keepOnlySelectedTabInObject(true, function() {
					plotModule.linkedNode.update();
				});
			}
			else {
				plotModule.linkedNode.update();
			}
0ead0129   Benjamin Renard   Modify save plot ...
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
			return;
		}

		//save new request
		var me = this;
		plotModule.linkedNode.isValidName(this.object.get('name'), function (res) {
			if (!res) {
				myDesktopApp.errorMsg('Error during object validation');
				return;
			}
			if (!res.valid) {
				if (res.error) {
					if (res.error.search('subtree') != -1) {
						Ext.Msg.show( { title : 'Warning',
							msg: res.error + '<br/>Do you want to overwrite it?',
							width: 300,
							buttons: Ext.Msg.OKCANCEL,
							icon: Ext.Msg.WARNING,
							fn :  me.overwriteProcess,
							scope : me
						});
					}
					else {
						myDesktopApp.errorMsg(res.error);
					}
				}
				else {
					myDesktopApp.errorMsg('Invalid object name');
				}
				return;
			}
6e2fdb1f   Benjamin Renard   Implments save cu...
315
316
317
318
319
320
321
322
323
			if (!allTabs) {
				me.keepOnlySelectedTabInObject((me.object.get('id') == ''), function() {
					me.saveProcess(false);
					me.setObject(me.object);
				});
			}
			else {
				me.saveProcess(false);
			}
0ead0129   Benjamin Renard   Modify save plot ...
324
325
		});
	},
27b2a53e   Benjamin Renard   Link tab plot to ...
326
    
18d4a11e   Benjamin Renard   Save and load plo...
327
	init : function(config) {
d341347d   Elena.Budnik   Plot Mgr ameliora...
328
		this.timeSelector = new amdaUI.TimeSelectorUI( { id: 'multiPlotTimeSelector' + config.id, title : 'MultiPlot Time Selection', border : false, collapsible : true, collapseDirection : 'bottom', visible : false, flex: 2 } );
18d4a11e   Benjamin Renard   Save and load plo...
329
		
d341347d   Elena.Budnik   Plot Mgr ameliora...
330
		this.plotOutput = new amdaPlotComp.PlotOutputForm({flex: 2, collapseDirection : 'bottom', collapsible : true });
18d4a11e   Benjamin Renard   Save and load plo...
331
		
d341347d   Elena.Budnik   Plot Mgr ameliora...
332
		this.plotElement = new amdaPlotComp.PlotElementPanel({flex: 4});
16035364   Benjamin Renard   First commit
333

d341347d   Elena.Budnik   Plot Mgr ameliora...
334
		this.plotTabs = new amdaPlotComp.PlotTabPanel({flex: 4, plotElementPanel : this.plotElement, plotUI : this});
18d4a11e   Benjamin Renard   Save and load plo...
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
		
		this.optionsPanel = new Ext.form.Panel({
			layout: {
			    type: 'vbox',
			    pack: 'start',
			    align: 'stretch'
			},
			bodyStyle: { background : '#dfe8f6' },  
			defaults: {
				border: false
			},
			items: [
			        this.plotElement,
			        this.plotOutput
			]
		});
		
18d4a11e   Benjamin Renard   Save and load plo...
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
		this.formPanel = new Ext.form.Panel({
			region: 'center',
			layout: {
			    type: 'hbox',
			    pack: 'start',
			    align: 'stretch'
			},
			bodyStyle: { background : '#dfe8f6' },  
			defaults: {
				border: false
			},
			items: [
			        {
						xtype : 'panel',
						layout: {
						    type: 'vbox',
						    pack: 'start',
						    align: 'stretch'
						},
						bodyStyle: { background : '#dfe8f6' },
						defaults: {
							border: false
						},
						flex: 1,
						items: [
	        				this.plotTabs,
d341347d   Elena.Budnik   Plot Mgr ameliora...
378
	        				this.timeSelector // this.multiPlotIntervalPanel
18d4a11e   Benjamin Renard   Save and load plo...
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
	        			]
					},
			        {
			        	xtype : 'panel',
			        	layout: 'fit',
			        	bodyStyle: { background : '#dfe8f6' },  
			        	defaults: {
							border: false
						},
			        	flex: 1,
			        	items: [
			        	        this.optionsPanel
			            ]
			        }
			],
0ead0129   Benjamin Renard   Modify save plot ...
394
395
			fbar: [
					{
e6065c11   Elena.Budnik   overwrite request...
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
						xtype: 'button',
						text: 'Plot',
						scope: this,
						handler: function(button) {
							this.doPlot();
						}
					},' ', {
						xtype: 'button',
						text: 'Get Data',
						scope: this,
						handler: function(button) {
							this.getDataProcess();
						}
					},' ', {
						xtype: 'button',
						text: 'Reset',
						scope: this,
						handler: function(button) {
							this.resetProcess();
						}
					},
9b3f49e3   Elena.Budnik   info bulls Plot r...
417
					'->', '-', {
0ead0129   Benjamin Renard   Modify save plot ...
418
419
420
421
422
423
424
425
426
427
428
429
430
						xtype: 'splitbutton',
						text: 'Save All Tabs',
						menu: {
							items: [
								{
									text: 'Save Current Tab',
									scope: this,
									handler: function() {
										this.savePlotRequest(false);
									}
								},
							]
						},
e6065c11   Elena.Budnik   overwrite request...
431
432
						scope: this,
						handler: function(button) {
0ead0129   Benjamin Renard   Modify save plot ...
433
							this.savePlotRequest(true);
13ad8aca   Elena.Budnik   2 options : all i...
434
						}
0ead0129   Benjamin Renard   Modify save plot ...
435
					 } 
18d4a11e   Benjamin Renard   Save and load plo...
436
437
			]
		});
e6065c11   Elena.Budnik   overwrite request...
438

18d4a11e   Benjamin Renard   Save and load plo...
439
		var myConf = {
e6065c11   Elena.Budnik   overwrite request...
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
			layout: 'border',
			items: [
				this.formPanel,
				{
					xtype: 'panel', 
					region: 'south',
					title: 'Information',
					collapsible: true,
					collapseMode: 'header',
					height: 100,
					autoHide: false,
					bodyStyle: 'padding:5px',
					iconCls: 'icon-information',
					loader: {
						autoLoad: true,
						url: helpDir+'plotHOWTO'
					}
				}
			]
18d4a11e   Benjamin Renard   Save and load plo...
459
		};
e6065c11   Elena.Budnik   overwrite request...
460
461
		
		Ext.apply(this, Ext.apply(arguments, myConf));
18d4a11e   Benjamin Renard   Save and load plo...
462
	}
8f85fbfa   Benjamin Renard   Remove deprecated...
463
});