Blame view

js/app/controllers/InteractiveModule.js 7.46 KB
16035364   Benjamin Renard   First commit
1
2
3
4
5
6
7
/** 
 * Project  : AMDA-NG4
 * Name     : InteractiveModule.js
 * @class   amdaDesktop.InteractiveModule 
 * @extends amdaDesktop.AmdaModule
 * @brief   Generic Interactive Module controller definition
 * @author  CDA
f9c8b272   elena   edit catalog
8
 * @version $Id: InteractiveModule.js 2109 2014-02-19 17:47:37Z elena $ 
16035364   Benjamin Renard   First commit
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 */

Ext.define('amdaDesktop.InteractiveModule', {
	extend: 'amdaDesktop.AmdaModule',	 
	
    /**
     * @cfg {amdaModel.InteractiveNode} the explorer node linked to this module
     */
	linkedNode : null,

	nodeDataModel: ' ',

	width : 700,
	height: 510,
 	uiType : ' ',
//	helpTitle : 'help on the module',
	/**
	 * Module link in Start Menu
	 */	
	init : function() {		 
		this.launcher = {
		    text : this.title,
		    iconCls : this.icon,
		    handler : this.createWindow,
		    scope : this
		};
	},
	
	/**
	 * Window Creation method of the Module
	 */
2048f5bc   Benjamin Renard   Fix save & edit plot
40
	createWindow : function (onShowEvent, onAfterCreateObject) {
16035364   Benjamin Renard   First commit
41
42
43
44

		if (this.linkedNode === null){		 
			this.createLinkedNode();		
		} 		
2048f5bc   Benjamin Renard   Fix save & edit plot
45
46
47
48
		this.createObject();
                if (onAfterCreateObject) {
                    onAfterCreateObject();
                }
16035364   Benjamin Renard   First commit
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
		var desktop = this.app.getDesktop();		
		var win = desktop.getWindow(this.id);	
		var me = this;

		if (!win) {
			win = desktop.createWindow({
				id : this.id,
				title : this.title,
				width : this.width,
				minWidth : this.width,
				height : this.height,
				minHeight: this.height,
				iconCls : this.icon,
				border : false,
				//constrainHeader : true,
				layout : 'fit',
				stateful : true,
				stateId : this.id,
				stateEvents: ['move','show','resize'],
				tools: [
			         {
			        	type:'help',
			        	qtip: this.helpTitle,
			        	scope:this,
			        	handler: function(event, toolEl, panel){					  
			        	 myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.info.id, true, function(module) {
			        		module.createWindow(me.helpFile, me.helpTitle); 
			        	 });					  
			        	}
			         }
				],
				items : [ 
				 {
f9c8b272   elena   edit catalog
82
83
84
					xtype :  this.uiType,
					object : this.linkedNode.get('object'),
					id : this.contentId
16035364   Benjamin Renard   First commit
85
86
87
88
89
90
				  }	
				]
			});
			
			this.closed = false;
			win.on({
f9c8b272   elena   edit catalog
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
				scope: this,
				// on window activation event
				activate: function(){
					// order to pin this Module with WsExplorer
					this.pin();
				},
				// on window closing event
				beforeclose: function (win, eOpts) {
					
					this.saveState();
					
					var isDirty = this.getUiContent().fclose();
					
					if (!this.closed && isDirty) {
					Ext.Msg.confirm('Close', 'Current window has been modified.\nDo you want to close the window ?' , function (btn, text){  
						if (btn == 'yes'){ 
						// mark this.closed as true before the call to close() as that will fire the beforeclose event again
						this.closed = true; 
						win.close();
						} 
16035364   Benjamin Renard   First commit
111
                                        },this); 
f9c8b272   elena   edit catalog
112
113
114
					} else if (!isDirty) {
						this.closed = true;
					}
16035364   Benjamin Renard   First commit
115
									
f9c8b272   elena   edit catalog
116
117
118
119
120
121
122
123
					if (this.closed) {
						//remove object from linkedNode in order to minimize used memory
						this.linkedNode.set('object','');
						// unlink Node
						this.setLinkedNode(null);
							// order to unpin this Module from WsExplorer
						this.unpin();
					}
16035364   Benjamin Renard   First commit
124
	 
f9c8b272   elena   edit catalog
125
126
127
128
				// Don't automatically close if the form is dirty, let the call to this.close() within the confirm box close the window.
				return this.closed;
				},	   
				minimize: function (win, eOpts) {
16035364   Benjamin Renard   First commit
129
130
					// Save form
					if (this.getUiContent().formPanel)
f9c8b272   elena   edit catalog
131
						this.getUiContent().formPanel.getForm().updateRecord(this.linkedNode.get('object'));
16035364   Benjamin Renard   First commit
132
					else 
f9c8b272   elena   edit catalog
133
						this.getUiContent().items.getAt(0).getForm().updateRecord(this.linkedNode.get('object'));
16035364   Benjamin Renard   First commit
134
135
					// Save grids
					this.getUiContent().updateObject();
f9c8b272   elena   edit catalog
136
137
				},
				show: function() {
f13f0bd4   Elena.Budnik   New Catalog creation
138
139
140
141
// 					// configuration of empty catalog
// 					if (this.isOperationOnShow)
// 						// Ext.Function.defer(this.operationOnShow, 2000, this);
// 						this.operationOnShow();
a73f0195   Benjamin Renard   Insert interval i...
142
143
					if (onShowEvent)
						onShowEvent();
fffed3e4   Benjamin Renard   use onShowEvent o...
144
					onShowEvent = null; // use onShowEvent only once after window creation (cf. #9510)
f9c8b272   elena   edit catalog
145
				}	 
16035364   Benjamin Renard   First commit
146
			});
16035364   Benjamin Renard   First commit
147
		} else {
f9c8b272   elena   edit catalog
148
149
			// second arg 'true' is used in CatalogUI to mark if Grid Reconfiguration is needed
			this.getUiContent().setObject(this.linkedNode.get('object'), true);
16035364   Benjamin Renard   First commit
150
		}
ebbb3638   Benjamin Renard   Edit plot tab on ...
151
152
153
154
155
156
157

		if (!win.isVisible()) {
			win.show();
		}
		else if (onShowEvent) {
			onShowEvent();
		}
16035364   Benjamin Renard   First commit
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
	},
	/**
	 * Mechanism to attach a Module to the Workspace Explorer to enable interactions
	 * @param moduleName the module to attach
	 */
	pin : function() {
		myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id).pinMechanism(this.id);
	},
	
	/**
	 * Mechanism to detach a Module to the Workspace Explorer to enable interactions
	 * @param moduleName the module to detach
	 */
	unpin : function() {
		myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id).setPinedModule(null);
	},
	
	/**
	 * Getter of linkedNode
	 * @return {amdaModel.InteractiveNode} linkedNode
	 */
	getLinkedNode : function (){
		return this.linkedNode;
	},
	
	/**
	 * link the current node in the current module
	 * @param {amdaModel.InteractiveNode} myLinkedNode
	 */
	setLinkedNode : function (myLinkedNode){
		if (this.linkedNode) {
			this.linkedNode.set('object','');
		}
		this.linkedNode = myLinkedNode;		
	},

	/**
	 * 
	 * create Node of Appropriate Type if it doesn't exist
	 */ 	
	createLinkedNode : function (){	
		var newNode = Ext.create(this.nodeDataModel, {
			leaf : true,
			contextNode : this.contextNode
		});
		this.setLinkedNode(newNode);		
	},

	/**
	 * 
	 *  
	*/ 
	createObject : function (obj){
	   
18d4a11e   Benjamin Renard   Save and load plo...
212
		var object;
16035364   Benjamin Renard   First commit
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
		if (this.linkedNode.get('object')){			 
		    object = this.linkedNode.get('object'); 		   
		} else  {
                
                    if (!obj) {
                         obj = this.getState();                        
                    }
                    
		    object = Ext.create(this.linkedNode.get('objectDataModel'), obj);
       
		    this.linkedNode.set('object',object);
		}
		 
	},

      /**
	* Setter of contextNode
	* @param {amdaModel.InteractiveNode} contextNode
	* the node from which the Module was called
	*/
	setContextNode : function (myContextNode){
		this.contextNode = myContextNode;
	},

    
	/**
	 * Color mechanism of Header of this intarctive module
	 */
	colorHeaderModule : function() {
		myDesktopApp.desktop.getWindow(this.id).getEl().addCls('window-active');
	},
	
	/**
	* UnColor mechanism of Header of this intarctive module
	*/
	uncolorHeaderModule : function() {
		myDesktopApp.desktop.getWindow(this.id).getEl().removeCls('window-active');
	},
	
	/**
	 * Receiption method of a parameter sent from explorer (by drop)
	 * @param {String} objectName The name of sent object
	 * @param {String} isLeaf boolean true if it's a leaf parameter
	 */
2fa56f95   Benjamin Renard   Predefined templa...
257
	 addParam : function(objectName, isLeaf, needsArgs, components, predefined_args) {
16035364   Benjamin Renard   First commit
258
	     var uiContent = this.getUiContent();
2fa56f95   Benjamin Renard   Predefined templa...
259
	     uiContent.addParam(objectName, isLeaf, needsArgs, components, predefined_args);
16035364   Benjamin Renard   First commit
260
	 },
2fa56f95   Benjamin Renard   Predefined templa...
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279

	parseTemplatedParam: function(templatedParamId, onParamParsed) {
		AmdaAction.parseTemplatedParam(templatedParamId, function(res,e) {
			if (!res || !res.success) {
				if (!res || !res.message) {
					myDesktopApp.errorMsg('Internal Error - Cannot parse the templated parameter');
				}
				else {
					myDesktopApp.errorMsg('Internal Error - ' + res.message);
				}
			}
			else {
				if (onParamParsed) {
					onParamParsed(res.info);
				}
			}
		});
	},

16035364   Benjamin Renard   First commit
280
281
282
283
284
285
286
          saveState : Ext.emptyFn,
           
          getState :  function() {
              
              return null;
          }
                       
ebbb3638   Benjamin Renard   Edit plot tab on ...
287
});