Blame view

js/app/views/PlotComponents/PlotTabContent.js 8.25 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
16
17
18
    extend: 'Ext.form.Panel',

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

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

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

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

    setTime : function(startDate, stopDate) {
        this.timeSelector.intervalSel.setInterval(startDate, stopDate);
        
    },
27b2a53e   Benjamin Renard   Link tab plot to ...
44
	
495fc7a3   Benjamin Renard   Adapt plot UI in ...
45
46
47
48
49
50
51
52
    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 ...
53
54

    doPlot : function() {
d29f5012   Benjamin Renard   Fix doPlot
55
56
        this.plotNode.get('object').set('tab-index', this.tabIndex);
        this.plotNode.get('object').set('tab-title', this.getPlotTitle());
57e15214   Benjamin Renard   Fix addParameter ...
57
58
59
        this.plotNode.execute();
    },

d29f5012   Benjamin Renard   Fix doPlot
60
61
62
63
    getPlotTitle: function() {
       return (this.plotNode.get('text') != '') ? this.plotNode.get('text') : 'Plot '+(this.tabIndex + 1); 
    },

c9db9962   Benjamin Renard   WIP
64
    savePlot : function() {
84d442b4   Benjamin Renard   Synchronize plot ...
65
66
        var me = this;

c9db9962   Benjamin Renard   WIP
67
68
69
70
71
72
        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 ...
73
            this.updateTimeObject();
84d442b4   Benjamin Renard   Synchronize plot ...
74
            this.plotNode.update({plot: true, callback: function() {
232cf098   Benjamin Renard   Another fix for p...
75
                me.setPlotNode(me.plotNode); //to update initial request data
84d442b4   Benjamin Renard   Synchronize plot ...
76
77
                me.plotTabPanel.updatePlotTabs();
            }});
c9db9962   Benjamin Renard   WIP
78
79
80
81
            return;
        }

        //save new request
c9db9962   Benjamin Renard   WIP
82
83
84
85
86
87
88
89
90
91
92
93
94
        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
95
96
97
98
                            fn :  function(btn) {
                                if (btn == 'cancel') return;
                                me.saveProcess(true);
                            },
c9db9962   Benjamin Renard   WIP
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
                            scope : me
                        });
                    }
                    else {
                        myDesktopApp.errorMsg(res.error);
                    }
                }
                else {
                    myDesktopApp.errorMsg('Invalid object name');
                }
                return;
            }
            me.saveProcess(false);
        });
    },

c9db9962   Benjamin Renard   WIP
115
    saveProcess : function(toRename) {
84d442b4   Benjamin Renard   Synchronize plot ...
116
        var me = this;
c9db9962   Benjamin Renard   WIP
117
        if (toRename) {
63c16a6c   Benjamin Renard   Fix plot request ...
118
            this.updateTimeObject();
84d442b4   Benjamin Renard   Synchronize plot ...
119
            this.plotNode.update({plot: true, callback: function() {
232cf098   Benjamin Renard   Another fix for p...
120
                me.setPlotNode(me.plotNode); //to update initial request data
84d442b4   Benjamin Renard   Synchronize plot ...
121
122
                me.plotTabPanel.updatePlotTabs();
            }});
c9db9962   Benjamin Renard   WIP
123
124
125
126
127
128
129
        }
        else {
            if (this.plotNode.get('object').get('id') != '') {
                //Duplicate request
                var plotModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id);
                if (!plotModule)
                    return;
9705c573   Benjamin Renard   Duplicate plot
130
131
                var newPlotNode = plotModule.linkedNode.get('object').duplicatePlot(this.plotNode);
                if (newPlotNode) {
232cf098   Benjamin Renard   Another fix for p...
132
133
134
135
136
                    //Reject modifications in old plot node
                    this.plotNode.reject();
                    this.plotNode.set('object', Ext.create('amdaPlotObj.PlotRequestObject', this.initialObjectData));
                    //Set new plot node
                    this.setPlotNode(newPlotNode);
9705c573   Benjamin Renard   Duplicate plot
137
                }
c9db9962   Benjamin Renard   WIP
138
            }
63c16a6c   Benjamin Renard   Fix plot request ...
139
            this.updateTimeObject();
84d442b4   Benjamin Renard   Synchronize plot ...
140
            this.plotNode.create({callback: function() {
63c16a6c   Benjamin Renard   Fix plot request ...
141
                me.plotNode.commit();
232cf098   Benjamin Renard   Another fix for p...
142
                me.setPlotNode(me.plotNode); //to update initial request data
84d442b4   Benjamin Renard   Synchronize plot ...
143
                me.plotTabPanel.updatePlotTabs();
63c16a6c   Benjamin Renard   Fix plot request ...
144
                me.updateUI();
84d442b4   Benjamin Renard   Synchronize plot ...
145
            }});
c9db9962   Benjamin Renard   WIP
146
        }
c9db9962   Benjamin Renard   WIP
147
148
    },

bab40211   Benjamin Renard   Test time selecti...
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
    getDataProcess : function() {
        var downObject = amdaModel.DownloadNode.decodeObject(this.plotNode.get('object'));
        amdaModel.DownloadNode.set('object',Ext.create('amdaModel.Download',downObject));
        amdaModel.DownloadNode.editInModule();
    },

    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
164
165
166
    updateUI : function() {
        this.plotOutput.setObject(this.plotNode.get('object'));
        this.timeSelector.intervalSel.setInterval(this.plotNode.get('object').get('startDate'), this.plotNode.get('object').get('stopDate'));
63c16a6c   Benjamin Renard   Fix plot request ...
167
	this.timeSelector.intervalSel.updateStop();
c9db9962   Benjamin Renard   WIP
168
        this.timeSelector.setTTTab(this.plotNode.get('object').get('timeTables'));
bab40211   Benjamin Renard   Test time selecti...
169
        this.timeSelector.timeSrc.setActiveTab(this.plotNode.get('object').get('timesrc'));
c9db9962   Benjamin Renard   WIP
170
171
172
        this.treePlot.buildTree(this.plotNode.get('object'));
    },

232cf098   Benjamin Renard   Another fix for p...
173
174
175
176
177
    setPlotNode : function(plotNode) {
        this.initialObjectData = plotNode.get('object').getJsonValues();
        this.plotNode = plotNode;
    },

c9db9962   Benjamin Renard   WIP
178
    init : function(config) {
232cf098   Benjamin Renard   Another fix for p...
179
        this.setPlotNode(config.plotNode);
d29f5012   Benjamin Renard   Fix doPlot
180
        this.tabIndex = config.tabIndex;
9705c573   Benjamin Renard   Duplicate plot
181
        this.plotTabPanel = config.plotTabPanel;
495fc7a3   Benjamin Renard   Adapt plot UI in ...
182

5c744625   Benjamin Renard   Synchronize reque...
183
        this.timeSelector = new amdaUI.TimeSelectorUI( { id: Ext.id()/*'plotTimeSelectorTab' + this.plotNode.id*/, border : false, flex: 6, collapsible: true, collapseDirection : 'bottom'} );
495fc7a3   Benjamin Renard   Adapt plot UI in ...
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
215
216
217
218
219
220
221
        this.plotElement = new amdaPlotComp.PlotElementPanel({flex: 11});
        this.treePlot = new amdaPlotComp.PlotTree({flex: 11, plotElementPanel: this.plotElement});
        this.plotOutput = new amdaPlotComp.PlotOutputForm({flex: 6, collapseDirection : 'bottom', collapsible : true });

        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,
                this.plotOutput
            ]
        });

437c4dbc   Benjamin Renard   First implementat...
222
		
495fc7a3   Benjamin Renard   Adapt plot UI in ...
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
        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
240
                    this.updateUI();
495fc7a3   Benjamin Renard   Adapt plot UI in ...
241
242
243
244
245
246
                },
                scope: this
            }
        };

        Ext.apply (this , Ext.apply (arguments, myConf));
437c4dbc   Benjamin Renard   First implementat...
247
248
		
		
495fc7a3   Benjamin Renard   Adapt plot UI in ...
249
250
    }
});