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.js | 34 |
1 files changed, 26 insertions, 8 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 index 1992154..1d816a9 100644 --- a/frontend/gamma/js/Clipperz/PM/UI/Common/Components/SimpleMessagePanel.js +++ b/frontend/gamma/js/Clipperz/PM/UI/Common/Components/SimpleMessagePanel.js | |||
@@ -1,279 +1,297 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2011 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz Community Edition. |
6 | Clipperz Community Edition is an online password manager. | 6 | Clipperz Community Edition is an online password manager. |
7 | For further information about its features and functionalities please | 7 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 8 | refer to http://www.clipperz.com. |
9 | 9 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 10 | * Clipperz Community Edition is free software: you can redistribute |
11 | it and/or modify it under the terms of the GNU Affero General Public | 11 | it and/or modify it under the terms of the GNU Affero General Public |
12 | License as published by the Free Software Foundation, either version | 12 | License as published by the Free Software Foundation, either version |
13 | 3 of the License, or (at your option) any later version. | 13 | 3 of the License, or (at your option) any later version. |
14 | 14 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 15 | * Clipperz Community Edition is distributed in the hope that it will |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 16 | be useful, but WITHOUT ANY WARRANTY; without even the implied |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 18 | See the GNU Affero General Public License for more details. |
19 | 19 | ||
20 | * You should have received a copy of the GNU Affero General Public | 20 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 21 | License along with Clipperz Community Edition. If not, see |
22 | <http://www.gnu.org/licenses/>. | 22 | <http://www.gnu.org/licenses/>. |
23 | 23 | ||
24 | */ | 24 | */ |
25 | 25 | ||
26 | Clipperz.Base.module('Clipperz.PM.UI.Web.Components'); | 26 | Clipperz.Base.module('Clipperz.PM.UI.Web.Components'); |
27 | 27 | ||
28 | Clipperz.PM.UI.Common.Components.SimpleMessagePanel = function(args) { | 28 | Clipperz.PM.UI.Common.Components.SimpleMessagePanel = function(args) { |
29 | args = args || {}; | 29 | args = args || {}; |
30 | 30 | ||
31 | Clipperz.PM.UI.Common.Components.SimpleMessagePanel.superclass.constructor.apply(this, arguments); | 31 | Clipperz.PM.UI.Common.Components.SimpleMessagePanel.superclass.constructor.apply(this, arguments); |
32 | 32 | ||
33 | this._title = args.title || Clipperz.Base.exception.raise('MandatoryParameter'); | 33 | this._title = args.title || Clipperz.Base.exception.raise('MandatoryParameter'); |
34 | this._text = args.text || Clipperz.Base.exception.raise('MandatoryParameter'); | 34 | this._text = args.text || Clipperz.Base.exception.raise('MandatoryParameter'); |
35 | this._type = args.type || Clipperz.Base.exception.raise('MandatoryParameter'); //ALERT, INFO, ERROR | 35 | this._type = args.type || Clipperz.Base.exception.raise('MandatoryParameter'); //ALERT, INFO, ERROR |
36 | this._buttons = args.buttons || Clipperz.Base.exception.raise('MandatoryParameter'); | 36 | this._buttons = args.buttons || Clipperz.Base.exception.raise('MandatoryParameter'); |
37 | 37 | ||
38 | this._buttonComponents = []; | 38 | this._buttonComponents = []; |
39 | this._deferred = null; | 39 | this._deferred = null; |
40 | 40 | ||
41 | this.renderModalMask(); | 41 | this.renderModalMask(); |
42 | 42 | ||
43 | return this; | 43 | return this; |
44 | } | 44 | } |
45 | 45 | ||
46 | //============================================================================= | 46 | //============================================================================= |
47 | 47 | ||
48 | Clipperz.Base.extend(Clipperz.PM.UI.Common.Components.SimpleMessagePanel, Clipperz.PM.UI.Common.Components.BaseComponent, { | 48 | Clipperz.Base.extend(Clipperz.PM.UI.Common.Components.SimpleMessagePanel, Clipperz.PM.UI.Common.Components.BaseComponent, { |
49 | 49 | ||
50 | //------------------------------------------------------------------------- | 50 | //------------------------------------------------------------------------- |
51 | 51 | ||
52 | 'toString': function () { | 52 | 'toString': function () { |
53 | return "Clipperz.PM.UI.Common.Components.SimpleMessagePanel component"; | 53 | return "Clipperz.PM.UI.Common.Components.SimpleMessagePanel component"; |
54 | }, | 54 | }, |
55 | 55 | ||
56 | //------------------------------------------------------------------------- | 56 | //------------------------------------------------------------------------- |
57 | 57 | ||
58 | 'deferred': function() { | 58 | 'deferred': function() { |
59 | if (this._deferred == null) { | 59 | if (this._deferred == null) { |
60 | this._deferred = new Clipperz.Async.Deferred("SimpleMessagePanel.deferred", {trace:false}); | 60 | this._deferred = new Clipperz.Async.Deferred("SimpleMessagePanel.deferred", {trace:false}); |
61 | } | 61 | } |
62 | 62 | ||
63 | return this._deferred; | 63 | return this._deferred; |
64 | }, | 64 | }, |
65 | 65 | ||
66 | //------------------------------------------------------------------------- | 66 | //------------------------------------------------------------------------- |
67 | 67 | ||
68 | 'title': function () { | 68 | 'title': function () { |
69 | return this._title; | 69 | return this._title; |
70 | }, | 70 | }, |
71 | 71 | ||
72 | 'setTitle': function (aValue) { | 72 | 'setTitle': function (aValue) { |
73 | this._title = aValue; | 73 | this._title = aValue; |
74 | 74 | ||
75 | if (this.getElement('title') != null) { | 75 | if (this.getElement('title') != null) { |
76 | this.getElement('title').innerHTML = aValue; | 76 | this.getElement('title').innerHTML = aValue; |
77 | } | 77 | } |
78 | }, | 78 | }, |
79 | 79 | ||
80 | //------------------------------------------------------------------------- | 80 | //------------------------------------------------------------------------- |
81 | 81 | ||
82 | 'text': function () { | 82 | 'text': function () { |
83 | return this._text; | 83 | return this._text; |
84 | }, | 84 | }, |
85 | 85 | ||
86 | 'setText': function (aValue) { | 86 | 'setText': function (aValue) { |
87 | this._text = aValue; | 87 | this._text = aValue; |
88 | 88 | ||
89 | if (this.getElement('text') != null) { | 89 | if (this.getElement('text') != null) { |
90 | this.getElement('text').innerHTML = aValue; | 90 | this.getElement('text').innerHTML = aValue; |
91 | } | 91 | } |
92 | }, | 92 | }, |
93 | 93 | ||
94 | //------------------------------------------------------------------------- | 94 | //------------------------------------------------------------------------- |
95 | 95 | ||
96 | 'type': function () { | 96 | 'type': function () { |
97 | return this._type; | 97 | return this._type; |
98 | }, | 98 | }, |
99 | 99 | ||
100 | 'setType': function (aValue) { | 100 | 'setType': function (aValue) { |
101 | if (this.getElement('icon') != null) { | 101 | // if (this.getElement('icon') != null) { |
102 | MochiKit.DOM.removeElementClass(this.getId('icon'), this._type); | 102 | // MochiKit.DOM.removeElementClass(this.getId('icon'), this._type); |
103 | MochiKit.DOM.addElementClass(this.getId('icon'), aValue); | 103 | // MochiKit.DOM.addElementClass(this.getId('icon'), aValue); |
104 | } | 104 | // } |
105 | 105 | ||
106 | this._type = aValue; | 106 | this._type = aValue; |
107 | }, | 107 | }, |
108 | 108 | ||
109 | 'icon': function () { | ||
110 | var type = this.type(); | ||
111 | var result; | ||
112 | |||
113 | if (type == 'ALERT') { | ||
114 | result = '!'; | ||
115 | } else if (type == 'INFO') { | ||
116 | result = 'i'; | ||
117 | } else if (type == 'ERROR') { | ||
118 | result = '!'; | ||
119 | } | ||
120 | |||
121 | return result; | ||
122 | }, | ||
123 | |||
109 | //------------------------------------------------------------------------- | 124 | //------------------------------------------------------------------------- |
110 | 125 | ||
111 | 'buttons': function () { | 126 | 'buttons': function () { |
112 | return this._buttons; | 127 | return this._buttons; |
113 | }, | 128 | }, |
114 | 129 | ||
115 | 'setButtons': function (someValues) { | 130 | 'setButtons': function (someValues) { |
116 | MochiKit.Iter.forEach(this.buttonComponents(), MochiKit.Base.methodcaller('clear')); | 131 | MochiKit.Iter.forEach(this.buttonComponents(), MochiKit.Base.methodcaller('clear')); |
117 | 132 | ||
118 | this._buttons = someValues; | 133 | this._buttons = someValues; |
119 | 134 | ||
120 | if (this.getElement('buttonArea') != null) { | 135 | if (this.getElement('buttonArea') != null) { |
121 | this.renderButtons(); | 136 | this.renderButtons(); |
122 | } | 137 | } |
123 | }, | 138 | }, |
124 | 139 | ||
125 | //......................................................................... | 140 | //......................................................................... |
126 | 141 | ||
127 | 'buttonComponents': function () { | 142 | 'buttonComponents': function () { |
128 | return this._buttonComponents; | 143 | return this._buttonComponents; |
129 | }, | 144 | }, |
130 | 145 | ||
131 | //------------------------------------------------------------------------- | 146 | //------------------------------------------------------------------------- |
132 | 147 | ||
133 | 'renderSelf': function() { | 148 | 'renderSelf': function() { |
134 | this.append(this.element(), {tag:'div', cls:'SimpleMessagePanel', id:this.getId('panel'), children: [ | 149 | this.append(this.element(), {tag:'div', cls:'SimpleMessagePanel', id:this.getId('panel'), children: [ |
135 | {tag:'div', cls:'header', children:[]}, | 150 | // {tag:'div', cls:'header', children:[]}, |
136 | {tag:'div', cls:'body', children:[ | 151 | {tag:'div', cls:'body', children:[ |
137 | {tag:'div', id:this.getId('icon'),cls:'img ' + this.type(), children:[{tag:'div'}]}, | 152 | // {tag:'div', id:this.getId('icon'),cls:'img ' + this.type(), children:[{tag:'div'}]}, |
153 | {tag:'div', /*id:this.getId('icon'),*/cls:'img ' + this.type(), children:[{tag:'canvas', id:this.getId('icon')}]}, | ||
138 | {tag:'h3', id:this.getId('title'),html:this.title()}, | 154 | {tag:'h3', id:this.getId('title'),html:this.title()}, |
139 | {tag:'p', id:this.getId('text'),html:this.text()}, | 155 | {tag:'p', id:this.getId('text'),html:this.text()}, |
140 | {tag:'div', id:this.getId('container')}, | 156 | {tag:'div', id:this.getId('container')}, |
141 | {tag:'div', id:this.getId('buttonArea'), cls:'buttonArea', children:[]} | 157 | {tag:'div', id:this.getId('buttonArea'), cls:'buttonArea', children:[]} |
142 | ]}, | 158 | ]} |
143 | {tag:'div', cls:'footer', children:[]} | 159 | // {tag:'div', cls:'footer', children:[]} |
144 | ]}); | 160 | ]}); |
145 | 161 | ||
162 | Clipperz.PM.UI.Canvas.marks[this.icon()](this.getElement('icon'), "#ffffff"); | ||
163 | |||
146 | MochiKit.Signal.connect(this.getId('panel'), 'onkeydown', this, 'keyDownHandler'); | 164 | MochiKit.Signal.connect(this.getId('panel'), 'onkeydown', this, 'keyDownHandler'); |
147 | 165 | ||
148 | this.renderButtons(); | 166 | this.renderButtons(); |
149 | }, | 167 | }, |
150 | 168 | ||
151 | //------------------------------------------------------------------------- | 169 | //------------------------------------------------------------------------- |
152 | 170 | ||
153 | 'renderButtons': function () { | 171 | 'renderButtons': function () { |
154 | this.getElement('buttonArea').innerHTML = ''; | 172 | this.getElement('buttonArea').innerHTML = ''; |
155 | 173 | ||
156 | MochiKit.Base.map(MochiKit.Base.bind(function (aButton) { | 174 | MochiKit.Base.map(MochiKit.Base.bind(function (aButton) { |
157 | var buttonElement; | 175 | var buttonElement; |
158 | var buttonComponent; | 176 | var buttonComponent; |
159 | 177 | ||
160 | // element = this.append(this.getElement('buttonArea'), {tag:'div', cls:'button' + (aButton['isDefault'] === true ? ' default' : ''), children:[ | 178 | // element = this.append(this.getElement('buttonArea'), {tag:'div', cls:'button' + (aButton['isDefault'] === true ? ' default' : ''), children:[ |
161 | // {tag:'a', href:'#'/*, id:this.getId('buttonLink')*/, html:aButton['text']} | 179 | // {tag:'a', href:'#'/*, id:this.getId('buttonLink')*/, html:aButton['text']} |
162 | // ]}); | 180 | // ]}); |
163 | 181 | ||
164 | buttonElement = this.append(this.getElement('buttonArea'), {tag:'div'}); | 182 | buttonElement = this.append(this.getElement('buttonArea'), {tag:'div'}); |
165 | buttonComponent = new Clipperz.PM.UI.Common.Components.Button({'element':buttonElement, 'text':aButton['text'], 'isDefault':aButton['isDefault']}); | 183 | buttonComponent = new Clipperz.PM.UI.Common.Components.Button({'element':buttonElement, 'text':aButton['text'], 'isDefault':aButton['isDefault']}); |
166 | this.buttonComponents().push(buttonComponent); | 184 | this.buttonComponents().push(buttonComponent); |
167 | 185 | ||
168 | MochiKit.Signal.connect(buttonComponent, 'onclick', MochiKit.Base.method(this, 'buttonEventHandler', aButton)); | 186 | MochiKit.Signal.connect(buttonComponent, 'onclick', MochiKit.Base.method(this, 'buttonEventHandler', aButton)); |
169 | }, this), MochiKit.Iter.reversed(this.buttons())); | 187 | }, this), MochiKit.Iter.reversed(this.buttons())); |
170 | }, | 188 | }, |
171 | 189 | ||
172 | //------------------------------------------------------------------------- | 190 | //------------------------------------------------------------------------- |
173 | 191 | ||
174 | 'displayElement': function() { | 192 | 'displayElement': function() { |
175 | return this.getElement('panel'); | 193 | return this.getElement('panel'); |
176 | }, | 194 | }, |
177 | 195 | ||
178 | //------------------------------------------------------------------------- | 196 | //------------------------------------------------------------------------- |
179 | 197 | ||
180 | 'closeOk': function () { | 198 | 'closeOk': function () { |
181 | this.deferred().callback(); | 199 | this.deferred().callback(); |
182 | this._deferred = null; | 200 | this._deferred = null; |
183 | }, | 201 | }, |
184 | 202 | ||
185 | 'closeCancel': function () { | 203 | 'closeCancel': function () { |
186 | this.deferred().cancel(); | 204 | this.deferred().cancel(); |
187 | this._deferred = null; | 205 | this._deferred = null; |
188 | }, | 206 | }, |
189 | 207 | ||
190 | 'closeError': function () { | 208 | 'closeError': function () { |
191 | this.deferred().errback(); | 209 | this.deferred().errback(); |
192 | this._deferred = null; | 210 | this._deferred = null; |
193 | }, | 211 | }, |
194 | 212 | ||
195 | //------------------------------------------------------------------------- | 213 | //------------------------------------------------------------------------- |
196 | 214 | ||
197 | 'buttonEventHandler': function(aButton, anEvent) { | 215 | 'buttonEventHandler': function(aButton, anEvent) { |
198 | anEvent.preventDefault(); | 216 | anEvent.preventDefault(); |
199 | 217 | ||
200 | // MochiKit.Signal.signal(this, 'cancelEvent'); | 218 | // MochiKit.Signal.signal(this, 'cancelEvent'); |
201 | switch (aButton['result']) { | 219 | switch (aButton['result']) { |
202 | case 'OK': | 220 | case 'OK': |
203 | //console.log("==> OK"); | 221 | //console.log("==> OK"); |
204 | this.closeOk(); | 222 | this.closeOk(); |
205 | break; | 223 | break; |
206 | case 'CANCEL': | 224 | case 'CANCEL': |
207 | //console.log("==> CANCEL"); | 225 | //console.log("==> CANCEL"); |
208 | this.closeCancel(); | 226 | this.closeCancel(); |
209 | break; | 227 | break; |
210 | default: | 228 | default: |
211 | //console.log("==> ????"); | 229 | //console.log("==> ????"); |
212 | this.closeError(); | 230 | this.closeError(); |
213 | break; | 231 | break; |
214 | } | 232 | } |
215 | //console.log("<=="); | 233 | //console.log("<=="); |
216 | }, | 234 | }, |
217 | 235 | ||
218 | //------------------------------------------------------------------------- | 236 | //------------------------------------------------------------------------- |
219 | 237 | ||
220 | 'deferredShow': function (someArgs, aResult) { | 238 | 'deferredShow': function (someArgs, aResult) { |
221 | this.deferredShowModal(someArgs); | 239 | this.deferredShowModal(someArgs); |
222 | 240 | ||
223 | this.deferred().addMethod(this, 'deferredHideModal', {closeToElement:someArgs.onOkCloseToElement }); | 241 | this.deferred().addMethod(this, 'deferredHideModal', {closeToElement:someArgs.onOkCloseToElement }); |
224 | this.deferred().addErrback (MochiKit.Base.method(this, 'deferredHideModal', {closeToElement:someArgs.onCancelCloseToElement })); | 242 | this.deferred().addErrback (MochiKit.Base.method(this, 'deferredHideModal', {closeToElement:someArgs.onCancelCloseToElement })); |
225 | this.deferred().addCallback(MochiKit.Async.succeed, aResult); | 243 | this.deferred().addCallback(MochiKit.Async.succeed, aResult); |
226 | 244 | ||
227 | return this.deferred(); | 245 | return this.deferred(); |
228 | }, | 246 | }, |
229 | 247 | ||
230 | //------------------------------------------------------------------------- | 248 | //------------------------------------------------------------------------- |
231 | 249 | ||
232 | 'modalDialogMask': function () { | 250 | 'modalDialogMask': function () { |
233 | return this.getId('modalDialogMask'); | 251 | return this.getId('modalDialogMask'); |
234 | }, | 252 | }, |
235 | 253 | ||
236 | 'modalDialog': function () { | 254 | 'modalDialog': function () { |
237 | return this.getId('modalDialog'); | 255 | return this.getId('modalDialog'); |
238 | }, | 256 | }, |
239 | 257 | ||
240 | 'modalDialogFrame': function() { | 258 | 'modalDialogFrame': function() { |
241 | return this.getId('modalDialogFrame'); | 259 | return this.getId('modalDialogFrame'); |
242 | }, | 260 | }, |
243 | 261 | ||
244 | //------------------------------------------------------------------------- | 262 | //------------------------------------------------------------------------- |
245 | 263 | ||
246 | 'renderModalMask': function () { | 264 | 'renderModalMask': function () { |
247 | Clipperz.DOM.Helper.append(MochiKit.DOM.currentDocument().body, | 265 | Clipperz.DOM.Helper.append(MochiKit.DOM.currentDocument().body, |
248 | {tag:'div', id:this.getId('modalDialogWrapper'), cls:'modalDialogWrapper simpleMessagePanelMask', children:[ | 266 | {tag:'div', id:this.getId('modalDialogWrapper'), cls:'modalDialogWrapper simpleMessagePanelMask', children:[ |
249 | {tag:'div', id:this.getId('modalDialogMask'), cls:'modalDialogMask simpleMessagePanelMask'}, | 267 | {tag:'div', id:this.getId('modalDialogMask'), cls:'modalDialogMask simpleMessagePanelMask'}, |
250 | {tag:'div', id:this.getId('modalDialogFrame'), cls:'modalDialogFrame simpleMessagePanelMask'}, | 268 | {tag:'div', id:this.getId('modalDialogFrame'), cls:'modalDialogFrame simpleMessagePanelMask'}, |
251 | {tag:'div', id:this.getId('modalDialog'), cls:'modalDialog simpleMessagePanelMask'} | 269 | {tag:'div', id:this.getId('modalDialog'), cls:'modalDialog simpleMessagePanelMask'} |
252 | ]} | 270 | ]} |
253 | ); | 271 | ); |
254 | 272 | ||
255 | MochiKit.Style.hideElement(this.getId('modalDialogMask')); | 273 | MochiKit.Style.hideElement(this.getId('modalDialogMask')); |
256 | MochiKit.Style.hideElement(this.getId('modalDialogFrame')); | 274 | MochiKit.Style.hideElement(this.getId('modalDialogFrame')); |
257 | }, | 275 | }, |
258 | 276 | ||
259 | //------------------------------------------------------------------------- | 277 | //------------------------------------------------------------------------- |
260 | 278 | ||
261 | 'keyDownHandler': function (anEvent) { | 279 | 'keyDownHandler': function (anEvent) { |
262 | if (anEvent.key().string == 'KEY_ENTER') { | 280 | if (anEvent.key().string == 'KEY_ENTER') { |
263 | anEvent.preventDefault(); | 281 | anEvent.preventDefault(); |
264 | //console.log("13 - RETURN ?", this); | 282 | //console.log("13 - RETURN ?", this); |
265 | this.closeOk(); | 283 | this.closeOk(); |
266 | //console.log('<<< 13') | 284 | //console.log('<<< 13') |
267 | } | 285 | } |
268 | 286 | ||
269 | if (anEvent.key().string == 'KEY_ESCAPE') { | 287 | if (anEvent.key().string == 'KEY_ESCAPE') { |
270 | anEvent.preventDefault(); | 288 | anEvent.preventDefault(); |
271 | //console.log("27 - ESC ?", this); | 289 | //console.log("27 - ESC ?", this); |
272 | this.closeCancel(); | 290 | this.closeCancel(); |
273 | //console.log("<<< 27"); | 291 | //console.log("<<< 27"); |
274 | } | 292 | } |
275 | }, | 293 | }, |
276 | 294 | ||
277 | //------------------------------------------------------------------------- | 295 | //------------------------------------------------------------------------- |
278 | __syntaxFix__: "syntax fix" | 296 | __syntaxFix__: "syntax fix" |
279 | }); | 297 | }); |