Blame view

js/app/models/InteractiveNode.js 24.4 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

eec153c1   Elena.Budnik   formattage, netto...
14
15
16
	requires: [
		'amdaPlotObj.PlotRequestObject'
	],
42e2e019   Benjamin Renard   Next step for cac...
17
18

	fields: [
eec153c1   Elena.Budnik   formattage, netto...
19
		{name: 'contextNode', type: 'amdaModel.AmdaNode', persist: false},
42e2e019   Benjamin Renard   Next step for cac...
20
		{name: 'objectDataModel', type: 'string', persist: false},
eec153c1   Elena.Budnik   formattage, netto...
21
22
23
		{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
24
		{name: 'needsArgs', type:'boolean', defaultValue: false},
eec153c1   Elena.Budnik   formattage, netto...
25
26
		{name: 'disable', type: 'boolean', defaultValue: false, persist: false}
	],
16035364   Benjamin Renard   First commit
27

eec153c1   Elena.Budnik   formattage, netto...
28
29
30
	statics: {
		preloadNodes : function(node,onready)
		{
42e2e019   Benjamin Renard   Next step for cac...
31
			var me = this;
eec153c1   Elena.Budnik   formattage, netto...
32
33
34
35
36
37
38
39
40
			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...
41
					});
eec153c1   Elena.Budnik   formattage, netto...
42
43
44
45
					if (isFinish && onready)
						onready.call();
				});
		},
16035364   Benjamin Renard   First commit
46

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

eec153c1   Elena.Budnik   formattage, netto...
51
52
53
			if (node.isLoaded())
			{
				node.eachChild(function(n)
42e2e019   Benjamin Renard   Next step for cac...
54
					{
429f876c   Benjamin Renard   Fix plot request ...
55
						if (!n.isLoaded() && !n.isRealLeaf())
eec153c1   Elena.Budnik   formattage, netto...
56
57
58
59
60
						{
							nodesToLoad.push(n);
							me.preloadTreeNode(n,nodesToLoad,onloaded);
						}
					});
42e2e019   Benjamin Renard   Next step for cac...
61

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

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

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

eec153c1   Elena.Budnik   formattage, netto...
88
89
	constructor : function(config)
	{
42e2e019   Benjamin Renard   Next step for cac...
90
91
		this.callParent(arguments);
		this.set('nodeType',this.self.nodeType);
74b77f58   Elena.Budnik   init remote branch
92
93
		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...
94
			// if id of this node have root category suffix
74b77f58   Elena.Budnik   init remote branch
95
96
97
98
			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...
99
			}
74b77f58   Elena.Budnik   init remote branch
100
		}
eec153c1   Elena.Budnik   formattage, netto...
101
	},
429f876c   Benjamin Renard   Fix plot request ...
102
103
104
105
106

	isRealLeaf: function()
	{
		return this.isLeaf();
	},
42e2e019   Benjamin Renard   Next step for cac...
107

eec153c1   Elena.Budnik   formattage, netto...
108
109
110
111
112
113
114
/**
* this method is overriden into ExecutableNode to return true
*/
	isExecutable: function()
	{
		return false;
	},
16035364   Benjamin Renard   First commit
115

eec153c1   Elena.Budnik   formattage, netto...
116
117
118
/**
* open Module with THIS NODE
*/
42e2e019   Benjamin Renard   Next step for cac...
119
	editInModule : function (contextNode, onReady)
eec153c1   Elena.Budnik   formattage, netto...
120
121
122
123
124
125
126
	{
		// 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...
127
			if (module.getLinkedNode() != me)
eec153c1   Elena.Budnik   formattage, netto...
128
129
			{
				// set relative node into parameter Module
42e2e019   Benjamin Renard   Next step for cac...
130
131
				module.setLinkedNode(me);
				if (contextNode==null)
eec153c1   Elena.Budnik   formattage, netto...
132
133
134
				{
					// set the root node as contextNode
					contextNode = me.getRootNode();
42e2e019   Benjamin Renard   Next step for cac...
135
136
137
				}
				module.setContextNode(contextNode);

f6206fd6   Elena.Budnik   rm 6522 First Der...
138
			} else if (module.getLinkedNode() != null){
eec153c1   Elena.Budnik   formattage, netto...
139
140
141
142
143
			//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...
144
145
146
			// Opening parameter window
			module.createWindow(onReady);
		});
eec153c1   Elena.Budnik   formattage, netto...
147
	},
16035364   Benjamin Renard   First commit
148

eec153c1   Elena.Budnik   formattage, netto...
149
150
151
/**
* Method to rename the workspace node
*/
42e2e019   Benjamin Renard   Next step for cac...
152
153
	rename: function(value,callBackFn)
	{
429f876c   Benjamin Renard   Fix plot request ...
154
		var dataToSend = {id : this.get('id'), old_name: this.modified.text, name: value,  parent : this.data.parentId, leaf: this.isRealLeaf(), nodeType: this.get('nodeType')};
42e2e019   Benjamin Renard   Next step for cac...
155
		AmdaAction.renameObject(dataToSend, callBackFn);
eec153c1   Elena.Budnik   formattage, netto...
156
	},
42e2e019   Benjamin Renard   Next step for cac...
157

eec153c1   Elena.Budnik   formattage, netto...
158
159
160
/**
* Method to rename the workspace node when D&D
*/
42e2e019   Benjamin Renard   Next step for cac...
161
162
	renameDD: function(parentId, callBackFn)
	{
429f876c   Benjamin Renard   Fix plot request ...
163
		var dataToSend = {id : this.get('id'), old_name: this.get('name'), name: this.get('name'), parent : parentId, leaf: this.isRealLeaf(), nodeType: this.get('nodeType')};
eec153c1   Elena.Budnik   formattage, netto...
164
165
		AmdaAction.renameObject(dataToSend, callBackFn);
	},
42e2e019   Benjamin Renard   Next step for cac...
166

eec153c1   Elena.Budnik   formattage, netto...
167
168
169
/**
* validation method on name (used in module forms)
* @param name the name to validate
42e2e019   Benjamin Renard   Next step for cac...
170
* @returns
eec153c1   Elena.Budnik   formattage, netto...
171
172
173
*/
	isValidName : function(name, callBackFn)
	{
429f876c   Benjamin Renard   Fix plot request ...
174
		var dataToSend = {name: name, nodeType: this.get('nodeType'), leaf: this.isRealLeaf()};
65ac4a9d   Nathanaël Jourdane   Fix folders debug...
175
		AmdaAction.validNameObject(dataToSend, callBackFn);
eec153c1   Elena.Budnik   formattage, netto...
176
	},
16035364   Benjamin Renard   First commit
177

eec153c1   Elena.Budnik   formattage, netto...
178
179
180
181
182
/**
* 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...
183
	{
eec153c1   Elena.Budnik   formattage, netto...
184
		AmdaAction.modifyObject(this.get('object').getJsonValues(true), function(res,e){
42e2e019   Benjamin Renard   Next step for cac...
185

eec153c1   Elena.Budnik   formattage, netto...
186
			if(e.status) {
42e2e019   Benjamin Renard   Next step for cac...
187
				if (res.id) {
eec153c1   Elena.Budnik   formattage, netto...
188
189
190
191
192
193
					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...
194

eec153c1   Elena.Budnik   formattage, netto...
195
196
					if (opt)
					{
5b64c444   Hacene SI HADJ MOHAND   rm-6903 corrected
197

eec153c1   Elena.Budnik   formattage, netto...
198
199
200
						var scope = opt.scope ? opt.scope : this;
						if (opt.callback)
							opt.callback.call(scope,'update');
42e2e019   Benjamin Renard   Next step for cac...
201
202
203
204
205
206
207
              if(opt.notDisplayMsg){
                   //do nothing
              }else{
                  Ext.Msg.alert('Complete', 'Object '+this.get('object').get('name')+' has been modified');
              }

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

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

eec153c1   Elena.Budnik   formattage, netto...
212
213
					if (res.info) {
						this.set('info',res.info);
eec153c1   Elena.Budnik   formattage, netto...
214
					}
42e2e019   Benjamin Renard   Next step for cac...
215

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

eec153c1   Elena.Budnik   formattage, netto...
219
220
221
222
223
224
225
226
					// reload object into the view of corresponding Module
					var me = this;
					myDesktopApp.getLoadedModule(this.get('moduleId'), true, function (module) {
						module.getUiContent().setObject(me.get('object'));
					});
				}
				else {
					//TODO proper error message handling
42e2e019   Benjamin Renard   Next step for cac...
227
					// error code from server; but e.status==true
eec153c1   Elena.Budnik   formattage, netto...
228
229
230
231
232
233
234
235
					// 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...
236
				myDesktopApp.errorMsg(e.message);
eec153c1   Elena.Budnik   formattage, netto...
237
238
239
			}
		},this);
	},
16035364   Benjamin Renard   First commit
240

eec153c1   Elena.Budnik   formattage, netto...
241
242
243
244
/**
* 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...
245
	create : function(opt)
eec153c1   Elena.Budnik   formattage, netto...
246
247
248
249
	{
		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...
250
251
252
		}
		// 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...
253
			//success
42e2e019   Benjamin Renard   Next step for cac...
254
255
			if(e.status)
			{
eec153c1   Elena.Budnik   formattage, netto...
256
257
258
				// 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...
259
					if (this.toRename)
eec153c1   Elena.Budnik   formattage, netto...
260
					{
42e2e019   Benjamin Renard   Next step for cac...
261
						this.toRename	= false;
eec153c1   Elena.Budnik   formattage, netto...
262
263
264
265
266
						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...
267
268
						updateNode.destroy();
					}
eec153c1   Elena.Budnik   formattage, netto...
269
270
					// set text of this node
					this.set('text',this.get('object').get('name'));
f6206fd6   Elena.Budnik   rm 6522 First Der...
271

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

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

eec153c1   Elena.Budnik   formattage, netto...
283
284
285
					if (res.info){
						// set the tooltip
						this.set('info',res.info);
75a3182b   Elena.Budnik   special MyDataPar...
286
287
288
					}
					//set globalStart & global Stop to be used for time selection
					this.specialUpdate(res, true);
42e2e019   Benjamin Renard   Next step for cac...
289

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

eec153c1   Elena.Budnik   formattage, netto...
294
					// if ownerTree panel is not active
663f6395   Elena.Budnik   nettoyage
295
					if (this.myGetOwnerTree().ownerCt.getActiveTab()!==this.myGetOwnerTree()) {
eec153c1   Elena.Budnik   formattage, netto...
296
						// 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...
297
						this.myGetOwnerTree().ownerCt.setActiveTab(this.myGetOwnerTree());
eec153c1   Elena.Budnik   formattage, netto...
298
					}
5b64c444   Hacene SI HADJ MOHAND   rm-6903 corrected
299
300
                                                                                                    if(opt.notDisplayMsg){
                                                                                                        //do nothing
42e2e019   Benjamin Renard   Next step for cac...
301
302
                                                                                                        }else{
                                                                                                                       Ext.Msg.alert('Complete', 'New object '+this.get('object').get('name')+' has been created');
5b64c444   Hacene SI HADJ MOHAND   rm-6903 corrected
303
                                                                                                            }
42e2e019   Benjamin Renard   Next step for cac...
304

eec153c1   Elena.Budnik   formattage, netto...
305
					// expand the contextNode
663f6395   Elena.Budnik   nettoyage
306
					this.get('contextNode').expand(false, function() {
eec153c1   Elena.Budnik   formattage, netto...
307
						if (!this.get('contextNode').findChild('text',this.get('text'))) {
42e2e019   Benjamin Renard   Next step for cac...
308
309
							// create node in tree as child of contextNode
							this.get('contextNode').appendChild(this);
eec153c1   Elena.Budnik   formattage, netto...
310
						}
42e2e019   Benjamin Renard   Next step for cac...
311
						// select the new node
eec153c1   Elena.Budnik   formattage, netto...
312
						this.myGetOwnerTree().getSelectionModel().select(this);
663f6395   Elena.Budnik   nettoyage
313
						if (opt) {
eec153c1   Elena.Budnik   formattage, netto...
314
315
316
							var scope = opt.scope ? opt.scope : this;
							if (opt.callback)
									opt.callback.call(scope,'create');
42e2e019   Benjamin Renard   Next step for cac...
317
						}
eec153c1   Elena.Budnik   formattage, netto...
318
					}, this);
42e2e019   Benjamin Renard   Next step for cac...
319
				}
eec153c1   Elena.Budnik   formattage, netto...
320
321
				// error code from server; but e.status==true
				else {
42e2e019   Benjamin Renard   Next step for cac...
322
					myDesktopApp.errorMsg(res.error);
eec153c1   Elena.Budnik   formattage, netto...
323
324
325
326
327
328
329
330
331
332
333
					// 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...
334
		},this);
eec153c1   Elena.Budnik   formattage, netto...
335
	},
16035364   Benjamin Renard   First commit
336

75a3182b   Elena.Budnik   special MyDataPar...
337
	specialUpdate : function() {},
eec153c1   Elena.Budnik   formattage, netto...
338
339
/**
* Generic part of Context Menu
42e2e019   Benjamin Renard   Next step for cac...
340
341
*
*/
eec153c1   Elena.Budnik   formattage, netto...
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
	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
375

eec153c1   Elena.Budnik   formattage, netto...
376
377
378
379
380
381
382
383
384
	allMenuMultiItems : function() {
		var menuMulti = [
		{
			fnId : 'mult-deleteMulti',
			text : 'Delete selected ' + this.self.objectName + 's'
		}
		];
		return menuMulti;
	},
d18b535d   elena   catalog draft + c...
385

42e2e019   Benjamin Renard   Next step for cac...
386
387
	getAllContextMenuItems: function(){
		return  this.allMenuItems();
eec153c1   Elena.Budnik   formattage, netto...
388
389
390
391
392
	},

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

eec153c1   Elena.Budnik   formattage, netto...
394
395
396
397
398
399
400
/**
* default implementation
* no menu display if there's no override of this function
*/
	getMultiContextMenuItems: function(){
		return null;
	},
42e2e019   Benjamin Renard   Next step for cac...
401

eec153c1   Elena.Budnik   formattage, netto...
402
403
/**
*  Context Menu Actions
42e2e019   Benjamin Renard   Next step for cac...
404
405
*
*/
eec153c1   Elena.Budnik   formattage, netto...
406
407
408
	onMenuItemClick : function(menu,item,event) {
		// fnId parsing :
		var fnId = Ext.util.Format.substr(item.fnId, 5, item.fnId.length);
16035364   Benjamin Renard   First commit
409

eec153c1   Elena.Budnik   formattage, netto...
410
411
		switch (fnId) {
			case 'deleteNode':
42e2e019   Benjamin Renard   Next step for cac...
412
				this.deleteNode();
eec153c1   Elena.Budnik   formattage, netto...
413
414
				break;
			case 'createDir':
42e2e019   Benjamin Renard   Next step for cac...
415
				this.createDir();
eec153c1   Elena.Budnik   formattage, netto...
416
417
418
				break;
			case 'createLeaf':
				this.createLeaf(this);
42e2e019   Benjamin Renard   Next step for cac...
419
				break;
eec153c1   Elena.Budnik   formattage, netto...
420
			case 'renameNode':
11d21073   Nathanaël Jourdane   Fix bugs when cre...
421
				this.renameNode(false);
eec153c1   Elena.Budnik   formattage, netto...
422
				break;
42e2e019   Benjamin Renard   Next step for cac...
423
424
425
			case 'editLeaf':
				this.editLeaf();
				break;
eec153c1   Elena.Budnik   formattage, netto...
426
427
			case 'deleteMulti':
				this.deleteMulti();
eec153c1   Elena.Budnik   formattage, netto...
428
				break;
42e2e019   Benjamin Renard   Next step for cac...
429
430
431
432
433
434
			case 'plotParam':
				this.createPlot(this);
				break;
			case 'downParam':
				this.createDownload(this);
				break;
eec153c1   Elena.Budnik   formattage, netto...
435
436
437
438
			default:
				break;
		} // switch end
	},
42e2e019   Benjamin Renard   Next step for cac...
439

eec153c1   Elena.Budnik   formattage, netto...
440
	getTimeFromNode: function(node)  {
eec153c1   Elena.Budnik   formattage, netto...
441
442
		var startString = new String(node.get('globalStart'));
		var stopString = new String(node.get('globalStop'));
a0f13ed1   Elena.Budnik   small format + ti...
443

42e2e019   Benjamin Renard   Next step for cac...
444
		var startDate =  new Date(startString.replace(/\-/g,'\/').replace(/[T|Z]/g,' '));
eec153c1   Elena.Budnik   formattage, netto...
445
		var stopDate =  new Date(stopString.replace(/\-/g,'\/').replace(/[T|Z]/g,' '));
a0f13ed1   Elena.Budnik   small format + ti...
446

eec153c1   Elena.Budnik   formattage, netto...
447
		if (stopDate -  startDate  > 86400000 ) {
42e2e019   Benjamin Renard   Next step for cac...
448
			var startTime = Ext.Date.add(stopDate, Ext.Date.DAY, -1);
a0f13ed1   Elena.Budnik   small format + ti...
449
450
			// var timeObj = {start: Ext.Date.format(startTime, 'Y/m/d H:i:s'), stop: Ext.Date.format(stopDate, 'Y/m/d H:i:s')};
			var timeObj = {start: Ext.Date.format(startTime, 'Y/m/d'), stop: Ext.Date.format(stopDate, 'Y/m/d')};
42e2e019   Benjamin Renard   Next step for cac...
451
		}
eec153c1   Elena.Budnik   formattage, netto...
452
453
454
		else {
			var timeObj = {start:  node.get('globalStart'), stop:  node.get('globalStop')};
		}
42e2e019   Benjamin Renard   Next step for cac...
455
		return timeObj;
eec153c1   Elena.Budnik   formattage, netto...
456
	},
16035364   Benjamin Renard   First commit
457

42e2e019   Benjamin Renard   Next step for cac...
458
459
460
	createPlot: function(node)
	{
		if (node.get('disable')) return;
eec153c1   Elena.Budnik   formattage, netto...
461
		myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id, true, function (module) {
42e2e019   Benjamin Renard   Next step for cac...
462
			if (!myDesktopApp.desktop.getWindow(myDesktopApp.dynamicModules.plot.id)) {
eec153c1   Elena.Budnik   formattage, netto...
463
				var request = Ext.create(amdaPlotObj.PlotRequestObject.$className);
42e2e019   Benjamin Renard   Next step for cac...
464
				var newNode = Ext.create(amdaModel.PlotNode.$className, { object : request });
eec153c1   Elena.Budnik   formattage, netto...
465
466
				// edit newNode into Plot Module with node as contextNode
				newNode.editInModule();
42e2e019   Benjamin Renard   Next step for cac...
467
468
				if((node.get('globalStart') != null) && (node.get('globalStop') != null) && node.get('globalStart') != 'depending on mission' && node.get('isParameter')) {
					module.getUiContent().setTimeFromData(node.getTimeFromNode(node));
eec153c1   Elena.Budnik   formattage, netto...
469
				}
42e2e019   Benjamin Renard   Next step for cac...
470
471
			}
			module.getUiContent().addParameter(node);
eec153c1   Elena.Budnik   formattage, netto...
472
473
		});
	},
42e2e019   Benjamin Renard   Next step for cac...
474
475
476

	createDownload: function(node)
	{
eec153c1   Elena.Budnik   formattage, netto...
477
		myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.download.id, true, function (module) {
42e2e019   Benjamin Renard   Next step for cac...
478
			if (!myDesktopApp.desktop.getWindow(myDesktopApp.dynamicModules.download.id)) {
eec153c1   Elena.Budnik   formattage, netto...
479
				var request = Ext.create(amdaModel.Download.$className);
42e2e019   Benjamin Renard   Next step for cac...
480
				amdaModel.DownloadNode.set('object',request);
eec153c1   Elena.Budnik   formattage, netto...
481
482
				// singleton!
				amdaModel.DownloadNode.editInModule();
a0f13ed1   Elena.Budnik   small format + ti...
483
				if ((node.get('globalStart') != null) && (node.get('globalStop') != null) && node.get('globalStart') != 'depending on mission' &&  node.get('isParameter')) {
42e2e019   Benjamin Renard   Next step for cac...
484
					module.getUiContent().setTimeFromData(node.getTimeFromNode(node));
eec153c1   Elena.Budnik   formattage, netto...
485
				}
42e2e019   Benjamin Renard   Next step for cac...
486
487
			}
				var paramName;
eec153c1   Elena.Budnik   formattage, netto...
488
489
				var components = null;
				switch (node.$className) {
42e2e019   Benjamin Renard   Next step for cac...
490
					case 'amdaModel.AliasNode'        :
eec153c1   Elena.Budnik   formattage, netto...
491
492
						paramName = "#"+node.get('text');
						break;
42e2e019   Benjamin Renard   Next step for cac...
493
                                                                                                    case 'amdaModel.DerivedParamComponentNode' :
f85f44e4   Benjamin Renard   us okkkkkkkkkk
494
495
496
497
498
499
500
501
502
503
504
                                                                                                    paramId = node.get('text');
                                                                                                    var parentId = paramId.substr(0, paramId.length - 3);
                                                                                                    paramName= "ws_" + parentId;
                                                                                                    var regExp = /\(([\d]+)\)/;
                                                                                                     var component_index = regExp.exec(paramId);
                                                                                                      if (component_index)
                                                                                                      {
                                                                                                        components = [];
                                                                                                        components['index1'] = component_index[1];
                                                                                                        }
                                                                                                    break;
42e2e019   Benjamin Renard   Next step for cac...
505
					case 'amdaModel.DerivedParamNode' :
eec153c1   Elena.Budnik   formattage, netto...
506
507
508
						paramName = "ws_"+node.get('text');
						break;
					case 'amdaModel.MyDataParamNode' :
42e2e019   Benjamin Renard   Next step for cac...
509
510
511
						paramName = 'wsd_'+node.get('text');
						break;
					default :
eec153c1   Elena.Budnik   formattage, netto...
512
513
						if (node.get('alias')!= "" )
							paramName = "#"+node.get('alias');
42e2e019   Benjamin Renard   Next step for cac...
514
						else
eec153c1   Elena.Budnik   formattage, netto...
515
							paramName = node.get('id');
42e2e019   Benjamin Renard   Next step for cac...
516
				}
f21cd402   Benjamin Renard   Fix components se...
517
518
519
520
521
522
523
524
525
 				var component_info = node.get('component_info');
 				if (component_info && component_info.parentId) {
 					//It's a component
 					paramName = component_info.parentId;
 					components = [];
 					if (component_info.index1)
 						components['index1'] = component_info.index1;
 					if (component_info.index2)
 						components['index2'] = component_info.index2;
42e2e019   Benjamin Renard   Next step for cac...
526
527
528
 				}
				module.addParam(paramName,true,node.get('needsArgs'),components);
		});
eec153c1   Elena.Budnik   formattage, netto...
529
	},
42e2e019   Benjamin Renard   Next step for cac...
530
531

	deleteNode: function() {
eec153c1   Elena.Budnik   formattage, netto...
532
			// if the target is a directory
429f876c   Benjamin Renard   Fix plot request ...
533
			if (!this.isRealLeaf()) {
eec153c1   Elena.Budnik   formattage, netto...
534
				// determine if this directory is empty before launching the delete confirmation method
42e2e019   Benjamin Renard   Next step for cac...
535
				this.isNotEmptyDir(this.confirmDirectoryDeletion);
eec153c1   Elena.Budnik   formattage, netto...
536
537
538
539
540
541
			// else (the target is a leaf)
			} else {
				// no confirmation prompt for leaves
				this.confirmDirectoryDeletion(false);
			}
	},
42e2e019   Benjamin Renard   Next step for cac...
542

eec153c1   Elena.Budnik   formattage, netto...
543
544
545
546
547
548
549
/**
* 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...
550
			// call directFunction to load this node
eec153c1   Elena.Budnik   formattage, netto...
551
552
553
			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...
554
		}
eec153c1   Elena.Budnik   formattage, netto...
555
556
557
558
		else {
			callbackFn.call(this,this.hasChildNodes());
		}
	},
42e2e019   Benjamin Renard   Next step for cac...
559

eec153c1   Elena.Budnik   formattage, netto...
560
561
562
563
/**
* this method is used to display a confirmation message
*/
	confirmDirectoryDeletion : function(isNotEmptyDir)
42e2e019   Benjamin Renard   Next step for cac...
564
	{
eec153c1   Elena.Budnik   formattage, netto...
565
566
567
568
569
570
571
572
573
		// 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...
574
		}
eec153c1   Elena.Budnik   formattage, netto...
575
576
		else {
			this.realDelete();
42e2e019   Benjamin Renard   Next step for cac...
577
		}
eec153c1   Elena.Budnik   formattage, netto...
578
	},
42e2e019   Benjamin Renard   Next step for cac...
579

eec153c1   Elena.Budnik   formattage, netto...
580
581
/*
*    Call the extDirect method to delete parameter
42e2e019   Benjamin Renard   Next step for cac...
582
*    Callback method needed to execute node deletion in tree if id in result or to show error msg
eec153c1   Elena.Budnik   formattage, netto...
583
584
*/
	realDelete : function()
42e2e019   Benjamin Renard   Next step for cac...
585
586
587
588
	{
		AmdaAction.deleteObject({id: this.get('id'), leaf: this.isRealLeaf(), nodeType: this.get('nodeType')}, function(res,e){
			//TODO proper errors handling
			// node deletion in tree
eec153c1   Elena.Budnik   formattage, netto...
589
590
591
592
			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) {
429f876c   Benjamin Renard   Fix plot request ...
593
						if (this.isRealLeaf()){
eec153c1   Elena.Budnik   formattage, netto...
594
							var moduleId = this.get('moduleId');
42e2e019   Benjamin Renard   Next step for cac...
595
							// if really interactive node
eec153c1   Elena.Budnik   formattage, netto...
596
							if (moduleId) {
3e9f7a84   Elena.Budnik   check if window i...
597
598
599
600
601
602
								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...
603
604

										// file node is not linked directly to the module
3e9f7a84   Elena.Budnik   check if window i...
605
										var isThisFile = false;
42e2e019   Benjamin Renard   Next step for cac...
606
										if (editedNode && editedNode.$className == 'amdaModel.MyDataParamNode')
3e9f7a84   Elena.Budnik   check if window i...
607
											if (editedNode.get('fileObject').get('fileName') == me.get('text'))
42e2e019   Benjamin Renard   Next step for cac...
608
609
610
												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...
611
612
613
614
										if ( editedNode && editedNode.get('id') == me.get('id') && editedNode !== me ) {
											module.setLinkedNode(me);
											isThisFile = true;
										}
42e2e019   Benjamin Renard   Next step for cac...
615

3e9f7a84   Elena.Budnik   check if window i...
616
617
618
619
620
621
										if (me.$className == 'amdaModel.DerivedParamNode') {
											var obj = {
												paramId : 'ws_'+me.get('text')
											};
											AmdaAction.compilParamDelete(obj);
										}
42e2e019   Benjamin Renard   Next step for cac...
622
623

										if (editedNode === me || isThisFile ){
3e9f7a84   Elena.Budnik   check if window i...
624
625
626
627
											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...
628

3e9f7a84   Elena.Budnik   check if window i...
629
												if (linkedNodes) {
42e2e019   Benjamin Renard   Next step for cac...
630
631
													linkedNodes.each(function(key, value){
														if (value === me) {
3e9f7a84   Elena.Budnik   check if window i...
632
633
															linkedNodes.replace(key,newNode);
															var tabPanel = module.getUiContent().tabPanel.items.getByKey(key);
42e2e019   Benjamin Renard   Next step for cac...
634
635
															tabPanel.setObject(Ext.create(amdaModel.Plot.$className, {}));
														}
3e9f7a84   Elena.Budnik   check if window i...
636
													}, me);
42e2e019   Benjamin Renard   Next step for cac...
637
638
												}
											}
3e9f7a84   Elena.Budnik   check if window i...
639
640
											newNode.editInModule();
										}
42e2e019   Benjamin Renard   Next step for cac...
641
									});
eec153c1   Elena.Budnik   formattage, netto...
642
								}
eec153c1   Elena.Budnik   formattage, netto...
643
							}
42e2e019   Benjamin Renard   Next step for cac...
644
645
						}
						//update mask info in myData
eec153c1   Elena.Budnik   formattage, netto...
646
647
648
						if (res.maskDesc && !res.maskDeleted) {
							this.parentNode.set('info', res.maskDesc);
							this.updateMyDataParam(res.mask, res.maskDesc);
42e2e019   Benjamin Renard   Next step for cac...
649
650
						}
						this.remove();
eec153c1   Elena.Budnik   formattage, netto...
651
					}
42e2e019   Benjamin Renard   Next step for cac...
652
653
					//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...
654
655
656
					if (res.params) {
						this.deleteDependence(res.params);
						//TODO reset
42e2e019   Benjamin Renard   Next step for cac...
657
658
					}
					// mask was deleted or updated - to update mydata tree
eec153c1   Elena.Budnik   formattage, netto...
659
					if (res.maskDeleted) {
42e2e019   Benjamin Renard   Next step for cac...
660
661
						this.updateMyData();
					}
eec153c1   Elena.Budnik   formattage, netto...
662
663
				}
				else {
42e2e019   Benjamin Renard   Next step for cac...
664
					myDesktopApp.warningMsg(res.error);
eec153c1   Elena.Budnik   formattage, netto...
665
666
667
				}
			}
			else {
42e2e019   Benjamin Renard   Next step for cac...
668
				myDesktopApp.errorMsg(e.message);
eec153c1   Elena.Budnik   formattage, netto...
669
670
671
			}
		}, this);
	},
16035364   Benjamin Renard   First commit
672

eec153c1   Elena.Budnik   formattage, netto...
673
674
675
676
677
678
679
680
681
682
683
/*
*  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...
684

eec153c1   Elena.Budnik   formattage, netto...
685
686
687
688
/*
*  Create Folder
*/
	createDir: function() {
eec153c1   Elena.Budnik   formattage, netto...
689
690
691
692
693
694
		var me = this;
		amdaModel.InteractiveNode.preloadNodes(this.getRootNode(),
			function()
			{
				var newNode = Ext.create(me.$className,
				{
82560cb2   Nathanaël Jourdane   fix folders (wip)
695
696
					leaf : false, nodeType : me.get('nodeType'),
					text : amdaModel.AmdaNode.NEW_DIR_NAME,
11d21073   Nathanaël Jourdane   Fix bugs when cre...
697
698
					children : [],
          parentId: me.get('id')
eec153c1   Elena.Budnik   formattage, netto...
699
				});
16035364   Benjamin Renard   First commit
700

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

eec153c1   Elena.Budnik   formattage, netto...
707
708
709
				// 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...
710
				newNode.renameNode(true);
eec153c1   Elena.Budnik   formattage, netto...
711
712
			});
	},
42e2e019   Benjamin Renard   Next step for cac...
713

eec153c1   Elena.Budnik   formattage, netto...
714
/*
42e2e019   Benjamin Renard   Next step for cac...
715
*
eec153c1   Elena.Budnik   formattage, netto...
716
717
718
719
*/
	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
720

eec153c1   Elena.Budnik   formattage, netto...
721
722
723
724
725
726
727
728
		// 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
729

11d21073   Nathanaël Jourdane   Fix bugs when cre...
730
	renameNode: function(deleteOnFailure)
65ac4a9d   Nathanaël Jourdane   Fix folders debug...
731
	{
eec153c1   Elena.Budnik   formattage, netto...
732
		if (this.myGetOwnerTree())
42e2e019   Benjamin Renard   Next step for cac...
733
		{
eec153c1   Elena.Budnik   formattage, netto...
734
735
736
737
738
739
			// 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...
740
741
742
743
					var item = me.myGetOwnerTree().getSelectionModel().selected.items[0];
					item.deleteOnFailure = deleteOnFailure;
					me.myGetOwnerTree().fireEvent('edition', me.myGetOwnerTree().view, item);
				});
eec153c1   Elena.Budnik   formattage, netto...
744
745
746
747
748
749
		}
		else
		{
			myDesktopApp.errorMsg('tree is undefined');
		}
	},
16035364   Benjamin Renard   First commit
750

eec153c1   Elena.Budnik   formattage, netto...
751
752
753
754
/*
*       load the rootNode and recursively all its child nodes
*       to know all names of DerivedParameters
*/
42e2e019   Benjamin Renard   Next step for cac...
755
756
	editLeaf: function(onReady)
	{
eec153c1   Elena.Budnik   formattage, netto...
757
758
759
760
		var me = this;
		amdaModel.InteractiveNode.preloadNodes(this.getRootNode(),
		function()
		{
42e2e019   Benjamin Renard   Next step for cac...
761
			if (me.get('object'))
eec153c1   Elena.Budnik   formattage, netto...
762
763
764
765
766
			{
				// launch edition of parameter into parameter module
				me.editInModule(null, onReady);
			}
			else
42e2e019   Benjamin Renard   Next step for cac...
767
			{
eec153c1   Elena.Budnik   formattage, netto...
768
				// call the ext method to get the details of parameter
42e2e019   Benjamin Renard   Next step for cac...
769
770
				// the edition of real parameter is done into callback method getObjectCallback
				if (onReady)
0c154100   Elena.Budnik   redmine #5141 part.2
771
					me.onReady = onReady;
42e2e019   Benjamin Renard   Next step for cac...
772

eec153c1   Elena.Budnik   formattage, netto...
773
774
				AmdaAction.getObject(me.get('id'), me.get('nodeType'), me.getObjectCallback, me);
			}
42e2e019   Benjamin Renard   Next step for cac...
775
		});
eec153c1   Elena.Budnik   formattage, netto...
776
	},
16035364   Benjamin Renard   First commit
777

eec153c1   Elena.Budnik   formattage, netto...
778
/*
42e2e019   Benjamin Renard   Next step for cac...
779
*
eec153c1   Elena.Budnik   formattage, netto...
780
781
782
783
*/
	getObjectCallback : function(result,remoteEvent)
	{
		var t = remoteEvent.getTransaction();
42e2e019   Benjamin Renard   Next step for cac...
784
785

		if (result) {
eec153c1   Elena.Budnik   formattage, netto...
786
787
788
			var paramObj = Ext.create(this.get('objectDataModel'), result);
			// set parameter into node
			this.set('object',paramObj);
42e2e019   Benjamin Renard   Next step for cac...
789
			// Edition of parameter into parameter Module
0c154100   Elena.Budnik   redmine #5141 part.2
790
			this.editInModule(null, this.onReady);
8b11b1af   Benjamin Renard   Insert intervals ...
791
			this.onReady = null;
42e2e019   Benjamin Renard   Next step for cac...
792
		}
eec153c1   Elena.Budnik   formattage, netto...
793
794
795
		else {
		// EXCEPTION : parameter not found !?
			myDesktopApp.errorMsg(t.action + "." + t.method + " : No parameter '"
42e2e019   Benjamin Renard   Next step for cac...
796
			+ this.get('name') + "' found!");
eec153c1   Elena.Budnik   formattage, netto...
797
		}
42e2e019   Benjamin Renard   Next step for cac...
798
	}
16035364   Benjamin Renard   First commit
799
});