]>
Commit | Line | Data |
---|---|---|
760966c1 | 1 | var hotkeys_enabled = true; |
730dbf19 | 2 | var notify_silent = false; |
99509451 | 3 | var last_progress_point = 0; |
4a3da1c8 | 4 | var sanity_check_done = false; |
6e4f4ce1 | 5 | var dialogs = []; |
61992f57 | 6 | |
b07b61da AD |
7 | /* add method to remove element from array */ |
8 | ||
9 | Array.prototype.remove = function(s) { | |
10 | for (var i=0; i < this.length; i++) { | |
11 | if (s == this[i]) this.splice(i, 1); | |
12 | } | |
13 | } | |
14 | ||
84c7b824 AD |
15 | /* create console.log if it doesn't exist */ |
16 | ||
17 | if (!window.console) console = {}; | |
f3f67c1b AD |
18 | console.log = console.log || function(msg) { }; |
19 | console.warn = console.warn || function(msg) { }; | |
20 | console.error = console.error || function(msg) { }; | |
583c58b8 | 21 | |
273d1e29 | 22 | function exception_error(location, e, ext_info) { |
e8a429e3 | 23 | var msg = format_exception_error(location, e); |
e8a429e3 | 24 | |
84c7b824 | 25 | if (!ext_info) ext_info = false; |
91743a49 | 26 | |
273d1e29 | 27 | try { |
e8a429e3 | 28 | |
951906dc AD |
29 | if (ext_info) { |
30 | if (ext_info.responseText) { | |
31 | ext_info = ext_info.responseText; | |
e8a429e3 | 32 | } |
951906dc | 33 | } |
84c7b824 | 34 | |
951906dc AD |
35 | var content = "<div class=\"fatalError\">" + |
36 | "<pre>" + msg + "</pre>"; | |
84c7b824 | 37 | |
951906dc AD |
38 | if (ext_info) { |
39 | content += "<div><b>Additional information:</b></div>" + | |
40 | "<textarea readonly=\"1\">" + ext_info + "</textarea>"; | |
e8a429e3 AD |
41 | } |
42 | ||
951906dc AD |
43 | content += "<div><b>Stack trace:</b></div>" + |
44 | "<textarea readonly=\"1\">" + e.stack + "</textarea>"; | |
45 | ||
6e4f4ce1 AD |
46 | // content += "<div style='text-align : center'>" + |
47 | // "<button onclick=\"closeInfoBox()\">" + | |
48 | // "Close this window" + "</button></div>"; | |
49 | ||
50 | content += "</div>"; | |
51 | ||
951906dc AD |
52 | // TODO: add code to automatically report errors to tt-rss.org |
53 | ||
6e4f4ce1 AD |
54 | var dialog = new dijit.Dialog({ |
55 | title: "Unhandled exception", | |
56 | style: "width: 600px", | |
57 | content: content}); | |
58 | ||
59 | dialog.show(); | |
951906dc | 60 | |
273d1e29 | 61 | } catch (e) { |
e8a429e3 | 62 | alert(msg); |
e8a429e3 | 63 | } |
273d1e29 | 64 | |
e8a429e3 AD |
65 | } |
66 | ||
67 | function format_exception_error(location, e) { | |
83f043bb AD |
68 | var msg; |
69 | ||
70 | if (e.fileName) { | |
71 | var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1); | |
72 | ||
73 | msg = "Exception: " + e.name + ", " + e.message + | |
74 | "\nFunction: " + location + "()" + | |
75 | "\nLocation: " + base_fname + ":" + e.lineNumber; | |
f74cfded AD |
76 | |
77 | } else if (e.description) { | |
78 | msg = "Exception: " + e.description + "\nFunction: " + location + "()"; | |
83f043bb AD |
79 | } else { |
80 | msg = "Exception: " + e + "\nFunction: " + location + "()"; | |
81 | } | |
82 | ||
84c7b824 | 83 | console.error("EXCEPTION: " + msg); |
ee1f45f4 | 84 | |
e8a429e3 | 85 | return msg; |
7719618b AD |
86 | } |
87 | ||
e8a429e3 | 88 | |
760966c1 AD |
89 | function disableHotkeys() { |
90 | hotkeys_enabled = false; | |
91 | } | |
92 | ||
93 | function enableHotkeys() { | |
94 | hotkeys_enabled = true; | |
95 | } | |
96 | ||
7726fa02 AD |
97 | function param_escape(arg) { |
98 | if (typeof encodeURIComponent != 'undefined') | |
99 | return encodeURIComponent(arg); | |
100 | else | |
101 | return escape(arg); | |
102 | } | |
103 | ||
104 | function param_unescape(arg) { | |
105 | if (typeof decodeURIComponent != 'undefined') | |
106 | return decodeURIComponent(arg); | |
107 | else | |
108 | return unescape(arg); | |
109 | } | |
110 | ||
ce3bf408 | 111 | var notify_hide_timerid = false; |
59a543f0 | 112 | |
ce3bf408 | 113 | function hide_notify() { |
acac8448 | 114 | var n = $("notify"); |
42c32916 | 115 | if (n) { |
d05514a4 | 116 | n.style.display = "none"; |
8dcfffd0 | 117 | } |
d05514a4 | 118 | } |
c05608c2 | 119 | |
730dbf19 AD |
120 | function notify_silent_next() { |
121 | notify_silent = true; | |
122 | } | |
123 | ||
42c32916 | 124 | function notify_real(msg, no_hide, n_type) { |
7726fa02 | 125 | |
730dbf19 AD |
126 | if (notify_silent) { |
127 | notify_silent = false; | |
128 | return; | |
129 | } | |
130 | ||
acac8448 AD |
131 | var n = $("notify"); |
132 | var nb = $("notify_body"); | |
7726fa02 | 133 | |
c05608c2 | 134 | if (!n || !nb) return; |
f0601b87 | 135 | |
0655a1d5 AD |
136 | if (notify_hide_timerid) { |
137 | window.clearTimeout(notify_hide_timerid); | |
138 | } | |
139 | ||
8dcfffd0 | 140 | if (msg == "") { |
0655a1d5 AD |
141 | if (n.style.display == "block") { |
142 | notify_hide_timerid = window.setTimeout("hide_notify()", 0); | |
143 | } | |
144 | return; | |
7726fa02 | 145 | } else { |
0ceded7a | 146 | n.style.display = "block"; |
8dcfffd0 | 147 | } |
7726fa02 | 148 | |
42c32916 AD |
149 | /* types: |
150 | ||
151 | 1 - generic | |
152 | 2 - progress | |
153 | 3 - error | |
154 | 4 - info | |
155 | ||
156 | */ | |
157 | ||
f3977cf5 AD |
158 | if (typeof __ != 'undefined') { |
159 | msg = __(msg); | |
160 | } | |
161 | ||
42c32916 AD |
162 | if (n_type == 1) { |
163 | n.className = "notify"; | |
164 | } else if (n_type == 2) { | |
165 | n.className = "notifyProgress"; | |
883fee8d | 166 | msg = "<img src='"+getInitParam("sign_progress")+"'> " + msg; |
42c32916 | 167 | } else if (n_type == 3) { |
f407c086 | 168 | n.className = "notifyError"; |
883fee8d | 169 | msg = "<img src='"+getInitParam("sign_excl")+"'> " + msg; |
42c32916 AD |
170 | } else if (n_type == 4) { |
171 | n.className = "notifyInfo"; | |
883fee8d | 172 | msg = "<img src='"+getInitParam("sign_info")+"'> " + msg; |
0530ddd8 AD |
173 | } |
174 | ||
106689b0 AD |
175 | // msg = "<img src='images/live_com_loading.gif'> " + msg; |
176 | ||
0ceded7a AD |
177 | nb.innerHTML = msg; |
178 | ||
4d4200a8 | 179 | if (!no_hide) { |
292a8a12 | 180 | notify_hide_timerid = window.setTimeout("hide_notify()", 3000); |
4d4200a8 | 181 | } |
ce3bf408 AD |
182 | } |
183 | ||
42c32916 AD |
184 | function notify(msg, no_hide) { |
185 | notify_real(msg, no_hide, 1); | |
ce3bf408 AD |
186 | } |
187 | ||
42c32916 AD |
188 | function notify_progress(msg, no_hide) { |
189 | notify_real(msg, no_hide, 2); | |
190 | } | |
191 | ||
192 | function notify_error(msg, no_hide) { | |
193 | notify_real(msg, no_hide, 3); | |
194 | ||
195 | } | |
196 | ||
197 | function notify_info(msg, no_hide) { | |
198 | notify_real(msg, no_hide, 4); | |
7726fa02 AD |
199 | } |
200 | ||
76b4eae1 AD |
201 | function setCookie(name, value, lifetime, path, domain, secure) { |
202 | ||
203 | var d = false; | |
204 | ||
205 | if (lifetime) { | |
206 | d = new Date(); | |
be0801a1 | 207 | d.setTime(d.getTime() + (lifetime * 1000)); |
76b4eae1 | 208 | } |
cdbb6dc6 | 209 | |
84c7b824 | 210 | console.log("setCookie: " + name + " => " + value + ": " + d); |
76b4eae1 AD |
211 | |
212 | int_setCookie(name, value, d, path, domain, secure); | |
213 | ||
214 | } | |
215 | ||
216 | function int_setCookie(name, value, expires, path, domain, secure) { | |
ac43eba1 AD |
217 | document.cookie= name + "=" + escape(value) + |
218 | ((expires) ? "; expires=" + expires.toGMTString() : "") + | |
219 | ((path) ? "; path=" + path : "") + | |
220 | ((domain) ? "; domain=" + domain : "") + | |
221 | ((secure) ? "; secure" : ""); | |
222 | } | |
223 | ||
76b4eae1 AD |
224 | function delCookie(name, path, domain) { |
225 | if (getCookie(name)) { | |
226 | document.cookie = name + "=" + | |
227 | ((path) ? ";path=" + path : "") + | |
228 | ((domain) ? ";domain=" + domain : "" ) + | |
229 | ";expires=Thu, 01-Jan-1970 00:00:01 GMT"; | |
230 | } | |
231 | } | |
232 | ||
233 | ||
ac43eba1 AD |
234 | function getCookie(name) { |
235 | ||
236 | var dc = document.cookie; | |
237 | var prefix = name + "="; | |
238 | var begin = dc.indexOf("; " + prefix); | |
239 | if (begin == -1) { | |
240 | begin = dc.indexOf(prefix); | |
241 | if (begin != 0) return null; | |
242 | } | |
243 | else { | |
244 | begin += 2; | |
245 | } | |
246 | var end = document.cookie.indexOf(";", begin); | |
247 | if (end == -1) { | |
248 | end = dc.length; | |
249 | } | |
250 | return unescape(dc.substring(begin + prefix.length, end)); | |
251 | } | |
252 | ||
e828e31e AD |
253 | function gotoPreferences() { |
254 | document.location.href = "prefs.php"; | |
255 | } | |
256 | ||
257 | function gotoMain() { | |
258 | document.location.href = "tt-rss.php"; | |
259 | } | |
260 | ||
8158c57a AD |
261 | function gotoExportOpml() { |
262 | document.location.href = "opml.php?op=Export"; | |
263 | } | |
86741347 | 264 | |
c9268ed5 | 265 | |
b6644d29 AD |
266 | /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj |
267 | * * @author Sundar Dorai-Raj | |
268 | * * Email: sdoraira@vt.edu | |
269 | * * This program is free software; you can redistribute it and/or | |
270 | * * modify it under the terms of the GNU General Public License | |
271 | * * as published by the Free Software Foundation; either version 2 | |
272 | * * of the License, or (at your option) any later version, | |
273 | * * provided that any use properly credits the author. | |
274 | * * This program is distributed in the hope that it will be useful, | |
275 | * * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
276 | * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
277 | * * GNU General Public License for more details at http://www.gnu.org * * */ | |
278 | ||
279 | var numbers=".0123456789"; | |
280 | function isNumeric(x) { | |
281 | // is x a String or a character? | |
282 | if(x.length>1) { | |
283 | // remove negative sign | |
284 | x=Math.abs(x)+""; | |
285 | for(j=0;j<x.length;j++) { | |
286 | // call isNumeric recursively for each character | |
287 | number=isNumeric(x.substring(j,j+1)); | |
288 | if(!number) return number; | |
289 | } | |
290 | return number; | |
291 | } | |
292 | else { | |
293 | // if x is number return true | |
294 | if(numbers.indexOf(x)>=0) return true; | |
295 | return false; | |
296 | } | |
297 | } | |
298 | ||
3745788e | 299 | |
386cbf27 | 300 | function toggleSelectRowById(sender, id) { |
acac8448 | 301 | var row = $(id); |
ca8e3d75 | 302 | return toggleSelectRow(sender, row); |
386cbf27 AD |
303 | } |
304 | ||
b92e6209 | 305 | function toggleSelectListRow(sender) { |
ca8e3d75 AD |
306 | var row = sender.parentNode; |
307 | return toggleSelectRow(sender, row); | |
b92e6209 AD |
308 | } |
309 | ||
ca8e3d75 AD |
310 | function tSR(sender, row) { |
311 | return toggleSelectRow(sender, row); | |
67343d9f | 312 | } |
386cbf27 | 313 | |
ca8e3d75 | 314 | function toggleSelectRow(sender, row) { |
1572afe5 | 315 | |
ca8e3d75 AD |
316 | if (!row) row = sender.parentNode.parentNode; |
317 | ||
318 | if (sender.checked && !row.hasClassName('Selected')) | |
319 | row.addClassName('Selected'); | |
320 | else | |
321 | row.removeClassName('Selected'); | |
1572afe5 AD |
322 | } |
323 | ||
b9073cd9 AD |
324 | function checkboxToggleElement(elem, id) { |
325 | if (elem.checked) { | |
6e4f4ce1 | 326 | Effect.Appear(id, {duration : 0.5}); |
b9073cd9 | 327 | } else { |
ecace165 | 328 | Effect.Fade(id, {duration : 0.5}); |
b9073cd9 AD |
329 | } |
330 | } | |
331 | ||
1b0809ae AD |
332 | function dropboxSelect(e, v) { |
333 | for (i = 0; i < e.length; i++) { | |
334 | if (e[i].value == v) { | |
335 | e.selectedIndex = i; | |
336 | break; | |
337 | } | |
338 | } | |
339 | } | |
0ee1d1a0 AD |
340 | |
341 | // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z | |
342 | // bugfixed just a little bit :-) | |
343 | function getURLParam(strParamName){ | |
344 | var strReturn = ""; | |
345 | var strHref = window.location.href; | |
346 | ||
347 | if (strHref.indexOf("#") == strHref.length-1) { | |
348 | strHref = strHref.substring(0, strHref.length-1); | |
349 | } | |
350 | ||
351 | if ( strHref.indexOf("?") > -1 ){ | |
352 | var strQueryString = strHref.substr(strHref.indexOf("?")); | |
353 | var aQueryString = strQueryString.split("&"); | |
354 | for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){ | |
355 | if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){ | |
356 | var aParam = aQueryString[iParam].split("="); | |
357 | strReturn = aParam[1]; | |
358 | break; | |
359 | } | |
360 | } | |
361 | } | |
362 | return strReturn; | |
363 | } | |
364 | ||
cf1bc085 AD |
365 | function leading_zero(p) { |
366 | var s = String(p); | |
367 | if (s.length == 1) s = "0" + s; | |
368 | return s; | |
369 | } | |
c38c2b69 | 370 | |
84c7b824 AD |
371 | function make_timestamp() { |
372 | var d = new Date(); | |
373 | ||
374 | return leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) + | |
375 | ":" + leading_zero(d.getSeconds()); | |
376 | } | |
377 | ||
378 | ||
e8a429e3 | 379 | function closeErrorBox() { |
5ede560f | 380 | |
273d1e29 | 381 | if (Element.visible("errorBoxShadow")) { |
e8a429e3 | 382 | Element.hide("dialog_overlay"); |
273d1e29 | 383 | Element.hide("errorBoxShadow"); |
e5d758e3 | 384 | |
e8a429e3 | 385 | enableHotkeys(); |
e5d758e3 AD |
386 | } |
387 | ||
e8a429e3 AD |
388 | return false; |
389 | } | |
86b682ce | 390 | |
e8a429e3 | 391 | function closeInfoBox(cleanup) { |
588e4dc3 AD |
392 | try { |
393 | enableHotkeys(); | |
6e4f4ce1 AD |
394 | |
395 | var dialog = dialogs.pop(); | |
396 | ||
397 | if (dialog) | |
398 | dialog.hide(); | |
e8a429e3 | 399 | |
588e4dc3 | 400 | } catch (e) { |
951906dc | 401 | //exception_error("closeInfoBox", e); |
e8a429e3 | 402 | } |
90ac84df | 403 | return false; |
e5d758e3 AD |
404 | } |
405 | ||
406 | ||
542aebac | 407 | function displayDlg(id, param, callback) { |
7b5c6012 | 408 | |
951906dc | 409 | notify_progress("Loading, please wait...", true); |
2371c520 | 410 | |
b4e75b2a | 411 | var query = "?op=dlg&id=" + |
288487e4 AD |
412 | param_escape(id) + "¶m=" + param_escape(param); |
413 | ||
b4e75b2a AD |
414 | new Ajax.Request("backend.php", { |
415 | parameters: query, | |
288487e4 AD |
416 | onComplete: function (transport) { |
417 | infobox_callback2(transport); | |
542aebac | 418 | if (callback) callback(transport); |
288487e4 AD |
419 | } }); |
420 | ||
90ac84df | 421 | return false; |
7b5c6012 AD |
422 | } |
423 | ||
288487e4 AD |
424 | function infobox_submit_callback2(transport) { |
425 | closeInfoBox(); | |
79f3553b | 426 | |
288487e4 AD |
427 | try { |
428 | // called from prefs, reload tab | |
438f2ce9 | 429 | if (typeof active_tab != 'undefined' && active_tab) { |
288487e4 | 430 | selectTab(active_tab, false); |
5e6f933a | 431 | } |
288487e4 | 432 | } catch (e) { } |
79f3553b | 433 | |
288487e4 AD |
434 | if (transport.responseText) { |
435 | notify_info(transport.responseText); | |
436 | } | |
7b5c6012 AD |
437 | } |
438 | ||
d395a942 AD |
439 | function infobox_callback2(transport) { |
440 | try { | |
5ede560f | 441 | |
951906dc AD |
442 | //console.log("infobox_callback2"); |
443 | notify(''); | |
5ede560f | 444 | |
951906dc AD |
445 | var content; |
446 | var dtitle = "Dialog"; | |
1dc47c41 | 447 | |
951906dc AD |
448 | if (transport.responseXML) { |
449 | var dlg = transport.responseXML.getElementsByTagName("dlg")[0]; | |
de85cac2 | 450 | |
951906dc AD |
451 | var title = transport.responseXML.getElementsByTagName("title")[0]; |
452 | if (title) | |
6e4f4ce1 | 453 | title = title.firstChild.nodeValue; |
de85cac2 | 454 | |
951906dc AD |
455 | var content = transport.responseXML.getElementsByTagName("content")[0]; |
456 | ||
457 | content = content.firstChild.nodeValue; | |
de85cac2 | 458 | |
951906dc AD |
459 | } else { |
460 | content = transport.responseText; | |
d395a942 | 461 | } |
05fcdf52 | 462 | |
6e4f4ce1 AD |
463 | var dialog = new dijit.Dialog({ |
464 | title: title, | |
465 | style: "width: 600px", | |
466 | onCancel: function() { | |
467 | dialogs.remove(this); | |
468 | return true; | |
469 | }, | |
470 | onExecute: function() { | |
471 | dialogs.remove(this); | |
472 | return true; | |
473 | }, | |
474 | onClose: function() { | |
475 | dialogs.remove(this); | |
476 | return true; | |
477 | }, | |
478 | content: content}); | |
479 | ||
480 | dialog.show(); | |
481 | ||
482 | dialogs.push(dialog); | |
6068d33b | 483 | |
d395a942 AD |
484 | notify(""); |
485 | } catch (e) { | |
486 | exception_error("infobox_callback2", e); | |
442d77f1 AD |
487 | } |
488 | } | |
489 | ||
18ab3d7a | 490 | function createFilter() { |
7b5c6012 | 491 | |
438f2ce9 | 492 | try { |
6068d33b | 493 | |
438f2ce9 AD |
494 | var form = document.forms['filter_add_form']; |
495 | var reg_exp = form.reg_exp.value; | |
496 | ||
497 | if (reg_exp == "") { | |
498 | alert(__("Can't add filter: nothing to match on.")); | |
499 | return false; | |
500 | } | |
f705f206 AD |
501 | |
502 | var query = "?op=rpc&subop=verifyRegexp®_exp=" + param_escape(reg_exp); | |
503 | ||
504 | notify_progress("Verifying regular expression..."); | |
505 | ||
506 | new Ajax.Request("backend.php", { | |
507 | parameters: query, | |
508 | onComplete: function(transport) { | |
509 | handle_rpc_reply(transport); | |
510 | ||
511 | var response = transport.responseXML; | |
512 | ||
513 | if (response) { | |
514 | var s = response.getElementsByTagName("status")[0].firstChild.nodeValue; | |
288487e4 | 515 | |
f705f206 AD |
516 | notify(''); |
517 | ||
518 | if (s == "INVALID") { | |
519 | alert("Match regular expression seems to be invalid."); | |
520 | return; | |
521 | } else { | |
522 | ||
523 | var query = Form.serialize("filter_add_form"); | |
524 | ||
525 | // we can be called from some other tab in Prefs | |
526 | if (typeof active_tab != 'undefined' && active_tab) { | |
527 | active_tab = "filterConfig"; | |
528 | } | |
529 | ||
530 | new Ajax.Request("backend.php?" + query, { | |
531 | onComplete: function (transport) { | |
532 | infobox_submit_callback2(transport); | |
533 | } }); | |
534 | ||
535 | return true; | |
536 | } | |
537 | } | |
538 | ||
438f2ce9 | 539 | } }); |
438f2ce9 AD |
540 | |
541 | } catch (e) { | |
542 | exception_error("createFilter", e); | |
543 | } | |
7b5c6012 AD |
544 | } |
545 | ||
605f7d46 | 546 | function isValidURL(s) { |
0d32b41e | 547 | return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null; |
605f7d46 | 548 | } |
07eb9178 | 549 | |
18ab3d7a | 550 | function subscribeToFeed() { |
07eb9178 | 551 | |
a5819bb3 AD |
552 | try { |
553 | ||
c91c2249 AD |
554 | var form = document.forms['feed_add_form']; |
555 | var feed_url = form.feed_url.value; | |
556 | ||
557 | if (feed_url == "") { | |
89cb787e | 558 | alert(__("Can't subscribe: no feed URL given.")); |
c91c2249 AD |
559 | return false; |
560 | } | |
561 | ||
1ba6daf7 | 562 | notify_progress(__("Subscribing to feed..."), true); |
07eb9178 | 563 | |
07eb9178 AD |
564 | var query = Form.serialize("feed_add_form"); |
565 | ||
84c7b824 | 566 | console.log("subscribe q: " + query); |
f27de515 | 567 | |
a5819bb3 AD |
568 | Form.disable("feed_add_form"); |
569 | ||
288487e4 AD |
570 | new Ajax.Request("backend.php", { |
571 | parameters: query, | |
572 | onComplete: function(transport) { | |
a5819bb3 AD |
573 | //dlg_frefresh_callback(transport); |
574 | ||
55a51373 | 575 | try { |
a5819bb3 | 576 | |
d3204726 | 577 | if (!transport.responseXML) { |
5414ad4c | 578 | console.log(transport.responseText); |
d3204726 AD |
579 | alert(__("Server error while trying to subscribe to specified feed.")); |
580 | return; | |
581 | } | |
5414ad4c | 582 | |
55a51373 AD |
583 | var result = transport.responseXML.getElementsByTagName('result')[0]; |
584 | var rc = parseInt(result.getAttribute('code')); | |
585 | ||
586 | Form.enable("feed_add_form"); | |
587 | ||
588 | notify(''); | |
589 | ||
590 | switch (rc) { | |
591 | case 1: | |
592 | closeInfoBox(); | |
593 | notify_info(__("Subscribed to %s").replace("%s", feed_url)); | |
594 | ||
595 | if (inPreferences()) { | |
596 | updateFeedList(); | |
597 | } else { | |
598 | setTimeout('updateFeedList(false, false)', 50); | |
599 | } | |
600 | break; | |
601 | case 2: | |
5414ad4c AD |
602 | alert(__("Specified URL seems to be invalid.")); |
603 | break; | |
55a51373 | 604 | case 3: |
5414ad4c | 605 | alert(__("Specified URL doesn't seem to contain any feeds.")); |
55a51373 AD |
606 | break; |
607 | case 4: | |
608 | new Ajax.Request("backend.php", { | |
609 | parameters: 'op=rpc&subop=extractfeedurls&url=' + encodeURIComponent(feed_url), | |
610 | onComplete: function(transport) { | |
611 | var result = transport.responseXML.getElementsByTagName('urls')[0]; | |
612 | var feeds = JSON.parse(result.firstChild.nodeValue); | |
613 | var select = document.getElementById("faad_feeds_container_select"); | |
614 | ||
615 | while (select.hasChildNodes()) { | |
616 | select.removeChild(elem.firstChild); | |
617 | } | |
618 | var count = 0; | |
619 | for (var feedUrl in feeds) { | |
620 | select.insert(new Option(feeds[feedUrl], feedUrl, false)); | |
621 | count++; | |
622 | } | |
623 | if (count > 5) count = 5; | |
624 | select.size = count; | |
625 | ||
6e4f4ce1 | 626 | Effect.Appear('fadd_feeds_container', {duration : 0.5}); |
5eeb3874 | 627 | } |
55a51373 AD |
628 | }); |
629 | break; | |
5414ad4c AD |
630 | case 5: |
631 | alert(__("Couldn't download the specified URL.")); | |
632 | break; | |
55a51373 AD |
633 | case 0: |
634 | alert(__("You are already subscribed to this feed.")); | |
635 | break; | |
636 | } | |
5eeb3874 | 637 | |
55a51373 AD |
638 | } catch (e) { |
639 | exception_error("subscribeToFeed", e); | |
a5819bb3 AD |
640 | } |
641 | ||
288487e4 | 642 | } }); |
7bc4f251 | 643 | |
a5819bb3 AD |
644 | } catch (e) { |
645 | exception_error("subscribeToFeed", e); | |
646 | } | |
647 | ||
7bc4f251 | 648 | return false; |
07eb9178 AD |
649 | } |
650 | ||
6e6504bc | 651 | function filterCR(e, f) |
86b682ce AD |
652 | { |
653 | var key; | |
654 | ||
655 | if(window.event) | |
656 | key = window.event.keyCode; //IE | |
657 | else | |
658 | key = e.which; //firefox | |
659 | ||
6e6504bc AD |
660 | if (key == 13) { |
661 | if (typeof f != 'undefined') { | |
662 | f(); | |
663 | return false; | |
664 | } else { | |
665 | return false; | |
666 | } | |
667 | } else { | |
668 | return true; | |
669 | } | |
86b682ce AD |
670 | } |
671 | ||
33d13e72 | 672 | function getInitParam(key) { |
40496720 | 673 | return init_params[key]; |
33d13e72 | 674 | } |
3ac2b520 | 675 | |
dbfc9522 | 676 | function setInitParam(key, value) { |
5158ced9 | 677 | init_params[key] = value; |
be0801a1 AD |
678 | } |
679 | ||
273d1e29 | 680 | function fatalError(code, msg, ext_info) { |
a7565293 | 681 | try { |
a7565293 | 682 | |
91743a49 AD |
683 | if (!ext_info) ext_info = "N/A"; |
684 | ||
b4c27af7 | 685 | if (code == 6) { |
206d4967 | 686 | window.location.href = "tt-rss.php"; |
b4c27af7 | 687 | } else if (code == 5) { |
661135c7 | 688 | window.location.href = "db-updater.php"; |
b4c27af7 | 689 | } else { |
4724a093 | 690 | |
273d1e29 | 691 | if (msg == "") msg = "Unknown error"; |
42c32916 | 692 | |
acac8448 | 693 | var ebc = $("xebContent"); |
4724a093 | 694 | |
273d1e29 AD |
695 | if (ebc) { |
696 | ||
697 | Element.show("dialog_overlay"); | |
698 | Element.show("errorBoxShadow"); | |
699 | Element.hide("xebBtn"); | |
700 | ||
701 | if (ext_info) { | |
702 | if (ext_info.responseText) { | |
703 | ext_info = ext_info.responseText; | |
704 | } | |
705 | } | |
706 | ||
707 | ebc.innerHTML = | |
708 | "<div><b>Error message:</b></div>" + | |
709 | "<pre>" + msg + "</pre>" + | |
710 | "<div><b>Additional information:</b></div>" + | |
711 | "<textarea readonly=\"1\">" + ext_info + "</textarea>"; | |
712 | } | |
4724a093 | 713 | } |
a7565293 AD |
714 | |
715 | } catch (e) { | |
716 | exception_error("fatalError", e); | |
717 | } | |
718 | } | |
719 | ||
d0da85c2 AD |
720 | function filterDlgCheckType(sender) { |
721 | ||
722 | try { | |
723 | ||
724 | var ftype = sender[sender.selectedIndex].value; | |
725 | ||
726 | var form = document.forms["filter_add_form"]; | |
727 | ||
728 | if (!form) { | |
729 | form = document.forms["filter_edit_form"]; | |
730 | } | |
731 | ||
732 | if (!form) { | |
84c7b824 | 733 | console.log("filterDlgCheckType: can't find form!"); |
d0da85c2 AD |
734 | return; |
735 | } | |
736 | ||
737 | // if selected filter type is 5 (Date) enable the modifier dropbox | |
738 | if (ftype == 5) { | |
739 | Element.show("filter_dlg_date_mod_box"); | |
740 | Element.show("filter_dlg_date_chk_box"); | |
741 | } else { | |
742 | Element.hide("filter_dlg_date_mod_box"); | |
743 | Element.hide("filter_dlg_date_chk_box"); | |
744 | ||
745 | } | |
746 | ||
747 | } catch (e) { | |
748 | exception_error("filterDlgCheckType", e); | |
749 | } | |
750 | ||
751 | } | |
752 | ||
350f0ad1 AD |
753 | function filterDlgCheckAction(sender) { |
754 | ||
755 | try { | |
756 | ||
757 | var action = sender[sender.selectedIndex].value; | |
758 | ||
759 | var form = document.forms["filter_add_form"]; | |
760 | ||
761 | if (!form) { | |
762 | form = document.forms["filter_edit_form"]; | |
763 | } | |
764 | ||
765 | if (!form) { | |
84c7b824 | 766 | console.log("filterDlgCheckAction: can't find form!"); |
350f0ad1 AD |
767 | return; |
768 | } | |
769 | ||
acac8448 | 770 | var action_param = $("filter_dlg_param_box"); |
350f0ad1 AD |
771 | |
772 | if (!action_param) { | |
84c7b824 | 773 | console.log("filterDlgCheckAction: can't find action param box!"); |
350f0ad1 AD |
774 | return; |
775 | } | |
776 | ||
777 | // if selected action supports parameters, enable params field | |
ceb30ba4 | 778 | if (action == 4 || action == 6 || action == 7) { |
143a4973 | 779 | Element.show(action_param); |
ceb30ba4 AD |
780 | if (action != 7) { |
781 | Element.show(form.action_param); | |
782 | Element.hide(form.action_param_label); | |
783 | } else { | |
784 | Element.show(form.action_param_label); | |
785 | Element.hide(form.action_param); | |
786 | } | |
350f0ad1 | 787 | } else { |
143a4973 | 788 | Element.hide(action_param); |
350f0ad1 AD |
789 | } |
790 | ||
791 | } catch (e) { | |
438f2ce9 | 792 | exception_error("filterDlgCheckAction", e); |
350f0ad1 AD |
793 | } |
794 | ||
795 | } | |
ef16ae37 | 796 | |
d0da85c2 AD |
797 | function filterDlgCheckDate() { |
798 | try { | |
799 | var form = document.forms["filter_add_form"]; | |
800 | ||
801 | if (!form) { | |
802 | form = document.forms["filter_edit_form"]; | |
803 | } | |
804 | ||
805 | if (!form) { | |
84c7b824 | 806 | console.log("filterDlgCheckAction: can't find form!"); |
d0da85c2 AD |
807 | return; |
808 | } | |
809 | ||
810 | var reg_exp = form.reg_exp.value; | |
811 | ||
b4e75b2a | 812 | var query = "?op=rpc&subop=checkDate&date=" + reg_exp; |
d0da85c2 | 813 | |
b4e75b2a AD |
814 | new Ajax.Request("backend.php", { |
815 | parameters: query, | |
d0da85c2 AD |
816 | onComplete: function(transport) { |
817 | ||
818 | var form = document.forms["filter_add_form"]; | |
819 | ||
820 | if (!form) { | |
821 | form = document.forms["filter_edit_form"]; | |
822 | } | |
823 | ||
824 | if (transport.responseXML) { | |
825 | var result = transport.responseXML.getElementsByTagName("result")[0]; | |
826 | ||
827 | if (result && result.firstChild) { | |
828 | if (result.firstChild.nodeValue == "1") { | |
829 | ||
830 | new Effect.Highlight(form.reg_exp, {startcolor : '#00ff00'}); | |
831 | ||
832 | return; | |
833 | } | |
834 | } | |
835 | } | |
836 | ||
837 | new Effect.Highlight(form.reg_exp, {startcolor : '#ff0000'}); | |
838 | ||
839 | } }); | |
840 | ||
841 | ||
842 | } catch (e) { | |
843 | exception_error("filterDlgCheckDate", e); | |
844 | } | |
845 | } | |
846 | ||
ef16ae37 AD |
847 | function explainError(code) { |
848 | return displayDlg("explainError", code); | |
849 | } | |
01a87dff | 850 | |
f6d40ed2 | 851 | function displayHelpInfobox(topic_id) { |
c4a36709 | 852 | |
f6d40ed2 AD |
853 | var url = "backend.php?op=help&tid=" + param_escape(topic_id); |
854 | ||
855 | var w = window.open(url, "ttrss_help", | |
856 | "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0"); | |
857 | ||
f6d40ed2 | 858 | } |
e635d56a | 859 | |
99509451 | 860 | function loading_set_progress(p) { |
730dbf19 | 861 | try { |
fca95d5f AD |
862 | if (p < last_progress_point || !Element.visible("overlay")) return; |
863 | ||
50eefedb | 864 | console.log("loading_set_progress : " + p + " (" + last_progress_point + ")"); |
99509451 | 865 | |
acac8448 | 866 | var o = $("l_progress_i"); |
99509451 | 867 | |
673c9946 AD |
868 | // o.style.width = (p * 2) + "px"; |
869 | ||
99509451 AD |
870 | new Effect.Scale(o, p, { |
871 | scaleY : false, | |
872 | scaleFrom : last_progress_point, | |
873 | scaleMode: { originalWidth : 200 }, | |
673c9946 | 874 | queue: { position: 'end', scope: 'LSP-Q', limit: 3 } }); |
99509451 AD |
875 | |
876 | last_progress_point = p; | |
730dbf19 AD |
877 | |
878 | } catch (e) { | |
879 | exception_error("loading_set_progress", e); | |
880 | } | |
881 | } | |
08827aaf AD |
882 | |
883 | function remove_splash() { | |
884 | if (Element.visible("overlay")) { | |
84c7b824 | 885 | console.log("about to remove splash, OMG!"); |
08827aaf | 886 | Element.hide("overlay"); |
84c7b824 | 887 | console.log("removed splash!"); |
08827aaf AD |
888 | } |
889 | } | |
071ec48f | 890 | |
c2913898 AD |
891 | function getSelectedFeedsFromBrowser() { |
892 | ||
3c8e3b15 | 893 | var list = $$("#browseFeedList li[id*=FBROW]"); |
c2913898 AD |
894 | |
895 | var selected = new Array(); | |
3c8e3b15 AD |
896 | |
897 | list.each(function(child) { | |
898 | var id = child.id.replace("FBROW-", ""); | |
899 | var cb = $("FBCHK-" + id); | |
900 | ||
901 | if (cb.checked) { | |
902 | selected.push(id); | |
903 | } | |
904 | }); | |
c2913898 AD |
905 | |
906 | return selected; | |
907 | } | |
908 | ||
2bab8824 AD |
909 | function updateFeedBrowser() { |
910 | try { | |
911 | ||
ef88b1cc | 912 | var query = Form.serialize("feed_browser"); |
f4280bdd AD |
913 | |
914 | Element.show('feed_browser_spinner'); | |
2bab8824 | 915 | |
b4e75b2a AD |
916 | new Ajax.Request("backend.php", { |
917 | parameters: query, | |
2bab8824 AD |
918 | onComplete: function(transport) { |
919 | notify(''); | |
920 | ||
f4280bdd AD |
921 | Element.hide('feed_browser_spinner'); |
922 | ||
acac8448 | 923 | var c = $("browseFeedList"); |
2bab8824 AD |
924 | var r = transport.responseXML.getElementsByTagName("content")[0]; |
925 | var nr = transport.responseXML.getElementsByTagName("num-results")[0]; | |
ef88b1cc | 926 | var mode = transport.responseXML.getElementsByTagName("mode")[0]; |
2bab8824 AD |
927 | |
928 | if (c && r) { | |
929 | c.innerHTML = r.firstChild.nodeValue; | |
930 | } | |
ef88b1cc AD |
931 | |
932 | if (parseInt(mode.getAttribute("value")) == 2) { | |
933 | Element.show('feed_archive_remove'); | |
934 | } else { | |
935 | Element.hide('feed_archive_remove'); | |
936 | } | |
2bab8824 | 937 | |
2bab8824 AD |
938 | } }); |
939 | ||
2bab8824 AD |
940 | } catch (e) { |
941 | exception_error("updateFeedBrowser", e); | |
942 | } | |
082ae95b | 943 | |
2bab8824 AD |
944 | } |
945 | ||
2184738a AD |
946 | function transport_error_check(transport) { |
947 | try { | |
948 | if (transport.responseXML) { | |
949 | var error = transport.responseXML.getElementsByTagName("error")[0]; | |
950 | ||
951 | if (error) { | |
952 | var code = error.getAttribute("error-code"); | |
953 | var msg = error.getAttribute("error-msg"); | |
954 | if (code != 0) { | |
955 | fatalError(code, msg); | |
956 | return false; | |
957 | } | |
958 | } | |
959 | } | |
960 | } catch (e) { | |
961 | exception_error("check_for_error_xml", e); | |
962 | } | |
963 | return true; | |
964 | } | |
2bab8824 | 965 | |
261b88b3 AD |
966 | function strip_tags(s) { |
967 | return s.replace(/<\/?[^>]+(>|$)/g, ""); | |
968 | } | |
969 | ||
970 | function truncate_string(s, length) { | |
971 | if (!length) length = 30; | |
972 | var tmp = s.substring(0, length); | |
973 | if (s.length > length) tmp += "…"; | |
974 | return tmp; | |
975 | } | |
ab553f9a | 976 | |
78935092 AD |
977 | function hotkey_prefix_timeout() { |
978 | try { | |
979 | ||
980 | var date = new Date(); | |
981 | var ts = Math.round(date.getTime() / 1000); | |
982 | ||
983 | if (hotkey_prefix_pressed && ts - hotkey_prefix_pressed >= 5) { | |
84c7b824 | 984 | console.log("hotkey_prefix seems to be stuck, aborting"); |
78935092 AD |
985 | hotkey_prefix_pressed = false; |
986 | hotkey_prefix = false; | |
987 | Element.hide('cmdline'); | |
988 | } | |
989 | ||
990 | setTimeout("hotkey_prefix_timeout()", 1000); | |
991 | ||
992 | } catch (e) { | |
993 | exception_error("hotkey_prefix_timeout", e); | |
994 | } | |
995 | } | |
996 | ||
37e93d6c AD |
997 | function hideAuxDlg() { |
998 | try { | |
999 | Element.hide('auxDlg'); | |
1000 | } catch (e) { | |
1001 | exception_error("hideAuxDlg", e); | |
1002 | } | |
1003 | } | |
1004 | ||
ef88b1cc AD |
1005 | function feedBrowserSubscribe() { |
1006 | try { | |
1007 | ||
1008 | var selected = getSelectedFeedsFromBrowser(); | |
1009 | ||
1010 | var mode = document.forms['feed_browser'].mode; | |
1011 | ||
1012 | mode = mode[mode.selectedIndex].value; | |
1013 | ||
1014 | if (selected.length > 0) { | |
1015 | closeInfoBox(); | |
1016 | ||
1017 | notify_progress("Loading, please wait...", true); | |
1018 | ||
1019 | var query = "?op=rpc&subop=massSubscribe&ids="+ | |
1020 | param_escape(selected.toString()) + "&mode=" + param_escape(mode); | |
1021 | ||
1022 | new Ajax.Request("backend.php", { | |
1023 | parameters: query, | |
1024 | onComplete: function(transport) { | |
1025 | ||
1026 | var nf = transport.responseXML.getElementsByTagName('num-feeds')[0]; | |
1027 | var nf_value = nf.getAttribute("value"); | |
1028 | ||
1029 | notify_info(__("Subscribed to %d feed(s).").replace("%d", nf_value)); | |
1030 | ||
1031 | if (inPreferences()) { | |
1032 | updateFeedList(); | |
1033 | } else { | |
1034 | setTimeout('updateFeedList(false, false)', 50); | |
1035 | } | |
1036 | } }); | |
1037 | ||
1038 | } else { | |
1039 | alert(__("No feeds are selected.")); | |
1040 | } | |
1041 | ||
1042 | } catch (e) { | |
1043 | exception_error("feedBrowserSubscribe", e); | |
1044 | } | |
1045 | } | |
1046 | ||
1047 | function feedArchiveRemove() { | |
1048 | try { | |
1049 | ||
1050 | var selected = getSelectedFeedsFromBrowser(); | |
1051 | ||
1052 | if (selected.length > 0) { | |
1053 | ||
d9084cf2 | 1054 | var pr = __("Remove selected feeds from the archive? Feeds with stored articles will not be removed."); |
ef88b1cc AD |
1055 | |
1056 | if (confirm(pr)) { | |
1057 | Element.show('feed_browser_spinner'); | |
1058 | ||
1059 | var query = "?op=rpc&subop=remarchived&ids=" + | |
1060 | param_escape(selected.toString());; | |
1061 | ||
1062 | new Ajax.Request("backend.php", { | |
1063 | parameters: query, | |
1064 | onComplete: function(transport) { | |
1065 | updateFeedBrowser(); | |
1066 | } }); | |
1067 | } | |
1068 | ||
1069 | } else { | |
1070 | alert(__("No feeds are selected.")); | |
1071 | } | |
1072 | ||
1073 | } catch (e) { | |
1074 | exception_error("feedArchiveRemove", e); | |
1075 | } | |
1076 | } | |
1077 | ||
7abf159d | 1078 | function uploadIconHandler(rc) { |
c3b7b797 | 1079 | try { |
7abf159d AD |
1080 | switch (rc) { |
1081 | case 0: | |
1082 | notify_info("Upload complete."); | |
1083 | if (inPreferences()) { | |
1084 | updateFeedList(); | |
1085 | } else { | |
1086 | setTimeout('updateFeedList(false, false)', 50); | |
1087 | } | |
1088 | break; | |
1089 | case 1: | |
1090 | notify_error("Upload failed: icon is too big."); | |
1091 | break; | |
1092 | case 2: | |
1093 | notify_error("Upload failed."); | |
1094 | break; | |
1095 | } | |
1096 | ||
1097 | } catch (e) { | |
1098 | exception_error("uploadIconHandler", e); | |
1099 | } | |
1100 | } | |
1101 | ||
1102 | function removeFeedIcon(id) { | |
1103 | ||
1104 | try { | |
1105 | ||
1106 | if (confirm(__("Remove stored feed icon?"))) { | |
1107 | var query = "backend.php?op=pref-feeds&subop=removeicon&feed_id=" + param_escape(id); | |
c3b7b797 | 1108 | |
84c7b824 | 1109 | console.log(query); |
c3b7b797 | 1110 | |
7abf159d | 1111 | notify_progress("Removing feed icon...", true); |
c3b7b797 | 1112 | |
7abf159d AD |
1113 | new Ajax.Request("backend.php", { |
1114 | parameters: query, | |
1115 | onComplete: function(transport) { | |
1116 | notify_info("Feed icon removed."); | |
1117 | if (inPreferences()) { | |
1118 | updateFeedList(); | |
1119 | } else { | |
1120 | setTimeout('updateFeedList(false, false)', 50); | |
1121 | } | |
1122 | } }); | |
1123 | } | |
1124 | ||
1125 | return false; | |
c3b7b797 | 1126 | } catch (e) { |
7abf159d | 1127 | exception_error("uploadFeedIcon", e); |
c3b7b797 AD |
1128 | } |
1129 | } | |
1130 | ||
1131 | function uploadFeedIcon() { | |
1132 | ||
1133 | try { | |
1134 | ||
1135 | var file = $("icon_file"); | |
1136 | ||
1137 | if (file.value.length == 0) { | |
1138 | alert(__("Please select an image file to upload.")); | |
c3b7b797 | 1139 | } else { |
7abf159d AD |
1140 | if (confirm(__("Upload new icon for this feed?"))) { |
1141 | notify_progress("Uploading, please wait...", true); | |
1142 | return true; | |
1143 | } | |
c3b7b797 AD |
1144 | } |
1145 | ||
7abf159d AD |
1146 | return false; |
1147 | ||
c3b7b797 AD |
1148 | } catch (e) { |
1149 | exception_error("uploadFeedIcon", e); | |
1150 | } | |
1151 | } | |
1152 | ||
1c31e190 | 1153 | function addLabel(select, callback) { |
d002edc7 AD |
1154 | |
1155 | try { | |
1156 | ||
1157 | var caption = prompt(__("Please enter label caption:"), ""); | |
1158 | ||
1159 | if (caption != undefined) { | |
1160 | ||
1161 | if (caption == "") { | |
1162 | alert(__("Can't create label: missing caption.")); | |
1163 | return false; | |
1164 | } | |
1165 | ||
1166 | var query = "?op=pref-labels&subop=add&caption=" + | |
1167 | param_escape(caption); | |
1168 | ||
1c31e190 AD |
1169 | if (select) |
1170 | query += "&output=select"; | |
1171 | ||
d002edc7 AD |
1172 | notify_progress("Loading, please wait...", true); |
1173 | ||
1c31e190 | 1174 | if (inPreferences() && !select) active_tab = "labelConfig"; |
d002edc7 AD |
1175 | |
1176 | new Ajax.Request("backend.php", { | |
1177 | parameters: query, | |
1178 | onComplete: function(transport) { | |
1c31e190 AD |
1179 | if (callback) { |
1180 | callback(transport); | |
1181 | } else if (inPreferences()) { | |
d002edc7 AD |
1182 | infobox_submit_callback2(transport); |
1183 | } else { | |
1184 | updateFeedList(); | |
1185 | } | |
1186 | } }); | |
1187 | ||
1188 | } | |
1189 | ||
1190 | } catch (e) { | |
1191 | exception_error("addLabel", e); | |
1192 | } | |
1193 | } | |
1194 | ||
3393238d AD |
1195 | function quickAddFeed() { |
1196 | displayDlg('quickAddFeed', '', | |
1197 | function () {$('feed_url').focus();}); | |
1198 | } | |
1199 | ||
1200 | function quickAddFilter() { | |
1201 | displayDlg('quickAddFilter', '', | |
1202 | function () {document.forms['filter_add_form'].reg_exp.focus();}); | |
1203 | } | |
78bcd2c4 AD |
1204 | |
1205 | function unsubscribeFeed(feed_id, title) { | |
1206 | ||
1207 | var msg = __("Unsubscribe from %s?").replace("%s", title); | |
1208 | ||
1209 | if (title == undefined || confirm(msg)) { | |
1210 | notify_progress("Removing feed..."); | |
1211 | ||
1212 | var query = "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id; | |
1213 | ||
1214 | new Ajax.Request("backend.php", { | |
1215 | parameters: query, | |
1216 | onComplete: function(transport) { | |
1217 | ||
1218 | closeInfoBox(); | |
1219 | ||
1220 | if (inPreferences()) { | |
1221 | updateFeedList(); | |
1222 | } else { | |
1223 | dlg_frefresh_callback(transport, feed_id); | |
1224 | } | |
1225 | ||
1226 | } }); | |
1227 | } | |
1228 | ||
1229 | return false; | |
1230 | } | |
1231 | ||
1232 | ||
4a3da1c8 AD |
1233 | function backend_sanity_check_callback(transport) { |
1234 | ||
1235 | try { | |
1236 | ||
1237 | if (sanity_check_done) { | |
1238 | fatalError(11, "Sanity check request received twice. This can indicate "+ | |
1239 | "presence of Firebug or some other disrupting extension. "+ | |
1240 | "Please disable it and try again."); | |
1241 | return; | |
1242 | } | |
1243 | ||
1244 | if (!transport.responseXML) { | |
1245 | if (!store) { | |
1246 | fatalError(3, "Sanity check: Received reply is not XML", | |
1247 | transport.responseText); | |
1248 | return; | |
4a3da1c8 AD |
1249 | } |
1250 | } | |
1251 | ||
5191a7ce | 1252 | var reply = transport.responseXML.getElementsByTagName("error")[0]; |
4a3da1c8 AD |
1253 | |
1254 | if (!reply) { | |
1255 | fatalError(3, "Sanity check: invalid RPC reply", transport.responseText); | |
1256 | return; | |
1257 | } | |
1258 | ||
1259 | var error_code = reply.getAttribute("error-code"); | |
1260 | ||
1261 | if (error_code && error_code != 0) { | |
1262 | return fatalError(error_code, reply.getAttribute("error-msg")); | |
1263 | } | |
1264 | ||
1265 | console.log("sanity check ok"); | |
1266 | ||
5191a7ce | 1267 | var params = transport.responseXML.getElementsByTagName("init-params")[0]; |
4a3da1c8 AD |
1268 | |
1269 | if (params) { | |
1270 | console.log('reading init-params...'); | |
f1f3a642 AD |
1271 | |
1272 | params = JSON.parse(params.firstChild.nodeValue); | |
4a3da1c8 | 1273 | |
f1f3a642 | 1274 | if (params) { |
c4f7ba80 | 1275 | for (k in params) { |
c4f7ba80 | 1276 | var v = params[k]; |
c4f7ba80 | 1277 | console.log("IP: " + k + " => " + v); |
f1f3a642 | 1278 | } |
4a3da1c8 | 1279 | } |
c4f7ba80 AD |
1280 | |
1281 | init_params = params; | |
4a3da1c8 AD |
1282 | } |
1283 | ||
1284 | sanity_check_done = true; | |
1285 | ||
1286 | init_second_stage(); | |
1287 | ||
1288 | } catch (e) { | |
1289 | exception_error("backend_sanity_check_callback", e, transport); | |
1290 | } | |
1291 | } | |
1292 | ||
ff0010c1 | 1293 | function has_local_storage() { |
ce40b580 AD |
1294 | return false; |
1295 | /* try { | |
ff0010c1 AD |
1296 | return 'localStorage' in window && window['localStorage'] != null; |
1297 | } catch (e) { | |
1298 | return false; | |
ce40b580 | 1299 | } */ |
ff0010c1 | 1300 | } |
5c7c7da9 AD |
1301 | |
1302 | function catSelectOnChange(elem) { | |
1303 | try { | |
1304 | var value = elem[elem.selectedIndex].value; | |
1305 | var def = elem.getAttribute('default'); | |
1306 | ||
1307 | if (value == "ADD_CAT") { | |
1308 | ||
1309 | if (def) | |
1310 | dropboxSelect(elem, def); | |
1311 | else | |
1312 | elem.selectedIndex = 0; | |
1313 | ||
1314 | quickAddCat(elem); | |
1315 | } | |
1316 | ||
1317 | } catch (e) { | |
1318 | exception_error("catSelectOnChange", e); | |
1319 | } | |
1320 | } | |
1321 | ||
c00907f2 | 1322 | function quickAddCat(elem) { |
5c7c7da9 AD |
1323 | try { |
1324 | var cat = prompt(__("Please enter category title:")); | |
1325 | ||
1326 | if (cat) { | |
1327 | ||
1328 | var query = "?op=rpc&subop=quickAddCat&cat=" + param_escape(cat); | |
1329 | ||
c00907f2 AD |
1330 | notify_progress("Loading, please wait...", true); |
1331 | ||
5c7c7da9 AD |
1332 | new Ajax.Request("backend.php", { |
1333 | parameters: query, | |
1334 | onComplete: function (transport) { | |
1335 | var response = transport.responseXML; | |
c00907f2 AD |
1336 | var select = response.getElementsByTagName("select")[0]; |
1337 | var options = select.getElementsByTagName("option"); | |
5c7c7da9 | 1338 | |
c00907f2 | 1339 | dropbox_replace_options(elem, options); |
5c7c7da9 | 1340 | |
c00907f2 | 1341 | notify(''); |
5c7c7da9 AD |
1342 | |
1343 | } }); | |
1344 | ||
1345 | } | |
1346 | ||
1347 | } catch (e) { | |
1348 | exception_error("quickAddCat", e); | |
1349 | } | |
1350 | } | |
8801fb01 AD |
1351 | |
1352 | function genUrlChangeKey(feed, is_cat) { | |
1353 | ||
1354 | try { | |
1355 | var ok = confirm(__("Generate new syndication address for this feed?")); | |
1356 | ||
1357 | if (ok) { | |
1358 | ||
1359 | notify_progress("Trying to change address...", true); | |
1360 | ||
1361 | var query = "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed) + | |
1362 | "&is_cat=" + param_escape(is_cat); | |
1363 | ||
1364 | new Ajax.Request("backend.php", { | |
1365 | parameters: query, | |
1366 | onComplete: function(transport) { | |
1367 | var new_link = transport.responseXML.getElementsByTagName("link")[0]; | |
1368 | ||
1369 | var e = $('gen_feed_url'); | |
1370 | ||
1371 | if (new_link) { | |
1372 | ||
1373 | new_link = new_link.firstChild.nodeValue; | |
1374 | ||
1375 | e.innerHTML = e.innerHTML.replace(/\&key=.*$/, | |
1376 | "&key=" + new_link); | |
1377 | ||
1378 | e.href = e.href.replace(/\&key=.*$/, | |
1379 | "&key=" + new_link); | |
1380 | ||
1381 | new Effect.Highlight(e); | |
1382 | ||
1383 | notify(''); | |
1384 | ||
1385 | } else { | |
1386 | notify_error("Could not change feed URL."); | |
1387 | } | |
1388 | } }); | |
1389 | } | |
1390 | } catch (e) { | |
1391 | exception_error("genUrlChangeKey", e); | |
1392 | } | |
1393 | return false; | |
1394 | } | |
1395 | ||
1c31e190 AD |
1396 | function labelSelectOnChange(elem) { |
1397 | try { | |
1398 | var value = elem[elem.selectedIndex].value; | |
1399 | var def = elem.getAttribute('default'); | |
1400 | ||
1401 | if (value == "ADD_LABEL") { | |
1402 | ||
1403 | if (def) | |
1404 | dropboxSelect(elem, def); | |
1405 | else | |
1406 | elem.selectedIndex = 0; | |
1407 | ||
1408 | addLabel(elem, function(transport) { | |
1c31e190 | 1409 | |
10249c41 | 1410 | try { |
1c31e190 | 1411 | |
10249c41 AD |
1412 | var response = transport.responseXML; |
1413 | var select = response.getElementsByTagName("select")[0]; | |
1414 | var options = select.getElementsByTagName("option"); | |
1415 | ||
1416 | dropbox_replace_options(elem, options); | |
1417 | ||
1418 | notify(''); | |
1419 | } catch (e) { | |
1420 | exception_error("addLabel", e); | |
1421 | } | |
1c31e190 AD |
1422 | }); |
1423 | } | |
1424 | ||
1425 | } catch (e) { | |
10249c41 | 1426 | exception_error("labelSelectOnChange", e); |
1c31e190 AD |
1427 | } |
1428 | } | |
1429 | ||
10249c41 AD |
1430 | function dropbox_replace_options(elem, options) { |
1431 | ||
1432 | try { | |
1433 | while (elem.hasChildNodes()) | |
1434 | elem.removeChild(elem.firstChild); | |
1435 | ||
1436 | var sel_idx = -1; | |
1437 | ||
1438 | for (var i = 0; i < options.length; i++) { | |
1439 | var text = options[i].firstChild.nodeValue; | |
1440 | var value = options[i].getAttribute("value"); | |
11eb3f4e AD |
1441 | |
1442 | if (value == undefined) value = text; | |
1443 | ||
10249c41 | 1444 | var issel = options[i].getAttribute("selected") == "1"; |
c00907f2 AD |
1445 | |
1446 | var option = new Option(text, value, issel); | |
1447 | ||
1448 | if (options[i].getAttribute("disabled")) | |
1449 | option.setAttribute("disabled", true); | |
1450 | ||
1451 | elem.insert(option); | |
1452 | ||
10249c41 AD |
1453 | if (issel) sel_idx = i; |
1454 | } | |
1c31e190 | 1455 | |
10249c41 AD |
1456 | // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true) |
1457 | if (sel_idx >= 0) elem.selectedIndex = sel_idx; | |
1458 | ||
1459 | } catch (e) { | |
1460 | exception_error("dropbox_replace_options", e); | |
1461 | } | |
1462 | } | |
e69fb880 AD |
1463 | |
1464 | // mode = all, none, invert | |
1465 | function selectTableRows(id, mode) { | |
1466 | try { | |
1467 | var rows = $(id).rows; | |
1468 | ||
1469 | for (var i = 0; i < rows.length; i++) { | |
1470 | var row = rows[i]; | |
1471 | var cb = false; | |
1472 | ||
1473 | if (row.id && row.className) { | |
1474 | var bare_id = row.id.replace(/^[A-Z]*?-/, ""); | |
1475 | var inputs = rows[i].getElementsByTagName("input"); | |
1476 | ||
1477 | for (var j = 0; j < inputs.length; j++) { | |
1478 | var input = inputs[j]; | |
1479 | ||
1480 | if (input.getAttribute("type") == "checkbox" && | |
1481 | input.id.match(bare_id)) { | |
1482 | ||
1483 | cb = input; | |
1484 | break; | |
1485 | } | |
1486 | } | |
1487 | ||
1488 | if (cb) { | |
ca8e3d75 | 1489 | var issel = row.hasClassName("Selected"); |
e69fb880 AD |
1490 | |
1491 | if (mode == "all" && !issel) { | |
ca8e3d75 | 1492 | row.addClassName("Selected"); |
e69fb880 AD |
1493 | cb.checked = true; |
1494 | } else if (mode == "none" && issel) { | |
ca8e3d75 | 1495 | row.removeClassName("Selected"); |
e69fb880 AD |
1496 | cb.checked = false; |
1497 | } else if (mode == "invert") { | |
1498 | ||
1499 | if (issel) { | |
ca8e3d75 | 1500 | row.removeClassName("Selected"); |
e69fb880 AD |
1501 | cb.checked = false; |
1502 | } else { | |
ca8e3d75 | 1503 | row.addClassName("Selected"); |
e69fb880 AD |
1504 | cb.checked = true; |
1505 | } | |
1506 | } | |
1507 | } | |
1508 | } | |
1509 | } | |
1510 | ||
1511 | } catch (e) { | |
1512 | exception_error("selectTableRows", e); | |
1513 | ||
1514 | } | |
1515 | } | |
1516 | ||
1517 | function getSelectedTableRowIds(id) { | |
1518 | var rows = []; | |
1519 | ||
1520 | try { | |
1521 | var elem_rows = $(id).rows; | |
1522 | ||
1523 | for (i = 0; i < elem_rows.length; i++) { | |
ca8e3d75 | 1524 | if (elem_rows[i].hasClassName("Selected")) { |
e69fb880 AD |
1525 | var bare_id = elem_rows[i].id.replace(/^[A-Z]*?-/, ""); |
1526 | rows.push(bare_id); | |
1527 | } | |
1528 | } | |
1529 | ||
1530 | } catch (e) { | |
1531 | exception_error("getSelectedTableRowIds", e); | |
1532 | } | |
1533 | ||
1534 | return rows; | |
1535 | } | |
1536 |