Blame view

js/app/controllers/InteropModule.js 8.36 KB
10200969   Roipoussiere   Remove whitespace...
1
/**
16035364   Benjamin Renard   First commit
2
3
4
 * Project   : AMDA-NG
 * Name      : InteropModule.js
 * @class    amdaDesktop.InteropModule
ce570000   Elena.Budnik   typo
5
 * @extends  amdaDesktop.AmdaModule
10200969   Roipoussiere   Remove whitespace...
6
 * @brief    Interop Module controller definition
16035364   Benjamin Renard   First commit
7
8
 * @author   Benjamin RENARD
 * $Id: InteropModule.js 1870 2013-11-22 13:43:34Z elena $
16035364   Benjamin Renard   First commit
9
10
11
12
13
 */


Ext.define('amdaDesktop.InteropModule', {
	extend: 'amdaDesktop.AmdaModule',
10200969   Roipoussiere   Remove whitespace...
14

16035364   Benjamin Renard   First commit
15
	requires: [
12be2344   Elena.Budnik   redmine #5507
16
17
		'amdaUI.InteropUI',
		'amdaDesktop.SampModule',
b034ce89   Nathanael Jourdane   Move EPN-TAP modu...
18
		'amdaDesktop.EpnTapModule'
12be2344   Elena.Budnik   redmine #5507
19
	],
10200969   Roipoussiere   Remove whitespace...
20

16035364   Benjamin Renard   First commit
21
	contentId : 'interopUI',
10200969   Roipoussiere   Remove whitespace...
22

12be2344   Elena.Budnik   redmine #5507
23
24
25
26
	/**
	* @cfg {String} window definitions
	* @required
	*/
fecd2848   Nathanael Jourdane   Fix panel/grid si...
27
28
	// height: 650,
	// width: 1050,
16035364   Benjamin Renard   First commit
29
30
	uiType :    'panelInterop',
	helpTitle :'Help on Interop Module',
598754b6   Nathanael Jourdane   Add the Interop h...
31
	helpFile: 'interopHelp.html',
10200969   Roipoussiere   Remove whitespace...
32

16035364   Benjamin Renard   First commit
33
	samp : null,
10200969   Roipoussiere   Remove whitespace...
34

16035364   Benjamin Renard   First commit
35
36
	sampclientsStore : new Ext.data.SimpleStore({
		idProperty: 'id',
12be2344   Elena.Budnik   redmine #5507
37
38
39
40
41
42
43
44
45
		fields: [
			{name: 'id'},
			{name: 'name'},
			{name: 'descriptionText'},
			{name: 'iconUrl'},
			{name: 'acceptVOTable', type : 'boolean'},
			{name: 'acceptFITS', type : 'boolean'}
		]
	}),
10200969   Roipoussiere   Remove whitespace...
46
47

	init : function() {
12be2344   Elena.Budnik   redmine #5507
48
49
50
51
52
		this.launcher = {
			text : this.title,
			iconCls : this.icon,
			handler : this.createWindow,
			scope : this
16035364   Benjamin Renard   First commit
53
		};
12be2344   Elena.Budnik   redmine #5507
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
	},

	initSampConnector : function(successfn){
		var me = this;
		
		if (!this.samp)
		{
			this.samp = Ext.create('amdaDesktop.SampModule',{
				listeners : {
					connected : function(o,success)
					{
						if (!success)
							Ext.Msg.show( {
								title : 'SAMP',
								msg : 'Cannot connect AMDA to a hub',
								modal : false,
								icon : Ext.Msg.ERROR,
								buttons : Ext.Msg.OK
							});
						me.updateStatus();
						me.updateClients();
					},
					disconnected : function(o,success)
					{
						me.updateStatus();
						me.sampclientsStore.removeAll();
						me.updateClients();
					},
					clientregister : function(o,id)
					{
						me.updateClients();
					},
					clientunregister : function(o,id)
					{
						var record = me.sampclientsStore.getById(id);
						if (record)
						{
							me.sampclientsStore.remove(record);
							me.updateClients();
						}
					},
					clientmetachange : function(o,id,data,subs)
					{
						var record = me.sampclientsStore.getById(id);

						if (!record){
							me.sampclientsStore.add({id : id});
							record = me.sampclientsStore.getById(id);
						}

						if (record){
							record.set('descriptionText',data['samp.description.text']);
							record.set('iconUrl',data['samp.icon.url']);
							record.set('name',data['samp.name']);
							
							if (subs){
								record.set('acceptVOTable',
										me.samp.isSubscribed(subs,"table.load.votable"));
								record.set('acceptFITS',
										me.samp.isSubscribed(subs,"image.load.fits"));
							}
						}

						me.updateClients();
					},
					clientsubs : function(o,id,data)
					{
						var record = me.sampclientsStore.getById(id);

						if (!record)
							return;

						if (record){
							record.set('acceptVOTable',
									me.samp.isSubscribed(data,"table.load.votable"));
							record.set('acceptFITS',
									me.samp.isSubscribed(data,"image.load.fits"));
						}

						me.updateClients();
					},
					uploadfile : function(o,clientName,url,format)
					{
						myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.upload.id, true, function (module) {
							module.uploadNotification(url,format);
						});
					}
				}
			});
			this.samp.loadScript(function (s){
				if (successfn)
					successfn.call(me.samp);
			});
		}
	else
		this.samp.loadScript(function (s){
			if (successfn)
				successfn.call(me.samp);
		});
	},

	updateStatus : function()
	{
		if (this.app && this.samp)
		{
			var desktop = this.app.getDesktop();

			var isConnected = this.samp.isConnected();

			if (desktop){
				var win = desktop.getWindow(this.id);
				if (win && win.isVisible)
					win.items.items[0].updateStatus(isConnected);

				var taskbar = desktop.taskbar;

				if (taskbar){
					var samptb = taskbar.getComponent('samptb');
					if (samptb)
						samptb.updateStatus(isConnected);
				}
			}
		}
	},

	updateClients : function()
	{
		if (this.app && this.samp)
		{
			var desktop = this.app.getDesktop();

			var isConnected = this.samp.isConnected();

			if (desktop)
			{
				var win = desktop.getWindow(this.id);

				var taskbar = desktop.taskbar;

				if (taskbar)
				{
					var samptb = taskbar.getComponent('samptb');
					if (samptb)
						samptb.updateClients(this.sampclientsStore);
				}
			}
		}
	},

	sampConnected : function()
	{
		if (!this.samp)
			return false;
			return this.samp.isConnected();
	},

	sendVOTable : function(file,clientId)
	{
		if (!this.samp)
			return false;
		var href = window.location.href;
		var baseurl = href.replace('desktop.php','');
		this.samp.sendVOTable(baseurl+file,clientId);
	},

	sendAladinScript : function(script)
	{
		if (!this.samp)
			return false;
		this.samp.sendAladinScript(script);
	},

	sendFITS : function(url,name)
	{
		if (!this.samp)
			return false;
		this.samp.sendFITS(url,name);
	},
10200969   Roipoussiere   Remove whitespace...
232

6de48c3d   Benjamin Renard   Implement data up...
233
234
235
236
237
238
	loadFile: function(url,onLoad,onError) {
		if (!this.samp)
			return null;
		this.samp.loadFile(url,onLoad,onError);
	},

c7f2e83c   Nathanael Jourdane   Improve filter an...
239
	loadEpnTap: function(filter) {
a8794c12   Nathanael Jourdane   Big refactoring (...
240
241
242
		if(!this.epntap) {
			this.epntap = Ext.create('amdaDesktop.EpnTapModule');
		}
c7f2e83c   Nathanael Jourdane   Improve filter an...
243
		this.epntap.loadTarget(filter);
a8794c12   Nathanael Jourdane   Big refactoring (...
244
245
	},

12be2344   Elena.Budnik   redmine #5507
246
247
248
	generateAladinScript : function(urlList, scriptType)
	{        
		var script = 'reset;';
10200969   Roipoussiere   Remove whitespace...
249

db3a6e4b   Nathanael Jourdane   fix tabs on inter...
250
		for( var i=0; i < urlList.length; i++) {
16035364   Benjamin Renard   First commit
251
252
			var url = urlList[i].url;
			var name = urlList[i].name;
10200969   Roipoussiere   Remove whitespace...
253
			script += 'get File(' + url +','+name+');';
16035364   Benjamin Renard   First commit
254
		}
10200969   Roipoussiere   Remove whitespace...
255

12be2344   Elena.Budnik   redmine #5507
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
		script += 'sync;';
		switch( scriptType )
		{
			case('mosaic'):
			{
				script += 'sync;mview 16';
			}
			break;
			case('movie'):
			{
				script += 'blink ';
					for( var i=1; i < urlList.length; i++){
						script += urlList[i].name+" ";
					}
					script += ';';
			}
			break;
		}
		return script;
	},

	switchSampConnect : function()
	{
		var me = this;
		//loadMask.show();
		this.initSampConnector(function (s){
			if (me.samp.isConnected())
			{
				me.samp.disconnect();
			}
			else
			{
				me.samp.connect();
				//	loadMask.hide();
			}
		});
	},

	forceSampDisconnect : function()
	{
		if (!this.samp)
			return;

		if (!this.samp.isConnected())
			return;

		this.samp.disconnect();
16035364   Benjamin Renard   First commit
303
	},
10200969   Roipoussiere   Remove whitespace...
304

12be2344   Elena.Budnik   redmine #5507
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
	getVOTableClients : function ()
	{
		//return list of all clients that can receive a VOTable
		if (!this.samp)
			return [];
		var result = new Array();
		this.sampclientsStore.each(function (client){
			if (client.get('acceptVOTable'))
				result.push({id : client.get('id'), name : client.get('name'), icon : client.get('iconUrl')});

		},this);
		return result;
	},

	getFITSClients : function ()
	{
		//return list of all clients that can receive a FITS image
		if (!this.samp)
			return [];
		var result = new Array();
		this.sampclientsStore.each(function (client){
			if (client.get('acceptFITS'))
				result.push({id : client.get('id'), name : client.get('name'), icon : client.get('iconUrl')});

		},this);
		return result;
	},
	
6191b7ed   Elena.Budnik   redmine #5507+
333
	// arguments from launcher : CONFIG (OBJECT!!!)
10200969   Roipoussiere   Remove whitespace...
334
	createWindow : function(config){
12be2344   Elena.Budnik   redmine #5507
335
336
		var me = this;
		var baseId = null;
10200969   Roipoussiere   Remove whitespace...
337

12be2344   Elena.Budnik   redmine #5507
338
339
340
341
342
		if (!Ext.isObject(config)) {
			baseId = config;
			var activeTab = 1;
		}
		else {
6191b7ed   Elena.Budnik   redmine #5507+
343
			var activeTab = 'activeTab' in config ? config['activeTab'] : 1;
12be2344   Elena.Budnik   redmine #5507
344
345
346
347
348
349
350
351
352
		}
		var desktop = this.app.getDesktop();
		var win = desktop.getWindow(this.id);
		
		if(!win)
		{
			win = desktop.createWindow({
				id: this.id,
				title:this.title,
fecd2848   Nathanael Jourdane   Fix panel/grid si...
353
354
355
356
				layout: 'fit',
				minWidth: 650,
				minHeight: 350,
				minimizable: false,
12be2344   Elena.Budnik   redmine #5507
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
				iconCls: this.icon,
				animCollapse:false,
				constrainHeader:true,
				bodyPadding : 5,
				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 : [
				{
					xtype: 'panelInterop',
					clientsStore : this.sampclientsStore,
					activeTab : activeTab,
					baseId : baseId,
					loadTab: function(tab) {
6191b7ed   Elena.Budnik   redmine #5507+
381
382
						if(tab['id'] === 'epntapTab') {							
							me.loadEpnTap(Ext.isObject(config) && 'epntapFilter' in config ? config['epntapFilter']: false);							
12be2344   Elena.Budnik   redmine #5507
383
384
385
386
387
388
389
390
391
						}
					},
					onSwitchConnect : function ()
					{
						me.switchSampConnect();
					}
				}]
			});
		} else if(activeTab == 2) {
6191b7ed   Elena.Budnik   redmine #5507+
392
				me.loadEpnTap(Ext.isObject(config) && 'epntapFilter' in config ? config['epntapFilter']: false);
67bd4723   Nathanael Jourdane   Update target fro...
393
		}
10200969   Roipoussiere   Remove whitespace...
394

12be2344   Elena.Budnik   redmine #5507
395
396
		if (me.samp && me.samp.ready)
			this.updateStatus();
10200969   Roipoussiere   Remove whitespace...
397

12be2344   Elena.Budnik   redmine #5507
398
399
		win.show();
		return win;
16035364   Benjamin Renard   First commit
400
	}
10200969   Roipoussiere   Remove whitespace...
401
});