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

Ext.define('amdaPlotComp.PlotLayoutForm', {
	extend: 'amdaPlotComp.PlotStandardForm',

	requires: [
	   	    'amdaPlotComp.PlotLayoutVerticalForm',
	   	    'amdaPlotComp.PlotLayoutAutoForm',
	   	    'amdaPlotComp.PlotLayoutManualForm'
	],
	   	    
	layoutOptionsContainer: null,
	
	layoutOptionsFormsManager : new Ext.AbstractManager(),
	
	destroy: function() {
		this.layoutOptionsFormsManager.each(function (key, value, length) {
    		this.layoutOptionsFormsManager.unregister(value);
    	}, this);
		this.callParent();
	},
	
	setObject : function(object) {
		this.object = object;
		this.loadRecord(this.object);
		this.updateLayoutOptions();
	},
	
	getLayoutOptionsForm: function(type) {
		var formId = '';
		if (!type || (type == ''))
			formId = 'none';
		else
			formId = type;
		
		formId += '-layout-options-form';
		
		if (!this.layoutOptionsFormsManager.get(formId))
		{
			switch(type)
			{
				//Create layout options form
				case 'vertical' :
					this.layoutOptionsFormsManager.register(new amdaPlotComp.PlotLayoutVerticalForm({id : formId}));
					break;
				case 'auto' :
					this.layoutOptionsFormsManager.register(new amdaPlotComp.PlotLayoutAutoForm({id : formId}));
					break;
				case 'manual' :
					this.layoutOptionsFormsManager.register(new amdaPlotComp.PlotLayoutManualForm({id : formId}));
					break;
 				default :
					this.layoutOptionsFormsManager.register(new Ext.form.Label({id : formId, text: 'No available options for this layout type'}));
			}
		}
		
		return this.layoutOptionsFormsManager.get(formId);
	
	},
	
	updateLayoutOptions: function() {
		var typeField = this.getForm().findField('page-layout-type');
		var layoutType = typeField.getValue();
		this.object.setLayout(layoutType);
		
		this.layoutOptionsContainer.removeAll(false);
		
		var layoutOptionsForm = this.getLayoutOptionsForm(layoutType);
		this.layoutOptionsContainer.add(layoutOptionsForm);
		layoutOptionsForm.crtTree = this.crtTree;
		if (layoutOptionsForm.setObject)
			layoutOptionsForm.setObject(this.object);
	},
	
	getFormItems: function() {
		var me = this;
		
		this.layoutOptionsContainer = Ext.create('Ext.container.Container', {
			layout: 'fit'
		});
		
		return [
		    this.addStandardCombo('page-layout-type', 'Layout type', amdaPlotObj.PlotObjectConfig.availablePageLayouts, function(name, value, oldValue) {
		    	if (me.object.get('page-layout-type') != value)
		    	{
		    		me.updateLayoutOptions();
		    		me.crtTree.getView().refresh();
		    	}
	        }),
	        this.layoutOptionsContainer
		];
	}
});