Diffstat (limited to 'frontend/beta/js/Clipperz/YUI/MessageBox.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/YUI/MessageBox.js | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Clipperz/YUI/MessageBox.js b/frontend/beta/js/Clipperz/YUI/MessageBox.js index c7b4702..8b8ca7f 100644 --- a/frontend/beta/js/Clipperz/YUI/MessageBox.js +++ b/frontend/beta/js/Clipperz/YUI/MessageBox.js | |||
@@ -1,214 +1,212 @@ | |||
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.YUI.MessageBox = function(){ | 24 | Clipperz.YUI.MessageBox = function(){ |
27 | var dlg, opt, mask; | 25 | var dlg, opt, mask; |
28 | var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp; | 26 | var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp; |
29 | var buttons, activeTextEl, bwidth; | 27 | var buttons, activeTextEl, bwidth; |
30 | 28 | ||
31 | var handleButton = function(button){ | 29 | var handleButton = function(button){ |
32 | if(typeof opt.fn == 'function'){ | 30 | if(typeof opt.fn == 'function'){ |
33 | if(opt.fn.call(opt.scope||window, button, activeTextEl.dom.value) !== false){ | 31 | if(opt.fn.call(opt.scope||window, button, activeTextEl.dom.value) !== false){ |
34 | dlg.hide(); | 32 | dlg.hide(); |
35 | } | 33 | } |
36 | }else{ | 34 | }else{ |
37 | dlg.hide(); | 35 | dlg.hide(); |
38 | } | 36 | } |
39 | }; | 37 | }; |
40 | 38 | ||
41 | return { | 39 | return { |
42 | updateButtons: function(b){ | 40 | updateButtons: function(b){ |
43 | var width = 0; | 41 | var width = 0; |
44 | if(!b){ | 42 | if(!b){ |
45 | buttons['ok'].hide(); | 43 | buttons['ok'].hide(); |
46 | buttons['cancel'].hide(); | 44 | buttons['cancel'].hide(); |
47 | buttons['yes'].hide(); | 45 | buttons['yes'].hide(); |
48 | buttons['no'].hide(); | 46 | buttons['no'].hide(); |
49 | return width; | 47 | return width; |
50 | } | 48 | } |
51 | for(var k in buttons){ | 49 | for(var k in buttons){ |
52 | if(typeof buttons[k] != 'function'){ | 50 | if(typeof buttons[k] != 'function'){ |
53 | if(b[k]){ | 51 | if(b[k]){ |
54 | buttons[k].show(); | 52 | buttons[k].show(); |
55 | buttons[k].setText(typeof b[k] == 'string' ? b[k] : YAHOO.ext.MessageBox.buttonText[k]); | 53 | buttons[k].setText(typeof b[k] == 'string' ? b[k] : YAHOO.ext.MessageBox.buttonText[k]); |
56 | width += buttons[k].el.getWidth()+15; | 54 | width += buttons[k].el.getWidth()+15; |
57 | }else{ | 55 | }else{ |
58 | buttons[k].hide(); | 56 | buttons[k].hide(); |
59 | } | 57 | } |
60 | } | 58 | } |
61 | } | 59 | } |
62 | return width; | 60 | return width; |
63 | }, | 61 | }, |
64 | 62 | ||
65 | getDialog : function(){ | 63 | getDialog : function(){ |
66 | if(!dlg){ | 64 | if(!dlg){ |
67 | dlg = new YAHOO.ext.BasicDialog('mb-dlg', { | 65 | dlg = new YAHOO.ext.BasicDialog('mb-dlg', { |
68 | autoCreate:true, | 66 | autoCreate:true, |
69 | shadow:true, | 67 | shadow:true, |
70 | draggable:true, | 68 | draggable:true, |
71 | resizable:false, | 69 | resizable:false, |
72 | constraintoviewport:true, | 70 | constraintoviewport:true, |
73 | fixedcenter:true, | 71 | fixedcenter:true, |
74 | shim:true, | 72 | shim:true, |
75 | modal:true, | 73 | modal:true, |
76 | width:400, height:100, | 74 | width:400, height:100, |
77 | buttonAlign:'center', | 75 | buttonAlign:'center', |
78 | closeClick : function(){ | 76 | closeClick : function(){ |
79 | if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){ | 77 | if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){ |
80 | handleButton('no'); | 78 | handleButton('no'); |
81 | }else{ | 79 | }else{ |
82 | handleButton('cancel'); | 80 | handleButton('cancel'); |
83 | } | 81 | } |
84 | } | 82 | } |
85 | }); | 83 | }); |
86 | dlg.closeClick = function(){ | 84 | dlg.closeClick = function(){ |
87 | alert('wtf'); | 85 | alert('wtf'); |
88 | }; | 86 | }; |
89 | mask = dlg.mask; | 87 | mask = dlg.mask; |
90 | dlg.addKeyListener(27, dlg.hide, dlg); | 88 | dlg.addKeyListener(27, dlg.hide, dlg); |
91 | buttons = {}; | 89 | buttons = {}; |
92 | buttons['ok'] = dlg.addButton(this.buttonText['ok'], handleButton.createCallback('ok')); | 90 | buttons['ok'] = dlg.addButton(this.buttonText['ok'], handleButton.createCallback('ok')); |
93 | buttons['yes'] = dlg.addButton(this.buttonText['yes'], handleButton.createCallback('yes')); | 91 | buttons['yes'] = dlg.addButton(this.buttonText['yes'], handleButton.createCallback('yes')); |
94 | buttons['no'] = dlg.addButton(this.buttonText['no'], handleButton.createCallback('no')); | 92 | buttons['no'] = dlg.addButton(this.buttonText['no'], handleButton.createCallback('no')); |
95 | buttons['cancel'] = dlg.addButton(this.buttonText['cancel'], handleButton.createCallback('cancel')); | 93 | buttons['cancel'] = dlg.addButton(this.buttonText['cancel'], handleButton.createCallback('cancel')); |
96 | bodyEl = dlg.body.createChild({ | 94 | bodyEl = dlg.body.createChild({ |
97 | tag:'div', | 95 | tag:'div', |
98 | html:'<span class="ext-mb-text"></span><br /><input type="text" class="ext-mb-input"><textarea class="ext-mb-textarea"></textarea><div class="ext-mb-progress-wrap"><div class="ext-mb-progress"><div class="ext-mb-progress-bar"> </div></div></div>' | 96 | html:'<span class="ext-mb-text"></span><br /><input type="text" class="ext-mb-input"><textarea class="ext-mb-textarea"></textarea><div class="ext-mb-progress-wrap"><div class="ext-mb-progress"><div class="ext-mb-progress-bar"> </div></div></div>' |
99 | }); | 97 | }); |
100 | msgEl = bodyEl.dom.firstChild; | 98 | msgEl = bodyEl.dom.firstChild; |
101 | textboxEl = getEl(bodyEl.dom.childNodes[2]); | 99 | textboxEl = getEl(bodyEl.dom.childNodes[2]); |
102 | textboxEl.enableDisplayMode(); | 100 | textboxEl.enableDisplayMode(); |
103 | textboxEl.addKeyListener([10,13], function(){ | 101 | textboxEl.addKeyListener([10,13], function(){ |
104 | if(dlg.isVisible() && opt && opt.buttons){ | 102 | if(dlg.isVisible() && opt && opt.buttons){ |
105 | if(opt.buttons.ok){ | 103 | if(opt.buttons.ok){ |
106 | handleButton('ok'); | 104 | handleButton('ok'); |
107 | }else if(opt.buttons.yes){ | 105 | }else if(opt.buttons.yes){ |
108 | handleButton('yes'); | 106 | handleButton('yes'); |
109 | } | 107 | } |
110 | } | 108 | } |
111 | }); | 109 | }); |
112 | textareaEl = getEl(bodyEl.dom.childNodes[3]); | 110 | textareaEl = getEl(bodyEl.dom.childNodes[3]); |
113 | textareaEl.enableDisplayMode(); | 111 | textareaEl.enableDisplayMode(); |
114 | progressEl = getEl(bodyEl.dom.childNodes[4]); | 112 | progressEl = getEl(bodyEl.dom.childNodes[4]); |
115 | progressEl.enableDisplayMode(); | 113 | progressEl.enableDisplayMode(); |
116 | pp = getEl(progressEl.dom.firstChild.firstChild); | 114 | pp = getEl(progressEl.dom.firstChild.firstChild); |
117 | } | 115 | } |
118 | return dlg; | 116 | return dlg; |
119 | }, | 117 | }, |
120 | 118 | ||
121 | updateText : function(text){ | 119 | updateText : function(text){ |
122 | if(!dlg.isVisible() && !opt.width){ | 120 | if(!dlg.isVisible() && !opt.width){ |
123 | dlg.resizeTo(this.maxWidth, 100); // resize first so content is never clipped from previous shows | 121 | dlg.resizeTo(this.maxWidth, 100); // resize first so content is never clipped from previous shows |
124 | } | 122 | } |
125 | msgEl.innerHTML = text; | 123 | msgEl.innerHTML = text; |
126 | var w = Math.max(Math.min(opt.width || msgEl.offsetWidth, this.maxWidth), | 124 | var w = Math.max(Math.min(opt.width || msgEl.offsetWidth, this.maxWidth), |
127 | Math.max(opt.minWidth || this.minWidth, bwidth)); | 125 | Math.max(opt.minWidth || this.minWidth, bwidth)); |
128 | if(opt.prompt){ | 126 | if(opt.prompt){ |
129 | activeTextEl.setWidth(w); | 127 | activeTextEl.setWidth(w); |
130 | } | 128 | } |
131 | dlg.setContentSize(w, bodyEl.getHeight()); | 129 | dlg.setContentSize(w, bodyEl.getHeight()); |
132 | }, | 130 | }, |
133 | 131 | ||
134 | updateProgress : function(value, text){ | 132 | updateProgress : function(value, text){ |
135 | if(text){ | 133 | if(text){ |
136 | this.updateText(text); | 134 | this.updateText(text); |
137 | } | 135 | } |
138 | pp.setWidth(value*progressEl.dom.firstChild.offsetWidth); | 136 | pp.setWidth(value*progressEl.dom.firstChild.offsetWidth); |
139 | }, | 137 | }, |
140 | 138 | ||
141 | isVisible : function(){ | 139 | isVisible : function(){ |
142 | return dlg && dlg.isVisible(); | 140 | return dlg && dlg.isVisible(); |
143 | }, | 141 | }, |
144 | 142 | ||
145 | hide : function(){ | 143 | hide : function(){ |
146 | if(this.isVisible()){ | 144 | if(this.isVisible()){ |
147 | dlg.hide(); | 145 | dlg.hide(); |
148 | } | 146 | } |
149 | }, | 147 | }, |
150 | 148 | ||
151 | show : function(options){ | 149 | show : function(options){ |
152 | var d = this.getDialog(); | 150 | var d = this.getDialog(); |
153 | opt = options; | 151 | opt = options; |
154 | d.setTitle(opt.title || ' '); | 152 | d.setTitle(opt.title || ' '); |
155 | d.close.setDisplayed(opt.closable !== false); | 153 | d.close.setDisplayed(opt.closable !== false); |
156 | activeTextEl = textboxEl; | 154 | activeTextEl = textboxEl; |
157 | opt.prompt = opt.prompt || (opt.multiline ? true : false) | 155 | opt.prompt = opt.prompt || (opt.multiline ? true : false) |
158 | if(opt.prompt){ | 156 | if(opt.prompt){ |
159 | if(opt.multiline){ | 157 | if(opt.multiline){ |
160 | textboxEl.hide(); | 158 | textboxEl.hide(); |
161 | textareaEl.show(); | 159 | textareaEl.show(); |
162 | textareaEl.setHeight(typeof opt.multiline == 'number' ? | 160 | textareaEl.setHeight(typeof opt.multiline == 'number' ? |
163 | opt.multiline : this.defaultTextHeight); | 161 | opt.multiline : this.defaultTextHeight); |
164 | activeTextEl = textareaEl; | 162 | activeTextEl = textareaEl; |
165 | }else{ | 163 | }else{ |
166 | textboxEl.show(); | 164 | textboxEl.show(); |
167 | textareaEl.hide(); | 165 | textareaEl.hide(); |
168 | } | 166 | } |
169 | }else{ | 167 | }else{ |
170 | textboxEl.hide(); | 168 | textboxEl.hide(); |
171 | textareaEl.hide(); | 169 | textareaEl.hide(); |
172 | } | 170 | } |
173 | progressEl.setDisplayed(opt.progress === true); | 171 | progressEl.setDisplayed(opt.progress === true); |
174 | this.updateProgress(0); | 172 | this.updateProgress(0); |
175 | activeTextEl.dom.value = opt.value || ''; | 173 | activeTextEl.dom.value = opt.value || ''; |
176 | if(opt.prompt){ | 174 | if(opt.prompt){ |
177 | dlg.setDefaultButton(activeTextEl); | 175 | dlg.setDefaultButton(activeTextEl); |
178 | }else{ | 176 | }else{ |
179 | var bs = opt.buttons; | 177 | var bs = opt.buttons; |
180 | var db = null; | 178 | var db = null; |
181 | if(bs && bs.ok){ | 179 | if(bs && bs.ok){ |
182 | db = buttons['ok']; | 180 | db = buttons['ok']; |
183 | }else if(bs && bs.yes){ | 181 | }else if(bs && bs.yes){ |
184 | db = buttons['yes']; | 182 | db = buttons['yes']; |
185 | } | 183 | } |
186 | dlg.setDefaultButton(db); | 184 | dlg.setDefaultButton(db); |
187 | } | 185 | } |
188 | bwidth = this.updateButtons(opt.buttons); | 186 | bwidth = this.updateButtons(opt.buttons); |
189 | this.updateText(opt.msg); | 187 | this.updateText(opt.msg); |
190 | d.modal = opt.modal !== false; | 188 | d.modal = opt.modal !== false; |
191 | d.mask = opt.modal !== false ? mask : false; | 189 | d.mask = opt.modal !== false ? mask : false; |
192 | d.animateTarget = null; | 190 | d.animateTarget = null; |
193 | d.show(options.animEl); | 191 | d.show(options.animEl); |
194 | }, | 192 | }, |
195 | 193 | ||
196 | progress : function(title, msg){ | 194 | progress : function(title, msg){ |
197 | this.show({ | 195 | this.show({ |
198 | title : title, | 196 | title : title, |
199 | msg : msg, | 197 | msg : msg, |
200 | buttons: false, | 198 | buttons: false, |
201 | progress:true, | 199 | progress:true, |
202 | closable:false | 200 | closable:false |
203 | }); | 201 | }); |
204 | }, | 202 | }, |
205 | 203 | ||
206 | progressElement : function() { | 204 | progressElement : function() { |
207 | return progressEl; | 205 | return progressEl; |
208 | }, | 206 | }, |
209 | 207 | ||
210 | opt: function() { | 208 | opt: function() { |
211 | return opt; | 209 | return opt; |
212 | }, | 210 | }, |
213 | 211 | ||
214 | alert : function(title, msg, fn, scope){ | 212 | alert : function(title, msg, fn, scope){ |