PlotCurveForm.js 3.49 KB
/**
 * Project   : AMDA-NG
 * Name      : PlotCurveForm.js
 * @class   amdaPlotComp.PlotCurveForm
 * @extends amdaPlotComp.PlotStandardForm
 * @brief   Form to define specifics curve options
 * @author  Benjamin Renard
 * @version $Id: PlotCurveForm.js benjamin $
 */

Ext.define('amdaPlotComp.PlotCurveForm', {
	extend: 'amdaPlotComp.PlotStandardForm',
	
	requires: [
	           'amdaPlotObj.PlotCurveDef'
	],
	
	curveParamsContainer : null,
	
	setObject : function(object) {
		this.object = object;
		if (this.object != null)
		{
			this.updateSerieIdList();
			this.loadRecord(this.object);
			this.updateParamsContainer();
		}
	},
	
	updateParamsContainer: function() {
		if (this.curveParamsContainer == null)
			return;
		
		var curveNameField = this.getForm().findField('curve-name');
		
		this.curveParamsContainer.removeAll();
		
		if (curveNameField.getValue() == '')
			return;
		
		var me = this;
		this.object.params().each(function (param) {
			if (param.get('curve-param-internal'))
				return;
			
			var newParamField = Ext.create('Ext.form.field.Number', {
				name: param.get('curve-param-name'),
				fieldLabel: param.get('curve-param-name'),
				decimalPrecision : 3,
				value: param.get('curve-param-value'),
				listeners: {
					change: function(field, newValue, oldValue, eOpts) {
						param.set(param.get('curve-param-name'), newValue);
					},
					scope: me
				}
			});
			me.curveParamsContainer.add(newParamField);
		});
	},
	
	updateCurveList: function(onReady) {
		var curvesDefStore = Ext.data.StoreManager.lookup('curvesDefStore');

		var curveNameField = this.getForm().findField('curve-name');
		
		if (!curvesDefStore)
		{
			curvesDefStore = Ext.create('Ext.data.Store', {
				model: 'amdaPlotObj.PlotCurveDef',
				storeId: 'curvesDefStore'
			});
			
			curveNameField.getStore().removeAll();
			curvesDefStore.load({
				scope: this,
				callback: function(records, operation, success) {
					curvesDefStore.each(function (curveDef) {
						curveNameField.getStore().add({key : curveDef.get('id'), value : curveDef.get('name')});
					});
					if (onReady != null)
						onReady();
				}
			});
		}
		else
		{
			curveNameField.getStore().removeAll();
			curvesDefStore.each(function (curveDef) {
				curveNameField.getStore().add({key : curveDef.get('id'), value : curveDef.get('name')});
			});
			if (onReady != null)
				onReady();
		}
	},
	
	updateSerieIdList: function() {
		var attachedSerieField = this.getForm().findField('curve-serie-id');
		attachedSerieField.getStore().removeAll();
		
		var panelObject = this.crtTree.getSelectedPanelObject();
		if (panelObject == null)
			return;
		
		panelObject.params().each(function(paramObject) {
			var drawingType = paramObject.get('param-drawing-type');
			if ((drawingType == 'serie') || (drawingType == 'orbit-serie'))
			{
				attachedSerieField.getStore().add({key : paramObject.get('id'), value : paramObject.getShortInfo(panelObject.get('panel-plot-type'))});
			}
		});
	},
	
	getFormItems: function() {
		var me = this;
		
		this.curveParamsContainer = Ext.create('Ext.container.Container', {
			layout: 'fit'
		});
		
		return [
		        this.addStandardCombo('curve-name', 'Curve name', [], function(name, value, oldValue) {
		        	me.object.setCurveName(value, function (){
		        		me.updateParamsContainer();
		        	});
		        }),
		        this.addStandardCombo('curve-serie-id', 'Attached serie', []),
		        this.addStandardFieldSet('Lines', '', this.addStandardLineItems('curve-line')),
		        this.curveParamsContainer
        ];
	}
});