LocalParamNode.js 7.57 KB
/**
 * Project  : AMDA-NG4
 * Name     : LocalParamNode.js
 * @class   amdaModel.LocalParamNode
 * @extends amdaModel.InteractiveNode
 * @brief   Basic Model of Node corresponding to a amda  parameter
 * @author
 * @version $Id: LocalParamNode.js 2800 2015-02-27 16:23:06Z elena $
 */

Ext.define('amdaModel.LocalParamNode',
{
	extend: 'amdaModel.InteractiveNode',

	statics: { 
		nodeType: 'localParam'
	},

	fields: [
		{name: 'alias', type:'string', persist: false},
		{name: 'isParameter', type: 'boolean', persist: false},
		{name: 'notyet', type: 'boolean', defaultValue: false, persist: false},
		{name: 'isSpectra', type: 'boolean', defaultValue: false, persist: false},
		{name: 'isStack', type: 'boolean', defaultValue: true, persist: false},
		{name: 'globalStart', type: 'string', persist: false},
		{name: 'globalStop', type: 'string', persist: false},
		{name: 'timeRestriction', type: 'boolean', persist: false},
		{name: 'rank', type: 'integer', persist: false, defaultValue: null}
	],
	
	icons : {'1' : 'icon-mercury','2' : 'icon-venus','3' : 'icon-sw','4' : 'icon-sw','5' : 'icon-earth','6' : 'icon-earth',
				'7' : 'icon-mars','8' : 'icon-jupiter','9' : 'icon-saturn','10' : 'icon-uranus','11' : 'icon-neptune',
				'93' :'icon-comet', '99' :'icon-solarsystem', '999' :'icon-solarsystem' 
	},
		
	constructor : function(config)
	{
		this.callParent(arguments);

		this.set('allowDrop', true);
		this.set('moduleId',myDesktopApp.dynamicModules.param.id);
		this.set('objectDataModel',amdaModel.Parameter.$className);

		// if future missions or 'depending on mission'
		if (this.get('globalStart')) {
			var now = Ext.Date.format(new Date(), 'Y/m/d');
			if ( this.get('globalStart') > now )
				this.set('cls','predicted');
		}
// 		// time restriction on parameters
// 		if (this.get('timeRestriction')) {
//                  TBD
// 		}
		
		if (this.get('rank')) {
			var rank = this.get('rank');
			this.set('iconCls', this.icons[rank]);
		}

		if (this.get('isParameter')) {
			if (this.get('leaf'))
				this.set('iconCls', 'icon-scalar');
			else
				this.set('iconCls', 'icon-vector');

			if (this.get('isStack') || this.get('isSpectra'))
				this.set('iconCls', 'icon-spectra');
		
			if (this.get('is2dSpectra'))
				this.set('iconCls', 'icon-2dspectra');
		}
	},

	allMenuItems : function()
	{
		var menuItems =
		[{
			fnId : 'root-collapseAll',
			text : 'Close All',
			hidden : true
		}, {
			fnId : 'dire-collapseAll',
			text : 'Close All',
			hidden : true
		}, {
			fnId : 'miss-collapseAll',
			text : 'Close All',
			hidden : true
		}, {
			fnId : 'para-plotParam',
			text : 'Plot Parameter',
			hidden : true
		}, {
			fnId : 'para-downParam',
			text : 'Download Parameter',
			hidden : true
		},{
			fnId : 'para-createDerivedParam',
			text : 'Create Derived Parameter',
			hidden : true
		}, {
			fnId : 'leaf-createAlias',
			text : 'Create/Edit Alias',
			hidden : true
		},{
			fnId : 'leaf-createDerivedParam',
			text : 'Create Derived Parameter',
			hidden : true
		},{
			fnId : 'leaf-plotParam',
			text : 'Plot Parameter',
			hidden : true
		}, {
			fnId : 'leaf-downParam',
			text : 'Download Parameter',
			hidden : true
		}, {
			fnId : 'miss-epnTap',
			text : 'Display EPN-TAP services',
			hidden : true
		}];

		return menuItems;
	},

	onMenuItemClick : function(menu,item,event)
	{
		switch (item.fnId)
		{
			case 'root-collapseAll':
			case 'dire-collapseAll':
			case 'miss-collapseAll':
				if(this && !this.isLeaf()) {
					this.collapse(true);
				}
				break;
			case 'leaf-plotParam':
			case 'para-plotParam':
					this.createPlot(this);
				break;
			case 'leaf-downParam':
			case 'para-downParam':
				if (!this.get('disable')) {
					if (this.get('notyet')) {
						myDesktopApp.warningMsg("Sorry! this parameter is PlotOnly");
					}
					else {
						this.createDownload(this);
					}
				}
				break;
			case 'para-createDerivedParam':
			case 'leaf-createDerivedParam':
				if (!this.get('disable')) {
					if (this.get('notyet')) {
						myDesktopApp.warningMsg("Sorry! this parameter is PlotOnly");
					}
					else {
						this.createLeaf(this);
					}
				}
				break;
			case 'leaf-createAlias':
				if (!this.get('disable')) {
					if (this.get('notyet')) {
						myDesktopApp.warningMsg("Sorry! this parameter is PlotOnly");
					}
					else {
						this.createAlias(this);
					}
				}
				break;
			case 'miss-epnTap':
				this.displayEpnTap();
				break;
			default:
				break;
		}
	},

	createLeaf: function(node)
	{
		myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.param.id, true, function(module) {
			if (!myDesktopApp.desktop.getWindow(myDesktopApp.dynamicModules.param.id)) {               
				var param =  Ext.create(node.get('objectDataModel')); 
				var newNode = Ext.create(amdaModel.DerivedParamNode.$className, {leaf : true, object : param});              
				// edit newNode into Parameter Module with node as contextNode
				newNode.editInModule();
			}  
			var paramName;
			var components = null;
			if (node.get('alias')!= "" )
				paramName = "#"+node.get('alias');
			else
				paramName = node.get('id');

			module.addParam(paramName,node.get('leaf'),node.get('needsArgs'),components);
		});
	},

	createAlias: function(node)
	{
		var win = myDesktopApp.desktop.getWindow('alias-win');
		if (!node.get('needsArgs') && node.get('leaf'))
		{
			if(!win)
			{
				var win = myDesktopApp.desktop.createWindow(
				{
					border: false,
					id : 'alias-win',
					title : 'Create Alias',
					width : 400,
					height : 200,
					layout : 'border',
					maximizable : false,
					items :
					[{
						xtype : 'alias',
						region : 'center',
						margins :
						{
							top: 0,
							right: 5,
							bottom: 5,
							left: 5
						},
						paramNode : node,
						id : 'aliasUI'
					}]
				});
			}
			else
			{
				//Set data into Alias Widget
				win.items.items[0].paramNode = node;
				win.items.items[0].setAlias(node);
			}
			win.show();
		}
		else
		{
			var message = 'Sorry, parameter ' + node.get('id') + ' cannot have alias';
			Ext.Msg.alert('Impossible Create Alias', message);
			if (win) win.close();
		}
	},

	isParameter : function()
	{
		return this.get('isParameter');
	},

  displayEpnTap: function () {
    const missions = {
      'Giotto': '1P',
      'ICE': '21P',
      'Rosetta': '67P',
      'Voyager': 'Jupiter, Io, Thébé, Métis Adrastée, Europe, ' +
      'Saturn, Atlas, Prométhée, Pandore, Téthys, Japet, Encelade, Uranus, Mirandaneptune, Triton',
      'Pioneer': 'Earth, Moon, Venus, Jupiter, Callisto, Ganymede, Io, Europa, Amalthea, Saturn, Iapetus, Phoebe, ' +
      'Hyperion, Epimetheus, Atlas, Dione, Mimas, Janus, Tethys, Enceladus, Calypso, Rhea, Titan',
      'Ulysses': 'Sun',
      'Solar_Probe_Plus': 'Sun',
      'Solar_Orbiter': 'Sun',
      'Ephemerides': 'Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Deimos, Phobos, 67P'
    }
    const icons = {
      'icon-mercury': 'Mercury',
      'icon-venus': 'Venus',
      'icon-earth': 'Earth',
      'icon-mars': 'Mars',
      'icon-jupiter': 'Jupiter',
      'icon-saturn': 'Saturn',
      'icon-sw': 'Earth, Sun'
    }

    const targetName = this.get('id') in missions ? missions[this.get('id')]
        : this.get('iconCls') in icons ? icons[this.get('iconCls')]
        : ''
    const start = this.get('globalStart') ? this.get('globalStart') : ''
    const stop = this.get('globalStop') ? this.get('globalStop') : ''
    const filter = {'productType': 'all', 'targetName': targetName, 'start': start, 'stop': stop}
    myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interop.id, true, function (module) {
      module.createWindow({'activeTab': 2, 'epntapFilter': filter})
    })
  }
});