Blame view

js/app/models/InteractiveNode.js 25.1 KB
42e2e019   Benjamin Renard   Next step for cac...
1
/**
16035364   Benjamin Renard   First commit
2
3
4
5
6
7
8
9
10
11
 * Project  : AMDA-NG4
 * Name     : InteractiveNode.js
 * @class   amdaModel.InteractiveNode
 * @extends amdaModel.AmdaNode
 * @brief   Generic Model of Interactive Node
 * @author  CDA
 * @version $Id: InteractiveNode.js 2683 2014-12-02 10:58:53Z elena $
 */

Ext.define('amdaModel.InteractiveNode', {
eec153c1   Elena.Budnik   formattage, netto...
12
	extend: 'amdaModel.AmdaNode',
16035364   Benjamin Renard   First commit
13

42e2e019   Benjamin Renard   Next step for cac...
14
	fields: [
eec153c1   Elena.Budnik   formattage, netto...
15
		{name: 'contextNode', type: 'amdaModel.AmdaNode', persist: false},
42e2e019   Benjamin Renard   Next step for cac...
16
		{name: 'objectDataModel', type: 'string', persist: false},
eec153c1   Elena.Budnik   formattage, netto...
17
18
19
		{name: 'object', type: 'object', persist: false},
		{name: 'moduleId', type: 'string', persist: false},
		{name: 'filtered', type: 'boolean', defaultValue: false, persist: false},
f29c5e66   Elena.Budnik   plot only option
20
		{name: 'needsArgs', type:'boolean', defaultValue: false},
2fa56f95   Benjamin Renard   Predefined templa...
21
		{name: 'predefinedArgs', type:'boolean', defaultValue: false},
698494ac   Benjamin Renard   Add tooltip for s...
22
23
		{name: 'disable', type: 'boolean', defaultValue: false, persist: false},
		{name: 'last_update', type: 'int', defaultValue: 0}
eec153c1   Elena.Budnik   formattage, netto...
24
	],
16035364   Benjamin Renard   First commit
25

eec153c1   Elena.Budnik   formattage, netto...
26
27
28
	statics: {
		preloadNodes : function(node,onready)
		{
42e2e019   Benjamin Renard   Next step for cac...
29
			var me = this;
eec153c1   Elena.Budnik   formattage, netto...
30
31
32
33
34
35
36
37
38
			var nodesToLoad = new Array();
			nodesToLoad.push(node);
			this.preloadTreeNode(node, nodesToLoad, function (node)
				{
					var isFinish = true;
					nodesToLoad.forEach(function (element, index, array)
					{
							if (!element.isLoaded())
								isFinish = false;
42e2e019   Benjamin Renard   Next step for cac...
39
					});
eec153c1   Elena.Budnik   formattage, netto...
40
41
42
43
					if (isFinish && onready)
						onready.call();
				});
		},
16035364   Benjamin Renard   First commit
44

eec153c1   Elena.Budnik   formattage, netto...
45
46
47
		preloadTreeNode : function(node, nodesToLoad, onloaded)
		{
			var me = this;
42e2e019   Benjamin Renard   Next step for cac...
48

eec153c1   Elena.Budnik   formattage, netto...
49
50
51
			if (node.isLoaded())
			{
				node.eachChild(function(n)
42e2e019   Benjamin Renard   Next step for cac...
52
					{
e1798fcc   Benjamin Renard   Cleanup PlotTabNode
53
						if (!n.isLoaded() && !n.isLeaf())
eec153c1   Elena.Budnik   formattage, netto...
54
55
56
57
58
						{
							nodesToLoad.push(n);
							me.preloadTreeNode(n,nodesToLoad,onloaded);
						}
					});
42e2e019   Benjamin Renard   Next step for cac...
59

eec153c1   Elena.Budnik   formattage, netto...
60
61
62
					if (onloaded)
						onloaded.call(me,node);
					return;
42e2e019   Benjamin Renard   Next step for cac...
63
64
			}

eec153c1   Elena.Budnik   formattage, netto...
65
			node.store.load({
42e2e019   Benjamin Renard   Next step for cac...
66
				node : node,
eec153c1   Elena.Budnik   formattage, netto...
67
68
69
				callback : function(records, operation, successful)
					{
						records.forEach(function (record)
42e2e019   Benjamin Renard   Next step for cac...
70
							{
e1798fcc   Benjamin Renard   Cleanup PlotTabNode
71
								if (!record.isLoaded() && !record.isLeaf())
eec153c1   Elena.Budnik   formattage, netto...
72
73
74
75
76
77
78
79
80
81
82
									{
										nodesToLoad.push(record);
										me.preloadTreeNode(record,nodesToLoad,onloaded);
									}
							});
						if (onloaded)
							onloaded.call(me,node);
					}
			});
		}
	},
42e2e019   Benjamin Renard   Next step for cac...
83

0c154100   Elena.Budnik   redmine #5141 part.2
84
	onReady : null,
42e2e019   Benjamin Renard   Next step for cac...
85

eec153c1   Elena.Budnik   formattage, netto...
86
87
	constructor : function(config)
	{
42e2e019   Benjamin Renard   Next step for cac...
88
89
		this.callParent(arguments);
		this.set('nodeType',this.self.nodeType);
74b77f58   Elena.Budnik   init remote branch
90
91
		this.set('ownerTreeId',amdaUI.ExplorerUI.RESRC_TAB.TREE_ID);
		if (this.get('id')) { // TODO why sometimes (delete in remote interoper tree) this.get('id') = undefined ?
42e2e019   Benjamin Renard   Next step for cac...
92
			// if id of this node have root category suffix
74b77f58   Elena.Budnik   init remote branch
93
94
95
96
			if (Ext.util.Format.substr(this.get('id'), -(amdaUI.ExplorerUI.CAT_SUFFIX.length), this.get('id').length) === amdaUI.ExplorerUI.CAT_SUFFIX)
			{
			// set the expanded property to true
				this.set('expanded',true);
42e2e019   Benjamin Renard   Next step for cac...
97
			}
74b77f58   Elena.Budnik   init remote branch
98
		}
eec153c1   Elena.Budnik   formattage, netto...
99
	},
429f876c   Benjamin Renard   Fix plot request ...
100

eec153c1   Elena.Budnik   formattage, netto...
101
102
103
104
105
106
107
/**
* this method is overriden into ExecutableNode to return true
*/
	isExecutable: function()
	{
		return false;
	},
16035364   Benjamin Renard   First commit
108

eec153c1   Elena.Budnik   formattage, netto...
109
110
111
/**
* open Module with THIS NODE
*/
42e2e019   Benjamin Renard   Next step for cac...
112
	editInModule : function (contextNode, onReady)
eec153c1   Elena.Budnik   formattage, netto...
113
114
115
116
117
118
119
	{
		// set the contextNode of this node
		this.set('contextNode',contextNode);
		// parameter module
		var me = this;
		myDesktopApp.getLoadedModule(this.get('moduleId'),true, function (module) {
		// If the node to edit is not already linked to this module
42e2e019   Benjamin Renard   Next step for cac...
120
			if (module.getLinkedNode() != me)
eec153c1   Elena.Budnik   formattage, netto...
121
122
			{
				// set relative node into parameter Module
42e2e019   Benjamin Renard   Next step for cac...
123
124
				module.setLinkedNode(me);
				if (contextNode==null)
eec153c1   Elena.Budnik   formattage, netto...
125
126
127
				{
					// set the root node as contextNode
					contextNode = me.getRootNode();
42e2e019   Benjamin Renard   Next step for cac...
128
129
130
				}
				module.setContextNode(contextNode);

f6206fd6   Elena.Budnik   rm 6522 First Der...
131
			} else if (module.getLinkedNode() != null){
eec153c1   Elena.Budnik   formattage, netto...
132
133
134
135
136
			//TODO the node to edit is already edited
				// myDesktopApp.warningMsg('This object is  being edited');
				//Sol1: msg alert: "warning this node is already edited! If you want to get the original, please press the 'reset' button"->'OK'
				//Sol2: msg with user choice: "warning this node is already edited! Would you confirm this action and lost your modification?"->'Confirm','Cancel'
			}
42e2e019   Benjamin Renard   Next step for cac...
137
138
139
			// Opening parameter window
			module.createWindow(onReady);
		});
eec153c1   Elena.Budnik   formattage, netto...
140
	},
16035364   Benjamin Renard   First commit
141

eec153c1   Elena.Budnik   formattage, netto...
142
143
144
/**
* Method to rename the workspace node
*/
42e2e019   Benjamin Renard   Next step for cac...
145
146
	rename: function(value,callBackFn)
	{
e1798fcc   Benjamin Renard   Cleanup PlotTabNode
147
		var dataToSend = {id : this.get('id'), old_name: this.modified.text, name: value,  parent : this.data.parentId, leaf: this.isLeaf(), nodeType: this.get('nodeType')};
42e2e019   Benjamin Renard   Next step for cac...
148
		AmdaAction.renameObject(dataToSend, callBackFn);
eec153c1   Elena.Budnik   formattage, netto...
149
	},
42e2e019   Benjamin Renard   Next step for cac...
150

eec153c1   Elena.Budnik   formattage, netto...
151
152
153
/**
* Method to rename the workspace node when D&D
*/
42e2e019   Benjamin Renard   Next step for cac...
154
155
	renameDD: function(parentId, callBackFn)
	{
e1798fcc   Benjamin Renard   Cleanup PlotTabNode
156
		var dataToSend = {id : this.get('id'), old_name: this.get('name'), name: this.get('name'), parent : parentId, leaf: this.isLeaf(), nodeType: this.get('nodeType')};
eec153c1   Elena.Budnik   formattage, netto...
157
158
		AmdaAction.renameObject(dataToSend, callBackFn);
	},
42e2e019   Benjamin Renard   Next step for cac...
159

eec153c1   Elena.Budnik   formattage, netto...
160
161
162
/**
* validation method on name (used in module forms)
* @param name the name to validate
42e2e019   Benjamin Renard   Next step for cac...
163
* @returns
eec153c1   Elena.Budnik   formattage, netto...
164
165
166
*/
	isValidName : function(name, callBackFn)
	{
e1798fcc   Benjamin Renard   Cleanup PlotTabNode
167
		var dataToSend = {name: name, nodeType: this.get('nodeType'), leaf: this.isLeaf()};
65ac4a9d   Nathanaël Jourdane   Fix folders debug...
168
		AmdaAction.validNameObject(dataToSend, callBackFn);
eec153c1   Elena.Budnik   formattage, netto...
169
	},
16035364   Benjamin Renard   First commit
170

eec153c1   Elena.Budnik   formattage, netto...
171
172
173
174
175
/**
* Method to persist modifications of an AmdaObject by Server side and update the workspace
* node linked to a Module
*/
	update : function(opt)
42e2e019   Benjamin Renard   Next step for cac...
176
	{
eec153c1   Elena.Budnik   formattage, netto...
177
		AmdaAction.modifyObject(this.get('object').getJsonValues(true), function(res,e){
42e2e019   Benjamin Renard   Next step for cac...
178

eec153c1   Elena.Budnik   formattage, netto...
179
			if(e.status) {
42e2e019   Benjamin Renard   Next step for cac...
180
				if (res.id) {
eec153c1   Elena.Budnik   formattage, netto...
181
182
183
184
185
186
					if (!this.get('contextNode')) {
						// set the root node of 'Derived Parameters' tree as contextNode
						this.set('contextNode',this.getRootNode());
					}
					this.get('contextNode').expand(false,false);
					this.myGetOwnerTree().getSelectionModel().select(this);
42e2e019   Benjamin Renard   Next step for cac...
187

eec153c1   Elena.Budnik   formattage, netto...
188
189
					if (opt)
					{
5b64c444   Hacene SI HADJ MOHAND   rm-6903 corrected
190

eec153c1   Elena.Budnik   formattage, netto...
191
192
193
						var scope = opt.scope ? opt.scope : this;
						if (opt.callback)
							opt.callback.call(scope,'update');
833e6c62   Hacene SI HADJ MOHAND   corrections to ca...
194
              if(opt.notDisplayMsg || opt.callback ){
42e2e019   Benjamin Renard   Next step for cac...
195
196
197
198
199
200
                   //do nothing
              }else{
                  Ext.Msg.alert('Complete', 'Object '+this.get('object').get('name')+' has been modified');
              }

					 }
5b64c444   Hacene SI HADJ MOHAND   rm-6903 corrected
201

eec153c1   Elena.Budnik   formattage, netto...
202
203
					// fix the modifications for object
					this.get('object').commit();
42e2e019   Benjamin Renard   Next step for cac...
204

eec153c1   Elena.Budnik   formattage, netto...
205
206
					if (res.info) {
						this.set('info',res.info);
eec153c1   Elena.Budnik   formattage, netto...
207
					}
42e2e019   Benjamin Renard   Next step for cac...
208

7cab5983   Benjamin Renard   Add modif. time f...
209
					if (res.last_update) {
698494ac   Benjamin Renard   Add tooltip for s...
210
						this.set('last_update', res.last_update);
7cab5983   Benjamin Renard   Add modif. time f...
211
212
213
						this.get('object').set('last_update', res.last_update);
					}

8ba47f72   Benjamin Renard   rest actualisatio...
214
					// myDataParam  and Parameter special update
75a3182b   Elena.Budnik   special MyDataPar...
215
					this.specialUpdate(res, false);
42e2e019   Benjamin Renard   Next step for cac...
216

eec153c1   Elena.Budnik   formattage, netto...
217
218
219
					// reload object into the view of corresponding Module
					var me = this;
					myDesktopApp.getLoadedModule(this.get('moduleId'), true, function (module) {
8dddc557   Benjamin Renard   Fix plot reload
220
221
222
223
224
225
						if (!opt || !opt.plot) {
							module.getUiContent().setObject(me.get('object'));
						}
						else {
							module.getUiContent().reloadPlot(me);
						}
eec153c1   Elena.Budnik   formattage, netto...
226
227
228
229
					});
				}
				else {
					//TODO proper error message handling
42e2e019   Benjamin Renard   Next step for cac...
230
					// error code from server; but e.status==true
eec153c1   Elena.Budnik   formattage, netto...
231
232
233
234
235
236
237
238
					// revert all modifications since last load or commit
					this.get('object').reject();
					myDesktopApp.errorMsg(res.error);
				}
			}
			else {
				// revert all modifications since last load or commit
				this.get('object').reject();
42e2e019   Benjamin Renard   Next step for cac...
239
				myDesktopApp.errorMsg(e.message);
eec153c1   Elena.Budnik   formattage, netto...
240
241
242
			}
		},this);
	},
16035364   Benjamin Renard   First commit
243

eec153c1   Elena.Budnik   formattage, netto...
244
245
246
247
/**
* Method to create a new AmdaObject by server side and create the workspace node linked to a Module
* under its contextNode or the root node corresponding to this nodeType category
*/
42e2e019   Benjamin Renard   Next step for cac...
248
	create : function(opt)
eec153c1   Elena.Budnik   formattage, netto...
249
250
251
252
	{
		if (!this.get('contextNode') || (this.get('contextNode').data.id == 'sharedtimeTable-treeRootNode') || (this.get('contextNode').data.id == 'sharedcatalog-treeRootNode')) {
			// set the root node of 'Derived Parameters' tree as contextNode
			this.set('contextNode',this.getRootNode());
42e2e019   Benjamin Renard   Next step for cac...
253
254
255
		}
		// call the Ext.Direct method to create parameter
		AmdaAction.createObject(this.get('object').getJsonValues(false), this.get('contextNode').get('id'), function(res,e){
eec153c1   Elena.Budnik   formattage, netto...
256
			//success
42e2e019   Benjamin Renard   Next step for cac...
257
258
			if(e.status)
			{
eec153c1   Elena.Budnik   formattage, netto...
259
260
261
				// if correct response received
				if (res.id) {   //if (res.id || res.error == 'NAME_EXISTS') {
					// 'save as' case ; delete old node if it exists
42e2e019   Benjamin Renard   Next step for cac...
262
					if (this.toRename)
eec153c1   Elena.Budnik   formattage, netto...
263
					{
42e2e019   Benjamin Renard   Next step for cac...
264
						this.toRename	= false;
eec153c1   Elena.Budnik   formattage, netto...
265
266
267
268
269
						var myRoot = this.getRootNode();
						// search the same named node to override
						var updateNode = myRoot.findChild('text',this.get('object').get('name'),true);
						// destroy the overrided node
						updateNode.parentNode.removeChild(updateNode);//TODO ??if destroy==true => too many recursions....
42e2e019   Benjamin Renard   Next step for cac...
270
271
						updateNode.destroy();
					}
eec153c1   Elena.Budnik   formattage, netto...
272
273
					// set text of this node
					this.set('text',this.get('object').get('name'));
f6206fd6   Elena.Budnik   rm 6522 First Der...
274

eec153c1   Elena.Budnik   formattage, netto...
275
276
277
					//set id of this node
					this.set('id',res.id);
					this.internalId = res.id;
f6206fd6   Elena.Budnik   rm 6522 First Der...
278

eec153c1   Elena.Budnik   formattage, netto...
279
					// set id of node's object
42e2e019   Benjamin Renard   Next step for cac...
280
					this.get('object').set('id',res.id);
eec153c1   Elena.Budnik   formattage, netto...
281
282
283
284
					if (res.created){
						// set the created date
						this.get('object').set('created',res.created);
					}
42e2e019   Benjamin Renard   Next step for cac...
285

eec153c1   Elena.Budnik   formattage, netto...
286
287
288
					if (res.info){
						// set the tooltip
						this.set('info',res.info);
75a3182b   Elena.Budnik   special MyDataPar...
289
					}
7cab5983   Benjamin Renard   Add modif. time f...
290
291
292

					var reloadObject = false;
					if (res.last_update) {
698494ac   Benjamin Renard   Add tooltip for s...
293
						this.set('last_update', res.last_update);
7cab5983   Benjamin Renard   Add modif. time f...
294
295
296
297
						this.get('object').set('last_update', res.last_update);
						reloadObject = true;
					}

75a3182b   Elena.Budnik   special MyDataPar...
298
299
					//set globalStart & global Stop to be used for time selection
					this.specialUpdate(res, true);
42e2e019   Benjamin Renard   Next step for cac...
300

7cab5983   Benjamin Renard   Add modif. time f...
301
302
303
304
305
306
307
308
309
310
311
312
313
					// reload object into the view of corresponding Module
					var me = this;
					if (reloadObject) {
						myDesktopApp.getLoadedModule(this.get('moduleId'), true, function (module) {
							if (!opt || !opt.plot) {
								module.getUiContent().setObject(me.get('object'));
							}
							else {
								module.getUiContent().reloadPlot(me);
							}
 						});
					}

eec153c1   Elena.Budnik   formattage, netto...
314
315
					//TODO do we need this commission ???
					// fix the modifications for object
42e2e019   Benjamin Renard   Next step for cac...
316
					this.get('object').commit();
663f6395   Elena.Budnik   nettoyage
317

eec153c1   Elena.Budnik   formattage, netto...
318
					// if ownerTree panel is not active
663f6395   Elena.Budnik   nettoyage
319
					if (this.myGetOwnerTree().ownerCt.getActiveTab()!==this.myGetOwnerTree()) {
eec153c1   Elena.Budnik   formattage, netto...
320
						// set ownerTree panel as the active tab - to enable selection of this node his ownerTree must have a view
42e2e019   Benjamin Renard   Next step for cac...
321
						this.myGetOwnerTree().ownerCt.setActiveTab(this.myGetOwnerTree());
eec153c1   Elena.Budnik   formattage, netto...
322
					}
134b0d67   Benjamin Renard   Fix typo (#7238)
323
                                                                                                    if(opt && opt.notDisplayMsg){
5b64c444   Hacene SI HADJ MOHAND   rm-6903 corrected
324
                                                                                                        //do nothing
42e2e019   Benjamin Renard   Next step for cac...
325
326
                                                                                                        }else{
                                                                                                                       Ext.Msg.alert('Complete', 'New object '+this.get('object').get('name')+' has been created');
5b64c444   Hacene SI HADJ MOHAND   rm-6903 corrected
327
                                                                                                            }
42e2e019   Benjamin Renard   Next step for cac...
328

eec153c1   Elena.Budnik   formattage, netto...
329
					// expand the contextNode
663f6395   Elena.Budnik   nettoyage
330
					this.get('contextNode').expand(false, function() {
eec153c1   Elena.Budnik   formattage, netto...
331
						if (!this.get('contextNode').findChild('text',this.get('text'))) {
42e2e019   Benjamin Renard   Next step for cac...
332
333
							// create node in tree as child of contextNode
							this.get('contextNode').appendChild(this);
eec153c1   Elena.Budnik   formattage, netto...
334
						}
42e2e019   Benjamin Renard   Next step for cac...
335
						// select the new node
eec153c1   Elena.Budnik   formattage, netto...
336
						this.myGetOwnerTree().getSelectionModel().select(this);
663f6395   Elena.Budnik   nettoyage
337
						if (opt) {
eec153c1   Elena.Budnik   formattage, netto...
338
339
340
							var scope = opt.scope ? opt.scope : this;
							if (opt.callback)
									opt.callback.call(scope,'create');
42e2e019   Benjamin Renard   Next step for cac...
341
						}
eec153c1   Elena.Budnik   formattage, netto...
342
					}, this);
42e2e019   Benjamin Renard   Next step for cac...
343
				}
eec153c1   Elena.Budnik   formattage, netto...
344
345
				// error code from server; but e.status==true
				else {
42e2e019   Benjamin Renard   Next step for cac...
346
					myDesktopApp.errorMsg(res.error);
eec153c1   Elena.Budnik   formattage, netto...
347
348
349
350
351
352
353
354
355
356
357
					// revert all modifications since last load or commit
					this.get('object').reject();
				}
			}
			// failure: e.status == false
			else {
				// revert all modifications since last load or commit
				this.get('object').reject();
				//TODO: this.destroy();
				myDesktopApp.errorMsg(e.message);
			}
42e2e019   Benjamin Renard   Next step for cac...
358
		},this);
eec153c1   Elena.Budnik   formattage, netto...
359
	},
16035364   Benjamin Renard   First commit
360

75a3182b   Elena.Budnik   special MyDataPar...
361
	specialUpdate : function() {},
eec153c1   Elena.Budnik   formattage, netto...
362
363
/**
* Generic part of Context Menu
42e2e019   Benjamin Renard   Next step for cac...
364
365
*
*/
eec153c1   Elena.Budnik   formattage, netto...
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
	allMenuItems : function() {
		var src = this.self.objectName;
		var menuItems =
		[ {
			fnId : 'root-createLeaf',
			text : 'Create '+ src
		}, {
			fnId : 'root-createDir',
			text : 'Create Folder'
		}, {
			fnId : 'dire-createLeaf',
			text : 'Create ' + src
		}, {
			fnId : 'dire-createDir',
			text : 'Create Folder'
		}, {
			fnId : 'dire-renameNode',
			text : 'Rename Folder'
		}, {
			fnId : 'dire-deleteNode',
			text : 'Delete Folder'
		}, {
			fnId : 'leaf-editLeaf',
			text : 'Edit ' + src
		}, {
			fnId : 'leaf-renameNode',
			text : 'Rename ' + src
		}, {
			fnId : 'leaf-deleteNode',
			text : 'Delete '+ src
		} ];
		return menuItems;
	},
16035364   Benjamin Renard   First commit
399

eec153c1   Elena.Budnik   formattage, netto...
400
401
402
403
404
405
406
407
408
	allMenuMultiItems : function() {
		var menuMulti = [
		{
			fnId : 'mult-deleteMulti',
			text : 'Delete selected ' + this.self.objectName + 's'
		}
		];
		return menuMulti;
	},
d18b535d   elena   catalog draft + c...
409

42e2e019   Benjamin Renard   Next step for cac...
410
411
	getAllContextMenuItems: function(){
		return  this.allMenuItems();
eec153c1   Elena.Budnik   formattage, netto...
412
413
414
415
416
	},

	getMultiContextMenuItems: function(){
		return this.allMenuMultiItems();
	},
42e2e019   Benjamin Renard   Next step for cac...
417

eec153c1   Elena.Budnik   formattage, netto...
418
419
420
421
422
423
424
/**
* default implementation
* no menu display if there's no override of this function
*/
	getMultiContextMenuItems: function(){
		return null;
	},
42e2e019   Benjamin Renard   Next step for cac...
425

eec153c1   Elena.Budnik   formattage, netto...
426
427
/**
*  Context Menu Actions
42e2e019   Benjamin Renard   Next step for cac...
428
429
*
*/
eec153c1   Elena.Budnik   formattage, netto...
430
431
432
	onMenuItemClick : function(menu,item,event) {
		// fnId parsing :
		var fnId = Ext.util.Format.substr(item.fnId, 5, item.fnId.length);
16035364   Benjamin Renard   First commit
433

eec153c1   Elena.Budnik   formattage, netto...
434
435
		switch (fnId) {
			case 'deleteNode':
42e2e019   Benjamin Renard   Next step for cac...
436
				this.deleteNode();
eec153c1   Elena.Budnik   formattage, netto...
437
438
				break;
			case 'createDir':
42e2e019   Benjamin Renard   Next step for cac...
439
				this.createDir();
eec153c1   Elena.Budnik   formattage, netto...
440
441
442
				break;
			case 'createLeaf':
				this.createLeaf(this);
42e2e019   Benjamin Renard   Next step for cac...
443
				break;
eec153c1   Elena.Budnik   formattage, netto...
444
			case 'renameNode':
11d21073   Nathanaël Jourdane   Fix bugs when cre...
445
				this.renameNode(false);
eec153c1   Elena.Budnik   formattage, netto...
446
				break;
42e2e019   Benjamin Renard   Next step for cac...
447
448
449
			case 'editLeaf':
				this.editLeaf();
				break;
eec153c1   Elena.Budnik   formattage, netto...
450
451
			case 'deleteMulti':
				this.deleteMulti();
eec153c1   Elena.Budnik   formattage, netto...
452
				break;
42e2e019   Benjamin Renard   Next step for cac...
453
454
455
456
457
458
			case 'plotParam':
				this.createPlot(this);
				break;
			case 'downParam':
				this.createDownload(this);
				break;
3b63d483   Hacene SI HADJ MOHAND   shared in progress
459
			case 'generateCatalog':
84a1734b   Hacene SI HADJ MOHAND   us 7833 plot TT c...
460
461
462
463
464
465
                                                                                 this.generateCatalog(this);
                                                                                break;
                                                            case 'generateTT':
                                                                                this.generateTT(this);
                                                                                break;
                                                           case 'plotTT':
86c573e5   Hacene SI HADJ MOHAND   correction du tic...
466
                                                                                this.createPlot(this);
84a1734b   Hacene SI HADJ MOHAND   us 7833 plot TT c...
467
                                                                                break;
eec153c1   Elena.Budnik   formattage, netto...
468
469
470
471
			default:
				break;
		} // switch end
	},
42e2e019   Benjamin Renard   Next step for cac...
472

eec153c1   Elena.Budnik   formattage, netto...
473
	getTimeFromNode: function(node)  {
eec153c1   Elena.Budnik   formattage, netto...
474
475
		var startString = new String(node.get('globalStart'));
		var stopString = new String(node.get('globalStop'));
a0f13ed1   Elena.Budnik   small format + ti...
476

42e2e019   Benjamin Renard   Next step for cac...
477
		var startDate =  new Date(startString.replace(/\-/g,'\/').replace(/[T|Z]/g,' '));
eec153c1   Elena.Budnik   formattage, netto...
478
		var stopDate =  new Date(stopString.replace(/\-/g,'\/').replace(/[T|Z]/g,' '));
b852834a   Hacene SI HADJ MOHAND   progress
479
                                                
eec153c1   Elena.Budnik   formattage, netto...
480
		if (stopDate -  startDate  > 86400000 ) {
42e2e019   Benjamin Renard   Next step for cac...
481
			var startTime = Ext.Date.add(stopDate, Ext.Date.DAY, -1);
a0f13ed1   Elena.Budnik   small format + ti...
482
			// var timeObj = {start: Ext.Date.format(startTime, 'Y/m/d H:i:s'), stop: Ext.Date.format(stopDate, 'Y/m/d H:i:s')};
b852834a   Hacene SI HADJ MOHAND   progress
483
			var timeObj = {start: Ext.Date.format(startTime, 'Y/m/d H:i:s.u'), stop: Ext.Date.format(stopDate, 'Y/m/d H:i:s.u')};
42e2e019   Benjamin Renard   Next step for cac...
484
		}
eec153c1   Elena.Budnik   formattage, netto...
485
		else {
b852834a   Hacene SI HADJ MOHAND   progress
486
			var timeObj = {start: Ext.Date.format(startTime, 'Y/m/d H:i:s.u'), stop: Ext.Date.format(stopDate, 'Y/m/d H:i:s.u')};
eec153c1   Elena.Budnik   formattage, netto...
487
		}
42e2e019   Benjamin Renard   Next step for cac...
488
		return timeObj;
eec153c1   Elena.Budnik   formattage, netto...
489
	},
16035364   Benjamin Renard   First commit
490

42e2e019   Benjamin Renard   Next step for cac...
491
492
493
	createPlot: function(node)
	{
		if (node.get('disable')) return;
eec153c1   Elena.Budnik   formattage, netto...
494
		myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id, true, function (module) {
57e15214   Benjamin Renard   Fix addParameter ...
495
                    module.addParameter(node);
eec153c1   Elena.Budnik   formattage, netto...
496
497
		});
	},
42e2e019   Benjamin Renard   Next step for cac...
498
499
500

	createDownload: function(node)
	{
eec153c1   Elena.Budnik   formattage, netto...
501
		myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.download.id, true, function (module) {
f569bae5   Benjamin Renard   Save download
502
		    module.addParameter(node);
42e2e019   Benjamin Renard   Next step for cac...
503
		});
eec153c1   Elena.Budnik   formattage, netto...
504
	},
42e2e019   Benjamin Renard   Next step for cac...
505
506

	deleteNode: function() {
eec153c1   Elena.Budnik   formattage, netto...
507
			// if the target is a directory
e1798fcc   Benjamin Renard   Cleanup PlotTabNode
508
			if (!this.isLeaf()) {
eec153c1   Elena.Budnik   formattage, netto...
509
				// determine if this directory is empty before launching the delete confirmation method
42e2e019   Benjamin Renard   Next step for cac...
510
				this.isNotEmptyDir(this.confirmDirectoryDeletion);
eec153c1   Elena.Budnik   formattage, netto...
511
512
513
514
515
516
			// else (the target is a leaf)
			} else {
				// no confirmation prompt for leaves
				this.confirmDirectoryDeletion(false);
			}
	},
42e2e019   Benjamin Renard   Next step for cac...
517

eec153c1   Elena.Budnik   formattage, netto...
518
519
520
521
522
523
524
/**
* this method return if node has Childs even if it was not already loaded
*/
	isNotEmptyDir : function(callbackFn) {
		var hasChilds;
		// if node not already loaded
		if (!this.isLoaded()){
42e2e019   Benjamin Renard   Next step for cac...
525
			// call directFunction to load this node
eec153c1   Elena.Budnik   formattage, netto...
526
527
528
			AmdaAction.getTree({node:this.get('id'),nodeType:this.get('nodeType')},function(res,e){
				callbackFn.call(this,res.length>0?true:false);
			},this);
42e2e019   Benjamin Renard   Next step for cac...
529
		}
eec153c1   Elena.Budnik   formattage, netto...
530
531
532
533
		else {
			callbackFn.call(this,this.hasChildNodes());
		}
	},
42e2e019   Benjamin Renard   Next step for cac...
534

eec153c1   Elena.Budnik   formattage, netto...
535
536
537
538
/**
* this method is used to display a confirmation message
*/
	confirmDirectoryDeletion : function(isNotEmptyDir)
42e2e019   Benjamin Renard   Next step for cac...
539
	{
eec153c1   Elena.Budnik   formattage, netto...
540
541
542
543
544
545
546
547
548
		// if this is a non-empty directory
		if (isNotEmptyDir) {
			// Prompt to the user if he also wants to delete its content
			Ext.Msg.confirm('non-empty directory', 'The target is a non-empty directory!<br>Do you want to continue and also delete its content?', function(btn, text){
				if (btn == 'yes'){
					// do delete
					this.realDelete();
				}
			},this);
42e2e019   Benjamin Renard   Next step for cac...
549
		}
eec153c1   Elena.Budnik   formattage, netto...
550
551
		else {
			this.realDelete();
42e2e019   Benjamin Renard   Next step for cac...
552
		}
eec153c1   Elena.Budnik   formattage, netto...
553
	},
42e2e019   Benjamin Renard   Next step for cac...
554

eec153c1   Elena.Budnik   formattage, netto...
555
556
/*
*    Call the extDirect method to delete parameter
42e2e019   Benjamin Renard   Next step for cac...
557
*    Callback method needed to execute node deletion in tree if id in result or to show error msg
eec153c1   Elena.Budnik   formattage, netto...
558
559
*/
	realDelete : function()
42e2e019   Benjamin Renard   Next step for cac...
560
	{
e1798fcc   Benjamin Renard   Cleanup PlotTabNode
561
		AmdaAction.deleteObject({id: this.get('id'), leaf: this.isLeaf(), nodeType: this.get('nodeType')}, function(res,e){
42e2e019   Benjamin Renard   Next step for cac...
562
563
			//TODO proper errors handling
			// node deletion in tree
eec153c1   Elena.Budnik   formattage, netto...
564
565
566
567
			if (res) {  // if success
				if (res.id) {
					//Ext.Msg.show({title:'Warning', msg: 'Requests with parameter '+node.data.text+' are deleted', icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
					if (this.parentNode) {
e1798fcc   Benjamin Renard   Cleanup PlotTabNode
568
						if (this.isLeaf()){
eec153c1   Elena.Budnik   formattage, netto...
569
							var moduleId = this.get('moduleId');
42e2e019   Benjamin Renard   Next step for cac...
570
							// if really interactive node
eec153c1   Elena.Budnik   formattage, netto...
571
							if (moduleId) {
3e9f7a84   Elena.Budnik   check if window i...
572
573
574
575
576
577
								var win = myDesktopApp.getDesktop().getWindow(moduleId);
								// if window is really open
								if (win) {
									var me = this;
									myDesktopApp.getLoadedModule(moduleId, true, function (module) {
										var editedNode = module.getLinkedNode();
42e2e019   Benjamin Renard   Next step for cac...
578
579

										// file node is not linked directly to the module
3e9f7a84   Elena.Budnik   check if window i...
580
										var isThisFile = false;
42e2e019   Benjamin Renard   Next step for cac...
581
										if (editedNode && editedNode.$className == 'amdaModel.MyDataParamNode')
3e9f7a84   Elena.Budnik   check if window i...
582
											if (editedNode.get('fileObject').get('fileName') == me.get('text'))
42e2e019   Benjamin Renard   Next step for cac...
583
584
585
												isThisFile = true;

										// node was created BEFORE tree loading; node.id are different ; but it is the same node
3e9f7a84   Elena.Budnik   check if window i...
586
587
588
589
										if ( editedNode && editedNode.get('id') == me.get('id') && editedNode !== me ) {
											module.setLinkedNode(me);
											isThisFile = true;
										}
42e2e019   Benjamin Renard   Next step for cac...
590

3e9f7a84   Elena.Budnik   check if window i...
591
592
593
594
595
596
										if (me.$className == 'amdaModel.DerivedParamNode') {
											var obj = {
												paramId : 'ws_'+me.get('text')
											};
											AmdaAction.compilParamDelete(obj);
										}
42e2e019   Benjamin Renard   Next step for cac...
597
598

										if (editedNode === me || isThisFile ){
3e9f7a84   Elena.Budnik   check if window i...
599
600
601
602
											var newNode = Ext.ModelManager.create({leaf : true}, me.$className);
											// several tabs could be connected to one node
											if (moduleId === myDesktopApp.dynamicModules.plot.id) {
												var linkedNodes = module.linkedNodes;
42e2e019   Benjamin Renard   Next step for cac...
603

3e9f7a84   Elena.Budnik   check if window i...
604
												if (linkedNodes) {
42e2e019   Benjamin Renard   Next step for cac...
605
606
													linkedNodes.each(function(key, value){
														if (value === me) {
3e9f7a84   Elena.Budnik   check if window i...
607
608
															linkedNodes.replace(key,newNode);
															var tabPanel = module.getUiContent().tabPanel.items.getByKey(key);
42e2e019   Benjamin Renard   Next step for cac...
609
610
															tabPanel.setObject(Ext.create(amdaModel.Plot.$className, {}));
														}
3e9f7a84   Elena.Budnik   check if window i...
611
													}, me);
42e2e019   Benjamin Renard   Next step for cac...
612
613
												}
											}
3e9f7a84   Elena.Budnik   check if window i...
614
615
											newNode.editInModule();
										}
42e2e019   Benjamin Renard   Next step for cac...
616
									});
eec153c1   Elena.Budnik   formattage, netto...
617
								}
eec153c1   Elena.Budnik   formattage, netto...
618
							}
42e2e019   Benjamin Renard   Next step for cac...
619
620
						}
						//update mask info in myData
eec153c1   Elena.Budnik   formattage, netto...
621
622
623
						if (res.maskDesc && !res.maskDeleted) {
							this.parentNode.set('info', res.maskDesc);
							this.updateMyDataParam(res.mask, res.maskDesc);
42e2e019   Benjamin Renard   Next step for cac...
624
625
						}
						this.remove();
eec153c1   Elena.Budnik   formattage, netto...
626
					}
42e2e019   Benjamin Renard   Next step for cac...
627
628
					//TODO Several special node-dependent actions - to move to node functions..
					// nodes of another nodeType to be deleted as they depend on deleted node
eec153c1   Elena.Budnik   formattage, netto...
629
630
631
					if (res.params) {
						this.deleteDependence(res.params);
						//TODO reset
42e2e019   Benjamin Renard   Next step for cac...
632
633
					}
					// mask was deleted or updated - to update mydata tree
eec153c1   Elena.Budnik   formattage, netto...
634
					if (res.maskDeleted) {
42e2e019   Benjamin Renard   Next step for cac...
635
636
						this.updateMyData();
					}
eec153c1   Elena.Budnik   formattage, netto...
637
638
				}
				else {
42e2e019   Benjamin Renard   Next step for cac...
639
					myDesktopApp.warningMsg(res.error);
eec153c1   Elena.Budnik   formattage, netto...
640
641
642
				}
			}
			else {
42e2e019   Benjamin Renard   Next step for cac...
643
				myDesktopApp.errorMsg(e.message);
eec153c1   Elena.Budnik   formattage, netto...
644
645
646
			}
		}, this);
	},
16035364   Benjamin Renard   First commit
647

eec153c1   Elena.Budnik   formattage, netto...
648
649
650
651
652
653
654
655
656
657
658
/*
*  Delete musti selection
*/
	deleteMulti: function()
	{
		var selection = this.myGetOwnerTree().getSelectionModel().selected.items;
		alert(selection.length +' to delete!');
		Ext.Array.each(selection,function(item,index,allItems){
			item.deleteNode();
		})
	},
42e2e019   Benjamin Renard   Next step for cac...
659

eec153c1   Elena.Budnik   formattage, netto...
660
661
662
663
/*
*  Create Folder
*/
	createDir: function() {
eec153c1   Elena.Budnik   formattage, netto...
664
665
666
667
668
669
		var me = this;
		amdaModel.InteractiveNode.preloadNodes(this.getRootNode(),
			function()
			{
				var newNode = Ext.create(me.$className,
				{
82560cb2   Nathanaël Jourdane   fix folders (wip)
670
671
					leaf : false, nodeType : me.get('nodeType'),
					text : amdaModel.AmdaNode.NEW_DIR_NAME,
11d21073   Nathanaël Jourdane   Fix bugs when cre...
672
673
					children : [],
          parentId: me.get('id')
eec153c1   Elena.Budnik   formattage, netto...
674
				});
16035364   Benjamin Renard   First commit
675

82560cb2   Nathanaël Jourdane   fix folders (wip)
676
				// insert the new node as a child of node
65ac4a9d   Nathanaël Jourdane   Fix folders debug...
677
        me.insertChild(0, newNode);
eec153c1   Elena.Budnik   formattage, netto...
678
679
680
				// start text edition on this new directory node
				me.expand(false);
				newNode.expand(false);
16035364   Benjamin Renard   First commit
681

eec153c1   Elena.Budnik   formattage, netto...
682
683
684
				// select the new node
				me.myGetOwnerTree().getSelectionModel().select(newNode);
				// call the renameNode method for this new node
11d21073   Nathanaël Jourdane   Fix bugs when cre...
685
				newNode.renameNode(true);
eec153c1   Elena.Budnik   formattage, netto...
686
687
			});
	},
42e2e019   Benjamin Renard   Next step for cac...
688

eec153c1   Elena.Budnik   formattage, netto...
689
/*
42e2e019   Benjamin Renard   Next step for cac...
690
*
eec153c1   Elena.Budnik   formattage, netto...
691
692
693
694
*/
	createLeaf: function(contextNode) {
		// create new node with the same type than the contextNode
		var newNode = Ext.create(contextNode.$className, {leaf : true});
16035364   Benjamin Renard   First commit
695

eec153c1   Elena.Budnik   formattage, netto...
696
697
698
699
700
701
702
703
		// load the rootNode and recursively all its child nodes
		amdaModel.InteractiveNode.preloadNodes(contextNode.getRootNode(),
			function()
			{
				// edit newNode into Parameter Module with node as contextNode
				newNode.editInModule(contextNode);
			});
	},
16035364   Benjamin Renard   First commit
704

11d21073   Nathanaël Jourdane   Fix bugs when cre...
705
	renameNode: function(deleteOnFailure)
65ac4a9d   Nathanaël Jourdane   Fix folders debug...
706
	{
eec153c1   Elena.Budnik   formattage, netto...
707
		if (this.myGetOwnerTree())
42e2e019   Benjamin Renard   Next step for cac...
708
		{
eec153c1   Elena.Budnik   formattage, netto...
709
710
711
712
713
714
			// load the rootNode and recursively all its child nodes if not already loaded
			var me = this;
			amdaModel.InteractiveNode.preloadNodes(this.getRootNode(),
				function()
				{
					// fire the edition event on tree
11d21073   Nathanaël Jourdane   Fix bugs when cre...
715
716
717
718
					var item = me.myGetOwnerTree().getSelectionModel().selected.items[0];
					item.deleteOnFailure = deleteOnFailure;
					me.myGetOwnerTree().fireEvent('edition', me.myGetOwnerTree().view, item);
				});
eec153c1   Elena.Budnik   formattage, netto...
719
720
721
722
723
724
		}
		else
		{
			myDesktopApp.errorMsg('tree is undefined');
		}
	},
16035364   Benjamin Renard   First commit
725

eec153c1   Elena.Budnik   formattage, netto...
726
727
728
729
/*
*       load the rootNode and recursively all its child nodes
*       to know all names of DerivedParameters
*/
42e2e019   Benjamin Renard   Next step for cac...
730
731
	editLeaf: function(onReady)
	{
eec153c1   Elena.Budnik   formattage, netto...
732
733
734
735
		var me = this;
		amdaModel.InteractiveNode.preloadNodes(this.getRootNode(),
		function()
		{
42e2e019   Benjamin Renard   Next step for cac...
736
			if (me.get('object'))
eec153c1   Elena.Budnik   formattage, netto...
737
738
739
740
741
			{
				// launch edition of parameter into parameter module
				me.editInModule(null, onReady);
			}
			else
42e2e019   Benjamin Renard   Next step for cac...
742
			{
eec153c1   Elena.Budnik   formattage, netto...
743
				// call the ext method to get the details of parameter
42e2e019   Benjamin Renard   Next step for cac...
744
745
				// the edition of real parameter is done into callback method getObjectCallback
				if (onReady)
0c154100   Elena.Budnik   redmine #5141 part.2
746
					me.onReady = onReady;
42e2e019   Benjamin Renard   Next step for cac...
747

eec153c1   Elena.Budnik   formattage, netto...
748
749
				AmdaAction.getObject(me.get('id'), me.get('nodeType'), me.getObjectCallback, me);
			}
42e2e019   Benjamin Renard   Next step for cac...
750
		});
eec153c1   Elena.Budnik   formattage, netto...
751
	},
16035364   Benjamin Renard   First commit
752

eec153c1   Elena.Budnik   formattage, netto...
753
/*
42e2e019   Benjamin Renard   Next step for cac...
754
*
eec153c1   Elena.Budnik   formattage, netto...
755
756
757
*/
	getObjectCallback : function(result,remoteEvent)
	{
eec153c1   Elena.Budnik   formattage, netto...
758
		var t = remoteEvent.getTransaction();
42e2e019   Benjamin Renard   Next step for cac...
759
760

		if (result) {
eec153c1   Elena.Budnik   formattage, netto...
761
762
763
			var paramObj = Ext.create(this.get('objectDataModel'), result);
			// set parameter into node
			this.set('object',paramObj);
42e2e019   Benjamin Renard   Next step for cac...
764
			// Edition of parameter into parameter Module
0c154100   Elena.Budnik   redmine #5141 part.2
765
			this.editInModule(null, this.onReady);
8b11b1af   Benjamin Renard   Insert intervals ...
766
			this.onReady = null;
42e2e019   Benjamin Renard   Next step for cac...
767
		}
eec153c1   Elena.Budnik   formattage, netto...
768
769
770
		else {
		// EXCEPTION : parameter not found !?
			myDesktopApp.errorMsg(t.action + "." + t.method + " : No parameter '"
42e2e019   Benjamin Renard   Next step for cac...
771
			+ this.get('name') + "' found!");
eec153c1   Elena.Budnik   formattage, netto...
772
		}
3b63d483   Hacene SI HADJ MOHAND   shared in progress
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
 	},

        generateCatalog: function(node){
            id = node.get('id');
            name = node.get('text');
            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('relatedTimeTableId', 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: ' + name;
                catObj.set('description', descr );
                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 ()
                        {
                            catNode.editInModule();
                        });
9b93ada1   Hacene SI HADJ MOHAND   shared cat to tt ok
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
              }
          }, this);
        }, 
      generateTT: function(node){
                       var catObj = Ext.create('amdaModel.TimeTable');
                              var timeTabNode = Ext.create('amdaModel.TimeTableNode',{leaf : true});
                              catObj.set('relatedCatalogId', node.get('id'));
                              desc =   'Generated by CDPP/Amda Catalog Module \n';
                              if (node.get('description'))
                                  desc = desc + node.get('description');
                              catObj.set('description', desc);
                              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()
                        {
                                timeTabNode.editInModule();
                        });
84a1734b   Hacene SI HADJ MOHAND   us 7833 plot TT c...
819
        },
3b63d483   Hacene SI HADJ MOHAND   shared in progress
820

16035364   Benjamin Renard   First commit
821
});