Blame view

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