InteropImpexUI.js 11.5 KB
/**
 * Project   : AMDA-NG
 * Name      : InteropImpexUI.js
 * @class 	    amdaUI.InteropImpexUI 
 * @extends     Ext.container.Container
 * @brief	  
 * @author 	Elena
 * @version  $Id: InteropImpexUI.js 2327 2014-04-29 08:47:22Z natacha $ 
 */ 
 
Ext.define('amdaUI.InteropImpexUI',{
		extend: 'Ext.container.Container',
		alias: 'widget.interop_impex', 
                
		nodeDataModel : 'amdaModel.remoteSimuParamNode',
		linkedNode : null,
        
		setLinkedNode : function (myLinkedNode)
		{           
			this.linkedNode = myLinkedNode;		
		},
        
		saveCallback: function(res,e)
		{  
			loadMask.hide();        
			//if success
			if(e.status && res.success) 
			{              
				// reload RemoteParam Tree in explorer
				var explorerTree = Ext.getCmp(amdaUI.ExplorerUI.RESRC_TAB.TREE_ID);
				if (explorerTree && this.linkedNode ) 
				{                                       
					var explorerTreeStore = explorerTree.getStore();
					var explorerRoot = explorerTreeStore.getRootNode();
					var updatedId = this.linkedNode.get('id');
					var explorerPath = '/root/parameters-treeBase/myRemoteSimuData-treeRootNode/'+updatedId+'/';
							
					explorerTreeStore.load({ node : explorerRoot, 
													params : { nodeType: 'resources'},
													callback : function()
													{
														explorerTree.selectPath(explorerPath);                                                 
													}
					});                
				}                
			}			
			else {
				myDesktopApp.errorMsg(res.message);
			}
		},
        
	/*
	* UI components description / creation
	*/
	initComponent : function()
	{
		var targetStore = Ext.create('Ext.data.Store', {
			fields: ['target'], 
			data : [
				{ target: 'Earth' }
				/* { target: 'Mars'  },
				{ target: 'Venus' }   */                
			]
		});
        
		var widthH = 110;
		var table = Ext.create('Ext.form.Panel', {       
			bodyStyle:'padding:5px 5px 5px',
			layout: 
			{
				type: 'table',   
				columns: 5   
			},
			defaults: 
			{    
				xtype: 'displayfield',          
				bodyStyle: 'padding:20px',
				hideTrigger: true,
				width : 40
			},            
			items: [ 
				// header
				{ width : widthH},
				{ value: 'value', width : 65 },				
				{ value: 'weight' , width : 65},
				{ value: 'scale', width : 65 },
				{ width : 20 },                   
				{ value: 'SW Density', width : widthH},
				{ xtype: 'numberfield', name : 'SW_Density_value'},				
				{ xtype: 'numberfield', name : 'SW_Density_weight' , value: '1.0'},
				{ xtype: 'numberfield', name: 'SW_Density_scale' , value: '7'},
				{ value: ' cm-3 '},  		    
				{ value: 'SW Velocity', width : widthH },    
				{ xtype: 'numberfield', name : 'SW_Utot_value'} ,
				{ xtype: 'numberfield', name : 'SW_Utot_weight' , value: '1.0'},
				{ xtype: 'numberfield', name: 'SW_Utot_scale' , value: '430'},
				{ value: ' km/s ' }, 		    				                                    
				{ value: 'SW Temperature', width : widthH },    
				{ xtype: 'numberfield', name : 'SW_Temperature_value'} ,
				{ xtype: 'numberfield', name : 'SW_Temperature_weight' , value: '1.0'},
				{ xtype: 'numberfield', name: 'SW_Temperature_scale' , value: '7' },
				{ value: ' eV ' },      				
				{ value: 'IMF Bx' , width : widthH},    
				{ xtype: 'numberfield', name : 'SW_Bx_value'} ,
				{ xtype: 'numberfield', name : 'SW_Bx_weight' , value: '1.0'},
				{ xtype: 'numberfield', name: 'SW_Bx_scale' , value: '6'},
				{ value: ' nT ' },                                          
				{ value: 'IMF By', width : widthH },    
				{ xtype: 'numberfield', name : 'SW_By_value' , width: 50 } ,
				{ xtype: 'numberfield', name : 'SW_By_weight' , value: '1.0'},
				{ xtype: 'numberfield', name: 'SW_By_scale' , value: '6'},
				{ value: ' nT ' },                      				
				{ value: 'IMF Bz', width : widthH },    
				{ xtype: 'numberfield', name : 'SW_Bz_value'} ,
				{ xtype: 'numberfield', name : 'SW_Bz_weight' , value: '1.0'},
				{ xtype: 'numberfield', name: 'SW_Bz_scale' , value: '6'},
				{ value: ' nT ' },
				{ value: 'IMF Btot', width : widthH },    
				{ xtype: 'numberfield', name : 'SW_Btot_value'} ,
				{ xtype: 'numberfield', name : 'SW_Btot_weight' , value: '1.0'},
				{ xtype: 'numberfield', name: 'SW_Btot_scale' , value: '6'},
				{ value: ' nT ' },      
				{ value: 'Function', width : widthH },    
				{ xtype: 'numberfield', name : 'SW_Function_value'} ,
				{ xtype: 'numberfield', name : 'SW_Function_weight' , value: '1.0'},
				{ xtype: 'numberfield', name: 'SW_Function_scale'},
				{ xtype: 'textfield', name: 'SW_Function_formule', width : 200 }                      
			]
		});  
           
		var inputForm = Ext.create(Ext.form.Panel, {
			bodyStyle:'padding:5px 5px 5px',
			title: 'Based on a FMI algorithm',
			items: [
					{ 
						xtype : 'combo', name: 'Object',
						store :  targetStore,
						displayField: 'target', valueField: 'target', value: 'Earth Magnetosphere' , width: 250 , 
						fieldLabel: 'Simulated Region', queryMode: 'local'                     
					},
					{                          
						xtype : 'numberfield', name : 'RunCount', value: 1 , width: 250 , minValue : 1,
						fieldLabel: 'Runs Number'                     
					},
					table
			],
			fbar: [
				{ 
					text: 'Get Runs', 
					scope: this,
					handler:  function() 
					{
						var values = this.down('form').getForm().getValues();  
						var i = 0;
						var j = 0;
						var nullValues = new Array();
						var hasValues = new Array();
						for (key in values) 
						{
							if (values.hasOwnProperty(key)) 
							{				
								if (values[key] == ''){
									nullValues[i] = key;
									i++;
								}
								else {
									hasValues[j] = key;
									j++;
								}
							}
						}
						var index;
						for (key in nullValues) 
						{
							// 	console.log(key + ": " + nullValues[key]);			 
							var index;
							for (index = 0; index < resOutput.columns.length; ++index) 
							{
								if (resOutput.columns[index].items)
								{
									if (resOutput.columns[index].items.items[1] && resOutput.columns[index].items.items[1].dataIndex) 
									{
										if (resOutput.columns[index].items.items[1].dataIndex == nullValues[key]) 
										{
											resOutput.columns[index].items.items[0].hidden = true;
											resOutput.columns[index].items.items[0].setText("");			 				      
										}
										if (resOutput.columns[index].items.items[1].dataIndex == hasValues[key]) 
										{
											resOutput.columns[index].items.items[0].hidden = false;
											resOutput.columns[index].items.items[0].setText("Diff. index");
										}
									}
								}
							}
						}
						resOutput.update();
						loadMask.show();
						
						AmdaAction.getRun(values, function(res,e){  
							loadMask.hide();        
							//success
							if(e.status) 
							{                                 
								resStore.load();
								resOutput.show(); 
							}
							//TODO error processing
							else {}
						}, this);
					}
				}]
		});
            
		var resStore =  Ext.create('Ext.data.Store', {              
			fields:[ { name : 'ToAdd', type : 'bool', defaultValue : false}, 
						'ResourceID', 'ResourceName', 'S_diff', 
						{ name : 'S_diff_n_SW_Density', mapping : 'S_diff_n.SW_Density' }, 
						{ name : 'SW_Density_value', mapping : 'Param_values.SW_Density' },
						{ name : 'S_diff_n_SW_Utot', mapping : 'S_diff_n.SW_Utot' }, 
						{ name : 'SW_Utot_value', mapping : 'Param_values.SW_Utot' },
						{ name : 'S_diff_n_SW_Btot', mapping : 'S_diff_n.SW_Btot' }, 
						{ name : 'SW_Btot_value', mapping : 'Param_values.SW_Btot' },
						{ name : 'S_diff_n_SW_Temperature', mapping : 'S_diff_n.SW_Temperature' }, 
						{ name : 'SW_Temperature_value', mapping : 'Param_values.SW_Temperature' },
						{ name : 'S_diff_n_SW_Bx', mapping : 'S_diff_n.SW_Bx' }, 
						{ name : 'SW_Bx_value', mapping : 'Param_values.SW_Bx' },
						{ name : 'S_diff_n_SW_By', mapping : 'S_diff_n.SW_By' }, 
						{ name : 'SW_By_value', mapping : 'Param_values.SW_By' },
						{ name : 'S_diff_n_SW_Bz', mapping : 'S_diff_n.SW_Bz' }, 
						{ name : 'SW_Bz_value', mapping : 'Param_values.SW_Bz' }
			],
			proxy: {
				type: 'ajax',
				//TODO use sessionID  user-dependent URL
				url: 'data/'+sessionID+'/WS/runs.json',
				reader: {
					type: 'json',                       
					root: 'runs',
					idProperty: 'ResourceID'
				}
			}
		});
		
		var checkcolumn = Ext.create('Ext.grid.column.Check',{ menuDisabled: true,
			sortable: false, dataIndex : 'ToAdd', width: 30, activeitem : 0});
		
		var columns = [
				checkcolumn,
			{
				text     : 'Run Name',         
				sortable : false,
				dataIndex:  'ResourceName',
				width: 150
			},
			{
				text     : 'Diff. index',         
				sortable : true,
				dataIndex:  'S_diff',
				width    : 50
			},  
			{
				text: 'SW_Density',
				columns: [{
					text     : 'Diff. index',
					width    : 50,                        
					dataIndex: 'S_diff_n_SW_Density'
				}, {
					text     : 'Value',
					width    : 50,                   
					dataIndex: 'SW_Density_value'
				}]
			},
			{
				text: 'SW_Utot',
				columns: [{
					text     : 'Diff. index',
					width    : 50,   
					dataIndex: 'S_diff_n_SW_Utot'
				}, {
					text     : 'Value',
					width    : 50,                   
					dataIndex: 'SW_Utot_value'
				}]
			},
			{
				text: 'SW_Temperature',
				columns: [{
					text     : 'Diff. index',
					width    : 50,                        
					dataIndex: 'S_diff_n_SW_Temperature'
				}, {
					text     : 'Value',
					width    : 50,                   
					dataIndex: 'SW_Temperature_value'
				}]
			},
			{
				text: 'SW_Btot',
				columns: [{
					text     : 'Diff. index',
					width    : 50,                        
					dataIndex: 'S_diff_n_SW_Btot'
				}, {
					text     : 'Value',
					width    : 50,                   
					dataIndex: 'SW_Btot_value'
				}]
			},
			{
				text: 'SW_Bx',
				columns: [{
					text     : 'Diff. index',
					width    : 50,                        
					dataIndex: 'S_diff_n_SW_Bx'
				}, {
					text     : 'Value',
					width    : 50,                   
					dataIndex: 'SW_Bx_value'
				}]
			},
			{
				text: 'SW_By',
				columns: [{
					text     : 'Diff. index',
					width    : 50,                        
					dataIndex: 'S_diff_n_SW_By'
				}, {
					text     : 'Value',
					width    : 50,                   
					dataIndex: 'SW_By_value'
				}]
			},
			{
				text: 'SW_Bz',
				columns: [{
					text     : 'Diff. index',
					width    : 75,                        
					dataIndex: 'S_diff_n_SW_Bz'
				}, {
					text     : 'Value',
					width    : 80,                   
					dataIndex: 'SW_Bz_value'
				}]
			}
		];
                
		var cellEditing = Ext.create('Ext.grid.plugin.CellEditing');
            
		var resOutput = Ext.create('Ext.grid.Panel', {
				title: 'Runs Info',             
				columns: columns, 
				store: resStore,
				scroll: 'both',
				hidden : true,
				selModel: {
					selType: 'cellmodel'
				},
				fbar: [
				{ 
					text: 'Save Runs', 
					scope: this,
					handler:  function() 
					{                       
						var me = this;  
						var runsToAdd = resStore.getModifiedRecords();
						var values = [];
						
						Ext.Array.each(runsToAdd,function(run){
							values.push(run.get('ResourceID'));
						});
							
						loadMask.show();                     
						AmdaAction.addRun(values, me.saveCallback, me);
					}
				}],
				plugins: [cellEditing]
		});
            
		var config = {		
		//    bodyStyle: 'background:#ddecfe;',                
				items: [
					inputForm,
					resOutput
				]  
		};
            
		Ext.apply(this , config);
		this.callParent(arguments);
	}  
});