Blame view

js/app/views/PlotComponents/PlotTabPanel.js 8.11 KB
437c4dbc   Benjamin Renard   First implementat...
1
2
3
4
5
6
7
8
9
10
11
/**
 * Project   : AMDA-NG
 * Name      : PlotTabPanel.js
 * @class   amdaPlotComp.PlotTabPanel
 * @extends Ext.tab.Panel
 * @brief   Component use to show Plot tabs definition
 * @author  Benjamin Renard
 * @version $Id: PlotTabPanel.js benjamin $
 */

Ext.define('amdaPlotComp.PlotTabPanel', {
495fc7a3   Benjamin Renard   Adapt plot UI in ...
12
    extend: 'Ext.tab.Panel',
437c4dbc   Benjamin Renard   First implementat...
13
	
495fc7a3   Benjamin Renard   Adapt plot UI in ...
14
15
16
    requires: [
        'amdaPlotComp.PlotTabContent'
    ],
437c4dbc   Benjamin Renard   First implementat...
17
	
495fc7a3   Benjamin Renard   Adapt plot UI in ...
18
19
    //Link to the Plot UI
    plotUI : null,
437c4dbc   Benjamin Renard   First implementat...
20
	
495fc7a3   Benjamin Renard   Adapt plot UI in ...
21
22
    //Multiplot object
    multiplot_object: null,
84d442b4   Benjamin Renard   Synchronize plot ...
23
24

    tabbar_destroy : false,
437c4dbc   Benjamin Renard   First implementat...
25
	
495fc7a3   Benjamin Renard   Adapt plot UI in ...
26
27
28
29
    constructor: function(config) {
        this.init(config);	    
        this.callParent(arguments);
    },
437c4dbc   Benjamin Renard   First implementat...
30
	
495fc7a3   Benjamin Renard   Adapt plot UI in ...
31
32
33
34
    setMultiplotObject: function(multiplot_object) {
        var me = this;
        this.removeAll();
        this.multiplot_object = multiplot_object;
b9249413   Elena.Budnik   correct init value
35

495fc7a3   Benjamin Renard   Adapt plot UI in ...
36
        this.multiplot_object.plots().each(function (rec, index) {
4efeb459   Benjamin Renard   First version for...
37
            this.addPlotNode(rec, index == 0, false);
495fc7a3   Benjamin Renard   Adapt plot UI in ...
38
        }, this);
4efeb459   Benjamin Renard   First version for...
39
        this.refreshMultiPlot();
495fc7a3   Benjamin Renard   Adapt plot UI in ...
40
    },
8dddc557   Benjamin Renard   Fix plot reload
41
42
43
44
45
46
47
48
49
50
51

    reloadPlot : function(plotNode) {
        for (i = 0; i < this.items.getCount(); ++i)
        {
            var tabItem = this.items.getAt(i);
            var tabContent = tabItem.items.getAt(0);
            if (plotNode == tabContent.plotNode) {
                tabContent.updateUI();
            }
        }
    },
55fa3bbc   Benjamin Renard   Reset plot reques...
52
53
54
55
56
57
58
59
60

    isDirty : function() {
        var dirty = false;
        this.multiplot_object.plots().each(function (rec, index) {
            if (rec.get('object').get('id') != '')
                dirty |= rec.get('object').isDirty();
        });
        return dirty;
    },
437c4dbc   Benjamin Renard   First implementat...
61
	
4efeb459   Benjamin Renard   First version for...
62
    addPlotNode: function(plotNode, selectTab, refreshMultiPlot)
495fc7a3   Benjamin Renard   Adapt plot UI in ...
63
    {
2048f5bc   Benjamin Renard   Fix save & edit plot
64
65
66
67
68
69
70
71
72
73
74
        for (i = 0; i < this.items.getCount(); ++i)
        {
            var tabItem = this.items.getAt(i);
            var tabContent = tabItem.items.getAt(0);
            if (plotNode == tabContent.plotNode) {
                //Already opened => select tab
                this.setActiveTab(tabItem);
                return;
            }
        }

495fc7a3   Benjamin Renard   Adapt plot UI in ...
75
        var tabNumber = this.getTabBar().items.getCount();
9705c573   Benjamin Renard   Duplicate plot
76
        var tabContent = new amdaPlotComp.PlotTabContent({plotNode: plotNode, tabIndex: tabNumber-1, plotTabPanel: this});
495fc7a3   Benjamin Renard   Adapt plot UI in ...
77
78
        var me = this;
        var tabComp = this.add({
d29f5012   Benjamin Renard   Fix doPlot
79
            title: tabContent.getPlotTitle(),
495fc7a3   Benjamin Renard   Adapt plot UI in ...
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
            closable: true,
            layout: 'fit',
            bodyStyle: 'background: none',
            defaults: {
                border: false
            },
            items: [
                tabContent
            ],
            listeners : {
                scope : this,
                beforeclose: function( tab, eOpts ) {
                    if (this.items.getCount() == 1)
                    {
                        myDesktopApp.warningMsg('You need to keep at least one plot definition');
                        return false;
                    }
                    return true;
                },
                close: function( tab, eOpts ) {
5c744625   Benjamin Renard   Synchronize reque...
100
                    if (tab.items.getAt(0).plotNode) {
d794a307   Benjamin Renard   Fix bug when a pl...
101
                        tab.items.getAt(0).resetModif();
57e15214   Benjamin Renard   Fix addParameter ...
102
                        this.multiplot_object.removePlotByInternalId(tab.items.getAt(0).plotNode.internalId);
5c744625   Benjamin Renard   Synchronize reque...
103
                    }
495fc7a3   Benjamin Renard   Adapt plot UI in ...
104
                },
84d442b4   Benjamin Renard   Synchronize plot ...
105
                destroy: function(tab, eOpts) {
d794a307   Benjamin Renard   Fix bug when a pl...
106
107
108
                    if (tab.items.getAt(0) && tab.items.getAt(0).plotNode) {
                        tab.items.getAt(0).resetModif();
                    }
84d442b4   Benjamin Renard   Synchronize plot ...
109
110
                    if (!this.tabbar_destroy)
                        this.updatePlotTabs();
495fc7a3   Benjamin Renard   Adapt plot UI in ...
111
112
113
                }
            }
        });
27b2a53e   Benjamin Renard   Link tab plot to ...
114
    	
495fc7a3   Benjamin Renard   Adapt plot UI in ...
115
116
        if (selectTab)
            this.setActiveTab(tabComp);
4efeb459   Benjamin Renard   First version for...
117
118
119

        if (refreshMultiPlot)
            this.refreshMultiPlot();
437c4dbc   Benjamin Renard   First implementat...
120
    	
495fc7a3   Benjamin Renard   Adapt plot UI in ...
121
122
        return tabContent;
    },
d794a307   Benjamin Renard   Fix bug when a pl...
123
124
125
126
127
128
129
130

    duplicatePlotNode: function(plotNode)
    {
        var newPlotNode = this.multiplot_object.duplicatePlot(plotNode);
        if (!newPlotNode)
            return null;
        return newPlotNode;
    },
437c4dbc   Benjamin Renard   First implementat...
131
	
495fc7a3   Benjamin Renard   Adapt plot UI in ...
132
133
    updatePlotTabs: function()
    {
57e15214   Benjamin Renard   Fix addParameter ...
134
135
136
137
        for (i = 0; i < this.items.getCount(); ++i)
        {
            var tabItem = this.items.getAt(i);
            var tabContent = tabItem.items.getAt(0);
d29f5012   Benjamin Renard   Fix doPlot
138
            tabContent.tabIndex = i;
57e15214   Benjamin Renard   Fix addParameter ...
139
            var plotNode = tabContent.plotNode;
d29f5012   Benjamin Renard   Fix doPlot
140
            var title = tabContent.getPlotTitle();
57e15214   Benjamin Renard   Fix addParameter ...
141
142
143
144
            tabItem.setTitle(title);
            if (!this.getActiveTab())
                this.setActiveTab(tabItem);
        }
4efeb459   Benjamin Renard   First version for...
145
        this.refreshMultiPlot();
57e15214   Benjamin Renard   Fix addParameter ...
146
147
    },

d794a307   Benjamin Renard   Fix bug when a pl...
148
149
150
151
152
153
154
155
    closePlotTabIfOpened: function(plotNodeToClose) {
        for (i = 0; i < this.items.getCount(); ++i)
        {
            var tabItem = this.items.getAt(i);
            var tabContent = tabItem.items.getAt(0);
            var plotNode = tabContent.plotNode;
            if (plotNode == renamedNode) {
                this.remove(tabItem.getId());
4efeb459   Benjamin Renard   First version for...
156
                this.refreshMultiPlot();
d794a307   Benjamin Renard   Fix bug when a pl...
157
158
159
160
            }
        }
    },

5c744625   Benjamin Renard   Synchronize reque...
161
162
163
164
165
166
167
168
169
170
    updateRequestName: function(renamedNode)
    {
        for (i = 0; i < this.items.getCount(); ++i)
        {
            var tabItem = this.items.getAt(i);
            var tabContent = tabItem.items.getAt(0);
            var plotNode = tabContent.plotNode;
            if (plotNode == renamedNode) {
		plotNode.get('object').set('name', renamedNode.get('text'));
                tabContent.updateUI();
4efeb459   Benjamin Renard   First version for...
171
                this.refreshMultiPlot();
5c744625   Benjamin Renard   Synchronize reque...
172
173
174
175
            }
        }
    },

57e15214   Benjamin Renard   Fix addParameter ...
176
177
178
179
    getCurrentPlotTabContent : function() {
        if (this.getActiveTab())
            return this.getActiveTab().child();
        return null;
495fc7a3   Benjamin Renard   Adapt plot UI in ...
180
    },
27b2a53e   Benjamin Renard   Link tab plot to ...
181
	
acafe456   Benjamin Renard   Fix Get Data
182
    updateTimeObjects : function() {
495fc7a3   Benjamin Renard   Adapt plot UI in ...
183
184
185
186
187
        for (i = 0; i < this.items.getCount(); ++i)
        {
            this.items.getAt(i).items.getAt(0).updateTimeObject();
        }
    },
27b2a53e   Benjamin Renard   Link tab plot to ...
188
	
495fc7a3   Benjamin Renard   Adapt plot UI in ...
189
190
191
192
    getTreeFromPlotTab: function(plotTab)
    {
        return plotTab.child().treePlot;
    },
4efeb459   Benjamin Renard   First version for...
193
194
195
196
197
198
199
200

    getTabsInfo: function()
    {
        var tabsInfo = [];
        for (i = 0; i < this.items.getCount(); ++i) {
            var tabItem = this.items.getAt(i);
            var tabContent = tabItem.items.getAt(0);
            var plotNode = tabContent.plotNode;
27a055f4   Benjamin Renard   Multiplot (#8314)
201
202
            plotNode.get('object').set('tab-index', tabContent.tabIndex);
            plotNode.get('object').set('tab-title', tabContent.getPlotTitle());
4efeb459   Benjamin Renard   First version for...
203
            tabsInfo.push({
27a055f4   Benjamin Renard   Multiplot (#8314)
204
                name: plotNode.get('object').get('tab-title'),
4efeb459   Benjamin Renard   First version for...
205
                object: plotNode.get('object'),
ae185f40   Benjamin Renard   Fix multiplot (#8...
206
207
                selected: (tabItem == this.getActiveTab()),
                tabContent: tabContent
4efeb459   Benjamin Renard   First version for...
208
209
210
211
212
213
214
215
216
217
            });
        }
        return tabsInfo;
    },

    refreshMultiPlot: function()
    {
        var plotModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id);
        plotModule.refreshMultiPlot();
    },
d4a8d462   Benjamin Renard   Improve MultiPlot...
218
219
220
221
222
223
224
225

    enableTimeSelection: function(enable)
    {
        for (i = 0; i < this.items.getCount(); ++i)
        {
            this.items.getAt(i).items.getAt(0).enableTimeSelection(enable);
        }
    },
437c4dbc   Benjamin Renard   First implementat...
226
	
495fc7a3   Benjamin Renard   Adapt plot UI in ...
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
    init : function(config) {
        var me = this;

        this.plotUI = config.plotUI;

        var myConf = {
            plain: true,
            bodyStyle: { background : '#dfe8f6' },
            border : false,
            defaults: {
                border: false
            },	
            tabBar:{
                items:[
                    {
                        text:'+',
                        closable: false,
                        handler:function(btn,e){
4efeb459   Benjamin Renard   First version for...
245
                            var tabContent = me.addPlotNode(me.multiplot_object.createNewPlot(), true, true);
495fc7a3   Benjamin Renard   Adapt plot UI in ...
246
247
                        }
                    }
84d442b4   Benjamin Renard   Synchronize plot ...
248
249
250
251
252
253
                ],
                listeners: {
                    beforedestroy: function(tabbar, eOpts) {
                        me.tabbar_destroy = true;
                    }
                }
ae185f40   Benjamin Renard   Fix multiplot (#8...
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
            },
            listeners: {
                tabchange: function(tabPanel, newCard, oldCard, eOpts) {
			if (newCard) {
				var newTree = this.getTreeFromPlotTab(newCard);
				if (newTree) {
					if (newTree.plotElementPanel != null) {
						var selectedNode = newTree.getSelectedNode();
						if (selectedNode != null) {
							newTree.plotElementPanel.setElement(selectedNode.type, selectedNode.object, newTree);
						}
					}
				}
			}
                },
                scope: this
495fc7a3   Benjamin Renard   Adapt plot UI in ...
270
271
272
273
274
            }
        };

        Ext.apply (this , Ext.apply (arguments, myConf));
    }
0b0c7bc6   Benjamin Renard   Fix bug #6488
275
});