summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/UI/Common/Controllers/TabPanelController.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/UI/Common/Controllers/TabPanelController.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/PM/UI/Common/Controllers/TabPanelController.js188
1 files changed, 188 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/UI/Common/Controllers/TabPanelController.js b/frontend/gamma/js/Clipperz/PM/UI/Common/Controllers/TabPanelController.js
new file mode 100644
index 0000000..fbc5929
--- a/dev/null
+++ b/frontend/gamma/js/Clipperz/PM/UI/Common/Controllers/TabPanelController.js
@@ -0,0 +1,188 @@
1/*
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer to http://www.clipperz.com
12
13* Javascript Crypto Library is free software: you can redistribute
14 it and/or modify it under the terms of the GNU Affero General Public
15 License as published by the Free Software Foundation, either version
16 3 of the License, or (at your option) any later version.
17
18* Javascript Crypto Library is distributed in the hope that it will
19 be useful, but WITHOUT ANY WARRANTY; without even the implied
20 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 See the GNU Affero General Public License for more details.
22
23* You should have received a copy of the GNU Affero General Public
24 License along with Javascript Crypto Library. If not, see
25 <http://www.gnu.org/licenses/>.
26
27*/
28
29Clipperz.Base.module('Clipperz.PM.UI.Common.Controllers');
30
31Clipperz.PM.UI.Common.Controllers.TabPanelController = function(args) {
32 args = args || {};
33
34 this._component = args.component;
35 this._configuration = args.configuration;
36 this._isEnabled = args.enabled || true;
37
38 this._selectedTab = null;
39 return this;
40}
41
42MochiKit.Base.update(Clipperz.PM.UI.Common.Controllers.TabPanelController.prototype, {
43
44 'toString': function() {
45 return "Clipperz.PM.UI.Common.Controllers.TabPanelController";
46 },
47
48 //-----------------------------------------------------------------------------
49
50 'component': function() {
51 return this._component;
52 },
53
54 'configuration': function() {
55 return this._configuration;
56 },
57
58 //-----------------------------------------------------------------------------
59
60 'getElement': function(anElementID) {
61 return this.component().getElement(anElementID);
62 },
63
64 'tabForTabElement': function(anElement) {
65 varresult;
66
67 for (result in this.configuration()) {
68 if (this.getElement(this.configuration()[result]['tab']) == anElement) {
69 break;
70 }
71 }
72
73 return result;
74 },
75
76 //-----------------------------------------------------------------------------
77
78 'setupTab': function(aConfiguration) {
79 vartabElement;
80
81 tabElement = this.getElement(aConfiguration['tab']);
82
83 MochiKit.DOM.removeElementClass(tabElement, 'selected');
84 MochiKit.Signal.connect(tabElement, 'onclick', this, 'handleTabClick')
85 },
86
87 'setupPanel': function(aConfiguration) {
88 this.hidePanel(aConfiguration['panel']);
89 },
90
91 'setup': function(args) {
92 args = args || {};
93
94 MochiKit.Base.map(MochiKit.Base.method(this, 'setupTab'),MochiKit.Base.values(this.configuration()));
95 MochiKit.Base.map(MochiKit.Base.method(this, 'setupPanel'),MochiKit.Base.values(this.configuration()));
96 this.selectTab(args.selected);
97 },
98
99 //-----------------------------------------------------------------------------
100
101 'hidePanel': function(aPanel) {
102 MochiKit.DOM.removeElementClass(this.getElement(aPanel), 'selected');
103 },
104
105 'selectTab': function(aTab) {
106 if ((aTab != this.selectedTab()) && (this.isEnabled())) {
107 if (this.selectedTab() != null) {
108 MochiKit.DOM.removeElementClass(this.getElement(this.configuration()[this.selectedTab()]['tab']),'selected');
109 MochiKit.DOM.removeElementClass(this.getElement(this.configuration()[this.selectedTab()]['panel']),'selected');
110 }
111
112 if (aTab != null) {
113 MochiKit.DOM.addElementClass(this.getElement(this.configuration()[aTab]['tab']),'selected');
114 MochiKit.DOM.addElementClass(this.getElement(this.configuration()[aTab]['panel']),'selected');
115 }
116
117 this.setSelectedTab(aTab);
118 MochiKit.Signal.signal(this, 'tabSelected', aTab);
119 }
120 },
121
122 //-----------------------------------------------------------------------------
123
124 'selectedTab': function() {
125 return this._selectedTab;
126 },
127
128 'setSelectedTab': function(aTab) {
129 this._selectedTab = aTab;
130 },
131
132 //-----------------------------------------------------------------------------
133
134 'selectedTabElement': function() {
135 var result;
136
137 if (this.selectedTab() != null) {
138 result = this.getElement(this.configuration()[this.selectedTab()]['tab']);
139 } else {
140 result = null;
141 }
142
143 return null;
144 },
145
146 'selectedTabPanelElement': function() {
147 var result;
148
149 if (this.selectedTab() != null) {
150 result = this.getElement(this.configuration()[this.selectedTab()]['panel']);
151 } else {
152 result = null;
153 }
154
155 return result;
156 },
157
158 //-----------------------------------------------------------------------------
159
160 'handleTabClick': function(anEvent) {
161 this.selectTab(this.tabForTabElement(anEvent.src()));
162 anEvent.preventDefault();
163 },
164
165 //=============================================================================
166
167 'isEnabled': function () {
168 return this._isEnabled;
169 },
170
171 'enable': function () {
172 this._isEnabled = true;
173 MochiKit.Base.map(MochiKit.Base.bind(function (aTabComponentID) {
174 MochiKit.DOM.removeElementClass(this.getElement(this.configuration()[aTabComponentID]['tab']), 'disabled');
175 }, this), MochiKit.Base.keys(this.configuration()));
176 },
177
178 'disable': function () {
179 this._isEnabled = false;
180 MochiKit.Base.map(MochiKit.Base.bind(function (aTabComponentID) {
181 MochiKit.DOM.addElementClass(this.getElement(this.configuration()[aTabComponentID]['tab']), 'disabled');
182 }, this), MochiKit.Base.keys(this.configuration()));
183 },
184
185 //=============================================================================
186
187 __syntaxFix__: "syntax fix"
188});