/** * 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: 'needsArgs', type: 'boolean', 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} ], 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')) { // this.set('cls','predicted'); var id = this.get('id'); var bracketPos = id.indexOf("("); if (bracketPos > 0) { id = Ext.String.insert(id, '_restr', bracketPos); } else { id += '_restr'; } this.set('id', id); } if (this.get('rank')) { var rank = this.get('rank'); if (rank == 1) this.set('iconCls', 'icon-mercury'); if (rank == 2) this.set('iconCls', 'icon-venus'); if (rank == 5) this.set('iconCls', 'icon-earth'); if (rank == 6) this.set('iconCls', 'icon-earth'); if (rank == 7) this.set('iconCls', 'icon-mars'); if (rank == 8) this.set('iconCls', 'icon-jupiter'); if (rank == 9) this.set('iconCls', 'icon-saturn'); if (rank == 93) this.set('iconCls', 'icon-comet'); if (rank == 3) this.set('iconCls', 'icon-sw'); if (rank == 4) this.set('iconCls', 'icon-sw'); if (rank >= 99) this.set('iconCls', 'icon-solarsystem'); } 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'); } }, allMenuItems : function() { var menuItems = [{ fnId : 'root-collapseAll', text : 'Close All', hidden : true }, { fnId : 'dire-collapseAll', text : 'Close All', hidden : true }, { fnId : 'para-plotParam', text : 'Plot Parameter', hidden : true }, { fnId : 'para-downParam', text : 'Download 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 : 'dire-epnTap', text : 'Display EPN-TAP services', hidden : false }]; return menuItems; }, onMenuItemClick : function(menu, item, evt) { switch (item.fnId) { case 'root-collapseAll': case 'dire-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': this.createDownload(this); break; case 'leaf-createDerivedParam': if (!this.get('notyet')) this.createLeaf(this); else myDesktopApp.warningMsg("Sorry! access to this parameter is restricted"); break; case 'leaf-createAlias': if (!this.get('notyet')) this.createAlias(this); else myDesktopApp.warningMsg("Sorry! access to this parameter is restricted"); break; case 'dire-epnTap': this.displayEpnTap(); default: break; } }, displayEpnTap: function() { var target = this.get('iconCls'); myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interop.id, true, function (module) { module.createWindow({'activeTab': 2, 'epntapTarget': target}); }); }, createLeaf: function(node) { // instanciate a Parameter object with the current data in his buidchain var param = Ext.create(this.get('objectDataModel'));//, { buildchain: node.get('alias') ? "#"+node.get('alias') : node.get('id') }); // instanciate a DerivedParamNode with this param object var newNode = Ext.create(amdaModel.DerivedParamNode.$className, {leaf : true, object : param}); // edit newNode into Parameter Module with node as contextNode newNode.editInModule(); var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.param.id, true, function(module) { var paramName; var components = null; if (node.get('alias')!= "" ) paramName = "#"+node.get('alias'); else paramName = node.get('id'); 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; } module.addParam(paramName,true,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'); } });