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