Blame view

js/app/views/PlotComponents/PlotTabPanel.js 5.19 KB
437c4dbc   Benjamin Renard   First implementat...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
 * 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', {
	extend: 'Ext.tab.Panel',
	
	requires: [
	           'amdaPlotComp.PlotTabContent'
	],
	
	//Link to the Plot Element Panel
    plotElementPanel: null,
27b2a53e   Benjamin Renard   Link tab plot to ...
20
21
22
    
    //Link to the Plot UI
    plotUI : null,
437c4dbc   Benjamin Renard   First implementat...
23
24
25
26
27
28
29
30
31
32
33
	
	//Request object
	object: null,
	
	constructor: function(config) {
		this.init(config);	    
		this.callParent(arguments);
	},
	
	setRequestObject: function(object)
	{
ebbb3638   Benjamin Renard   Edit plot tab on ...
34
		var me = this;
abe09878   Benjamin Renard   Add panels and ax...
35
		this.removeAll();
0b0c7bc6   Benjamin Renard   Fix bug #6488
36
		this.object = object;
b9249413   Elena.Budnik   correct init value
37

ebbb3638   Benjamin Renard   Edit plot tab on ...
38
		var haveSelectedTab = false;
e9e906ad   Elena.Budnik   update mulritab p...
39
		this.object.tabs().each(function (rec, index) {
ebbb3638   Benjamin Renard   Edit plot tab on ...
40
41
42
43
			if (rec.get('id') == me.object.get('active-tab-id')) {
				haveSelectedTab = true;
			}
		});
487a2e40   Elena.Budnik   init for plot
44

ebbb3638   Benjamin Renard   Edit plot tab on ...
45
46
47
		this.object.tabs().each(function (rec, index) {
			var isSelectedTab = haveSelectedTab ? (rec.get('id') == me.object.get('active-tab-id')) : (index == 0);
			this.addPlotTab(rec, isSelectedTab); 	
437c4dbc   Benjamin Renard   First implementat...
48
49
50
		}, this);
	},
	
27b2a53e   Benjamin Renard   Link tab plot to ...
51
	addPlotTab: function(tabObject, selectTab)
437c4dbc   Benjamin Renard   First implementat...
52
	{
abe09878   Benjamin Renard   Add panels and ax...
53
		var tabNumber = this.getTabBar().items.getCount();
27b2a53e   Benjamin Renard   Link tab plot to ...
54
		var tabContent = new amdaPlotComp.PlotTabContent({plotElementPanel: this.plotElementPanel, plotTabPanel : this, tabId : tabObject.get('id')});
abe09878   Benjamin Renard   Add panels and ax...
55
		tabContent.setTabObject(tabObject);
87dcaf01   Benjamin Renard   Rename plot name ...
56
		var me = this;
27b2a53e   Benjamin Renard   Link tab plot to ...
57
    	var tabComp = this.add({
0c99c4b7   Benjamin Renard   Implements plot t...
58
    		title: (tabObject.get('tab-name') != '') ? tabObject.get('tab-name') : 'Plot '+tabNumber,
437c4dbc   Benjamin Renard   First implementat...
59
60
61
62
63
64
65
66
    		closable: true,
    		layout: 'fit',
    		bodyStyle: 'background: none',
    		defaults: {
				border: false
			},
    		items: [
    		        tabContent
abe09878   Benjamin Renard   Add panels and ax...
67
68
69
70
71
72
73
74
75
76
77
78
    		],
    		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 ) {
dbb7bcbe   Benjamin Renard   Add curves defint...
79
80
    				if (tab.items.getAt(0).object)
    					this.object.removeTabById(tab.items.getAt(0).object.get('id'));
abe09878   Benjamin Renard   Add panels and ax...
81
82
    			},
    			destroy: function(tab, eOpts) {
87dcaf01   Benjamin Renard   Rename plot name ...
83
				
abe09878   Benjamin Renard   Add panels and ax...
84
    				this.updatePlotTabs();
87dcaf01   Benjamin Renard   Rename plot name ...
85
86
    			},
			afterrender: function(tab, e0pts) {
1ecf03bb   Benjamin Renard   Fix
87
88
89
				if (!tab.tab.el) {
					return;
				}
87dcaf01   Benjamin Renard   Rename plot name ...
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
				tab.tab.el.on('contextmenu', function(e, t, eOpts) {
					var menu = new Ext.menu.Menu({
						items: [
							{
								text: 'Rename',
								handler: function() {
									Ext.Msg.prompt('Rename', 'Please enter new plot tab name:', function(btn, text){
										if (btn == 'ok'){
											tabObject.set('tab-name',text);
											me.updatePlotTabs();
										}
									}, me);
								}
							}
						]
					});
					var position = e.getXY();
					e.stopEvent();
					menu.showAt(position);
				},this);
			}
abe09878   Benjamin Renard   Add panels and ax...
111
    		}
27b2a53e   Benjamin Renard   Link tab plot to ...
112
113
114
115
    	});
    	
    	if (selectTab)
    		this.setActiveTab(tabComp);
437c4dbc   Benjamin Renard   First implementat...
116
117
118
119
    	
    	return tabContent;
	},
	
abe09878   Benjamin Renard   Add panels and ax...
120
121
	updatePlotTabs: function()
	{
7c762483   Benjamin Renard   Fix some bugs rel...
122
123
124
125
126
127
128
129
		var me = this;
		var haveSelectedTab = false;
		this.object.tabs().each(function (rec, index) {
			if (rec.get('id') == me.object.get('active-tab-id')) {
				haveSelectedTab = true;
			}
		});

abe09878   Benjamin Renard   Add panels and ax...
130
131
132
		var i = 0;
		for (i = 0; i < this.items.getCount(); ++i)
		{
6e2fdb1f   Benjamin Renard   Implments save cu...
133
134
135
136
137
138
			var tabItem = this.items.getAt(i);
			var tabContent = tabItem.items.getAt(0);
			var tabObj = this.object.tabs().getById(tabContent.tabId);
			if (!tabObj) {
				continue;
			}
7c762483   Benjamin Renard   Fix some bugs rel...
139
140
			if (!haveSelectedTab) {
				//Set first tab as the selected one
6e2fdb1f   Benjamin Renard   Implments save cu...
141
				this.setActiveTab(tabItem);
7c762483   Benjamin Renard   Fix some bugs rel...
142
143
144
145
				this.object.set('active-tab-id', tabObj.get('id'));
				haveSelectedTab = true;
			}
			var tabNumber =  i+1;
6e2fdb1f   Benjamin Renard   Implments save cu...
146
147
			tabItem.setTitle((tabObj.get('tab-name') != '') ? tabObj.get('tab-name') : 'Plot '+tabNumber);
			tabContent.setTabObject(tabObj);
abe09878   Benjamin Renard   Add panels and ax...
148
149
150
		}
	},
	
27b2a53e   Benjamin Renard   Link tab plot to ...
151
152
153
154
155
156
157
158
159
160
161
	updateLinkedToMultiPlotMode : function(isLinkedToMultiPlotMode) {
		this.plotUI.updateLinkedToMultiPlotMode(isLinkedToMultiPlotMode);
	},
	
	updateTimeObject : function() {
		for (i = 0; i < this.items.getCount(); ++i)
		{
			this.items.getAt(i).items.getAt(0).updateTimeObject();
		}
	},
	
437c4dbc   Benjamin Renard   First implementat...
162
163
164
165
166
	getTreeFromPlotTab: function(plotTab)
	{
		return plotTab.child().treePlot;
	},
	
87658ba0   Benjamin Renard   TT Navigation in ...
167
168
169
170
171
172
173
	getSelectedTabId: function()
	{
		if (this.getActiveTab())
			return this.getActiveTab().child().tabId;
		return 0;
	},
	
437c4dbc   Benjamin Renard   First implementat...
174
175
176
177
	init : function(config) {
		var me = this;
		
		this.plotElementPanel = config.plotElementPanel;
27b2a53e   Benjamin Renard   Link tab plot to ...
178
		this.plotUI = config.plotUI;
437c4dbc   Benjamin Renard   First implementat...
179
180
181
		
		var myConf = {
				plain: true,
d341347d   Elena.Budnik   Plot Mgr ameliora...
182
183
				bodyStyle: { background : '#dfe8f6' },
				border : false,
437c4dbc   Benjamin Renard   First implementat...
184
185
				defaults: {
					border: false
d341347d   Elena.Budnik   Plot Mgr ameliora...
186
				},	
437c4dbc   Benjamin Renard   First implementat...
187
188
189
190
191
192
				tabBar:{
					items:[
					       {
					    text:'+',
					    closable: false,
					    handler:function(btn,e){
27b2a53e   Benjamin Renard   Link tab plot to ...
193
					    	var tabContent = me.addPlotTab(me.object.createNewTab(), true);
437c4dbc   Benjamin Renard   First implementat...
194
					    }
87dcaf01   Benjamin Renard   Rename plot name ...
195
					}]
437c4dbc   Benjamin Renard   First implementat...
196
197
198
199
				},
				
				listeners: {
					tabchange: function(tabPanel, newCard, oldCard, eOpts ) {
abe09878   Benjamin Renard   Add panels and ax...
200
201
						var newCardTree = this.getTreeFromPlotTab(newCard);
						var selectedNode = newCardTree.getSelectedNode();
437c4dbc   Benjamin Renard   First implementat...
202
203
204
						if (selectedNode == null)
							me.plotElementPanel.resetElement();
						else
abe09878   Benjamin Renard   Add panels and ax...
205
							me.plotElementPanel.setElement(selectedNode.type,selectedNode.object, newCardTree);
27b2a53e   Benjamin Renard   Link tab plot to ...
206
						newCardTree.updateLinkedToMultiPlotMode();
437c4dbc   Benjamin Renard   First implementat...
207
208
209
210
211
212
213
					},
					scope: me
				}
		};
		
		Ext.apply (this , Ext.apply (arguments, myConf));
	}
0b0c7bc6   Benjamin Renard   Fix bug #6488
214
});