Blame view

js/app/models/PlotObjects/PlotRequestObject.js 12.7 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},
940afd8d   Benjamin Renard   Introduce multipl...
32

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

	      {name: 'tree-full-view', type: 'boolean'},
940afd8d   Benjamin Renard   Introduce multipl...
39
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
	      {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...
66
67
    ],
    
940afd8d   Benjamin Renard   Introduce multipl...
68
69
70
71
72
73
74
    associations : [
              {
            	  type : 'hasMany', 
            	  model : 'amdaPlotObj.PlotPanelObject',
            	  name  : 'panels'
              }
    ],
18d4a11e   Benjamin Renard   Save and load plo...
75
76
    
    constructor: function(){
940afd8d   Benjamin Renard   Introduce multipl...
77
78
79
        var me = this;
        me.callParent(arguments);
        if ((arguments.length > 0) && arguments[0])
18d4a11e   Benjamin Renard   Save and load plo...
80
        {
940afd8d   Benjamin Renard   Introduce multipl...
81
82
83
84
        	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...
85
86
87
88
89
        }
        else
        {
        	//new object, set default fields values
        	me.setDefaultValues();
18d4a11e   Benjamin Renard   Save and load plo...
90
        }
940afd8d   Benjamin Renard   Introduce multipl...
91
        this.dirty = false;
18d4a11e   Benjamin Renard   Save and load plo...
92
93
    },
    
940afd8d   Benjamin Renard   Introduce multipl...
94
    loadPanels: function(panels)
18d4a11e   Benjamin Renard   Save and load plo...
95
    {
940afd8d   Benjamin Renard   Introduce multipl...
96
97
       this.panels().loadData(panels);
       this.updatePanelIndex();
437c4dbc   Benjamin Renard   First implementat...
98
99
    },
    
940afd8d   Benjamin Renard   Introduce multipl...
100
    loadLayoutObject: function(layout)
437c4dbc   Benjamin Renard   First implementat...
101
    {
940afd8d   Benjamin Renard   Introduce multipl...
102
103
104
    	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...
105
106
    },
    
940afd8d   Benjamin Renard   Introduce multipl...
107
108
109
110
    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
111
    	this.dirty = true;
940afd8d   Benjamin Renard   Introduce multipl...
112
113
    	this.updatePanelIndex();
		return recs[0];
abe09878   Benjamin Renard   Add panels and ax...
114
115
    },
    
940afd8d   Benjamin Renard   Introduce multipl...
116
117
118
119
    removePanelById: function(panelId) {
    	//Retrieve panel record
    	var panelRecord = this.panels().getById(panelId);
    	if (panelRecord == null)
dbb7bcbe   Benjamin Renard   Add curves defint...
120
    		return false;
940afd8d   Benjamin Renard   Introduce multipl...
121
    	this.panels().remove(panelRecord);
a971060f   Benjamin Renard   Fix some bugs
122
    	this.dirty = true;
940afd8d   Benjamin Renard   Introduce multipl...
123
    	this.updatePanelIndex();
dbb7bcbe   Benjamin Renard   Add curves defint...
124
    	return true;
abe09878   Benjamin Renard   Add panels and ax...
125
126
    },
    
940afd8d   Benjamin Renard   Introduce multipl...
127
128
129
130
131
132
133
    updatePanelIndex: function() {
    	this.panels().each(function(panel, index) {
    		panel.set('panel-index', index);
    	});
    },
    
    createLayoutByType : function(layoutType, data)
a971060f   Benjamin Renard   Fix some bugs
134
    {
940afd8d   Benjamin Renard   Introduce multipl...
135
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
    	//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
167
    	
940afd8d   Benjamin Renard   Introduce multipl...
168
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
    	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
214
215
216
    	if (this.dirty)
    		return true;
    	
940afd8d   Benjamin Renard   Introduce multipl...
217
218
219
220
    	if (this.get('page-layout-object') != null)
    		if (this.get('page-layout-object').dirty)
    			return true;
    	
a971060f   Benjamin Renard   Fix some bugs
221
    	var d = false;
940afd8d   Benjamin Renard   Introduce multipl...
222
223
    	this.panels().each(function (panel, index) {
    		if (panel.isDirty())
a971060f   Benjamin Renard   Fix some bugs
224
225
226
227
228
    			d = true;
    	});
    	return d;
    },
    
940afd8d   Benjamin Renard   Introduce multipl...
229
    getJsonValues : function() 
437c4dbc   Benjamin Renard   First implementat...
230
231
    {
    	var requestValues  = new Object();
57e15214   Benjamin Renard   Fix addParameter ...
232
233

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

        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...
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
    	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...
271
    	
940afd8d   Benjamin Renard   Introduce multipl...
272
    	requestValues['timesrc'] =  this.get('timesrc');       
437c4dbc   Benjamin Renard   First implementat...
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
        // 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...
290
291
292
293
294
295
296
        	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...
297
    	
940afd8d   Benjamin Renard   Introduce multipl...
298
299
300
301
302
303
304
305
306
307
308
309
310
    	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...
311
    }
ebbb3638   Benjamin Renard   Edit plot tab on ...
312
});