/** * Project  : AMDA-NG * Name : InteropImpexUI.js * @class amdaUI.InteropImpexUI * @extends Ext.form.Panel * @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', requires: [ 'Ext.ux.CheckColumn'], nodeDataModel : 'amdaModel.remoteSimuParamNode', linkedNode : null, setLinkedNode : function (myLinkedNode){ this.linkedNode = myLinkedNode; }, saveCallback: function(res,e) { loadMask.hide(); //if success if(e.status) { // 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); } }); } } //TODO error processing else { } }, /* * UI components description / creation */ initComponent : function() { //TODO Earth Only ??? var targetStore = Ext.create('Ext.data.Store', { fields: ['target'], data : [ { target: 'Earth' } /* { target: 'Mars' }, { target: 'Venus' } */ ] }); var table = Ext.create('Ext.form.Panel', { bodyStyle:'padding:5px 5px 5px', layout: { type: 'table', columns: 7 }, defaults: { xtype: 'displayfield', bodyStyle: 'padding:20px', hideTrigger: true }, items: [ // header { width : 110}, { value: 'value', width : 65 }, { width : 20 }, { value: 'weight' , width : 65}, { width : 20}, { value: 'scale', width : 65 }, { width : 20 }, { value: 'Density' }, { xtype: 'numberfield', name : 'SW_Density_value', width: 50 }, { value: ' *10^6m-3 ' }, { xtype: 'numberfield', name : 'SW_Density_weight' , value: '1.0' , width: 50 }, { value: ' ' }, { xtype: 'numberfield', name: 'SW_Density_scale' , value: '7' , width: 50 }, { value: ' *10^6m-3 '}, { value: 'Utot' }, { xtype: 'numberfield', name : 'SW_Utot_value' , width: 50 } , { value: ' *10^3 m/s ' }, { xtype: 'numberfield', name : 'SW_Utot_weight' , value: '1.0' , width: 50 }, { value: ' ' }, { xtype: 'numberfield', name: 'SW_Utot_scale' , value: '430' , width: 50 }, { value: ' *10^3 m/s ' }, { value: 'Btot' }, { xtype: 'numberfield', name : 'SW_Btot_value' , width: 50 } , { value: ' *10^-9 T ' }, { xtype: 'numberfield', name : 'SW_Btot_weight' , value: '1.0' , width: 50 }, { value: ' ' }, { xtype: 'numberfield', name: 'SW_Btot_scale' , value: '6' , width: 50 }, { value: ' *10^-9 T ' }, { value: 'Temperature' }, { xtype: 'numberfield', name : 'SW_Temperature_value' , width: 50 } , { value: ' *10^3K ' }, { xtype: 'numberfield', name : 'SW_Temperature_weight' , value: '1.0' , width: 50 }, { value: ' ' }, { xtype: 'numberfield', name: 'SW_Temperature_scale' , value: '80' , width: 50 }, { value: ' *10^3K ' }, { value: 'Bx' }, { xtype: 'numberfield', name : 'SW_Bx_value' , width: 50 } , { value: ' *10^-9 T ' }, { xtype: 'numberfield', name : 'SW_Bx_weight' , value: '1.0' , width: 50 }, { value: ' ' }, { xtype: 'numberfield', name: 'SW_Bx_scale' , value: '6' , width: 50 }, { value: ' *10^-9 T ' }, { value: 'By' }, { xtype: 'numberfield', name : 'SW_By_value' , width: 50 } , { value: ' *10^-9 T ' }, { xtype: 'numberfield', name : 'SW_By_weight' , value: '1.0' , width: 50 }, { value: ' ' }, { xtype: 'numberfield', name: 'SW_By_scale' , value: '6' , width: 50 }, { value: ' *10^-9 T ' }, { value: 'Bz' }, { xtype: 'numberfield', name : 'SW_Bz_value' , width: 50 } , { value: ' *10^-9 T ' }, { xtype: 'numberfield', name : 'SW_Bz_weight' , value: '1.0' , width: 50 }, { value: ' ' }, { xtype: 'numberfield', name: 'SW_Bz_scale' , value: '6' , width: 50 }, { value: ' *10^-9 T ' }, { value: 'Function' }, { xtype: 'numberfield', name : 'SW_Function_value' , width: 50 } , { value: ' ' }, { xtype: 'numberfield', name : 'SW_Function_weight' , value: '1.0' , width: 50 }, { value: ' ' }, { xtype: 'numberfield', name: 'SW_Function_scale' , width: 50 }, { xtype: 'textfield', name: 'SW_Function_formule' } ] }); 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' , width: 170 , fieldLabel: 'Object', queryMode: 'local' }, { xtype : 'numberfield', name : 'RunCount', value: 1 , width: 170 , fieldLabel: 'RunCount' }, 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 columns = [ { xtype : 'checkcolumn', menuDisabled: true, sortable: false, dataIndex : 'ToAdd', width: 30 }, { text : 'Run Name', sortable : false, dataIndex: 'ResourceName', width: 150 },{ text : 'Total diff. index', sortable : true, dataIndex: 'S_diff' }, { text: 'SW_Density', columns: [{ text : 'Diff. index', width : 75, dataIndex: 'S_diff_n_SW_Density' }, { text : 'Value', width : 80, dataIndex: 'SW_Density_value' }] }, { text: 'SW_Utot', columns: [{ text : 'Diff. index', width : 75, dataIndex: 'S_diff_n_SW_Utot' }, { text : 'Value', width : 80, dataIndex: 'SW_Utot_value' }] }, { text: 'SW_Temperature', columns: [{ text : 'Diff. index', width : 75, dataIndex: 'S_diff_n_SW_Temperature' }, { text : 'Value', width : 80, dataIndex: 'SW_Temperature_value' }] }, { text: 'SW_Btot', columns: [{ text : 'Diff. index', width : 75, dataIndex: 'S_diff_n_SW_Btot' }, { text : 'Value', width : 80, dataIndex: 'SW_Btot_value' }] }, { text: 'SW_Bx', columns: [{ text : 'Diff. index', width : 75, dataIndex: 'S_diff_n_SW_Bx' }, { text : 'Value', width : 80, dataIndex: 'SW_Bx_value' }] }, { text: 'SW_By', columns: [{ text : 'Diff. index', width : 75, dataIndex: 'S_diff_n_SW_By' }, { text : 'Value', width : 80, 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); } });