PlotTabObject.js 11.7 KB
/**
 * Project      : AMDA-NG
 * Name         : PlotTabObject.js
 * @class   amdaPlotObj.PlotTabObject
 * @extends amdaModel.AmdaTimeObject
 * @brief   Plot Tab Business Object Definition 
 * @author  Benjamin Renard
 * @version $Id: PlotTabObject.js benjamin $
 ******************************************************************************
 *    FT Id     :   Date   : Name - Description
 ******************************************************************************
 *	:           :22/07/2015: BRE  - file creation
 */
 
 		
Ext.define('amdaPlotObj.PlotTabObject', {
	extend: 'amdaModel.AmdaTimeObject',
	idProperty: 'id',
	
	requires: [
	           'amdaPlotObj.PlotObjectConfig',
	           'amdaPlotObj.PlotPanelObject',
	           'amdaPlotObj.PlotLayoutVerticalObject',
	           'amdaPlotObj.PlotLayoutAutoObject',
	           'amdaPlotObj.PlotLayoutManualObject'
	],
	
	fields : [
	          {name: 'id', type: 'int'},
                  {name: 'tab-name', type: 'string', defaultValue: ''},
	          {name: 'tree-full-view', type: 'boolean'},
	          {name: 'multi-plot-linked', type: 'boolean'},
	          {name: 'page-node-state', type: 'int', defaultValue: 2}, //0 : collapsed, 1 : expanded, 2 : not set 
	          {name: 'panels-node-state', type: 'int', defaultValue: 2},  //0 : collapsed, 1 : expanded, 2 : not set
	          {name: 'page-title-text', type: 'string'},
              {name: 'page-title-color', type: 'string'},
              {name: 'page-title-position', type: 'string'},
              {name: 'page-title-alignment', type: 'string'},
              {name: 'page-title-font-activated', type: 'boolean'},
              {name: 'page-title-font-name', type: 'string'},
              {name: 'page-title-font-size', type: 'int'},
              {name: 'page-title-font-bold', type: 'boolean'},
              {name: 'page-title-font-italic', type: 'boolean'},
              {name: 'page-margins-activated', type: 'boolean'},
              {name: 'page-margin-x', type: 'float'},
              {name: 'page-margin-y', type: 'float'},
              {name: 'page-mode', type: 'string'},
              {name: 'page-orientation', type: 'string'},
              {name: 'page-dimension', type: 'string'},
              {name: 'page-superpose-mode', type: 'boolean'},
              {name: 'page-font-activated', type: 'boolean'},
              {name: 'page-font-name', type: 'string'},
              {name: 'page-font-size', type: 'int'},
              {name: 'page-font-bold', type: 'boolean'},
              {name: 'page-font-italic', type: 'boolean'},
              {name: 'page-layout-type', type: 'string'},
              {name: 'page-layout-object', type: 'auto', defaultValue: null},
              {name: 'last-panel-id', type: 'int', defaultValue: 0}
    ],
    
    associations : [
              {
            	  type : 'hasMany', 
            	  model : 'amdaPlotObj.PlotPanelObject',
            	  name  : 'panels'
              },
              {
            	  type  : 'belongsTo',
                  model : 'amdaPlotObj.PlotRequestObject'
              }
    ],
    
    constructor: function(){
        var me = this;
        me.callParent(arguments);
        if ((arguments.length > 0) && arguments[0])
        {
        	if (arguments[0].panels)
        		me.loadPanels(arguments[0].panels);
        	if (arguments[0]['page-layout-object'])
        		me.loadLayoutObject(arguments[0]['page-layout-object']);
        }
        else
        {
        	//new object, set default fields values
        	me.setDefaultValues();
        }
        this.dirty = false;
    },
    
    loadPanels: function(panels)
    {
       this.panels().loadData(panels);
       this.updatePanelIndex();
    },
    
    loadLayoutObject: function(layout)
    {
    	this.set('page-layout-object', this.createLayoutByType(this.get('page-layout-type'), layout));
    	if (this.get('page-layout-object') != null)
    		this.get('page-layout-object').dirty = false;
    },
    
    createNewPanel: function() {
    	this.set('last-panel-id', this.get('last-panel-id') + 1);
    	var recs = this.panels().add({id : this.get('last-panel-id')});
    	recs[0].setDefaultValues();
    	this.dirty = true;
    	this.updatePanelIndex();
		return recs[0];
    },
    
    removePanelById: function(panelId) {
    	//Retrieve panel record
    	var panelRecord = this.panels().getById(panelId);
    	if (panelRecord == null)
    		return false;
    	this.panels().remove(panelRecord);
    	this.dirty = true;
    	this.updatePanelIndex();
    	return true;
    },
    
    updatePanelIndex: function() {
    	this.panels().each(function(panel, index) {
    		panel.set('panel-index', index);
    	});
    },
    
    createLayoutByType : function(layoutType, data)
    {
    	//Create layout object in relation with the type
    	switch (layoutType)
    	{
    	case 'vertical' :
    		return new amdaPlotObj.PlotLayoutVerticalObject(data);
    	case 'auto' :
    		return new amdaPlotObj.PlotLayoutAutoObject(data);
    	case 'manual' :
    		return new amdaPlotObj.PlotLayoutManualObject(data);
     	default :
     		return null;
    	}
    },
    
    setLayout: function(layoutType)
    {
    	if (layoutType == this.get('page-layout-type'))
    		return;
    	
    	this.set('page-layout-type', layoutType);
    	this.set('page-layout-object', this.createLayoutByType(layoutType));
    },
    
    setDefaultValues: function()
    {
    	this.set('tree-full-view', amdaPlotObj.PlotObjectConfig.defaultValues.tree.fullView);
    	
    	this.set('multi-plot-linked', false);
    	
    	this.set('page-title-text', '');
    	this.set('page-title-color', amdaPlotObj.PlotObjectConfig.defaultValues.page.title.color);
    	this.set('page-title-position', amdaPlotObj.PlotObjectConfig.defaultValues.page.title.position);
    	this.set('page-title-alignment', amdaPlotObj.PlotObjectConfig.defaultValues.page.title.alignment);
    	
    	this.set('page-title-font-activated', false);
    	this.set('page-title-font-name', amdaPlotObj.PlotObjectConfig.defaultValues.page.font.name);
    	this.set('page-title-font-size', amdaPlotObj.PlotObjectConfig.defaultValues.page.font.size);
    	this.set('page-title-font-bold', false);
    	this.set('page-title-font-italic', false);
    	
    	this.set('page-margins-activated', false);
    	this.set('page-margin-x', amdaPlotObj.PlotObjectConfig.defaultValues.page.xMargin);
    	this.set('page-margin-y', amdaPlotObj.PlotObjectConfig.defaultValues.page.yMargin);
    	this.set('page-mode', amdaPlotObj.PlotObjectConfig.defaultValues.page.mode);
    	this.set('page-orientation', amdaPlotObj.PlotObjectConfig.defaultValues.page.orientation);
    	this.set('page-dimension', amdaPlotObj.PlotObjectConfig.defaultValues.page.dimension);
    	this.set('page-superpose-mode', false);
    	this.set('page-font-activated', false);
    	this.set('page-font-name', amdaPlotObj.PlotObjectConfig.defaultValues.page.font.name);
    	this.set('page-font-size', amdaPlotObj.PlotObjectConfig.defaultValues.page.font.size);
    	this.set('page-font-bold', false);
    	this.set('page-font-italic', false);
    	
    	this.setLayout(amdaPlotObj.PlotObjectConfig.defaultValues.page.layout.type);
    },
    
    getPageShortInfo : function()
    {
    	var dimension = amdaPlotObj.PlotObjectConfig.getValueByKey(amdaPlotObj.PlotObjectConfig.availablePageDimensions, this.get('page-dimension'));
		var orientation = amdaPlotObj.PlotObjectConfig.getValueByKey(amdaPlotObj.PlotObjectConfig.availablePageOrientations, this.get('page-orientation'));
		
		var info = dimension+', '+orientation;
		if (this.get('page-superpose-mode'))
			info += ', Epoch superposed mode';
		return info;
    },
    
    getLayoutShortInfo : function()
    {
    	var type = amdaPlotObj.PlotObjectConfig.getValueByKey(amdaPlotObj.PlotObjectConfig.availablePageLayouts, this.get('page-layout-type'));
		return type;
    },
    
    isDirty : function()
    {
    	if (this.dirty)
    		return true;
    	
    	if (this.get('page-layout-object') != null)
    		if (this.get('page-layout-object').dirty)
    			return true;
    	
    	var d = false;
    	this.panels().each(function (panel, index) {
    		if (panel.isDirty())
    			d = true;
    	});
    	return d;
    },
    
    getJsonValues : function() 
    {
    	var tabValues  = new Object();
    	
    	tabValues['id'] = this.get('id');
	tabValues['tab-name'] = this.get('tab-name');
    	tabValues['tree-full-view'] = this.get('tree-full-view');
    	tabValues['multi-plot-linked'] = this.get('multi-plot-linked');
    	tabValues['page-node-state'] = this.get('page-node-state');
    	tabValues['panels-node-state'] = this.get('panels-node-state');
    	tabValues['page-title-text'] = this.get('page-title-text');
    	tabValues['page-title-color'] = this.get('page-title-color');
    	tabValues['page-title-position'] = this.get('page-title-position');
    	tabValues['page-title-alignment'] = this.get('page-title-alignment');
    	tabValues['page-title-font-activated'] = this.get('page-title-font-activated');
    	tabValues['page-title-font-name'] = this.get('page-title-font-name');
    	tabValues['page-title-font-size'] = this.get('page-title-font-size');
    	tabValues['page-title-font-bold'] = this.get('page-title-font-bold');
    	tabValues['page-title-font-italic'] = this.get('page-title-font-italic');
    	tabValues['page-margins-activated'] = this.get('page-margins-activated');
    	tabValues['page-margin-x'] = this.get('page-margin-x');
    	tabValues['page-margin-y'] = this.get('page-margin-y');
    	tabValues['page-mode'] = this.get('page-mode');
    	tabValues['page-orientation'] = this.get('page-orientation');
    	tabValues['page-dimension'] = this.get('page-dimension');
    	tabValues['page-superpose-mode'] = this.get('page-superpose-mode');
    	tabValues['page-font-activated'] = this.get('page-font-activated');
    	tabValues['page-font-name'] = this.get('page-font-name');
    	tabValues['page-font-size'] = this.get('page-font-size');
    	tabValues['page-font-bold'] = this.get('page-font-bold');
    	tabValues['page-font-italic'] = this.get('page-font-italic');
    	
    	tabValues['timesrc'] =  this.get('timesrc');       
        // if there's at least one timeTable name into 'timeTables' collection
        if (this.get('timesrc') == amdaModel.AmdaTimeObject.inputTimeSrc[0] && this.get('timeTables') && this.get('timeTables').length){
            // get complete timeTables collection
            var timeTables = this.get('timeTables');	    
            // init an empty array for timeTables
            tabValues['timeTables'] = [];
            // for each interval record
            Ext.Array.each(timeTables, function(item, index, all){
            	if (!item.$className) {
            		tabValues['timeTables'][index] = {timeTableName : item.timeTableName, id : item.id};
            	}
            	// get Json simplified value 
            	else {
            		tabValues['timeTables'][index] = item.getJsonValues();
            	}
            });            
        } else {
        	tabValues['startDate'] = this.get('startDate');	
            tabValues['stopDate'] = this.get('stopDate'); 
            tabValues['durationDay'] = this.get('durationDay');
            tabValues['durationHour'] = this.get('durationHour');
            tabValues['durationMin'] = this.get('durationMin');
            tabValues['durationSec'] = this.get('durationSec');
        }
    	
    	tabValues['page-layout-type'] = this.get('page-layout-type');
    	if (this.get('page-layout-object') != null)
    		tabValues['page-layout-object'] = this.get('page-layout-object').getJsonValues();
    	
    	tabValues['panels'] = [];
    	
    	this.panels().each(function (panel, index) {
    		tabValues['panels'][index] = panel.getJsonValues();
    	});
    	
    	tabValues['last-panel-id'] = this.get('last-panel-id');
    	
    	return tabValues;
    }
});