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