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

Ext.define('amdaPlotComp.PlotParamForm', {
	extend: 'amdaPlotComp.PlotStandardForm',
	
	requires: [
	    'amdaPlotComp.PlotSerieForm',
	    'amdaPlotComp.PlotSpectroForm',
	    'amdaPlotComp.PlotStatusBarForm',
	    'amdaPlotComp.PlotTickBarForm',
	    'amdaPlotComp.PlotInstantSerieForm',
	    'amdaPlotComp.PlotInstantSpectroForm'
	],
	
	drawingOptionsContainer: null,
	
	drawingOptionsFormsManager : new Ext.AbstractManager(),
	
	destroy: function() {
		this.drawingOptionsFormsManager.each(function (key, value, length) {
    		this.drawingOptionsFormsManager.unregister(value);
    	}, this);
		this.callParent();
	},
	
	setObject : function(object) {
		this.object = object;
		this.loadRecord(this.object);
		this.updateDrawingOptions(this.object.get('param-drawing-type'));
	},
	
	getDrawingOptionsForm: function(type) {
		var formId = '';
		if (!type || (type == ''))
			formId = 'none';
		else
			formId = type;
		
		formId += '-drawing-options-form';
		
		if (!this.drawingOptionsFormsManager.get(formId))
		{
			switch(type)
			{
				//Create drawing options form
				case 'serie' :
					this.drawingOptionsFormsManager.register(new amdaPlotComp.PlotSerieForm({id : formId}));
					break;
				case 'spectro' :
					this.drawingOptionsFormsManager.register(new amdaPlotComp.PlotSpectroForm({id : formId}));
					break;
				case 'status-bar' :
					this.drawingOptionsFormsManager.register(new amdaPlotComp.PlotStatusBarForm({id : formId}));
					break;
				case 'tick-bar' :
					this.drawingOptionsFormsManager.register(new amdaPlotComp.PlotTickBarForm({id : formId}));
					break;
				case 'iserie' :
					this.drawingOptionsFormsManager.register(new amdaPlotComp.PlotInstantSerieForm({id : formId}));
					break;
				case 'ispectro' :
					this.drawingOptionsFormsManager.register(new amdaPlotComp.PlotInstantSpectroForm({id : formId}));
					break;
 				default :
					this.drawingOptionsFormsManager.register(new Ext.form.Label({id : formId, text: 'No available options for this drawing type'}));
			}
		}
		
		return this.drawingOptionsFormsManager.get(formId);
	
	},
	
	updateDrawingOptions: function(drawingType) {
		var typeField = this.getForm().findField('param-drawing-type');
		
		var availableDrawingObjects = this.object.getAvailableDrawingObjectByPlotType(this.crtTree.getSelectedPlotType());
		typeField.getStore().loadData(availableDrawingObjects);
		typeField.suspendEvents();
		typeField.setValue(drawingType);
		typeField.resumeEvents(false);
		
		this.drawingOptionsContainer.removeAll(false);
		
		var drawingOptionsForm = this.getDrawingOptionsForm(drawingType);
		this.drawingOptionsContainer.add(drawingOptionsForm);
		drawingOptionsForm.crtTree = this.crtTree;
		if (drawingOptionsForm.setObject)
			drawingOptionsForm.setObject(this.object);
	},
	
	getFormItems: function() {
		var me = this;
		
		this.drawingOptionsContainer = Ext.create('Ext.container.Container', {
			layout: 'fit'
		});
		
		return [
		    this.addStandardCombo('param-drawing-type', 'Drawing type', [{'key' : '', 'value' : 'None'}], function(name, value, oldValue) {
		    	if (me.object.get('param-drawing-type') != value)
		    	{
		    		me.object.changeDrawingType(value);
		    		me.crtTree.getView().refresh();
		    		me.updateDrawingOptions(value);
		    	}
	        }),
	        this.drawingOptionsContainer
		];
	}
});