Blame view

js/app/models/PlotObjects/PlotTabObject.js 11.7 KB
437c4dbc   Benjamin Renard   First implementat...
1
2
3
4
/**
 * Project      : AMDA-NG
 * Name         : PlotTabObject.js
 * @class   amdaPlotObj.PlotTabObject
27b2a53e   Benjamin Renard   Link tab plot to ...
5
 * @extends amdaModel.AmdaTimeObject
437c4dbc   Benjamin Renard   First implementat...
6
7
8
9
10
11
12
13
14
15
16
 * @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', {
27b2a53e   Benjamin Renard   Link tab plot to ...
17
	extend: 'amdaModel.AmdaTimeObject',
abe09878   Benjamin Renard   Add panels and ax...
18
19
	idProperty: 'id',
	
437c4dbc   Benjamin Renard   First implementat...
20
	requires: [
abe09878   Benjamin Renard   Add panels and ax...
21
	           'amdaPlotObj.PlotObjectConfig',
003ba315   Benjamin Renard   Add Epoch Plot an...
22
23
24
25
	           'amdaPlotObj.PlotPanelObject',
	           'amdaPlotObj.PlotLayoutVerticalObject',
	           'amdaPlotObj.PlotLayoutAutoObject',
	           'amdaPlotObj.PlotLayoutManualObject'
437c4dbc   Benjamin Renard   First implementat...
26
27
28
	],
	
	fields : [
fd5552a4   Benjamin Renard   Info for plot ele...
29
	          {name: 'id', type: 'int'},
f31bea1c   Benjamin Renard   wip for save plot
30
                  {name: 'tab-name', type: 'string', defaultValue: ''},
8816e270   Elena.Budnik   simplified vies c...
31
	          {name: 'tree-full-view', type: 'boolean'},
27b2a53e   Benjamin Renard   Link tab plot to ...
32
	          {name: 'multi-plot-linked', type: 'boolean'},
2a0b8d2c   Benjamin Renard   Restore node stat...
33
34
35
	          {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'},
437c4dbc   Benjamin Renard   First implementat...
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
              {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'},
003ba315   Benjamin Renard   Add Epoch Plot an...
55
56
              {name: 'page-font-italic', type: 'boolean'},
              {name: 'page-layout-type', type: 'string'},
dbb7bcbe   Benjamin Renard   Add curves defint...
57
58
              {name: 'page-layout-object', type: 'auto', defaultValue: null},
              {name: 'last-panel-id', type: 'int', defaultValue: 0}
437c4dbc   Benjamin Renard   First implementat...
59
60
61
62
    ],
    
    associations : [
              {
abe09878   Benjamin Renard   Add panels and ax...
63
64
65
66
67
            	  type : 'hasMany', 
            	  model : 'amdaPlotObj.PlotPanelObject',
            	  name  : 'panels'
              },
              {
437c4dbc   Benjamin Renard   First implementat...
68
            	  type  : 'belongsTo',
17433635   Benjamin Renard   Add series and sp...
69
                  model : 'amdaPlotObj.PlotRequestObject'
437c4dbc   Benjamin Renard   First implementat...
70
71
72
              }
    ],
    
18d4a11e   Benjamin Renard   Save and load plo...
73
74
75
    constructor: function(){
        var me = this;
        me.callParent(arguments);
18d4a11e   Benjamin Renard   Save and load plo...
76
77
78
79
80
81
82
83
84
85
86
87
        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();
        }
a971060f   Benjamin Renard   Fix some bugs
88
        this.dirty = false;
18d4a11e   Benjamin Renard   Save and load plo...
89
90
91
92
93
    },
    
    loadPanels: function(panels)
    {
       this.panels().loadData(panels);
509bf9fa   Benjamin Renard   Replace panel ID ...
94
       this.updatePanelIndex();
18d4a11e   Benjamin Renard   Save and load plo...
95
96
97
98
    },
    
    loadLayoutObject: function(layout)
    {
a971060f   Benjamin Renard   Fix some bugs
99
100
101
    	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;
18d4a11e   Benjamin Renard   Save and load plo...
102
103
    },
    
abe09878   Benjamin Renard   Add panels and ax...
104
    createNewPanel: function() {
dbb7bcbe   Benjamin Renard   Add curves defint...
105
106
    	this.set('last-panel-id', this.get('last-panel-id') + 1);
    	var recs = this.panels().add({id : this.get('last-panel-id')});
abe09878   Benjamin Renard   Add panels and ax...
107
    	recs[0].setDefaultValues();
a971060f   Benjamin Renard   Fix some bugs
108
    	this.dirty = true;
509bf9fa   Benjamin Renard   Replace panel ID ...
109
    	this.updatePanelIndex();
abe09878   Benjamin Renard   Add panels and ax...
110
111
112
		return recs[0];
    },
    
17433635   Benjamin Renard   Add series and sp...
113
114
115
116
117
118
    removePanelById: function(panelId) {
    	//Retrieve panel record
    	var panelRecord = this.panels().getById(panelId);
    	if (panelRecord == null)
    		return false;
    	this.panels().remove(panelRecord);
a971060f   Benjamin Renard   Fix some bugs
119
    	this.dirty = true;
509bf9fa   Benjamin Renard   Replace panel ID ...
120
    	this.updatePanelIndex();
17433635   Benjamin Renard   Add series and sp...
121
122
123
    	return true;
    },
    
509bf9fa   Benjamin Renard   Replace panel ID ...
124
125
126
127
128
129
    updatePanelIndex: function() {
    	this.panels().each(function(panel, index) {
    		panel.set('panel-index', index);
    	});
    },
    
a971060f   Benjamin Renard   Fix some bugs
130
    createLayoutByType : function(layoutType, data)
003ba315   Benjamin Renard   Add Epoch Plot an...
131
    {
003ba315   Benjamin Renard   Add Epoch Plot an...
132
133
134
135
    	//Create layout object in relation with the type
    	switch (layoutType)
    	{
    	case 'vertical' :
a971060f   Benjamin Renard   Fix some bugs
136
    		return new amdaPlotObj.PlotLayoutVerticalObject(data);
003ba315   Benjamin Renard   Add Epoch Plot an...
137
    	case 'auto' :
a971060f   Benjamin Renard   Fix some bugs
138
    		return new amdaPlotObj.PlotLayoutAutoObject(data);
003ba315   Benjamin Renard   Add Epoch Plot an...
139
    	case 'manual' :
a971060f   Benjamin Renard   Fix some bugs
140
    		return new amdaPlotObj.PlotLayoutManualObject(data);
003ba315   Benjamin Renard   Add Epoch Plot an...
141
     	default :
a971060f   Benjamin Renard   Fix some bugs
142
     		return null;
003ba315   Benjamin Renard   Add Epoch Plot an...
143
    	}
a971060f   Benjamin Renard   Fix some bugs
144
145
146
147
148
149
    },
    
    setLayout: function(layoutType)
    {
    	if (layoutType == this.get('page-layout-type'))
    		return;
003ba315   Benjamin Renard   Add Epoch Plot an...
150
    	
a971060f   Benjamin Renard   Fix some bugs
151
152
    	this.set('page-layout-type', layoutType);
    	this.set('page-layout-object', this.createLayoutByType(layoutType));
003ba315   Benjamin Renard   Add Epoch Plot an...
153
154
    },
    
437c4dbc   Benjamin Renard   First implementat...
155
156
    setDefaultValues: function()
    {
8816e270   Elena.Budnik   simplified vies c...
157
    	this.set('tree-full-view', amdaPlotObj.PlotObjectConfig.defaultValues.tree.fullView);
27b2a53e   Benjamin Renard   Link tab plot to ...
158
159
160
    	
    	this.set('multi-plot-linked', false);
    	
437c4dbc   Benjamin Renard   First implementat...
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
    	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);
003ba315   Benjamin Renard   Add Epoch Plot an...
184
    	
a971060f   Benjamin Renard   Fix some bugs
185
    	this.setLayout(amdaPlotObj.PlotObjectConfig.defaultValues.page.layout.type);
437c4dbc   Benjamin Renard   First implementat...
186
187
    },
    
fd5552a4   Benjamin Renard   Info for plot ele...
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
    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;
    },
    
a971060f   Benjamin Renard   Fix some bugs
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
    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;
    },
    
17433635   Benjamin Renard   Add series and sp...
222
    getJsonValues : function() 
437c4dbc   Benjamin Renard   First implementat...
223
224
225
    {
    	var tabValues  = new Object();
    	
dbb7bcbe   Benjamin Renard   Add curves defint...
226
    	tabValues['id'] = this.get('id');
f31bea1c   Benjamin Renard   wip for save plot
227
	tabValues['tab-name'] = this.get('tab-name');
8816e270   Elena.Budnik   simplified vies c...
228
    	tabValues['tree-full-view'] = this.get('tree-full-view');
27b2a53e   Benjamin Renard   Link tab plot to ...
229
    	tabValues['multi-plot-linked'] = this.get('multi-plot-linked');
2a0b8d2c   Benjamin Renard   Restore node stat...
230
231
    	tabValues['page-node-state'] = this.get('page-node-state');
    	tabValues['panels-node-state'] = this.get('panels-node-state');
437c4dbc   Benjamin Renard   First implementat...
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
    	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');
    	
27b2a53e   Benjamin Renard   Link tab plot to ...
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
    	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');
        }
    	
003ba315   Benjamin Renard   Add Epoch Plot an...
280
281
282
283
    	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();
    	
abe09878   Benjamin Renard   Add panels and ax...
284
285
286
287
288
289
    	tabValues['panels'] = [];
    	
    	this.panels().each(function (panel, index) {
    		tabValues['panels'][index] = panel.getJsonValues();
    	});
    	
dbb7bcbe   Benjamin Renard   Add curves defint...
290
291
    	tabValues['last-panel-id'] = this.get('last-panel-id');
    	
437c4dbc   Benjamin Renard   First implementat...
292
293
    	return tabValues;
    }
f31bea1c   Benjamin Renard   wip for save plot
294
});