summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/YUI/MessageBox.js
authorGiulio Cesare Solaroli <giulio.cesare@clipperz.com>2011-10-02 23:56:18 (UTC)
committer Giulio Cesare Solaroli <giulio.cesare@clipperz.com>2011-10-02 23:56:18 (UTC)
commitef68436ac04da078ffdcacd7e1f785473a303d45 (patch) (unidiff)
treec403752d66a2c4775f00affd4fa8431b29c5b68c /frontend/beta/js/Clipperz/YUI/MessageBox.js
parent597ecfbc0249d83e1b856cbd558340c01237a360 (diff)
downloadclipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.zip
clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.gz
clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.bz2
First version of the newly restructured repository
Diffstat (limited to 'frontend/beta/js/Clipperz/YUI/MessageBox.js') (more/less context) (show whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/YUI/MessageBox.js265
1 files changed, 265 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/YUI/MessageBox.js b/frontend/beta/js/Clipperz/YUI/MessageBox.js
new file mode 100644
index 0000000..ec33d7d
--- a/dev/null
+++ b/frontend/beta/js/Clipperz/YUI/MessageBox.js
@@ -0,0 +1,265 @@
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.YUI.MessageBox = function(){
30 var dlg, opt, mask;
31 var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
32 var buttons, activeTextEl, bwidth;
33
34 var handleButton = function(button){
35 if(typeof opt.fn == 'function'){
36 if(opt.fn.call(opt.scope||window, button, activeTextEl.dom.value) !== false){
37 dlg.hide();
38 }
39 }else{
40 dlg.hide();
41 }
42 };
43
44 return {
45 updateButtons: function(b){
46 var width = 0;
47 if(!b){
48 buttons['ok'].hide();
49 buttons['cancel'].hide();
50 buttons['yes'].hide();
51 buttons['no'].hide();
52 return width;
53 }
54 for(var k in buttons){
55 if(typeof buttons[k] != 'function'){
56 if(b[k]){
57 buttons[k].show();
58 buttons[k].setText(typeof b[k] == 'string' ? b[k] : YAHOO.ext.MessageBox.buttonText[k]);
59 width += buttons[k].el.getWidth()+15;
60 }else{
61 buttons[k].hide();
62 }
63 }
64 }
65 return width;
66 },
67
68 getDialog : function(){
69 if(!dlg){
70 dlg = new YAHOO.ext.BasicDialog('mb-dlg', {
71 autoCreate:true,
72 shadow:true,
73 draggable:true,
74 resizable:false,
75 constraintoviewport:true,
76 fixedcenter:true,
77 shim:true,
78 modal:true,
79 width:400, height:100,
80 buttonAlign:'center',
81 closeClick : function(){
82 if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
83 handleButton('no');
84 }else{
85 handleButton('cancel');
86 }
87 }
88 });
89 dlg.closeClick = function(){
90 alert('wtf');
91 };
92 mask = dlg.mask;
93 dlg.addKeyListener(27, dlg.hide, dlg);
94 buttons = {};
95 buttons['ok'] = dlg.addButton(this.buttonText['ok'], handleButton.createCallback('ok'));
96 buttons['yes'] = dlg.addButton(this.buttonText['yes'], handleButton.createCallback('yes'));
97 buttons['no'] = dlg.addButton(this.buttonText['no'], handleButton.createCallback('no'));
98 buttons['cancel'] = dlg.addButton(this.buttonText['cancel'], handleButton.createCallback('cancel'));
99 bodyEl = dlg.body.createChild({
100 tag:'div',
101 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">&#160;</div></div></div>'
102 });
103 msgEl = bodyEl.dom.firstChild;
104 textboxEl = getEl(bodyEl.dom.childNodes[2]);
105 textboxEl.enableDisplayMode();
106 textboxEl.addKeyListener([10,13], function(){
107 if(dlg.isVisible() && opt && opt.buttons){
108 if(opt.buttons.ok){
109 handleButton('ok');
110 }else if(opt.buttons.yes){
111 handleButton('yes');
112 }
113 }
114 });
115 textareaEl = getEl(bodyEl.dom.childNodes[3]);
116 textareaEl.enableDisplayMode();
117 progressEl = getEl(bodyEl.dom.childNodes[4]);
118 progressEl.enableDisplayMode();
119 pp = getEl(progressEl.dom.firstChild.firstChild);
120 }
121 return dlg;
122 },
123
124 updateText : function(text){
125 if(!dlg.isVisible() && !opt.width){
126 dlg.resizeTo(this.maxWidth, 100); // resize first so content is never clipped from previous shows
127 }
128 msgEl.innerHTML = text;
129 var w = Math.max(Math.min(opt.width || msgEl.offsetWidth, this.maxWidth),
130 Math.max(opt.minWidth || this.minWidth, bwidth));
131 if(opt.prompt){
132 activeTextEl.setWidth(w);
133 }
134 dlg.setContentSize(w, bodyEl.getHeight());
135 },
136
137 updateProgress : function(value, text){
138 if(text){
139 this.updateText(text);
140 }
141 pp.setWidth(value*progressEl.dom.firstChild.offsetWidth);
142 },
143
144 isVisible : function(){
145 return dlg && dlg.isVisible();
146 },
147
148 hide : function(){
149 if(this.isVisible()){
150 dlg.hide();
151 }
152 },
153
154 show : function(options){
155 var d = this.getDialog();
156 opt = options;
157 d.setTitle(opt.title || '&#160;');
158 d.close.setDisplayed(opt.closable !== false);
159 activeTextEl = textboxEl;
160 opt.prompt = opt.prompt || (opt.multiline ? true : false)
161 if(opt.prompt){
162 if(opt.multiline){
163 textboxEl.hide();
164 textareaEl.show();
165 textareaEl.setHeight(typeof opt.multiline == 'number' ?
166 opt.multiline : this.defaultTextHeight);
167 activeTextEl = textareaEl;
168 }else{
169 textboxEl.show();
170 textareaEl.hide();
171 }
172 }else{
173 textboxEl.hide();
174 textareaEl.hide();
175 }
176 progressEl.setDisplayed(opt.progress === true);
177 this.updateProgress(0);
178 activeTextEl.dom.value = opt.value || '';
179 if(opt.prompt){
180 dlg.setDefaultButton(activeTextEl);
181 }else{
182 var bs = opt.buttons;
183 var db = null;
184 if(bs && bs.ok){
185 db = buttons['ok'];
186 }else if(bs && bs.yes){
187 db = buttons['yes'];
188 }
189 dlg.setDefaultButton(db);
190 }
191 bwidth = this.updateButtons(opt.buttons);
192 this.updateText(opt.msg);
193 d.modal = opt.modal !== false;
194 d.mask = opt.modal !== false ? mask : false;
195 d.animateTarget = null;
196 d.show(options.animEl);
197 },
198
199 progress : function(title, msg){
200 this.show({
201 title : title,
202 msg : msg,
203 buttons: false,
204 progress:true,
205 closable:false
206 });
207 },
208
209 progressElement : function() {
210 return progressEl;
211 },
212
213 opt: function() {
214 return opt;
215 },
216
217 alert : function(title, msg, fn, scope){
218 this.show({
219 title : title,
220 msg : msg,
221 buttons: this.OK,
222 fn: fn,
223 scope : scope
224 });
225 },
226
227 confirm : function(title, msg, fn, scope){
228 this.show({
229 title : title,
230 msg : msg,
231 buttons: this.YESNO,
232 fn: fn,
233 scope : scope
234 });
235 },
236
237 prompt : function(title, msg, fn, scope, multiline){
238 this.show({
239 title : title,
240 msg : msg,
241 buttons: this.OKCANCEL,
242 fn: fn,
243 minWidth:250,
244 scope : scope,
245 prompt:true,
246 multiline: multiline
247 });
248 },
249
250 OK : {ok:true},
251 YESNO : {yes:true, no:true},
252 OKCANCEL : {ok:true, cancel:true},
253 YESNOCANCEL : {yes:true, no:true, cancel:true},
254
255 defaultTextHeight:75,
256 maxWidth : 500,
257 minWidth : 100,
258 buttonText : {
259 ok : 'OK',
260 cancel : 'Cancel',
261 yes : 'Yes',
262 no : 'No'
263 }
264 };
265}();