Blame view

js/app/views/PlotComponents/PlotTabPanel.js 5.26 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
37
38
39
        this.multiplot_object.plots().each(function (rec, index) {
            this.addPlotNode(rec, index == 0);
        }, this);
    },
8dddc557   Benjamin Renard   Fix plot reload
40
41
42
43
44
45
46
47
48
49
50

    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();
            }
        }
    },
437c4dbc   Benjamin Renard   First implementat...
51
	
495fc7a3   Benjamin Renard   Adapt plot UI in ...
52
53
    addPlotNode: function(plotNode, selectTab)
    {
2048f5bc   Benjamin Renard   Fix save & edit plot
54
55
56
57
58
59
60
61
62
63
64
        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 ...
65
        var tabNumber = this.getTabBar().items.getCount();
9705c573   Benjamin Renard   Duplicate plot
66
        var tabContent = new amdaPlotComp.PlotTabContent({plotNode: plotNode, tabIndex: tabNumber-1, plotTabPanel: this});
495fc7a3   Benjamin Renard   Adapt plot UI in ...
67
68
        var me = this;
        var tabComp = this.add({
d29f5012   Benjamin Renard   Fix doPlot
69
            title: tabContent.getPlotTitle(),
495fc7a3   Benjamin Renard   Adapt plot UI in ...
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
            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...
90
                    if (tab.items.getAt(0).plotNode) {
57e15214   Benjamin Renard   Fix addParameter ...
91
                        this.multiplot_object.removePlotByInternalId(tab.items.getAt(0).plotNode.internalId);
5c744625   Benjamin Renard   Synchronize reque...
92
                    }
495fc7a3   Benjamin Renard   Adapt plot UI in ...
93
                },
84d442b4   Benjamin Renard   Synchronize plot ...
94
95
96
                destroy: function(tab, eOpts) {
                    if (!this.tabbar_destroy)
                        this.updatePlotTabs();
495fc7a3   Benjamin Renard   Adapt plot UI in ...
97
98
99
                }
            }
        });
27b2a53e   Benjamin Renard   Link tab plot to ...
100
    	
495fc7a3   Benjamin Renard   Adapt plot UI in ...
101
102
        if (selectTab)
            this.setActiveTab(tabComp);
437c4dbc   Benjamin Renard   First implementat...
103
    	
495fc7a3   Benjamin Renard   Adapt plot UI in ...
104
105
        return tabContent;
    },
437c4dbc   Benjamin Renard   First implementat...
106
	
495fc7a3   Benjamin Renard   Adapt plot UI in ...
107
108
    updatePlotTabs: function()
    {
57e15214   Benjamin Renard   Fix addParameter ...
109
110
111
112
        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
113
            tabContent.tabIndex = i;
57e15214   Benjamin Renard   Fix addParameter ...
114
            var plotNode = tabContent.plotNode;
d29f5012   Benjamin Renard   Fix doPlot
115
            var title = tabContent.getPlotTitle();
57e15214   Benjamin Renard   Fix addParameter ...
116
117
118
119
120
121
            tabItem.setTitle(title);
            if (!this.getActiveTab())
                this.setActiveTab(tabItem);
        }
    },

5c744625   Benjamin Renard   Synchronize reque...
122
123
124
125
126
127
128
129
130
131
132
133
134
135
    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();
            }
        }
    },

57e15214   Benjamin Renard   Fix addParameter ...
136
137
138
139
    getCurrentPlotTabContent : function() {
        if (this.getActiveTab())
            return this.getActiveTab().child();
        return null;
495fc7a3   Benjamin Renard   Adapt plot UI in ...
140
    },
27b2a53e   Benjamin Renard   Link tab plot to ...
141
	
acafe456   Benjamin Renard   Fix Get Data
142
    updateTimeObjects : function() {
495fc7a3   Benjamin Renard   Adapt plot UI in ...
143
144
145
146
147
        for (i = 0; i < this.items.getCount(); ++i)
        {
            this.items.getAt(i).items.getAt(0).updateTimeObject();
        }
    },
27b2a53e   Benjamin Renard   Link tab plot to ...
148
	
495fc7a3   Benjamin Renard   Adapt plot UI in ...
149
150
151
152
    getTreeFromPlotTab: function(plotTab)
    {
        return plotTab.child().treePlot;
    },
437c4dbc   Benjamin Renard   First implementat...
153
	
495fc7a3   Benjamin Renard   Adapt plot UI in ...
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
    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){
                            var tabContent = me.addPlotNode(me.multiplot_object.createNewPlot(), true);
                        }
                    }
84d442b4   Benjamin Renard   Synchronize plot ...
175
176
177
178
179
180
                ],
                listeners: {
                    beforedestroy: function(tabbar, eOpts) {
                        me.tabbar_destroy = true;
                    }
                }
495fc7a3   Benjamin Renard   Adapt plot UI in ...
181
182
183
184
185
            }
        };

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