Blame view

js/app/views/PlotComponents/PlotTabContent.js 10.2 KB
437c4dbc   Benjamin Renard   First implementat...
1
2
3
4
5
6
7
8
9
10
11
/**
 * Project   : AMDA-NG
 * Name      : PlotTab.js
 * @class   amdaPlotComp.PlotTab
 * @extends Ext.form.Panel
 * @brief   Tab content to define a plot
 * @author  Benjamin Renard
 * @version $Id: PlotTab.js benjamin $
 */

Ext.define('amdaPlotComp.PlotTabContent', {
495fc7a3   Benjamin Renard   Adapt plot UI in ...
12
13
14
15
    extend: 'Ext.form.Panel',

    requires: [
        'amdaUI.TimeSelectorUI',
533ea933   Benjamin Renard   Show description ...
16
        'amdaUI.DescriptionField',
495fc7a3   Benjamin Renard   Adapt plot UI in ...
17
18
19
        'amdaPlotComp.PlotTree',
        'amdaPlotComp.PlotOutputForm',
        'amdaPlotComp.PlotElementPanel'
437c4dbc   Benjamin Renard   First implementat...
20
21
    ],
	
495fc7a3   Benjamin Renard   Adapt plot UI in ...
22
23
24
    //Link to the Plot Node
    plotNode: null,

232cf098   Benjamin Renard   Another fix for p...
25
26
27
    //Save initial request data to have the possibility to reject all modifications
    initialObjectData: null,

495fc7a3   Benjamin Renard   Adapt plot UI in ...
28
29
30
31
    timeSelector: null,
    plotTree: null,
    plotElement: null,
    plotOutput: null,
d29f5012   Benjamin Renard   Fix doPlot
32
33

    tabIndex: 0,
9705c573   Benjamin Renard   Duplicate plot
34
    plotTabPanel: null,
437c4dbc   Benjamin Renard   First implementat...
35
36
37
38
    
    constructor: function(config) {
		this.init(config);	    
		this.callParent(arguments);
495fc7a3   Benjamin Renard   Adapt plot UI in ...
39
    },
57e15214   Benjamin Renard   Fix addParameter ...
40
41
42

    setTime : function(startDate, stopDate) {
        this.timeSelector.intervalSel.setInterval(startDate, stopDate);
46bd4591   Hacene SI HADJ MOHAND   us ok
43
        this.timeSelector.setActiveTimeSource(amdaModel.AmdaTimeObject.inputTimeSrc[1]);
57e15214   Benjamin Renard   Fix addParameter ...
44
45
        
    },
1b2281a1   Hacene SI HADJ MOHAND   ok for tt
46
47
48
    getTimeSelector: function(){
        return this.timeSelector;
    },
27b2a53e   Benjamin Renard   Link tab plot to ...
49
	
495fc7a3   Benjamin Renard   Adapt plot UI in ...
50
51
52
53
54
55
56
57
    updateTimeObject : function() {
        var timeSource = this.timeSelector.getActiveTimeSource();
        var tabForm = this.getForm();
        tabForm.updateRecord(this.plotNode.get('object'));
        this.plotNode.get('object').set('timesrc', timeSource);
        if (timeSource === amdaModel.AmdaTimeObject.inputTimeSrc[0])
            this.plotNode.get('object').set('timeTables',this.timeSelector.TTGrid.getStore().data.items);
    },
57e15214   Benjamin Renard   Fix addParameter ...
58
59

    doPlot : function() {
d29f5012   Benjamin Renard   Fix doPlot
60
61
        this.plotNode.get('object').set('tab-index', this.tabIndex);
        this.plotNode.get('object').set('tab-title', this.getPlotTitle());
4efeb459   Benjamin Renard   First version for...
62
63
64
        this.plotNode.get('object').set('multi-selected', false);
        var plotModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id);
        plotModule.refreshMultiPlot();
57e15214   Benjamin Renard   Fix addParameter ...
65
66
67
        this.plotNode.execute();
    },

d29f5012   Benjamin Renard   Fix doPlot
68
69
70
71
    getPlotTitle: function() {
       return (this.plotNode.get('text') != '') ? this.plotNode.get('text') : 'Plot '+(this.tabIndex + 1); 
    },

c9db9962   Benjamin Renard   WIP
72
    savePlot : function() {
84d442b4   Benjamin Renard   Synchronize plot ...
73
74
        var me = this;

c9db9962   Benjamin Renard   WIP
75
76
77
78
79
80
        var object = this.plotNode.get('object');
        if (!object)
            return;

        if ((object.get('id') != '') && (this.plotNode.get('text') == object.get('name'))) {
            //update existing request
63c16a6c   Benjamin Renard   Fix plot request ...
81
            this.updateTimeObject();
84d442b4   Benjamin Renard   Synchronize plot ...
82
            this.plotNode.update({plot: true, callback: function() {
232cf098   Benjamin Renard   Another fix for p...
83
                me.setPlotNode(me.plotNode); //to update initial request data
84d442b4   Benjamin Renard   Synchronize plot ...
84
85
                me.plotTabPanel.updatePlotTabs();
            }});
c9db9962   Benjamin Renard   WIP
86
87
88
89
            return;
        }

        //save new request
c9db9962   Benjamin Renard   WIP
90
91
92
93
94
95
96
97
98
99
100
101
102
        this.plotNode.isValidName(object.get('name'), function (res) {
            if (!res) {
                myDesktopApp.errorMsg('Error during object validation');
                return;
            }
            if (!res.valid) {
                if (res.error) {
                    if (res.error.search('subtree') != -1) {
                        Ext.Msg.show( { title : 'Warning',
                            msg: res.error + '<br/>Do you want to overwrite it?',
                            width: 300,
                            buttons: Ext.Msg.OKCANCEL,
                            icon: Ext.Msg.WARNING,
2048f5bc   Benjamin Renard   Fix save & edit plot
103
104
105
106
                            fn :  function(btn) {
                                if (btn == 'cancel') return;
                                me.saveProcess(true);
                            },
c9db9962   Benjamin Renard   WIP
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
                            scope : me
                        });
                    }
                    else {
                        myDesktopApp.errorMsg(res.error);
                    }
                }
                else {
                    myDesktopApp.errorMsg('Invalid object name');
                }
                return;
            }
            me.saveProcess(false);
        });
    },

d794a307   Benjamin Renard   Fix bug when a pl...
123
124
125
126
127
    saveProcess : function(overwriteExistingNode) {
        var plotModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id);
        if (!plotModule)
            return;

84d442b4   Benjamin Renard   Synchronize plot ...
128
        var me = this;
d794a307   Benjamin Renard   Fix bug when a pl...
129
        if (overwriteExistingNode) {
63c16a6c   Benjamin Renard   Fix plot request ...
130
            this.updateTimeObject();
d794a307   Benjamin Renard   Fix bug when a pl...
131
132
133
134
135
136
137
138
139
140
141
142
143
144
            amdaModel.InteractiveNode.preloadNodes(this.plotNode.getRootNode(), function () {
                var targetPlotNode = me.plotNode.getRootNode().findChild('text', me.plotNode.get('object').get('name'), true);
                if (!targetPlotNode) {
                    myDesktopApp.errorMsg('Cannot retrieve request node');
                    return;
                }
                targetPlotNode = plotModule.linkedNode.get('object').overwritePlot(me.plotNode, targetPlotNode);
                if (targetPlotNode) {
                    //Reject modifications in old plot node
                    me.resetModif();
                    targetPlotNode.update({plot: true, callback: function() {
                        me.setPlotNode(targetPlotNode);
                        me.plotTabPanel.updatePlotTabs();
                        me.updateUI();
d4ab05cd   Benjamin Renard   Update interactiv...
145
			plotModule.updatePlotResultTitle(me.tabIndex, targetPlotNode.get('text'));
d794a307   Benjamin Renard   Fix bug when a pl...
146
147
148
                    }});
                }
            });
c9db9962   Benjamin Renard   WIP
149
150
151
152
        }
        else {
            if (this.plotNode.get('object').get('id') != '') {
                //Duplicate request
d794a307   Benjamin Renard   Fix bug when a pl...
153
                var newPlotNode = this.plotTabPanel.duplicatePlotNode(this.plotNode);
9705c573   Benjamin Renard   Duplicate plot
154
                if (newPlotNode) {
232cf098   Benjamin Renard   Another fix for p...
155
                    //Reject modifications in old plot node
d794a307   Benjamin Renard   Fix bug when a pl...
156
157
                    this.resetModif();
                    //Set new plot node to the current tab
232cf098   Benjamin Renard   Another fix for p...
158
                    this.setPlotNode(newPlotNode);
9705c573   Benjamin Renard   Duplicate plot
159
                }
c9db9962   Benjamin Renard   WIP
160
            }
63c16a6c   Benjamin Renard   Fix plot request ...
161
            this.updateTimeObject();
f5df7de1   Benjamin Renard   Fix #8567
162
            this.plotNode.create({plot: true, callback: function() {
63c16a6c   Benjamin Renard   Fix plot request ...
163
                me.plotNode.commit();
232cf098   Benjamin Renard   Another fix for p...
164
                me.setPlotNode(me.plotNode); //to update initial request data
84d442b4   Benjamin Renard   Synchronize plot ...
165
                me.plotTabPanel.updatePlotTabs();
63c16a6c   Benjamin Renard   Fix plot request ...
166
                me.updateUI();
d4ab05cd   Benjamin Renard   Update interactiv...
167
		plotModule.updatePlotResultTitle(me.tabIndex, me.plotNode.get('text'));
84d442b4   Benjamin Renard   Synchronize plot ...
168
            }});
c9db9962   Benjamin Renard   WIP
169
        }
c9db9962   Benjamin Renard   WIP
170
171
    },

d794a307   Benjamin Renard   Fix bug when a pl...
172
173
174
175
    resetModif : function() {
        this.plotNode.set('object', Ext.create('amdaPlotObj.PlotRequestObject', this.initialObjectData));
    },

bab40211   Benjamin Renard   Test time selecti...
176
    getDataProcess : function() {
0e540b69   Benjamin Renard   Finalize save of ...
177
178
	var plotModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id);
	plotModule.editInDownloadModule(this.plotNode);
bab40211   Benjamin Renard   Test time selecti...
179
180
181
182
183
184
185
186
187
188
189
    },

    isValidRequest : function(acceptEmptyTTList = true) {
        this.updateTimeObject();
        if (!this.timeSelector.isValid(acceptEmptyTTList)) {
            myDesktopApp.errorMsg('Error in Time definition');
            return false;
        }
        return true;
    },

c9db9962   Benjamin Renard   WIP
190
191
    updateUI : function() {
        this.plotOutput.setObject(this.plotNode.get('object'));
ef44d141   Benjamin Renard   Fix bug with desc...
192
        var descField = this.descriptionCase.items.items[0];
29a2024c   Erdogan Furkan   10852
193
        descField.setValue(this.plotNode.get('object').get('description'));
c9db9962   Benjamin Renard   WIP
194
        this.timeSelector.intervalSel.setInterval(this.plotNode.get('object').get('startDate'), this.plotNode.get('object').get('stopDate'));
63c16a6c   Benjamin Renard   Fix plot request ...
195
	this.timeSelector.intervalSel.updateStop();
c9db9962   Benjamin Renard   WIP
196
        this.timeSelector.setTTTab(this.plotNode.get('object').get('timeTables'));
bab40211   Benjamin Renard   Test time selecti...
197
        this.timeSelector.timeSrc.setActiveTab(this.plotNode.get('object').get('timesrc'));
c9db9962   Benjamin Renard   WIP
198
199
200
        this.treePlot.buildTree(this.plotNode.get('object'));
    },

232cf098   Benjamin Renard   Another fix for p...
201
202
203
204
205
    setPlotNode : function(plotNode) {
        this.initialObjectData = plotNode.get('object').getJsonValues();
        this.plotNode = plotNode;
    },

d4a8d462   Benjamin Renard   Improve MultiPlot...
206
207
208
209
    enableTimeSelection : function(enable) {
        this.timeSelector.setDisabled(!enable);
    },

c9db9962   Benjamin Renard   WIP
210
    init : function(config) {
232cf098   Benjamin Renard   Another fix for p...
211
        this.setPlotNode(config.plotNode);
d29f5012   Benjamin Renard   Fix doPlot
212
        this.tabIndex = config.tabIndex;
9705c573   Benjamin Renard   Duplicate plot
213
        this.plotTabPanel = config.plotTabPanel;
495fc7a3   Benjamin Renard   Adapt plot UI in ...
214

5c744625   Benjamin Renard   Synchronize reque...
215
        this.timeSelector = new amdaUI.TimeSelectorUI( { id: Ext.id()/*'plotTimeSelectorTab' + this.plotNode.id*/, border : false, flex: 6, collapsible: true, collapseDirection : 'bottom'} );
29a2024c   Erdogan Furkan   10852
216
        this.plotElement = new amdaPlotComp.PlotElementPanel({flex: 12});
495fc7a3   Benjamin Renard   Adapt plot UI in ...
217
        this.treePlot = new amdaPlotComp.PlotTree({flex: 11, plotElementPanel: this.plotElement});
29a2024c   Erdogan Furkan   10852
218
        this.plotOutput = new amdaPlotComp.PlotOutputForm({flex: 8, collapseDirection : 'bottom', collapsible : true });
ef44d141   Benjamin Renard   Fix bug with desc...
219
        this.descriptionCase = new Ext.form.FieldSet({
29a2024c   Erdogan Furkan   10852
220
221
222
223
224
225
226
            title:'Request description',
            collapsible:true,
            collapsed:true,
            flex:3,
            bodyStyle: {background: '#dfe8f6',padding: '1', },
            border:false, 
            layout:'fit',
6d324fbe   Benjamin Renard   Merge FER_10828_2...
227
            items:[{ xtype: 'descriptionfield', name: 'description', height:50, 
ef44d141   Benjamin Renard   Fix bug with desc...
228
229
            emptyText:'Description', fieldLabel: ''}]
        });
495fc7a3   Benjamin Renard   Adapt plot UI in ...
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260

        var treePanel = new Ext.form.Panel({
            flex: 1,
            layout: {
                type: 'vbox',
                pack: 'start',
                align: 'stretch'
            },
            bodyStyle: { background : '#dfe8f6' },
            defaults: {
                border: false
            },
            items: [
                this.treePlot,
                this.timeSelector
            ]
        });

        var optionsPanel = new Ext.form.Panel({
            flex: 1,
            layout: {
                type: 'vbox',
                pack: 'start',
                align: 'stretch'
            },
            bodyStyle: { background : '#dfe8f6' },
            defaults: {
                border: false
            },
            items: [
                this.plotElement,
29a2024c   Erdogan Furkan   10852
261
262
                this.plotOutput,
                this.descriptionCase
495fc7a3   Benjamin Renard   Adapt plot UI in ...
263
264
265
            ]
        });

437c4dbc   Benjamin Renard   First implementat...
266
		
495fc7a3   Benjamin Renard   Adapt plot UI in ...
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
        var myConf = {
            bodyStyle: { background : '#dfe8f6' },
            border : false,
            defaults: {
                border: false
            },
            layout: {
                type: 'hbox',
                pack: 'start',
                align: 'stretch'
            },
            items: [
                treePanel,
                optionsPanel
            ],
            listeners: {
                afterrender: function(comp, eOpts) {
c9db9962   Benjamin Renard   WIP
284
                    this.updateUI();
495fc7a3   Benjamin Renard   Adapt plot UI in ...
285
                },
55fa3bbc   Benjamin Renard   Reset plot reques...
286
287
288
                beforedestroy: function(comp, eOpts) {
                    this.resetModif();
                },
495fc7a3   Benjamin Renard   Adapt plot UI in ...
289
290
291
292
293
                scope: this
            }
        };

        Ext.apply (this , Ext.apply (arguments, myConf));
437c4dbc   Benjamin Renard   First implementat...
294
295
		
		
495fc7a3   Benjamin Renard   Adapt plot UI in ...
296
297
    }
});