PlotElementPanel.js 7.44 KB
/**
 * Project   : AMDA-NG
 * Name      : PlotElementPanel.js
 * @class   amdaPlotComp.PlotElementPanel
 * @extends Ext.form.Panel
 * @brief   Element of a plot request definition
 * @author  Benjamin Renard
 * @version $Id: PlotElementPanel.js benjamin $
 */

Ext.define('amdaPlotComp.PlotElementPanel', {
	extend: 'Ext.form.Panel',
	
	requires: [
	           'amdaPlotComp.PlotPageForm',
	           'amdaPlotComp.PlotPanelForm',
	           'amdaPlotComp.PlotBaseAxisForm',
	           'amdaPlotComp.PlotTimeAxisForm',
	           'amdaPlotComp.PlotEpochAxisForm',
	           'amdaPlotComp.PlotColorAxisForm',
	           'amdaPlotComp.PlotParamForm',
	           'amdaPlotComp.PlotLayoutForm',
	           'amdaPlotComp.PlotLegendSeriesForm',
	           'amdaPlotComp.PlotLegendTextForm',
	           'amdaPlotComp.PlotLegendsTextForm',
	           'amdaPlotComp.PlotDrawingObjectForm',
	           'amdaPlotComp.PlotConstantForm',
	           'amdaPlotComp.PlotTextForm',
	           'amdaPlotComp.PlotCurveForm',
	           'amdaPlotComp.PlotFillsForm',
	           'amdaPlotComp.PlotFillForm'
	],
	
	elementFormsManager : new Ext.AbstractManager(),
	
	crtTree   : null,
	
	constructor: function(config) {
		this.init(config);	    
		this.callParent(arguments);
	},
	
	destroy: function() {
		this.elementFormsManager.each(function (key, value, length) {
			this.elementFormsManager.unregister(value);
    	}, this);
		this.callParent();
	},
	
	setElement: function(type, object, tree) {
		this.removeAll(false);
		
		this.crtTree   = tree;
		
		var me =this;
		this.getElementForm(type, function (elementForm) {
			me.add(elementForm);
			elementForm.crtTree = tree;
			if (elementForm.setObject)
				elementForm.setObject(object);
		});
	},
	
	resetElement: function() {
		this.setElement('',null,null);
	},
	
	getElementForm: function(type, onFormReady) {
		var formId = type;
		if (type == '')
			formId = 'none';

		formId += '-element-form';
		
		if (this.rendered)
			this.getEl().mask();
			
		var me = this;
		if (!this.elementFormsManager.get(formId))
		{
			//Create element form
			switch (type)
			{
			case 'page' :
				this.elementFormsManager.register(new amdaPlotComp.PlotPageForm({id : formId}));
				if (onFormReady != null)
					onFormReady(this.elementFormsManager.get(formId));
				if (this.rendered)
					this.getEl().unmask();
				break;
			case 'panel' :
				this.elementFormsManager.register(new amdaPlotComp.PlotPanelForm({id : formId}));
				if (onFormReady != null)
					onFormReady(this.elementFormsManager.get(formId));
				if (this.rendered)
					this.getEl().unmask();
				break;
			case 'time-axis' :
				this.elementFormsManager.register(new amdaPlotComp.PlotTimeAxisForm({id : formId}));
				if (onFormReady != null)
					onFormReady(this.elementFormsManager.get(formId));
				if (this.rendered)
					this.getEl().unmask();
				break;
			case 'epoch-axis' :
				this.elementFormsManager.register(new amdaPlotComp.PlotEpochAxisForm({id : formId}));
				if (onFormReady != null)
					onFormReady(this.elementFormsManager.get(formId));
				if (this.rendered)
					this.getEl().unmask();
				break;
			case 'color-axis' :
				this.elementFormsManager.register(new amdaPlotComp.PlotColorAxisForm({id : formId}));
				if (onFormReady != null)
					onFormReady(this.elementFormsManager.get(formId));
				if (this.rendered)
					this.getEl().unmask();
				break;
			case 'x-axis' :
			case 'y-left-axis' :
			case 'y-right-axis' :
				this.elementFormsManager.register(new amdaPlotComp.PlotBaseAxisForm({id : formId}));
				if (onFormReady != null)
					onFormReady(this.elementFormsManager.get(formId));
				if (this.rendered)
					this.getEl().unmask();
				break;
			case 'param' :
				this.elementFormsManager.register(new amdaPlotComp.PlotParamForm({id : formId}));
				if (onFormReady != null)
					onFormReady(this.elementFormsManager.get(formId));
				if (this.rendered)
					this.getEl().unmask();
				break;
			case 'layout' :
				this.elementFormsManager.register(new amdaPlotComp.PlotLayoutForm({id : formId}));
				if (onFormReady != null)
					onFormReady(this.elementFormsManager.get(formId));
				if (this.rendered)
					this.getEl().unmask();
				break;
			case 'series-legend' :
				this.elementFormsManager.register(new amdaPlotComp.PlotLegendSeriesForm({id : formId}));
				if (onFormReady != null)
					onFormReady(this.elementFormsManager.get(formId));
				if (this.rendered)
					this.getEl().unmask();
				break;
			case 'text-legend' :
				this.elementFormsManager.register(new amdaPlotComp.PlotLegendTextForm({id : formId}));
				if (onFormReady != null)
					onFormReady(this.elementFormsManager.get(formId));
				if (this.rendered)
					this.getEl().unmask();
				break;
			case 'text-legends' :
				this.elementFormsManager.register(new amdaPlotComp.PlotLegendsTextForm({id : formId}));
				if (onFormReady != null)
					onFormReady(this.elementFormsManager.get(formId));
				if (this.rendered)
					this.getEl().unmask();
				break;
			case 'drawing-objects' :
				this.elementFormsManager.register(new amdaPlotComp.PlotDrawingObjectForm({id : formId}));
				if (onFormReady != null)
					onFormReady(this.elementFormsManager.get(formId));
				if (this.rendered)
					this.getEl().unmask();
				break;
			case 'constant' :
				this.elementFormsManager.register(new amdaPlotComp.PlotConstantForm({id : formId}));
				if (onFormReady != null)
					onFormReady(this.elementFormsManager.get(formId));
				if (this.rendered)
					this.getEl().unmask();
				break;
			case 'text-obj' :
				this.elementFormsManager.register(new amdaPlotComp.PlotTextForm({id : formId}));
				if (onFormReady != null)
					onFormReady(this.elementFormsManager.get(formId));
				if (this.rendered)
					this.getEl().unmask();
				break;
			case 'curve' :
				var curveForm = new amdaPlotComp.PlotCurveForm({id : formId});
				this.elementFormsManager.register(curveForm);
				curveForm.updateCurveList(function () {
					if (onFormReady != null)
						onFormReady(me.elementFormsManager.get(formId));
					if (me.rendered)
						me.getEl().unmask();
				});
				break;
			case 'fills' :
				this.elementFormsManager.register(new amdaPlotComp.PlotFillsForm({id : formId}));
				if (onFormReady != null)
					onFormReady(this.elementFormsManager.get(formId));
				if (this.rendered)
					this.getEl().unmask();
				break;
			case 'fill' :
				this.elementFormsManager.register(new amdaPlotComp.PlotFillForm({id : formId}));
				if (onFormReady != null)
					onFormReady(this.elementFormsManager.get(formId));
				if (this.rendered)
					this.getEl().unmask();
				break;
			case '' :
				this.elementFormsManager.register(new Ext.form.Label({id : formId, text: 'Select an element to the tree to show options'}));
				if (onFormReady != null)
					onFormReady(this.elementFormsManager.get(formId));
				if (this.rendered)
					this.getEl().unmask();
				break;
			default :
				this.elementFormsManager.register(new Ext.form.Label({id : formId, text: 'No available options for this element'}));
				if (onFormReady != null)
					onFormReady(this.elementFormsManager.get(formId));
				if (this.rendered)
					this.getEl().unmask();
			}
			return;
		}
		
		if (this.rendered)
			this.getEl().unmask();
		
		if (onFormReady != null)
			onFormReady(this.elementFormsManager.get(formId));
	},
	
	init : function(config) {
		var me = this;
		
		var myConf = {
				title : 'Selected element options',
	        	bodyStyle: { background : '#dfe8f6' },
	        	autoScroll: true,
				defaults: {
					border: false
				}
		};
		
		Ext.apply (this , Ext.apply (arguments, myConf));
	}
});