Blame view

js/app/models/PlotObjects/PlotRequestObject.js 12.8 KB
437c4dbc   Benjamin Renard   First implementat...
1
2
3
4
5
6
7
/**
 * Project      : AMDA-NG
 * Name         : PlotRequestObject.js
 * @class   amdaPlotObj.PlotRequestObject
 * @extends amdaModel.AmdaTimeObject
 * @brief   Plot Request Business Object Definition 
 * @author  Benjamin Renard
940afd8d   Benjamin Renard   Introduce multipl...
8
 * @version $Id: PlotTabObject.js benjamin $
437c4dbc   Benjamin Renard   First implementat...
9
10
11
 ******************************************************************************
 *    FT Id     :   Date   : Name - Description
 ******************************************************************************
940afd8d   Benjamin Renard   Introduce multipl...
12
13
 *	:           :22/07/2015: BRE  - file creation
 *	             20/03/2020: BRE  - full rework
437c4dbc   Benjamin Renard   First implementat...
14
15
16
17
18
19
20
 */
 
 		
Ext.define('amdaPlotObj.PlotRequestObject', {
	extend: 'amdaModel.AmdaTimeObject',
	idProperty: 'id',
	
437c4dbc   Benjamin Renard   First implementat...
21
22
	requires: [
	           'amdaPlotObj.PlotObjectConfig',
940afd8d   Benjamin Renard   Introduce multipl...
23
24
25
26
	           'amdaPlotObj.PlotPanelObject',
	           'amdaPlotObj.PlotLayoutVerticalObject',
	           'amdaPlotObj.PlotLayoutAutoObject',
	           'amdaPlotObj.PlotLayoutManualObject'
437c4dbc   Benjamin Renard   First implementat...
27
28
29
	],
	
	fields : [
d29f5012   Benjamin Renard   Fix doPlot
30
31
              {name: 'tab-index', type: 'int', defaultValue: 0, persist: false},
              {name: 'tab-title', type: 'string', defaultValue: '', persist: false},
4efeb459   Benjamin Renard   First version for...
32
              {name: 'multi-selected', type: 'boolean', defaultValue: false, persist: false},
940afd8d   Benjamin Renard   Introduce multipl...
33

437c4dbc   Benjamin Renard   First implementat...
34
35
36
              {name: 'file-format', type: 'string'},
              {name: 'file-output', type: 'string'},
              {name: 'file-prefix', type: 'string'},
dbb7bcbe   Benjamin Renard   Add curves defint...
37
              {name: 'one-file-per-interval', type: 'boolean'},
940afd8d   Benjamin Renard   Introduce multipl...
38
39

	      {name: 'tree-full-view', type: 'boolean'},
940afd8d   Benjamin Renard   Introduce multipl...
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
	      {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}
437c4dbc   Benjamin Renard   First implementat...
67
68
    ],
    
940afd8d   Benjamin Renard   Introduce multipl...
69
70
71
72
73
74
75
    associations : [
              {
            	  type : 'hasMany', 
            	  model : 'amdaPlotObj.PlotPanelObject',
            	  name  : 'panels'
              }
    ],
18d4a11e   Benjamin Renard   Save and load plo...
76
77
    
    constructor: function(){
940afd8d   Benjamin Renard   Introduce multipl...
78
79
80
        var me = this;
        me.callParent(arguments);
        if ((arguments.length > 0) && arguments[0])
18d4a11e   Benjamin Renard   Save and load plo...
81
        {
940afd8d   Benjamin Renard   Introduce multipl...
82
83
84
85
        	if (arguments[0].panels)
        		me.loadPanels(arguments[0].panels);
        	if (arguments[0]['page-layout-object'])
        		me.loadLayoutObject(arguments[0]['page-layout-object']);
18d4a11e   Benjamin Renard   Save and load plo...
86
87
88
89
90
        }
        else
        {
        	//new object, set default fields values
        	me.setDefaultValues();
18d4a11e   Benjamin Renard   Save and load plo...
91
        }
940afd8d   Benjamin Renard   Introduce multipl...
92
        this.dirty = false;
18d4a11e   Benjamin Renard   Save and load plo...
93
94
    },
    
940afd8d   Benjamin Renard   Introduce multipl...
95
    loadPanels: function(panels)
18d4a11e   Benjamin Renard   Save and load plo...
96
    {
940afd8d   Benjamin Renard   Introduce multipl...
97
98
       this.panels().loadData(panels);
       this.updatePanelIndex();
437c4dbc   Benjamin Renard   First implementat...
99
100
    },
    
940afd8d   Benjamin Renard   Introduce multipl...
101
    loadLayoutObject: function(layout)
437c4dbc   Benjamin Renard   First implementat...
102
    {
940afd8d   Benjamin Renard   Introduce multipl...
103
104
105
    	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;
437c4dbc   Benjamin Renard   First implementat...
106
107
    },
    
940afd8d   Benjamin Renard   Introduce multipl...
108
109
110
111
    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();
a971060f   Benjamin Renard   Fix some bugs
112
    	this.dirty = true;
940afd8d   Benjamin Renard   Introduce multipl...
113
114
    	this.updatePanelIndex();
		return recs[0];
abe09878   Benjamin Renard   Add panels and ax...
115
116
    },
    
940afd8d   Benjamin Renard   Introduce multipl...
117
118
119
120
    removePanelById: function(panelId) {
    	//Retrieve panel record
    	var panelRecord = this.panels().getById(panelId);
    	if (panelRecord == null)
dbb7bcbe   Benjamin Renard   Add curves defint...
121
    		return false;
940afd8d   Benjamin Renard   Introduce multipl...
122
    	this.panels().remove(panelRecord);
a971060f   Benjamin Renard   Fix some bugs
123
    	this.dirty = true;
940afd8d   Benjamin Renard   Introduce multipl...
124
    	this.updatePanelIndex();
dbb7bcbe   Benjamin Renard   Add curves defint...
125
    	return true;
abe09878   Benjamin Renard   Add panels and ax...
126
127
    },
    
940afd8d   Benjamin Renard   Introduce multipl...
128
129
130
131
132
133
134
    updatePanelIndex: function() {
    	this.panels().each(function(panel, index) {
    		panel.set('panel-index', index);
    	});
    },
    
    createLayoutByType : function(layoutType, data)
a971060f   Benjamin Renard   Fix some bugs
135
    {
940afd8d   Benjamin Renard   Introduce multipl...
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
    	//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('file-format', amdaPlotObj.PlotObjectConfig.defaultValues.file.format);
        this.set('file-output', amdaPlotObj.PlotObjectConfig.defaultValues.file.output);
        this.set('file-prefix', '');
        this.set('one-file-per-interval', amdaPlotObj.PlotObjectConfig.defaultValues.file.oneFilePerInterval);
        this.set('name', '');

    	this.set('tree-full-view', amdaPlotObj.PlotObjectConfig.defaultValues.tree.fullView);
a971060f   Benjamin Renard   Fix some bugs
168
    	
940afd8d   Benjamin Renard   Introduce multipl...
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
    	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()
    {
a971060f   Benjamin Renard   Fix some bugs
215
216
217
    	if (this.dirty)
    		return true;
    	
940afd8d   Benjamin Renard   Introduce multipl...
218
219
220
221
    	if (this.get('page-layout-object') != null)
    		if (this.get('page-layout-object').dirty)
    			return true;
    	
a971060f   Benjamin Renard   Fix some bugs
222
    	var d = false;
940afd8d   Benjamin Renard   Introduce multipl...
223
224
    	this.panels().each(function (panel, index) {
    		if (panel.isDirty())
a971060f   Benjamin Renard   Fix some bugs
225
226
227
228
229
    			d = true;
    	});
    	return d;
    },
    
940afd8d   Benjamin Renard   Introduce multipl...
230
    getJsonValues : function() 
437c4dbc   Benjamin Renard   First implementat...
231
232
    {
    	var requestValues  = new Object();
57e15214   Benjamin Renard   Fix addParameter ...
233
234

        requestValues['nodeType'] = 'request';
c9db9962   Benjamin Renard   WIP
235
        requestValues['leaf'] = true;
437c4dbc   Benjamin Renard   First implementat...
236
    	
940afd8d   Benjamin Renard   Introduce multipl...
237
    	requestValues['id'] = this.get('id');
d29f5012   Benjamin Renard   Fix doPlot
238
239
        requestValues['tab-index'] = this.get('tab-index');
        requestValues['tab-title'] = this.get('tab-title');
8dddc557   Benjamin Renard   Fix plot reload
240
        requestValues['name'] = this.get('name');
940afd8d   Benjamin Renard   Introduce multipl...
241
242
243
244
245
246
247

        requestValues['file-format'] = this.get('file-format');
        requestValues['file-output'] = this.get('file-output');
        requestValues['file-prefix'] = this.get('file-prefix');
        requestValues['one-file-per-interval'] = this.get('one-file-per-interval');

    	requestValues['tree-full-view'] = this.get('tree-full-view');
940afd8d   Benjamin Renard   Introduce multipl...
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
    	requestValues['page-node-state'] = this.get('page-node-state');
    	requestValues['panels-node-state'] = this.get('panels-node-state');

    	requestValues['page-title-text'] = this.get('page-title-text');
    	requestValues['page-title-color'] = this.get('page-title-color');
    	requestValues['page-title-position'] = this.get('page-title-position');
    	requestValues['page-title-alignment'] = this.get('page-title-alignment');
    	requestValues['page-title-font-activated'] = this.get('page-title-font-activated');
    	requestValues['page-title-font-name'] = this.get('page-title-font-name');
    	requestValues['page-title-font-size'] = this.get('page-title-font-size');
    	requestValues['page-title-font-bold'] = this.get('page-title-font-bold');
    	requestValues['page-title-font-italic'] = this.get('page-title-font-italic');
    	requestValues['page-margins-activated'] = this.get('page-margins-activated');
    	requestValues['page-margin-x'] = this.get('page-margin-x');
    	requestValues['page-margin-y'] = this.get('page-margin-y');
    	requestValues['page-mode'] = this.get('page-mode');
    	requestValues['page-orientation'] = this.get('page-orientation');
    	requestValues['page-dimension'] = this.get('page-dimension');
    	requestValues['page-superpose-mode'] = this.get('page-superpose-mode');
    	requestValues['page-font-activated'] = this.get('page-font-activated');
    	requestValues['page-font-name'] = this.get('page-font-name');
    	requestValues['page-font-size'] = this.get('page-font-size');
    	requestValues['page-font-bold'] = this.get('page-font-bold');
    	requestValues['page-font-italic'] = this.get('page-font-italic');
18d4a11e   Benjamin Renard   Save and load plo...
272
    	
940afd8d   Benjamin Renard   Introduce multipl...
273
    	requestValues['timesrc'] =  this.get('timesrc');       
437c4dbc   Benjamin Renard   First implementat...
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
        // 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
            requestValues['timeTables'] = [];
            // for each interval record
            Ext.Array.each(timeTables, function(item, index, all){
            	if (!item.$className) {
            		requestValues['timeTables'][index] = {timeTableName : item.timeTableName, id : item.id};
            	}
            	// get Json simplified value 
            	else {
            		requestValues['timeTables'][index] = item.getJsonValues();
            	}
            });            
        } else {
940afd8d   Benjamin Renard   Introduce multipl...
291
292
293
294
295
296
297
        	requestValues['startDate'] = this.get('startDate');	
            requestValues['stopDate'] = this.get('stopDate'); 
            requestValues['durationDay'] = this.get('durationDay');
            requestValues['durationHour'] = this.get('durationHour');
            requestValues['durationMin'] = this.get('durationMin');
            requestValues['durationSec'] = this.get('durationSec');
        }
437c4dbc   Benjamin Renard   First implementat...
298
    	
940afd8d   Benjamin Renard   Introduce multipl...
299
300
301
302
303
304
305
306
307
308
309
310
311
    	requestValues['page-layout-type'] = this.get('page-layout-type');
    	if (this.get('page-layout-object') != null)
    		requestValues['page-layout-object'] = this.get('page-layout-object').getJsonValues();
    	
    	requestValues['panels'] = [];
    	
    	this.panels().each(function (panel, index) {
    		requestValues['panels'][index] = panel.getJsonValues();
    	});
    	
    	requestValues['last-panel-id'] = this.get('last-panel-id');
    	
    	return requestValues;
437c4dbc   Benjamin Renard   First implementat...
312
    }
ebbb3638   Benjamin Renard   Edit plot tab on ...
313
});