PlotParamObject.js 4.28 KB
/**
 * Project      : AMDA-NG
 * Name         : PlotParamObject.js
 * @class   amdaPlotObj.PlotParamObject
 * @extends Ext.data.Model
 * @brief   Plot Param Business Object Definition 
 * @author  Benjamin Renard
 * @version $Id: PlotParamObject.js benjamin $
 ******************************************************************************
 *    FT Id     :   Date   : Name - Description
 ******************************************************************************
 *	:           :17/08/2015: BRE  - file creation
 */
 
 		
Ext.define('amdaPlotObj.PlotParamObject', {
	extend: 'Ext.data.Model',
	
	requires: [
	           'amdaPlotObj.PlotObjectConfig',
	           'amdaPlotObj.PlotSerieObject',
	           'amdaPlotObj.PlotSpectroObject',
	           'amdaPlotObj.PlotStatusBarObject',
	           'amdaPlotObj.PlotTickBarObject'
	],
	
	fields : [
	          {name: 'id', type: 'string'},
	          {name: 'param-id', type: 'string'},
	          {name: 'param-drawing-type', type: 'string'},
	          {name: 'param-drawing-object', type: 'auto'}
    ],
    
    associations : [
              {
            	  type  : 'belongsTo',
                  model : 'amdaPlotObj.PlotPanelObject',
                  getterName : 'Panel'
              }
    ],
    
    constructor: function(){
        var me = this;
        me.callParent(arguments);
        me.updateDrawingType(this.get('param-drawing-type'), true);
        if ((arguments.length > 0) && arguments[0])
        {
        	if (arguments[0]['param-drawing-object'])
        		me.loadDrawingObject(arguments[0]['param-drawing-object']);
        }
    },
    
    loadDrawingObject: function(drawing)
    {
    	var drawingObject = this.get('param-drawing-object');
    	if (drawingObject == null)
    		return;
    	Ext.Object.each(drawing, function(key,value) {
    		drawingObject.set(key,value);
    	});
    },
    
    updateDrawingType: function(type, forceUpdate)
    {
    	forceUpdate = (typeof forceUpdate !== 'undefined') ? forceUpdate : false;
    	
    	if (!forceUpdate && (type == this.get('param-drawing-type')))
    		return;
    	
    	this.set('param-drawing-type', type);
    	
    	//Create drawing object in relation with the type
    	switch (type)
    	{
    	case 'serie' :
    		this.set('param-drawing-object', new amdaPlotObj.PlotSerieObject());
    		break;
    	case 'spectro' :
    		this.set('param-drawing-object', new amdaPlotObj.PlotSpectroObject());
    		break;
    	case 'status-bar' :
    		this.set('param-drawing-object', new amdaPlotObj.PlotStatusBarObject());
    		break;
    	case 'tick-bar' :
    		this.set('param-drawing-object', new amdaPlotObj.PlotTickBarObject());
    		break;
    	default :
    		this.set('param-drawing-object', null);
    	}
    	
    	//Set drawing object to default status
    	if (this.get('param-drawing-object') != null)
    		this.get('param-drawing-object').setDefaultValues();
    },
    
    getAvailableDrawingObjectByPlotType: function(plotType) {
    	switch (plotType)
    	{
    	case 'timePlot'  :
    	case 'epochPlot' :
    		return [
    		        {'key' : 'serie', 'value' : 'Serie'},
    		        {'key' : 'spectro', 'value' : 'Spectro'},
    		        {'key' : 'tick-bar', 'value' : 'Tick Bar'},
    		        {'key' : 'status-bar', 'value' : 'Status Bar'}
    		];
    	case 'xyPlot' :
    		return [
    		        {'key' : 'serie', 'value' : 'Serie'},
    		        {'key' : 'orbit-serie', 'value' : 'Orbit Serie'} 
    		];
    	case 'instantPlot' :
    		return [
    		        {'key' : 'serie', 'value' : 'Serie'},
    		        {'key' : 'spectro', 'value' : 'Spectro'}
    		];
    	case 'statusPlot' :
    		return [
    		        {'key' : 'status-bar', 'value' : 'Status Bar'}
    		];
    	case 'tickPlot' :
    		return [
    		        {'key' : 'tick-bar', 'value' : 'Tick Bar'}
    		];
    	}
    	return [];
    },
    
    setDefaultValues: function(type)
    {
    	this.updateDrawingType(type, true);
    },
    
    getJsonValues : function() 
    {
    	var paramValues  = new Object();
    	
    	paramValues['param-id'] = this.get('param-id');
    	paramValues['param-drawing-type'] = this.get('param-drawing-type');
    	
    	if (this.get('param-drawing-object') != null)
    		paramValues['param-drawing-object'] = this.get('param-drawing-object').getJsonValues();
    	
    	return paramValues;
    }
});