Blame view

js/app/views/PlotComponents/PlotTabPanel.js 3.79 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
34
	
	//Request object
	object: null,
	
	constructor: function(config) {
		this.init(config);	    
		this.callParent(arguments);
	},
	
	setRequestObject: function(object)
	{
		this.object = object;
abe09878   Benjamin Renard   Add panels and ax...
35
		this.removeAll();
e9e906ad   Elena.Budnik   update mulritab p...
36
		var selectedTab = this.object.get('active-tab-id');
b9249413   Elena.Budnik   correct init value
37

e9e906ad   Elena.Budnik   update mulritab p...
38
39
40
41
		this.object.tabs().each(function (rec, index) {
			var isSelected = false;
			if (index+1 == selectedTab) 
				isSelected = true;
487a2e40   Elena.Budnik   init for plot
42

e9e906ad   Elena.Budnik   update mulritab p...
43
			this.addPlotTab(rec, isSelected); 	
437c4dbc   Benjamin Renard   First implementat...
44
45
46
		}, this);
	},
	
27b2a53e   Benjamin Renard   Link tab plot to ...
47
	addPlotTab: function(tabObject, selectTab)
437c4dbc   Benjamin Renard   First implementat...
48
	{
abe09878   Benjamin Renard   Add panels and ax...
49
		var tabNumber = this.getTabBar().items.getCount();
27b2a53e   Benjamin Renard   Link tab plot to ...
50
		var tabContent = new amdaPlotComp.PlotTabContent({plotElementPanel: this.plotElementPanel, plotTabPanel : this, tabId : tabObject.get('id')});
abe09878   Benjamin Renard   Add panels and ax...
51
		tabContent.setTabObject(tabObject);
27b2a53e   Benjamin Renard   Link tab plot to ...
52
    	var tabComp = this.add({
abe09878   Benjamin Renard   Add panels and ax...
53
    		title: 'Plot '+tabNumber,
437c4dbc   Benjamin Renard   First implementat...
54
55
56
57
58
59
60
61
    		closable: true,
    		layout: 'fit',
    		bodyStyle: 'background: none',
    		defaults: {
				border: false
			},
    		items: [
    		        tabContent
abe09878   Benjamin Renard   Add panels and ax...
62
63
64
65
66
67
68
69
70
71
72
73
    		],
    		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...
74
75
    				if (tab.items.getAt(0).object)
    					this.object.removeTabById(tab.items.getAt(0).object.get('id'));
abe09878   Benjamin Renard   Add panels and ax...
76
77
78
79
80
    			},
    			destroy: function(tab, eOpts) {
    				this.updatePlotTabs();
    			}
    		}
27b2a53e   Benjamin Renard   Link tab plot to ...
81
82
83
84
    	});
    	
    	if (selectTab)
    		this.setActiveTab(tabComp);
437c4dbc   Benjamin Renard   First implementat...
85
86
87
88
    	
    	return tabContent;
	},
	
abe09878   Benjamin Renard   Add panels and ax...
89
90
	updatePlotTabs: function()
	{
abe09878   Benjamin Renard   Add panels and ax...
91
92
93
94
95
		var i = 0;
		for (i = 0; i < this.items.getCount(); ++i)
		{
			var tabNumber =  i+1;
			this.items.getAt(i).setTitle('Plot '+tabNumber);
dbb7bcbe   Benjamin Renard   Add curves defint...
96
			this.items.getAt(i).items.getAt(0).setTabObject(this.object.tabs().getAt(i));
abe09878   Benjamin Renard   Add panels and ax...
97
98
99
		}
	},
	
27b2a53e   Benjamin Renard   Link tab plot to ...
100
101
102
103
104
105
106
107
108
109
110
	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...
111
112
113
114
115
	getTreeFromPlotTab: function(plotTab)
	{
		return plotTab.child().treePlot;
	},
	
87658ba0   Benjamin Renard   TT Navigation in ...
116
117
118
119
120
121
122
	getSelectedTabId: function()
	{
		if (this.getActiveTab())
			return this.getActiveTab().child().tabId;
		return 0;
	},
	
437c4dbc   Benjamin Renard   First implementat...
123
124
125
126
	init : function(config) {
		var me = this;
		
		this.plotElementPanel = config.plotElementPanel;
27b2a53e   Benjamin Renard   Link tab plot to ...
127
		this.plotUI = config.plotUI;
437c4dbc   Benjamin Renard   First implementat...
128
129
130
		
		var myConf = {
				plain: true,
d341347d   Elena.Budnik   Plot Mgr ameliora...
131
132
				bodyStyle: { background : '#dfe8f6' },
				border : false,
437c4dbc   Benjamin Renard   First implementat...
133
134
				defaults: {
					border: false
d341347d   Elena.Budnik   Plot Mgr ameliora...
135
				},	
437c4dbc   Benjamin Renard   First implementat...
136
137
138
139
140
141
				tabBar:{
					items:[
					       {
					    text:'+',
					    closable: false,
					    handler:function(btn,e){
27b2a53e   Benjamin Renard   Link tab plot to ...
142
					    	var tabContent = me.addPlotTab(me.object.createNewTab(), true);
437c4dbc   Benjamin Renard   First implementat...
143
144
145
146
147
148
					    }
					}]
				},
				
				listeners: {
					tabchange: function(tabPanel, newCard, oldCard, eOpts ) {
abe09878   Benjamin Renard   Add panels and ax...
149
150
						var newCardTree = this.getTreeFromPlotTab(newCard);
						var selectedNode = newCardTree.getSelectedNode();
437c4dbc   Benjamin Renard   First implementat...
151
152
153
						if (selectedNode == null)
							me.plotElementPanel.resetElement();
						else
abe09878   Benjamin Renard   Add panels and ax...
154
							me.plotElementPanel.setElement(selectedNode.type,selectedNode.object, newCardTree);
27b2a53e   Benjamin Renard   Link tab plot to ...
155
						newCardTree.updateLinkedToMultiPlotMode();
437c4dbc   Benjamin Renard   First implementat...
156
157
158
159
160
161
162
163
					},
					scope: me
				}
		};
		
		Ext.apply (this , Ext.apply (arguments, myConf));
	}
});