summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/UI/Common/Components/SimpleMessagePanel.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/UI/Common/Components/SimpleMessagePanel.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/PM/UI/Common/Components/SimpleMessagePanel.js282
1 files changed, 282 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/UI/Common/Components/SimpleMessagePanel.js b/frontend/gamma/js/Clipperz/PM/UI/Common/Components/SimpleMessagePanel.js
new file mode 100644
index 0000000..b9bb850
--- a/dev/null
+++ b/frontend/gamma/js/Clipperz/PM/UI/Common/Components/SimpleMessagePanel.js
@@ -0,0 +1,282 @@
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.Web.Components');
30
31Clipperz.PM.UI.Common.Components.SimpleMessagePanel = function(args) {
32 args = args || {};
33
34 Clipperz.PM.UI.Common.Components.SimpleMessagePanel.superclass.constructor.apply(this, arguments);
35
36 this._title = args.title || Clipperz.Base.exception.raise('MandatoryParameter');
37 this._text = args.text || Clipperz.Base.exception.raise('MandatoryParameter');
38 this._type = args.type || Clipperz.Base.exception.raise('MandatoryParameter'); //ALERT, INFO, ERROR
39 this._buttons = args.buttons || Clipperz.Base.exception.raise('MandatoryParameter');
40
41 this._buttonComponents = [];
42 this._deferred = null;
43
44 this.renderModalMask();
45
46 return this;
47}
48
49//=============================================================================
50
51Clipperz.Base.extend(Clipperz.PM.UI.Common.Components.SimpleMessagePanel, Clipperz.PM.UI.Common.Components.BaseComponent, {
52
53 //-------------------------------------------------------------------------
54
55 'toString': function () {
56 return "Clipperz.PM.UI.Common.Components.SimpleMessagePanel component";
57 },
58
59 //-------------------------------------------------------------------------
60
61 'deferred': function() {
62 if (this._deferred == null) {
63 this._deferred = new Clipperz.Async.Deferred("SimpleMessagePanel.deferred", {trace:false});
64 }
65
66 return this._deferred;
67 },
68
69 //-------------------------------------------------------------------------
70
71 'title': function () {
72 return this._title;
73 },
74
75 'setTitle': function (aValue) {
76 this._title = aValue;
77
78 if (this.getElement('title') != null) {
79 this.getElement('title').innerHTML = aValue;
80 }
81 },
82
83 //-------------------------------------------------------------------------
84
85 'text': function () {
86 return this._text;
87 },
88
89 'setText': function (aValue) {
90 this._text = aValue;
91
92 if (this.getElement('text') != null) {
93 this.getElement('text').innerHTML = aValue;
94 }
95 },
96
97 //-------------------------------------------------------------------------
98
99 'type': function () {
100 return this._type;
101 },
102
103 'setType': function (aValue) {
104 if (this.getElement('icon') != null) {
105 MochiKit.DOM.removeElementClass(this.getId('icon'), this._type);
106 MochiKit.DOM.addElementClass(this.getId('icon'), aValue);
107 }
108
109 this._type = aValue;
110 },
111
112 //-------------------------------------------------------------------------
113
114 'buttons': function () {
115 return this._buttons;
116 },
117
118 'setButtons': function (someValues) {
119 MochiKit.Iter.forEach(this.buttonComponents(), MochiKit.Base.methodcaller('clear'));
120
121 this._buttons = someValues;
122
123 if (this.getElement('buttonArea') != null) {
124 this.renderButtons();
125 }
126 },
127
128 //.........................................................................
129
130 'buttonComponents': function () {
131 return this._buttonComponents;
132 },
133
134 //-------------------------------------------------------------------------
135
136 'renderSelf': function() {
137 this.append(this.element(), {tag:'div', cls:'SimpleMessagePanel', id:this.getId('panel'), children: [
138 {tag:'div', cls:'header', children:[]},
139 {tag:'div', cls:'body', children:[
140 {tag:'div', id:this.getId('icon'),cls:'img ' + this.type(), children:[{tag:'div'}]},
141 {tag:'h3', id:this.getId('title'),html:this.title()},
142 {tag:'p', id:this.getId('text'),html:this.text()},
143 {tag:'div', id:this.getId('container')},
144 {tag:'div', id:this.getId('buttonArea'), cls:'buttonArea', children:[]}
145 ]},
146 {tag:'div', cls:'footer', children:[]}
147 ]});
148
149 MochiKit.Signal.connect(this.getId('panel'), 'onkeydown', this, 'keyDownHandler');
150
151 this.renderButtons();
152 },
153
154 //-------------------------------------------------------------------------
155
156 'renderButtons': function () {
157 this.getElement('buttonArea').innerHTML = '';
158
159 MochiKit.Base.map(MochiKit.Base.bind(function (aButton) {
160 var buttonElement;
161 var buttonComponent;
162
163 // element = this.append(this.getElement('buttonArea'), {tag:'div', cls:'button' + (aButton['isDefault'] === true ? ' default' : ''), children:[
164 // {tag:'a', href:'#'/*, id:this.getId('buttonLink')*/, html:aButton['text']}
165 // ]});
166
167 buttonElement = this.append(this.getElement('buttonArea'), {tag:'div'});
168 buttonComponent = new Clipperz.PM.UI.Common.Components.Button({'element':buttonElement, 'text':aButton['text'], 'isDefault':aButton['isDefault']});
169 this.buttonComponents().push(buttonComponent);
170
171 MochiKit.Signal.connect(buttonComponent, 'onclick', MochiKit.Base.method(this, 'buttonEventHandler', aButton));
172 }, this), MochiKit.Iter.reversed(this.buttons()));
173 },
174
175 //-------------------------------------------------------------------------
176
177 'displayElement': function() {
178 return this.getElement('panel');
179 },
180
181 //-------------------------------------------------------------------------
182
183 'closeOk': function () {
184 this.deferred().callback();
185 this._deferred = null;
186 },
187
188 'closeCancel': function () {
189 this.deferred().cancel();
190 this._deferred = null;
191 },
192
193 'closeError': function () {
194 this.deferred().errback();
195 this._deferred = null;
196 },
197
198 //-------------------------------------------------------------------------
199
200 'buttonEventHandler': function(aButton, anEvent) {
201 anEvent.preventDefault();
202
203 // MochiKit.Signal.signal(this, 'cancelEvent');
204 switch (aButton['result']) {
205 case 'OK':
206//console.log("==> OK");
207 this.closeOk();
208 break;
209 case 'CANCEL':
210//console.log("==> CANCEL");
211 this.closeCancel();
212 break;
213 default:
214//console.log("==> ????");
215 this.closeError();
216 break;
217 }
218//console.log("<==");
219 },
220
221 //-------------------------------------------------------------------------
222
223 'deferredShow': function (someArgs, aResult) {
224 this.deferredShowModal(someArgs);
225
226 this.deferred().addMethod(this, 'deferredHideModal', {closeToElement:someArgs.onOkCloseToElement });
227 this.deferred().addErrback (MochiKit.Base.method(this, 'deferredHideModal', {closeToElement:someArgs.onCancelCloseToElement }));
228 this.deferred().addCallback(MochiKit.Async.succeed, aResult);
229
230 return this.deferred();
231 },
232
233 //-------------------------------------------------------------------------
234
235 'modalDialogMask': function () {
236 return this.getId('modalDialogMask');
237 },
238
239 'modalDialog': function () {
240 return this.getId('modalDialog');
241 },
242
243 'modalDialogFrame': function() {
244 return this.getId('modalDialogFrame');
245 },
246
247 //-------------------------------------------------------------------------
248
249 'renderModalMask': function () {
250 Clipperz.DOM.Helper.append(MochiKit.DOM.currentDocument().body,
251 {tag:'div', id:this.getId('modalDialogWrapper'), cls:'modalDialogWrapper simpleMessagePanelMask', children:[
252 {tag:'div', id:this.getId('modalDialogMask'), cls:'modalDialogMask simpleMessagePanelMask'},
253 {tag:'div', id:this.getId('modalDialogFrame'), cls:'modalDialogFrame simpleMessagePanelMask'},
254 {tag:'div', id:this.getId('modalDialog'), cls:'modalDialog simpleMessagePanelMask'}
255 ]}
256 );
257
258 MochiKit.Style.hideElement(this.getId('modalDialogMask'));
259 MochiKit.Style.hideElement(this.getId('modalDialogFrame'));
260 },
261
262 //-------------------------------------------------------------------------
263
264 'keyDownHandler': function (anEvent) {
265 if (anEvent.key().string == 'KEY_ENTER') {
266 anEvent.preventDefault();
267//console.log("13 - RETURN ?", this);
268 this.closeOk();
269//console.log('<<< 13')
270 }
271
272 if (anEvent.key().string == 'KEY_ESCAPE') {
273 anEvent.preventDefault();
274//console.log("27 - ESC ?", this);
275 this.closeCancel();
276//console.log("<<< 27");
277 }
278 },
279
280 //-------------------------------------------------------------------------
281 __syntaxFix__: "syntax fix"
282});