Blame view

js/app/views/PlotComponents/PlotTabPanel.js 2.96 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
20
21
22
23
24
25
26
27
28
29
30
31
/**
 * 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,
	
	//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...
32
		this.removeAll();
437c4dbc   Benjamin Renard   First implementat...
33
		this.object.tabs().each(function (rec) {
abe09878   Benjamin Renard   Add panels and ax...
34
			this.addPlotTab(rec);
437c4dbc   Benjamin Renard   First implementat...
35
36
37
		}, this);
	},
	
abe09878   Benjamin Renard   Add panels and ax...
38
	addPlotTab: function(tabObject)
437c4dbc   Benjamin Renard   First implementat...
39
	{
abe09878   Benjamin Renard   Add panels and ax...
40
		var tabNumber = this.getTabBar().items.getCount();
dbb7bcbe   Benjamin Renard   Add curves defint...
41
		var tabContent = new amdaPlotComp.PlotTabContent({plotElementPanel: this.plotElementPanel});
abe09878   Benjamin Renard   Add panels and ax...
42
		tabContent.setTabObject(tabObject);
437c4dbc   Benjamin Renard   First implementat...
43
    	this.add({
abe09878   Benjamin Renard   Add panels and ax...
44
    		title: 'Plot '+tabNumber,
437c4dbc   Benjamin Renard   First implementat...
45
46
47
48
49
50
51
52
    		closable: true,
    		layout: 'fit',
    		bodyStyle: 'background: none',
    		defaults: {
				border: false
			},
    		items: [
    		        tabContent
abe09878   Benjamin Renard   Add panels and ax...
53
54
55
56
57
58
59
60
61
62
63
64
    		],
    		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...
65
66
    				if (tab.items.getAt(0).object)
    					this.object.removeTabById(tab.items.getAt(0).object.get('id'));
abe09878   Benjamin Renard   Add panels and ax...
67
68
69
70
71
    			},
    			destroy: function(tab, eOpts) {
    				this.updatePlotTabs();
    			}
    		}
437c4dbc   Benjamin Renard   First implementat...
72
73
74
75
76
    	}).show();
    	
    	return tabContent;
	},
	
abe09878   Benjamin Renard   Add panels and ax...
77
78
	updatePlotTabs: function()
	{
abe09878   Benjamin Renard   Add panels and ax...
79
80
81
82
83
		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...
84
			this.items.getAt(i).items.getAt(0).setTabObject(this.object.tabs().getAt(i));
abe09878   Benjamin Renard   Add panels and ax...
85
86
87
		}
	},
	
437c4dbc   Benjamin Renard   First implementat...
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
	getTreeFromPlotTab: function(plotTab)
	{
		return plotTab.child().treePlot;
	},
	
	init : function(config) {
		var me = this;
		
		this.plotElementPanel = config.plotElementPanel;
		
		var myConf = {
				plain: true,
				bodyStyle: { background : '#dfe8f6' },  
				defaults: {
					border: false
				},
				
				tabBar:{
					items:[
					       {
					    text:'+',
					    closable: false,
					    handler:function(btn,e){
abe09878   Benjamin Renard   Add panels and ax...
111
					    	var tabContent = me.addPlotTab(me.object.createNewTab());
437c4dbc   Benjamin Renard   First implementat...
112
113
114
115
116
117
					    }
					}]
				},
				
				listeners: {
					tabchange: function(tabPanel, newCard, oldCard, eOpts ) {
abe09878   Benjamin Renard   Add panels and ax...
118
119
						var newCardTree = this.getTreeFromPlotTab(newCard);
						var selectedNode = newCardTree.getSelectedNode();
437c4dbc   Benjamin Renard   First implementat...
120
121
122
						if (selectedNode == null)
							me.plotElementPanel.resetElement();
						else
abe09878   Benjamin Renard   Add panels and ax...
123
							me.plotElementPanel.setElement(selectedNode.type,selectedNode.object, newCardTree);
437c4dbc   Benjamin Renard   First implementat...
124
125
126
127
128
129
130
131
					},
					scope: me
				}
		};
		
		Ext.apply (this , Ext.apply (arguments, myConf));
	}
});