summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/UI/Common/Components/BaseComponent.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/UI/Common/Components/BaseComponent.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/PM/UI/Common/Components/BaseComponent.js611
1 files changed, 611 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/UI/Common/Components/BaseComponent.js b/frontend/gamma/js/Clipperz/PM/UI/Common/Components/BaseComponent.js
new file mode 100644
index 0000000..26f2fc4
--- a/dev/null
+++ b/frontend/gamma/js/Clipperz/PM/UI/Common/Components/BaseComponent.js
@@ -0,0 +1,611 @@
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.Components');
30
31//#############################################################################
32
33var _Clipperz_PM_Components_base_id_ = 0;
34
35//#############################################################################
36
37Clipperz.PM.UI.Common.Components.BaseComponent = function(args) {
38 args = args || {};
39 Clipperz.PM.UI.Common.Components.BaseComponent.superclass.constructor.call(this, args);
40
41 this._element = args.element || null;
42 this._ids = {};
43
44 this._slots = {};
45 this._slotComponents = {};
46
47 this._components = {};
48
49 this._cachedSlots = {};
50
51 this._isModal = false;
52
53 this._isActive = false;
54 this._elementUsedToEnterModalState;
55
56 this._isFullyRendered = false;
57 this._renderingWaitingQueue = [];
58
59 //this._slots = {
60 // 'header':'header',
61 // 'body': 'body',
62 // 'footer':'footer'
63 //};
64
65 return this;
66}
67
68//=============================================================================
69
70//TODO get back to MochiKit.Base.update as we are not extending anything
71//MochiKit.Base.update(Clipperz.PM.UI.Common.Components.BaseComponent.prototype, {
72Clipperz.Base.extend(Clipperz.PM.UI.Common.Components.BaseComponent, /*Ext.Component*/ Object, {
73
74 'isClipperzPMComponent': true,
75
76 //-------------------------------------------------------------------------
77
78 'toString': function () {
79 return "Clipperz.PM.UI.Common.Components.BaseComponent component";
80 },
81
82 'componentId': function () {
83 return this.getId('_id_');
84 },
85
86 //-------------------------------------------------------------------------
87/*
88 'slots': function() {
89 return this._slots;
90 },
91*/
92 'slotComponents': function() {
93 return this._slotComponents;
94 },
95
96 //-------------------------------------------------------------------------
97
98 'components': function () {
99 return this._components;
100 },
101
102 'addComponent': function (aComponent) {
103 this.components()[aComponent.componentId()] = aComponent;
104 },
105
106 'removeComponent': function (aComponent) {
107 var componentId;
108
109 componentId = aComponent.componentId();
110 this.components()[componentId].remove();
111 delete this.components()[componentId];
112 },
113
114 //-------------------------------------------------------------------------
115/*
116 'domHelper': function() {
117 return Clipperz.YUI.DomHelper;
118 },
119 */
120 //-------------------------------------------------------------------------
121/*
122 'domHelperAppend': function(aValue) {
123 Clipperz.YUI.DomHelper.append(this.element().dom, aValue);
124 },
125 */
126 //-------------------------------------------------------------------------
127
128 'element': function() {
129//MochiKit.Logging.logDebug(">>> BaseComponent.element");
130 return MochiKit.DOM.getElement(this._element);
131 },
132
133 'setElement': function(aNode) {
134 this._element = aNode;
135 },
136
137 //-----------------------------------------------------
138
139 'displayElement': function() {
140 return this.element();
141 },
142
143 //-------------------------------------------------------------------------
144
145 'renderInNode': function(aDomNode) {
146 this.setElement(aDomNode);
147 this.render();
148 },
149
150 'render': function() {
151 this.clear();
152 this.renderSelf();
153 this.renderComponents();
154 if (this.shouldShowTranslationHints()) {
155 this.renderTranslationHints();
156 }
157 if (this.shouldShowElementWhileRendering()) {
158 MochiKit.Style.showElement(this.displayElement());
159 };
160
161 this._isFullyRendered = true;
162
163 MochiKit.Iter.forEach(this.renderingWaitingQueue(), MochiKit.Base.methodcaller('callback'));
164 this.resetRenderingWaitingQueue();
165 },
166
167 'renderSelf': function() {
168 throw Clipperz.Base.exception.AbstractMethod;
169 },
170
171 'renderComponents': function() {
172 varslotName;
173
174 for (slotName in this.slotComponents()) {
175 this.slotComponents()[slotName].renderInNode(this.elementForSlotNamed(slotName));
176 }
177 },
178
179 //.........................................................................
180
181 'isFullyRendered': function () {
182 return this._isFullyRendered;
183 },
184
185 //.........................................................................
186
187 'renderingWaitingQueue': function () {
188 return this._renderingWaitingQueue;
189 },
190
191 'resetRenderingWaitingQueue': function () {
192 this._renderingWaitingQueue = [];
193 },
194
195 //.........................................................................
196
197 'waitUntilFullyRendered': function () {
198 var deferredResult;
199
200 if (this.isFullyRendered() == true) {
201 deferredResult = MochiKit.Async.succeed
202 } else {
203 deferredResult = new Clipperz.Async.Deferred("BaseComponent.waitUntilFullyRendered", {trace:false});
204 this.renderingWaitingQueue().push(deferredResult);
205 }
206
207 return deferredResult;
208 },
209
210 //-----------------------------------------------------
211
212 'renderTranslationHints': function () {
213 vartranslatableItems;
214
215 translatableItems = MochiKit.Selector.findChildElements(this.displayElement(), ['[stringID]']);
216 MochiKit.Iter.forEach(translatableItems, MochiKit.Base.method(this, 'enhanceTranslatableElement'))
217 },
218
219 'enhanceTranslatableElement': function (anElement) {
220//Clipperz.log(">>> enhanceTranslatableElement", anElement);
221 // new Clipperz.PM.UI.Common.Components.TranslatorWidget({
222 // 'element':anElement
223 // });
224
225 MochiKit.Signal.connect(anElement, 'onmouseenter', MochiKit.Base.partial(Clipperz.PM.UI.Common.Components.TranslatorWidget.show, anElement, MochiKit.DOM.getNodeAttribute(anElement, 'stringID')));
226 MochiKit.Signal.connect(anElement, 'onmouseleave', Clipperz.PM.UI.Common.Components.TranslatorWidget.hide);
227//Clipperz.log("<<< enhanceTranslatableElement");
228 },
229
230 //-----------------------------------------------------
231
232 'update': function(args) {
233 throw Clipperz.Base.exception.AbstractMethod;
234 },
235
236 'updateSelf': function(args) {
237 throw Clipperz.Base.exception.AbstractMethod;
238 },
239
240 'updateComponents': function(args) {
241 throw Clipperz.Base.exception.AbstractMethod;
242 },
243
244 //-----------------------------------------------------
245
246 'refresh': function() {
247 throw Clipperz.Base.exception.AbstractMethod;
248 },
249
250 'refreshSelf': function() {
251 throw Clipperz.Base.exception.AbstractMethod;
252 },
253
254 'refreshComponents': function(args) {
255 throw Clipperz.Base.exception.AbstractMethod;
256 },
257
258 //-----------------------------------------------------
259
260 'checkSlotNamed': function(aSlotName) {
261 if (typeof(this._slots[aSlotName]) == 'undefined') {
262 throw new Error("undefined slot");
263 };
264 },
265
266 //-----------------------------------------------------
267
268 'cachedSlots': function() {
269 return this._cachedSlots;
270 },
271
272 'slotNamed': function(aSlotName) {
273 var result;
274
275 this.checkSlotNamed(aSlotName);
276 if (typeof(this.cachedSlots()[aSlotName]) == 'undefined') {
277 this.cachedSlots()[aSlotName] = new Clipperz.PM.UI.Common.Components.ComponentSlot(this,aSlotName);
278 }
279
280 result = this.cachedSlots()[aSlotName];
281
282 return result;
283 },
284
285 //-----------------------------------------------------
286
287 'elementForSlotNamed': function(aSlotName) {
288 return MochiKit.DOM.getElement(this._slots[aSlotName]);
289 },
290
291 //-----------------------------------------------------
292
293 'componentForSlotNamed': function(aSlotName) {
294 return this.slotComponents()[aSlotName];
295 },
296
297 'setComponentForSlotNamed': function(aComponent, aSlotName) {
298 var domNode;
299
300 this.checkSlotNamed(aSlotName);
301
302 if (this.slotComponents()[aSlotName] != null) {
303 this.slotComponents()[aSlotName].remove();
304 }
305
306 this.slotComponents()[aSlotName] = aComponent;
307
308 // domNode = MochiKit.DOM.getElement(this.slotNamed(aSlotName));
309 domNode = this.elementForSlotNamed(aSlotName);
310
311 if (domNode != null) {
312 aComponent.renderInNode(domNode);
313 }
314 },
315
316 //-----------------------------------------------------
317/*
318 'purgeListeners': function() {
319//MochiKit.Logging.logDebug(">>> Clipperz.PM.UI.Common.Components.BaseComponent.purgeListeners [" + this + "]");
320//MochiKit.Logging.logDebug("--- " + this + ".purgeListeners");
321 Clipperz.NotificationCenter.unregister(this);
322 MochiKit.Signal.disconnectAllTo(this);
323//MochiKit.Logging.logDebug("<<< Clipperz.PM.UI.Common.Components.BaseComponent.purgeListeners");
324 },
325 */
326 //-----------------------------------------------------
327
328 'clear': function() {
329 varslotName;
330 var componentId;
331
332 MochiKit.Signal.disconnectAllTo(this);
333
334 for (slotName in this.slotComponents()) {
335 this.slotComponents()[slotName].clear();
336 }
337
338 for (componentId in this.components()) {
339 this.components()[componentId].clear();
340 }
341
342 // if (this.element() != null) {
343 // this.element().innerHTML = "";
344 // }
345
346 if (this.displayElement() != null) {
347 if (this.element() != this.displayElement()) {
348 MochiKit.DOM.removeElement(this.displayElement());
349 } else {
350 this.displayElement().innerHTML = "";
351 }
352 }
353
354 if (this.isModal()) {
355 //TODO: cleanup when the closed element was shown modally.
356 }
357 },
358
359
360 'remove': function() {
361 varslotName;
362 var componentId;
363
364 for (slotName in this.slotComponents()) {
365 this.slotComponents()[slotName].remove();
366 delete this.slotComponents()[slotName];
367 }
368
369 for (componentId in this.components()) {
370 this.components()[componentId].remove();
371 delete this.components()[componentId];
372 }
373
374 this.clear();
375 MochiKit.Signal.disconnectAll(this);
376 },
377
378 'append': function(aNode, aValue) {
379 return Clipperz.DOM.Helper.append(aNode, aValue);
380 },
381
382 'insertBefore': function (aNode, aValue) {
383 return Clipperz.DOM.Helper.insertBefore(aNode, aValue);
384 },
385
386 'insertAfter': function (aNode, aValue) {
387 return Clipperz.DOM.Helper.insertAfter(aNode, aValue);
388 },
389
390 //-------------------------------------------------------------------------
391
392 'getId': function(aValue) {
393 varresult;
394
395 if (typeof(aValue) != 'undefined') {
396 result = this._ids[aValue];
397
398 if (typeof(result) == 'undefined') {
399 _Clipperz_PM_Components_base_id_ ++;
400
401 result = "Clipperz_PM_Components_" + aValue + "_" + _Clipperz_PM_Components_base_id_;
402 this._ids[aValue] = result;
403 }
404 } else {
405 // result = Clipperz.PM.UI.Common.Components.BaseComponent.superclass.getId.call(this);
406 throw "call to BaseComponent.getId with an undefined value";
407 }
408
409 return result;
410 },
411
412 //-------------------------------------------------------------------------
413
414 'getElement': function(aValue) {
415 return Clipperz.DOM.get(this.getId(aValue));
416 },
417
418 //-------------------------------------------------------------------------
419
420 'hideElement': function(anElementName) {
421 MochiKit.Style.hideElement(this.getElement(anElementName));
422 },
423
424 'showElement': function(anElementName) {
425 MochiKit.Style.showElement(this.getElement(anElementName));
426 },
427
428 //-------------------------------------------------------------------------
429
430 'activate': function () {
431 this._isActive = true;
432 },
433
434 'deactivate': function () {
435 this._isActive = false;
436 },
437
438 'isActive': function () {
439 return this._isActive;
440 },
441
442 //-------------------------------------------------------------------------
443
444 'hideSlot': function(aSlotName) {
445 if (this.componentForSlotNamed(aSlotName)) {
446 this.componentForSlotNamed(aSlotName).deactivate();
447 }
448 MochiKit.Style.hideElement(this.elementForSlotNamed(aSlotName));
449 },
450
451 'showSlot': function(aSlotName) {
452 if (this.componentForSlotNamed(aSlotName)) {
453 this.componentForSlotNamed(aSlotName).activate();
454 }
455 MochiKit.Style.showElement(this.elementForSlotNamed(aSlotName));
456 },
457
458 //-------------------------------------------------------------------------
459
460 'shouldShowTranslationHints': function () {
461 return false;
462 },
463
464 'shouldShowElementWhileRendering': function() {
465 return true;
466 },
467
468 //'shouldRemoveElementWhenClearningUp': function () {
469 // return true;
470 //},
471
472 //-------------------------------------------------------------------------
473
474 'isModal': function() {
475 return this._isModal;
476 },
477
478 'setIsModal': function(aValue) {
479 this._isModal = aValue;
480 },
481
482 //-------------------------------------------------------------------------
483
484 'elementUsedToEnterModalState': function () {
485 return this._elementUsedToEnterModalState;
486 },
487
488 'setElementUsedToEnterModalState': function (aValue) {
489 this._elementUsedToEnterModalState = aValue;
490 },
491
492 //-------------------------------------------------------------------------
493
494 'modalDialogMask': function () {
495 return 'modalDialogMask';
496 },
497
498 'modalDialog': function () {
499 return 'modalDialog';
500 },
501
502 'modalDialogFrame': function() {
503 return 'modalDialogFrame'
504 },
505
506 //-------------------------------------------------------------------------
507
508 'deferredShowModal': function(args) {
509 var deferredResult;
510
511 deferredResult = new Clipperz.Async.Deferred("BaseComponent.deferredShowModal", {trace:false});
512
513 deferredResult.addMethod(this, 'setIsModal', true);
514 deferredResult.addCallback(MochiKit.Style.showElement, this.modalDialogMask());
515 deferredResult.addCallback(MochiKit.Base.bind(function(someArgs) {
516 var result;
517 var duration;
518 var from;
519 var to;
520
521 duration = someArgs.duration || 0.4;
522
523 this.setElementUsedToEnterModalState(someArgs.openFromElement);
524 from = Clipperz.Style.getSizeAndPosition(someArgs.openFromElement);
525 this.renderInNode(this.modalDialog());
526 MochiKit.DOM.addElementClass(this.modalDialog(), 'fixed');
527 to = Clipperz.Style.getSizeAndPosition(this.displayElement());
528 Clipperz.PM.UI.Common.Components.BaseComponent.targetModalDimensionsAndPosition = Clipperz.Base.deepClone(to);
529
530 MochiKit.Style.hideElement(this.displayElement());
531 MochiKit.Style.showElement(this.modalDialogFrame());
532
533 result = {from:from, to:to, duration:duration};
534 return result;
535 }, this, args));
536 deferredResult.addCallback(Clipperz.Visual.deferredResize, this.modalDialogFrame());
537 deferredResult.addCallback(MochiKit.Base.bind(function(someArgs) {
538 MochiKit.Style.hideElement(this.modalDialogFrame());
539 MochiKit.Style.showElement(this.displayElement());
540 }, this));
541 deferredResult.addCallback(MochiKit.Async.succeed, arguments[arguments.length - 1]);
542 deferredResult.callback();
543
544 return deferredResult;
545 },
546
547 //-------------------------------------------------------------------------
548
549 'deferredHideModal': function(args) {
550 var deferredResult;
551
552 args = args || {};
553
554 deferredResult = new Clipperz.Async.Deferred("BaseComponent.deferredHideModal", {trace:false});
555 deferredResult.addCallback(MochiKit.Base.bind(function(someArgs) {
556 var result;
557 var from;
558 var toElement;
559 var to;
560 var duration;
561
562 toElement = args.closeToElement || this.elementUsedToEnterModalState();
563 duration = someArgs.duration || 0.4;
564 from = Clipperz.Style.getSizeAndPosition(this.displayElement());
565 to = Clipperz.Style.getSizeAndPosition(toElement);
566
567 MochiKit.Style.hideElement(this.displayElement());
568 MochiKit.Style.showElement(this.modalDialogFrame());
569
570 result = {from:from, to:to, duration:duration};
571 return result;
572 }, this, args));
573 deferredResult.addCallback(Clipperz.Visual.deferredResize, this.modalDialogFrame());
574 deferredResult.addCallback(MochiKit.Base.bind(function() {
575 MochiKit.Style.hideElement(this.modalDialogFrame());
576 MochiKit.Style.hideElement(this.modalDialogMask());
577 }, this));
578 deferredResult.addMethod(this, 'setIsModal', false);
579 deferredResult.addMethod(this, 'clear'); //##############
580 deferredResult.addCallback(MochiKit.Async.succeed, arguments[arguments.length - 1]);
581 deferredResult.callback();
582
583 return deferredResult;
584 },
585
586 //-------------------------------------------------------------------------
587
588 __syntaxFix__: "syntax fix"
589
590});
591
592Clipperz.PM.UI.Common.Components.BaseComponent_modalDialog = function() {
593 Clipperz.DOM.Helper.append(MochiKit.DOM.currentDocument().body,
594 {tag:'div', id:'modalDialogWrapper', cls:'modalDialogWrapper', children:[
595 {tag:'div', id:'modalDialogMask', cls:'modalDialogMask'},
596 {tag:'div', id:'modalDialogFrame', cls:'modalDialogFrame' /*, html:"modal dialog frame"*/},
597 {tag:'div', id:'modalDialog', cls:'modalDialog'}
598 // {tag:'div', id:'modalDialog', cls:'modalDialog', children:[{tag:'div'}]}
599 ]}
600 );
601
602 //MochiKit.Style.hideElement('modalDialogWrapper');
603 MochiKit.Style.hideElement('modalDialogMask');
604 MochiKit.Style.hideElement('modalDialogFrame');
605 //MochiKit.Style.hideElement('modalDialog');
606
607};
608
609//Clipperz.PM.UI.Common.Components.BaseComponent.targetModalDimensionsAndPosition = {'x':'X', 'y':'Y'};
610
611MochiKit.DOM.addLoadEvent(Clipperz.PM.UI.Common.Components.BaseComponent_modalDialog);