Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/UI/Web/Components/GridComponent.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/PM/UI/Web/Components/GridComponent.js | 262 |
1 files changed, 262 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/UI/Web/Components/GridComponent.js b/frontend/gamma/js/Clipperz/PM/UI/Web/Components/GridComponent.js new file mode 100644 index 0000000..8b3e6c9 --- a/dev/null +++ b/frontend/gamma/js/Clipperz/PM/UI/Web/Components/GridComponent.js | |||
@@ -0,0 +1,262 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | ||
11 | refer 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 | |||
29 | Clipperz.Base.module('Clipperz.PM.UI.Web.Components'); | ||
30 | |||
31 | Clipperz.PM.UI.Web.Components.GridComponent = function(args) { | ||
32 | args = args || {}; | ||
33 | |||
34 | Clipperz.PM.UI.Web.Components.GridComponent.superclass.constructor.apply(this, arguments); | ||
35 | |||
36 | this._columnsManagers = args.columnsManagers; | ||
37 | |||
38 | this._rowsObjects = []; | ||
39 | this._noRowsGridComponent = null; | ||
40 | |||
41 | this._slots = { | ||
42 | 'headerSlot':this.getId('headerSlot') | ||
43 | }; | ||
44 | |||
45 | return this; | ||
46 | } | ||
47 | |||
48 | //============================================================================= | ||
49 | |||
50 | Clipperz.Base.extend(Clipperz.PM.UI.Web.Components.GridComponent, Clipperz.PM.UI.Common.Components.BaseComponent, { | ||
51 | |||
52 | //------------------------------------------------------------------------- | ||
53 | |||
54 | 'toString': function () { | ||
55 | return "Clipperz.PM.UI.Web.Components.GridComponent component"; | ||
56 | }, | ||
57 | |||
58 | //------------------------------------------------------------------------- | ||
59 | |||
60 | 'rows': function () { | ||
61 | throw Clipperz.Base.exception.AbstractMethod; | ||
62 | // return this._rows; | ||
63 | }, | ||
64 | |||
65 | //------------------------------------------------------------------------- | ||
66 | |||
67 | 'columnsManagers': function () { | ||
68 | return this._columnsManagers; | ||
69 | }, | ||
70 | |||
71 | //------------------------------------------------------------------------- | ||
72 | |||
73 | 'renderSelf': function(/*aContainer, aPosition*/) { | ||
74 | this.append(this.element(), [ | ||
75 | {tag:'div', cls:'header', children:[ | ||
76 | {tag:'form', id:this.getId('searchForm'), cls:'search', children:[ | ||
77 | {tag:'div', cls:'search', children:[ | ||
78 | {tag:'input', type:'text', id:this.getId('search'), cls:'search', placeholder:"search", name:'textToSearch'/*, value:"clipperz"*/} | ||
79 | ]}, | ||
80 | {tag:'div', cls:'clearSearchButton', id:this.getId('clearSearch')}, | ||
81 | // {tag:'input', type:'button', cls:'searchButton', name:'searchButton', value:"search"}, | ||
82 | {tag:'div', cls:'headerSlot', id:this.getId('headerSlot')} | ||
83 | ]} | ||
84 | ]}, | ||
85 | {tag:'div', cls:'body', children:[ | ||
86 | {tag:'div', cls:'rows', id:this.getId('rows'), children:[ | ||
87 | {tag:'table', cellpadding:'0', cellspacing:'0', cls:'rows', children:[ | ||
88 | {tag:'thead', children:[ | ||
89 | {tag:'tr', id:this.getId('thead_tr'), children:[]} | ||
90 | ]}, | ||
91 | {tag:'tbody', id:this.getId('gridRows'), children:[]} | ||
92 | ]} | ||
93 | ]}, | ||
94 | {tag:'div', cls:'noRowsBlock', id:this.getId('noRowsBlock'), children:[]} | ||
95 | ]}, | ||
96 | {tag:'div', cls:'footer'} | ||
97 | ]); | ||
98 | |||
99 | this.renderHeader(); | ||
100 | MochiKit.Signal.connect(this.getId('clearSearch'), 'onclick', this, 'clearSearchHandler'); | ||
101 | }, | ||
102 | |||
103 | //------------------------------------------------------------------------- | ||
104 | |||
105 | 'renderHeader': function () { | ||
106 | var headerElement; | ||
107 | |||
108 | headerElement = this.getElement('thead_tr'); | ||
109 | headerElement.innerHTML = ""; | ||
110 | |||
111 | MochiKit.Iter.forEach(this.columnsManagers(), function (aColumnManager) { | ||
112 | aColumnManager.renderHeader(headerElement); | ||
113 | }); | ||
114 | }, | ||
115 | |||
116 | //------------------------------------------------------------------------- | ||
117 | |||
118 | 'update': function (someObjects) { | ||
119 | this._rowsObjects = someObjects | ||
120 | this.refresh(); | ||
121 | this.focus(); | ||
122 | }, | ||
123 | |||
124 | 'focus': function () { | ||
125 | this.getElement('search').focus(); | ||
126 | }, | ||
127 | |||
128 | //------------------------------------------------------------------------- | ||
129 | |||
130 | 'startSearch': function () { | ||
131 | //console.log("--> startSearch"); | ||
132 | MochiKit.DOM.addElementClass(this.getElement('search'), 'running'); | ||
133 | }, | ||
134 | |||
135 | 'endSearch': function () { | ||
136 | MochiKit.DOM.removeElementClass(this.getElement('search'), 'running'); | ||
137 | //console.log("<-- startSearch"); | ||
138 | }, | ||
139 | |||
140 | //------------------------------------------------------------------------- | ||
141 | |||
142 | 'disconnectColumnManagersRowsSignals': function () { | ||
143 | MochiKit.Iter.forEach(this.columnsManagers(), function (aColumnManager) { | ||
144 | aColumnManager.disconnectRowsSignals(); | ||
145 | }); | ||
146 | }, | ||
147 | |||
148 | //------------------------------------------------------------------------- | ||
149 | |||
150 | 'refresh': function () { | ||
151 | var gridRowsElement; | ||
152 | var rowClass; | ||
153 | |||
154 | this.disconnectColumnManagersRowsSignals(); | ||
155 | |||
156 | { | ||
157 | MochiKit.DOM.removeElementClass(this.getElement('search'), 'disabled'); | ||
158 | // MochiKit.DOM.setNodeAttribute(this.getElement('search'), 'disabled', null); | ||
159 | MochiKit.DOM.removeElementClass(this.element(), 'empty'); | ||
160 | MochiKit.DOM.removeElementClass(this.element(), 'noRows'); | ||
161 | } | ||
162 | |||
163 | |||
164 | gridRowsElement = this.getElement('gridRows'); | ||
165 | gridRowsElement.innerHTML = ""; | ||
166 | |||
167 | MochiKit.DOM.removeElementClass(this.element(), 'empty'); | ||
168 | |||
169 | rowClass = 'odd'; | ||
170 | MochiKit.Iter.forEach(this._rowsObjects, MochiKit.Base.bind(function (aRowObject) { | ||
171 | var cardRowElement; | ||
172 | |||
173 | cardRowElement = this.append(gridRowsElement, {tag:'tr', id:this.getId(aRowObject['_reference']), cls:rowClass}); | ||
174 | MochiKit.Iter.forEach(this.columnsManagers(), function (aColumnManager) { | ||
175 | aColumnManager.renderCell(cardRowElement, aRowObject); | ||
176 | }); | ||
177 | |||
178 | rowClass = (rowClass == 'odd') ? 'even' : 'odd'; | ||
179 | }, this)); | ||
180 | }, | ||
181 | |||
182 | //----------------------------------------------------------------------------- | ||
183 | |||
184 | 'filterElement': function () { | ||
185 | return this.getElement('search'); | ||
186 | }, | ||
187 | |||
188 | //------------------------------------------------------------------------- | ||
189 | |||
190 | 'shouldShowElementWhileRendering': function () { | ||
191 | return false; | ||
192 | }, | ||
193 | |||
194 | //------------------------------------------------------------------------- | ||
195 | |||
196 | 'selectRow': function (aRowObject) { | ||
197 | MochiKit.DOM.addElementClass(this.getId(aRowObject['_reference']), 'selected'); | ||
198 | }, | ||
199 | |||
200 | 'unselectRow': function (aRowObject) { | ||
201 | MochiKit.DOM.removeElementClass(this.getId(aRowObject['_reference']), 'selected'); | ||
202 | }, | ||
203 | |||
204 | //------------------------------------------------------------------------- | ||
205 | /* | ||
206 | 'passOpenDirectLogin': function(aDirectLoginReferenceId) { | ||
207 | MochiKit.Signal.signal(this, 'openDirectLogin', aDirectLoginReferenceId); | ||
208 | }, | ||
209 | */ | ||
210 | //------------------------------------------------------------------------- | ||
211 | |||
212 | 'clearSearchHandler': function (anEvent) { | ||
213 | var searchElement; | ||
214 | |||
215 | anEvent.preventDefault(); | ||
216 | |||
217 | searchElement = this.getElement('search'); | ||
218 | searchElement.value = ""; | ||
219 | searchElement.focus(); | ||
220 | }, | ||
221 | |||
222 | //------------------------------------------------------------------------- | ||
223 | |||
224 | 'drawEmpty': function () { | ||
225 | this.disconnectColumnManagersRowsSignals(); | ||
226 | MochiKit.DOM.addElementClass(this.getElement('search'), 'disabled'); | ||
227 | // MochiKit.DOM.setNodeAttribute(this.getElement('search'), 'disabled', 'disabled'); | ||
228 | |||
229 | gridRowsElement = this.getElement('gridRows'); | ||
230 | gridRowsElement.innerHTML = ""; | ||
231 | MochiKit.DOM.addElementClass(this.element(), 'empty'); | ||
232 | }, | ||
233 | |||
234 | //------------------------------------------------------------------------- | ||
235 | |||
236 | 'setNoRowsGridComponent': function (aComponent) { | ||
237 | this.removeNoRowsGridComponent(); | ||
238 | this._noRowsGridComponent = aComponent; | ||
239 | |||
240 | this.disconnectColumnManagersRowsSignals(); | ||
241 | MochiKit.DOM.addElementClass(this.getElement('search'), 'disabled'); | ||
242 | // MochiKit.DOM.setNodeAttribute(this.getElement('search'), 'disabled', 'disabled'); | ||
243 | |||
244 | gridRowsElement = this.getElement('gridRows'); | ||
245 | gridRowsElement.innerHTML = ""; | ||
246 | MochiKit.DOM.addElementClass(this.element(), 'noRows'); | ||
247 | |||
248 | if (aComponent != null) { | ||
249 | aComponent.renderInNode(this.getElement('noRowsBlock')); | ||
250 | } | ||
251 | }, | ||
252 | |||
253 | 'removeNoRowsGridComponent': function () { | ||
254 | if (this._noRowsGridComponent != null) { | ||
255 | this._noRowsGridComponent.remove(); | ||
256 | this._noRowsGridComponent = null; | ||
257 | } | ||
258 | }, | ||
259 | |||
260 | //------------------------------------------------------------------------- | ||
261 | __syntaxFix__: "syntax fix" | ||
262 | }); | ||