]>
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 | ||
6f3976c9 | 397 | if (dialog) { |
154d2ac4 AD |
398 | dialog.attr('content', ''); |
399 | dialog.hide(); | |
6f3976c9 | 400 | } |
e8a429e3 | 401 | |
588e4dc3 | 402 | } catch (e) { |
951906dc | 403 | //exception_error("closeInfoBox", e); |
e8a429e3 | 404 | } |
90ac84df | 405 | return false; |
e5d758e3 AD |
406 | } |
407 | ||
408 | ||
542aebac | 409 | function displayDlg(id, param, callback) { |
7b5c6012 | 410 | |
951906dc | 411 | notify_progress("Loading, please wait...", true); |
2371c520 | 412 | |
6f3976c9 AD |
413 | while (dialogs.length > 0) |
414 | closeInfoBox(); | |
415 | ||
b4e75b2a | 416 | var query = "?op=dlg&id=" + |
288487e4 AD |
417 | param_escape(id) + "¶m=" + param_escape(param); |
418 | ||
b4e75b2a AD |
419 | new Ajax.Request("backend.php", { |
420 | parameters: query, | |
288487e4 AD |
421 | onComplete: function (transport) { |
422 | infobox_callback2(transport); | |
542aebac | 423 | if (callback) callback(transport); |
288487e4 AD |
424 | } }); |
425 | ||
90ac84df | 426 | return false; |
7b5c6012 AD |
427 | } |
428 | ||
288487e4 AD |
429 | function infobox_submit_callback2(transport) { |
430 | closeInfoBox(); | |
79f3553b | 431 | |
288487e4 AD |
432 | try { |
433 | // called from prefs, reload tab | |
438f2ce9 | 434 | if (typeof active_tab != 'undefined' && active_tab) { |
288487e4 | 435 | selectTab(active_tab, false); |
5e6f933a | 436 | } |
288487e4 | 437 | } catch (e) { } |
79f3553b | 438 | |
288487e4 AD |
439 | if (transport.responseText) { |
440 | notify_info(transport.responseText); | |
441 | } | |
7b5c6012 AD |
442 | } |
443 | ||
d395a942 AD |
444 | function infobox_callback2(transport) { |
445 | try { | |
5ede560f | 446 | |
951906dc AD |
447 | //console.log("infobox_callback2"); |
448 | notify(''); | |
5ede560f | 449 | |
951906dc AD |
450 | var content; |
451 | var dtitle = "Dialog"; | |
1dc47c41 | 452 | |
951906dc AD |
453 | if (transport.responseXML) { |
454 | var dlg = transport.responseXML.getElementsByTagName("dlg")[0]; | |
de85cac2 | 455 | |
951906dc AD |
456 | var title = transport.responseXML.getElementsByTagName("title")[0]; |
457 | if (title) | |
6e4f4ce1 | 458 | title = title.firstChild.nodeValue; |
de85cac2 | 459 | |
951906dc AD |
460 | var content = transport.responseXML.getElementsByTagName("content")[0]; |
461 | ||
462 | content = content.firstChild.nodeValue; | |
de85cac2 | 463 | |
951906dc AD |
464 | } else { |
465 | content = transport.responseText; | |
d395a942 | 466 | } |
05fcdf52 | 467 | |
6e4f4ce1 AD |
468 | var dialog = new dijit.Dialog({ |
469 | title: title, | |
470 | style: "width: 600px", | |
471 | onCancel: function() { | |
472 | dialogs.remove(this); | |
154d2ac4 | 473 | this.attr('content', ''); |
6e4f4ce1 AD |
474 | return true; |
475 | }, | |
476 | onExecute: function() { | |
477 | dialogs.remove(this); | |
154d2ac4 | 478 | this.attr('content', ''); |
6e4f4ce1 AD |
479 | return true; |
480 | }, | |
481 | onClose: function() { | |
482 | dialogs.remove(this); | |
154d2ac4 | 483 | this.attr('content', ''); |
6e4f4ce1 AD |
484 | return true; |
485 | }, | |
486 | content: content}); | |
487 | ||
488 | dialog.show(); | |
489 | ||
490 | dialogs.push(dialog); | |
6068d33b | 491 | |
d395a942 AD |
492 | notify(""); |
493 | } catch (e) { | |
494 | exception_error("infobox_callback2", e); | |
442d77f1 AD |
495 | } |
496 | } | |
497 | ||
18ab3d7a | 498 | function createFilter() { |
7b5c6012 | 499 | |
438f2ce9 | 500 | try { |
6068d33b | 501 | |
438f2ce9 AD |
502 | var form = document.forms['filter_add_form']; |
503 | var reg_exp = form.reg_exp.value; | |
504 | ||
505 | if (reg_exp == "") { | |
506 | alert(__("Can't add filter: nothing to match on.")); | |
507 | return false; | |
508 | } | |
f705f206 AD |
509 | |
510 | var query = "?op=rpc&subop=verifyRegexp®_exp=" + param_escape(reg_exp); | |
511 | ||
512 | notify_progress("Verifying regular expression..."); | |
513 | ||
514 | new Ajax.Request("backend.php", { | |
515 | parameters: query, | |
516 | onComplete: function(transport) { | |
517 | handle_rpc_reply(transport); | |
518 | ||
519 | var response = transport.responseXML; | |
520 | ||
521 | if (response) { | |
522 | var s = response.getElementsByTagName("status")[0].firstChild.nodeValue; | |
288487e4 | 523 | |
f705f206 AD |
524 | notify(''); |
525 | ||
526 | if (s == "INVALID") { | |
527 | alert("Match regular expression seems to be invalid."); | |
528 | return; | |
529 | } else { | |
530 | ||
531 | var query = Form.serialize("filter_add_form"); | |
532 | ||
533 | // we can be called from some other tab in Prefs | |
534 | if (typeof active_tab != 'undefined' && active_tab) { | |
535 | active_tab = "filterConfig"; | |
536 | } | |
537 | ||
538 | new Ajax.Request("backend.php?" + query, { | |
539 | onComplete: function (transport) { | |
540 | infobox_submit_callback2(transport); | |
541 | } }); | |
542 | ||
543 | return true; | |
544 | } | |
545 | } | |
546 | ||
438f2ce9 | 547 | } }); |
438f2ce9 AD |
548 | |
549 | } catch (e) { | |
550 | exception_error("createFilter", e); | |
551 | } | |
7b5c6012 AD |
552 | } |
553 | ||
605f7d46 | 554 | function isValidURL(s) { |
0d32b41e | 555 | return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null; |
605f7d46 | 556 | } |
07eb9178 | 557 | |
18ab3d7a | 558 | function subscribeToFeed() { |
07eb9178 | 559 | |
a5819bb3 AD |
560 | try { |
561 | ||
c91c2249 AD |
562 | var form = document.forms['feed_add_form']; |
563 | var feed_url = form.feed_url.value; | |
564 | ||
565 | if (feed_url == "") { | |
89cb787e | 566 | alert(__("Can't subscribe: no feed URL given.")); |
c91c2249 AD |
567 | return false; |
568 | } | |
569 | ||
1ba6daf7 | 570 | notify_progress(__("Subscribing to feed..."), true); |
07eb9178 | 571 | |
07eb9178 AD |
572 | var query = Form.serialize("feed_add_form"); |
573 | ||
84c7b824 | 574 | console.log("subscribe q: " + query); |
f27de515 | 575 | |
a5819bb3 AD |
576 | Form.disable("feed_add_form"); |
577 | ||
288487e4 AD |
578 | new Ajax.Request("backend.php", { |
579 | parameters: query, | |
580 | onComplete: function(transport) { | |
a5819bb3 AD |
581 | //dlg_frefresh_callback(transport); |
582 | ||
55a51373 | 583 | try { |
a5819bb3 | 584 | |
d3204726 | 585 | if (!transport.responseXML) { |
5414ad4c | 586 | console.log(transport.responseText); |
d3204726 AD |
587 | alert(__("Server error while trying to subscribe to specified feed.")); |
588 | return; | |
589 | } | |
5414ad4c | 590 | |
55a51373 AD |
591 | var result = transport.responseXML.getElementsByTagName('result')[0]; |
592 | var rc = parseInt(result.getAttribute('code')); | |
593 | ||
594 | Form.enable("feed_add_form"); | |
595 | ||
596 | notify(''); | |
597 | ||
598 | switch (rc) { | |
599 | case 1: | |
600 | closeInfoBox(); | |
601 | notify_info(__("Subscribed to %s").replace("%s", feed_url)); | |
602 | ||
603 | if (inPreferences()) { | |
604 | updateFeedList(); | |
605 | } else { | |
606 | setTimeout('updateFeedList(false, false)', 50); | |
607 | } | |
608 | break; | |
609 | case 2: | |
5414ad4c AD |
610 | alert(__("Specified URL seems to be invalid.")); |
611 | break; | |
55a51373 | 612 | case 3: |
5414ad4c | 613 | alert(__("Specified URL doesn't seem to contain any feeds.")); |
55a51373 AD |
614 | break; |
615 | case 4: | |
616 | new Ajax.Request("backend.php", { | |
617 | parameters: 'op=rpc&subop=extractfeedurls&url=' + encodeURIComponent(feed_url), | |
618 | onComplete: function(transport) { | |
619 | var result = transport.responseXML.getElementsByTagName('urls')[0]; | |
620 | var feeds = JSON.parse(result.firstChild.nodeValue); | |
621 | var select = document.getElementById("faad_feeds_container_select"); | |
622 | ||
623 | while (select.hasChildNodes()) { | |
624 | select.removeChild(elem.firstChild); | |
625 | } | |
626 | var count = 0; | |
627 | for (var feedUrl in feeds) { | |
628 | select.insert(new Option(feeds[feedUrl], feedUrl, false)); | |
629 | count++; | |
630 | } | |
631 | if (count > 5) count = 5; | |
632 | select.size = count; | |
633 | ||
6e4f4ce1 | 634 | Effect.Appear('fadd_feeds_container', {duration : 0.5}); |
5eeb3874 | 635 | } |
55a51373 AD |
636 | }); |
637 | break; | |
5414ad4c AD |
638 | case 5: |
639 | alert(__("Couldn't download the specified URL.")); | |
640 | break; | |
55a51373 AD |
641 | case 0: |
642 | alert(__("You are already subscribed to this feed.")); | |
643 | break; | |
644 | } | |
5eeb3874 | 645 | |
55a51373 AD |
646 | } catch (e) { |
647 | exception_error("subscribeToFeed", e); | |
a5819bb3 AD |
648 | } |
649 | ||
288487e4 | 650 | } }); |
7bc4f251 | 651 | |
a5819bb3 AD |
652 | } catch (e) { |
653 | exception_error("subscribeToFeed", e); | |
654 | } | |
655 | ||
7bc4f251 | 656 | return false; |
07eb9178 AD |
657 | } |
658 | ||
6e6504bc | 659 | function filterCR(e, f) |
86b682ce AD |
660 | { |
661 | var key; | |
662 | ||
663 | if(window.event) | |
664 | key = window.event.keyCode; //IE | |
665 | else | |
666 | key = e.which; //firefox | |
667 | ||
6e6504bc AD |
668 | if (key == 13) { |
669 | if (typeof f != 'undefined') { | |
670 | f(); | |
671 | return false; | |
672 | } else { | |
673 | return false; | |
674 | } | |
675 | } else { | |
676 | return true; | |
677 | } | |
86b682ce AD |
678 | } |
679 | ||
33d13e72 | 680 | function getInitParam(key) { |
40496720 | 681 | return init_params[key]; |
33d13e72 | 682 | } |
3ac2b520 | 683 | |
dbfc9522 | 684 | function setInitParam(key, value) { |
5158ced9 | 685 | init_params[key] = value; |
be0801a1 AD |
686 | } |
687 | ||
273d1e29 | 688 | function fatalError(code, msg, ext_info) { |
a7565293 | 689 | try { |
a7565293 | 690 | |
91743a49 AD |
691 | if (!ext_info) ext_info = "N/A"; |
692 | ||
b4c27af7 | 693 | if (code == 6) { |
206d4967 | 694 | window.location.href = "tt-rss.php"; |
b4c27af7 | 695 | } else if (code == 5) { |
661135c7 | 696 | window.location.href = "db-updater.php"; |
b4c27af7 | 697 | } else { |
4724a093 | 698 | |
273d1e29 | 699 | if (msg == "") msg = "Unknown error"; |
42c32916 | 700 | |
acac8448 | 701 | var ebc = $("xebContent"); |
4724a093 | 702 | |
273d1e29 AD |
703 | if (ebc) { |
704 | ||
705 | Element.show("dialog_overlay"); | |
706 | Element.show("errorBoxShadow"); | |
707 | Element.hide("xebBtn"); | |
708 | ||
709 | if (ext_info) { | |
710 | if (ext_info.responseText) { | |
711 | ext_info = ext_info.responseText; | |
712 | } | |
713 | } | |
714 | ||
715 | ebc.innerHTML = | |
716 | "<div><b>Error message:</b></div>" + | |
717 | "<pre>" + msg + "</pre>" + | |
718 | "<div><b>Additional information:</b></div>" + | |
719 | "<textarea readonly=\"1\">" + ext_info + "</textarea>"; | |
720 | } | |
4724a093 | 721 | } |
a7565293 AD |
722 | |
723 | } catch (e) { | |
724 | exception_error("fatalError", e); | |
725 | } | |
726 | } | |
727 | ||
d0da85c2 AD |
728 | function filterDlgCheckType(sender) { |
729 | ||
730 | try { | |
731 | ||
732 | var ftype = sender[sender.selectedIndex].value; | |
733 | ||
734 | var form = document.forms["filter_add_form"]; | |
735 | ||
736 | if (!form) { | |
737 | form = document.forms["filter_edit_form"]; | |
738 | } | |
739 | ||
740 | if (!form) { | |
84c7b824 | 741 | console.log("filterDlgCheckType: can't find form!"); |
d0da85c2 AD |
742 | return; |
743 | } | |
744 | ||
745 | // if selected filter type is 5 (Date) enable the modifier dropbox | |
746 | if (ftype == 5) { | |
747 | Element.show("filter_dlg_date_mod_box"); | |
748 | Element.show("filter_dlg_date_chk_box"); | |
749 | } else { | |
750 | Element.hide("filter_dlg_date_mod_box"); | |
751 | Element.hide("filter_dlg_date_chk_box"); | |
752 | ||
753 | } | |
754 | ||
755 | } catch (e) { | |
756 | exception_error("filterDlgCheckType", e); | |
757 | } | |
758 | ||
759 | } | |
760 | ||
350f0ad1 AD |
761 | function filterDlgCheckAction(sender) { |
762 | ||
763 | try { | |
764 | ||
765 | var action = sender[sender.selectedIndex].value; | |
766 | ||
767 | var form = document.forms["filter_add_form"]; | |
768 | ||
769 | if (!form) { | |
770 | form = document.forms["filter_edit_form"]; | |
771 | } | |
772 | ||
773 | if (!form) { | |
84c7b824 | 774 | console.log("filterDlgCheckAction: can't find form!"); |
350f0ad1 AD |
775 | return; |
776 | } | |
777 | ||
acac8448 | 778 | var action_param = $("filter_dlg_param_box"); |
350f0ad1 AD |
779 | |
780 | if (!action_param) { | |
84c7b824 | 781 | console.log("filterDlgCheckAction: can't find action param box!"); |
350f0ad1 AD |
782 | return; |
783 | } | |
784 | ||
785 | // if selected action supports parameters, enable params field | |
ceb30ba4 | 786 | if (action == 4 || action == 6 || action == 7) { |
143a4973 | 787 | Element.show(action_param); |
ceb30ba4 AD |
788 | if (action != 7) { |
789 | Element.show(form.action_param); | |
790 | Element.hide(form.action_param_label); | |
791 | } else { | |
792 | Element.show(form.action_param_label); | |
793 | Element.hide(form.action_param); | |
794 | } | |
350f0ad1 | 795 | } else { |
143a4973 | 796 | Element.hide(action_param); |
350f0ad1 AD |
797 | } |
798 | ||
799 | } catch (e) { | |
438f2ce9 | 800 | exception_error("filterDlgCheckAction", e); |
350f0ad1 AD |
801 | } |
802 | ||
803 | } | |
ef16ae37 | 804 | |
d0da85c2 AD |
805 | function filterDlgCheckDate() { |
806 | try { | |
807 | var form = document.forms["filter_add_form"]; | |
808 | ||
809 | if (!form) { | |
810 | form = document.forms["filter_edit_form"]; | |
811 | } | |
812 | ||
813 | if (!form) { | |
84c7b824 | 814 | console.log("filterDlgCheckAction: can't find form!"); |
d0da85c2 AD |
815 | return; |
816 | } | |
817 | ||
818 | var reg_exp = form.reg_exp.value; | |
819 | ||
b4e75b2a | 820 | var query = "?op=rpc&subop=checkDate&date=" + reg_exp; |
d0da85c2 | 821 | |
b4e75b2a AD |
822 | new Ajax.Request("backend.php", { |
823 | parameters: query, | |
d0da85c2 AD |
824 | onComplete: function(transport) { |
825 | ||
826 | var form = document.forms["filter_add_form"]; | |
827 | ||
828 | if (!form) { | |
829 | form = document.forms["filter_edit_form"]; | |
830 | } | |
831 | ||
832 | if (transport.responseXML) { | |
833 | var result = transport.responseXML.getElementsByTagName("result")[0]; | |
834 | ||
835 | if (result && result.firstChild) { | |
836 | if (result.firstChild.nodeValue == "1") { | |
837 | ||
838 | new Effect.Highlight(form.reg_exp, {startcolor : '#00ff00'}); | |
839 | ||
840 | return; | |
841 | } | |
842 | } | |
843 | } | |
844 | ||
845 | new Effect.Highlight(form.reg_exp, {startcolor : '#ff0000'}); | |
846 | ||
847 | } }); | |
848 | ||
849 | ||
850 | } catch (e) { | |
851 | exception_error("filterDlgCheckDate", e); | |
852 | } | |
853 | } | |
854 | ||
ef16ae37 AD |
855 | function explainError(code) { |
856 | return displayDlg("explainError", code); | |
857 | } | |
01a87dff | 858 | |
f6d40ed2 | 859 | function displayHelpInfobox(topic_id) { |
c4a36709 | 860 | |
f6d40ed2 AD |
861 | var url = "backend.php?op=help&tid=" + param_escape(topic_id); |
862 | ||
863 | var w = window.open(url, "ttrss_help", | |
864 | "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0"); | |
865 | ||
f6d40ed2 | 866 | } |
e635d56a | 867 | |
99509451 | 868 | function loading_set_progress(p) { |
730dbf19 | 869 | try { |
fca95d5f AD |
870 | if (p < last_progress_point || !Element.visible("overlay")) return; |
871 | ||
50eefedb | 872 | console.log("loading_set_progress : " + p + " (" + last_progress_point + ")"); |
99509451 | 873 | |
acac8448 | 874 | var o = $("l_progress_i"); |
99509451 | 875 | |
673c9946 AD |
876 | // o.style.width = (p * 2) + "px"; |
877 | ||
99509451 AD |
878 | new Effect.Scale(o, p, { |
879 | scaleY : false, | |
880 | scaleFrom : last_progress_point, | |
881 | scaleMode: { originalWidth : 200 }, | |
673c9946 | 882 | queue: { position: 'end', scope: 'LSP-Q', limit: 3 } }); |
99509451 AD |
883 | |
884 | last_progress_point = p; | |
730dbf19 AD |
885 | |
886 | } catch (e) { | |
887 | exception_error("loading_set_progress", e); | |
888 | } | |
889 | } | |
08827aaf AD |
890 | |
891 | function remove_splash() { | |
892 | if (Element.visible("overlay")) { | |
84c7b824 | 893 | console.log("about to remove splash, OMG!"); |
08827aaf | 894 | Element.hide("overlay"); |
84c7b824 | 895 | console.log("removed splash!"); |
08827aaf AD |
896 | } |
897 | } | |
071ec48f | 898 | |
c2913898 AD |
899 | function getSelectedFeedsFromBrowser() { |
900 | ||
3c8e3b15 | 901 | var list = $$("#browseFeedList li[id*=FBROW]"); |
c2913898 AD |
902 | |
903 | var selected = new Array(); | |
3c8e3b15 AD |
904 | |
905 | list.each(function(child) { | |
906 | var id = child.id.replace("FBROW-", ""); | |
907 | var cb = $("FBCHK-" + id); | |
908 | ||
909 | if (cb.checked) { | |
910 | selected.push(id); | |
911 | } | |
912 | }); | |
c2913898 AD |
913 | |
914 | return selected; | |
915 | } | |
916 | ||
2bab8824 AD |
917 | function updateFeedBrowser() { |
918 | try { | |
919 | ||
ef88b1cc | 920 | var query = Form.serialize("feed_browser"); |
f4280bdd AD |
921 | |
922 | Element.show('feed_browser_spinner'); | |
2bab8824 | 923 | |
b4e75b2a AD |
924 | new Ajax.Request("backend.php", { |
925 | parameters: query, | |
2bab8824 AD |
926 | onComplete: function(transport) { |
927 | notify(''); | |
928 | ||
f4280bdd AD |
929 | Element.hide('feed_browser_spinner'); |
930 | ||
acac8448 | 931 | var c = $("browseFeedList"); |
2bab8824 AD |
932 | var r = transport.responseXML.getElementsByTagName("content")[0]; |
933 | var nr = transport.responseXML.getElementsByTagName("num-results")[0]; | |
ef88b1cc | 934 | var mode = transport.responseXML.getElementsByTagName("mode")[0]; |
2bab8824 AD |
935 | |
936 | if (c && r) { | |
937 | c.innerHTML = r.firstChild.nodeValue; | |
938 | } | |
ef88b1cc AD |
939 | |
940 | if (parseInt(mode.getAttribute("value")) == 2) { | |
941 | Element.show('feed_archive_remove'); | |
942 | } else { | |
943 | Element.hide('feed_archive_remove'); | |
944 | } | |
2bab8824 | 945 | |
2bab8824 AD |
946 | } }); |
947 | ||
2bab8824 AD |
948 | } catch (e) { |
949 | exception_error("updateFeedBrowser", e); | |
950 | } | |
082ae95b | 951 | |
2bab8824 AD |
952 | } |
953 | ||
2184738a AD |
954 | function transport_error_check(transport) { |
955 | try { | |
956 | if (transport.responseXML) { | |
957 | var error = transport.responseXML.getElementsByTagName("error")[0]; | |
958 | ||
959 | if (error) { | |
960 | var code = error.getAttribute("error-code"); | |
961 | var msg = error.getAttribute("error-msg"); | |
962 | if (code != 0) { | |
963 | fatalError(code, msg); | |
964 | return false; | |
965 | } | |
966 | } | |
967 | } | |
968 | } catch (e) { | |
969 | exception_error("check_for_error_xml", e); | |
970 | } | |
971 | return true; | |
972 | } | |
2bab8824 | 973 | |
261b88b3 AD |
974 | function strip_tags(s) { |
975 | return s.replace(/<\/?[^>]+(>|$)/g, ""); | |
976 | } | |
977 | ||
978 | function truncate_string(s, length) { | |
979 | if (!length) length = 30; | |
980 | var tmp = s.substring(0, length); | |
981 | if (s.length > length) tmp += "…"; | |
982 | return tmp; | |
983 | } | |
ab553f9a | 984 | |
78935092 AD |
985 | function hotkey_prefix_timeout() { |
986 | try { | |
987 | ||
988 | var date = new Date(); | |
989 | var ts = Math.round(date.getTime() / 1000); | |
990 | ||
991 | if (hotkey_prefix_pressed && ts - hotkey_prefix_pressed >= 5) { | |
84c7b824 | 992 | console.log("hotkey_prefix seems to be stuck, aborting"); |
78935092 AD |
993 | hotkey_prefix_pressed = false; |
994 | hotkey_prefix = false; | |
995 | Element.hide('cmdline'); | |
996 | } | |
997 | ||
998 | setTimeout("hotkey_prefix_timeout()", 1000); | |
999 | ||
1000 | } catch (e) { | |
1001 | exception_error("hotkey_prefix_timeout", e); | |
1002 | } | |
1003 | } | |
1004 | ||
37e93d6c AD |
1005 | function hideAuxDlg() { |
1006 | try { | |
1007 | Element.hide('auxDlg'); | |
1008 | } catch (e) { | |
1009 | exception_error("hideAuxDlg", e); | |
1010 | } | |
1011 | } | |
1012 | ||
ef88b1cc AD |
1013 | function feedBrowserSubscribe() { |
1014 | try { | |
1015 | ||
1016 | var selected = getSelectedFeedsFromBrowser(); | |
1017 | ||
1018 | var mode = document.forms['feed_browser'].mode; | |
1019 | ||
1020 | mode = mode[mode.selectedIndex].value; | |
1021 | ||
1022 | if (selected.length > 0) { | |
1023 | closeInfoBox(); | |
1024 | ||
1025 | notify_progress("Loading, please wait...", true); | |
1026 | ||
1027 | var query = "?op=rpc&subop=massSubscribe&ids="+ | |
1028 | param_escape(selected.toString()) + "&mode=" + param_escape(mode); | |
1029 | ||
1030 | new Ajax.Request("backend.php", { | |
1031 | parameters: query, | |
1032 | onComplete: function(transport) { | |
1033 | ||
1034 | var nf = transport.responseXML.getElementsByTagName('num-feeds')[0]; | |
1035 | var nf_value = nf.getAttribute("value"); | |
1036 | ||
1037 | notify_info(__("Subscribed to %d feed(s).").replace("%d", nf_value)); | |
1038 | ||
1039 | if (inPreferences()) { | |
1040 | updateFeedList(); | |
1041 | } else { | |
1042 | setTimeout('updateFeedList(false, false)', 50); | |
1043 | } | |
1044 | } }); | |
1045 | ||
1046 | } else { | |
1047 | alert(__("No feeds are selected.")); | |
1048 | } | |
1049 | ||
1050 | } catch (e) { | |
1051 | exception_error("feedBrowserSubscribe", e); | |
1052 | } | |
1053 | } | |
1054 | ||
1055 | function feedArchiveRemove() { | |
1056 | try { | |
1057 | ||
1058 | var selected = getSelectedFeedsFromBrowser(); | |
1059 | ||
1060 | if (selected.length > 0) { | |
1061 | ||
d9084cf2 | 1062 | var pr = __("Remove selected feeds from the archive? Feeds with stored articles will not be removed."); |
ef88b1cc AD |
1063 | |
1064 | if (confirm(pr)) { | |
1065 | Element.show('feed_browser_spinner'); | |
1066 | ||
1067 | var query = "?op=rpc&subop=remarchived&ids=" + | |
1068 | param_escape(selected.toString());; | |
1069 | ||
1070 | new Ajax.Request("backend.php", { | |
1071 | parameters: query, | |
1072 | onComplete: function(transport) { | |
1073 | updateFeedBrowser(); | |
1074 | } }); | |
1075 | } | |
1076 | ||
1077 | } else { | |
1078 | alert(__("No feeds are selected.")); | |
1079 | } | |
1080 | ||
1081 | } catch (e) { | |
1082 | exception_error("feedArchiveRemove", e); | |
1083 | } | |
1084 | } | |
1085 | ||
7abf159d | 1086 | function uploadIconHandler(rc) { |
c3b7b797 | 1087 | try { |
7abf159d AD |
1088 | switch (rc) { |
1089 | case 0: | |
1090 | notify_info("Upload complete."); | |
1091 | if (inPreferences()) { | |
1092 | updateFeedList(); | |
1093 | } else { | |
1094 | setTimeout('updateFeedList(false, false)', 50); | |
1095 | } | |
1096 | break; | |
1097 | case 1: | |
1098 | notify_error("Upload failed: icon is too big."); | |
1099 | break; | |
1100 | case 2: | |
1101 | notify_error("Upload failed."); | |
1102 | break; | |
1103 | } | |
1104 | ||
1105 | } catch (e) { | |
1106 | exception_error("uploadIconHandler", e); | |
1107 | } | |
1108 | } | |
1109 | ||
1110 | function removeFeedIcon(id) { | |
1111 | ||
1112 | try { | |
1113 | ||
1114 | if (confirm(__("Remove stored feed icon?"))) { | |
1115 | var query = "backend.php?op=pref-feeds&subop=removeicon&feed_id=" + param_escape(id); | |
c3b7b797 | 1116 | |
84c7b824 | 1117 | console.log(query); |
c3b7b797 | 1118 | |
7abf159d | 1119 | notify_progress("Removing feed icon...", true); |
c3b7b797 | 1120 | |
7abf159d AD |
1121 | new Ajax.Request("backend.php", { |
1122 | parameters: query, | |
1123 | onComplete: function(transport) { | |
1124 | notify_info("Feed icon removed."); | |
1125 | if (inPreferences()) { | |
1126 | updateFeedList(); | |
1127 | } else { | |
1128 | setTimeout('updateFeedList(false, false)', 50); | |
1129 | } | |
1130 | } }); | |
1131 | } | |
1132 | ||
1133 | return false; | |
c3b7b797 | 1134 | } catch (e) { |
7abf159d | 1135 | exception_error("uploadFeedIcon", e); |
c3b7b797 AD |
1136 | } |
1137 | } | |
1138 | ||
1139 | function uploadFeedIcon() { | |
1140 | ||
1141 | try { | |
1142 | ||
1143 | var file = $("icon_file"); | |
1144 | ||
1145 | if (file.value.length == 0) { | |
1146 | alert(__("Please select an image file to upload.")); | |
c3b7b797 | 1147 | } else { |
7abf159d AD |
1148 | if (confirm(__("Upload new icon for this feed?"))) { |
1149 | notify_progress("Uploading, please wait...", true); | |
1150 | return true; | |
1151 | } | |
c3b7b797 AD |
1152 | } |
1153 | ||
7abf159d AD |
1154 | return false; |
1155 | ||
c3b7b797 AD |
1156 | } catch (e) { |
1157 | exception_error("uploadFeedIcon", e); | |
1158 | } | |
1159 | } | |
1160 | ||
1c31e190 | 1161 | function addLabel(select, callback) { |
d002edc7 AD |
1162 | |
1163 | try { | |
1164 | ||
1165 | var caption = prompt(__("Please enter label caption:"), ""); | |
1166 | ||
1167 | if (caption != undefined) { | |
1168 | ||
1169 | if (caption == "") { | |
1170 | alert(__("Can't create label: missing caption.")); | |
1171 | return false; | |
1172 | } | |
1173 | ||
1174 | var query = "?op=pref-labels&subop=add&caption=" + | |
1175 | param_escape(caption); | |
1176 | ||
1c31e190 AD |
1177 | if (select) |
1178 | query += "&output=select"; | |
1179 | ||
d002edc7 AD |
1180 | notify_progress("Loading, please wait...", true); |
1181 | ||
1c31e190 | 1182 | if (inPreferences() && !select) active_tab = "labelConfig"; |
d002edc7 AD |
1183 | |
1184 | new Ajax.Request("backend.php", { | |
1185 | parameters: query, | |
1186 | onComplete: function(transport) { | |
1c31e190 AD |
1187 | if (callback) { |
1188 | callback(transport); | |
1189 | } else if (inPreferences()) { | |
d002edc7 AD |
1190 | infobox_submit_callback2(transport); |
1191 | } else { | |
1192 | updateFeedList(); | |
1193 | } | |
1194 | } }); | |
1195 | ||
1196 | } | |
1197 | ||
1198 | } catch (e) { | |
1199 | exception_error("addLabel", e); | |
1200 | } | |
1201 | } | |
1202 | ||
3393238d AD |
1203 | function quickAddFeed() { |
1204 | displayDlg('quickAddFeed', '', | |
1205 | function () {$('feed_url').focus();}); | |
1206 | } | |
1207 | ||
1208 | function quickAddFilter() { | |
1209 | displayDlg('quickAddFilter', '', | |
1210 | function () {document.forms['filter_add_form'].reg_exp.focus();}); | |
1211 | } | |
78bcd2c4 AD |
1212 | |
1213 | function unsubscribeFeed(feed_id, title) { | |
1214 | ||
1215 | var msg = __("Unsubscribe from %s?").replace("%s", title); | |
1216 | ||
1217 | if (title == undefined || confirm(msg)) { | |
1218 | notify_progress("Removing feed..."); | |
1219 | ||
1220 | var query = "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id; | |
1221 | ||
1222 | new Ajax.Request("backend.php", { | |
1223 | parameters: query, | |
1224 | onComplete: function(transport) { | |
1225 | ||
1226 | closeInfoBox(); | |
1227 | ||
1228 | if (inPreferences()) { | |
1229 | updateFeedList(); | |
1230 | } else { | |
1231 | dlg_frefresh_callback(transport, feed_id); | |
1232 | } | |
1233 | ||
1234 | } }); | |
1235 | } | |
1236 | ||
1237 | return false; | |
1238 | } | |
1239 | ||
1240 | ||
4a3da1c8 AD |
1241 | function backend_sanity_check_callback(transport) { |
1242 | ||
1243 | try { | |
1244 | ||
1245 | if (sanity_check_done) { | |
1246 | fatalError(11, "Sanity check request received twice. This can indicate "+ | |
1247 | "presence of Firebug or some other disrupting extension. "+ | |
1248 | "Please disable it and try again."); | |
1249 | return; | |
1250 | } | |
1251 | ||
1252 | if (!transport.responseXML) { | |
1253 | if (!store) { | |
1254 | fatalError(3, "Sanity check: Received reply is not XML", | |
1255 | transport.responseText); | |
1256 | return; | |
4a3da1c8 AD |
1257 | } |
1258 | } | |
1259 | ||
5191a7ce | 1260 | var reply = transport.responseXML.getElementsByTagName("error")[0]; |
4a3da1c8 AD |
1261 | |
1262 | if (!reply) { | |
1263 | fatalError(3, "Sanity check: invalid RPC reply", transport.responseText); | |
1264 | return; | |
1265 | } | |
1266 | ||
1267 | var error_code = reply.getAttribute("error-code"); | |
1268 | ||
1269 | if (error_code && error_code != 0) { | |
1270 | return fatalError(error_code, reply.getAttribute("error-msg")); | |
1271 | } | |
1272 | ||
1273 | console.log("sanity check ok"); | |
1274 | ||
5191a7ce | 1275 | var params = transport.responseXML.getElementsByTagName("init-params")[0]; |
4a3da1c8 AD |
1276 | |
1277 | if (params) { | |
1278 | console.log('reading init-params...'); | |
f1f3a642 AD |
1279 | |
1280 | params = JSON.parse(params.firstChild.nodeValue); | |
4a3da1c8 | 1281 | |
f1f3a642 | 1282 | if (params) { |
c4f7ba80 | 1283 | for (k in params) { |
c4f7ba80 | 1284 | var v = params[k]; |
c4f7ba80 | 1285 | console.log("IP: " + k + " => " + v); |
f1f3a642 | 1286 | } |
4a3da1c8 | 1287 | } |
c4f7ba80 AD |
1288 | |
1289 | init_params = params; | |
4a3da1c8 AD |
1290 | } |
1291 | ||
1292 | sanity_check_done = true; | |
1293 | ||
1294 | init_second_stage(); | |
1295 | ||
1296 | } catch (e) { | |
1297 | exception_error("backend_sanity_check_callback", e, transport); | |
1298 | } | |
1299 | } | |
1300 | ||
ff0010c1 | 1301 | function has_local_storage() { |
ce40b580 AD |
1302 | return false; |
1303 | /* try { | |
ff0010c1 AD |
1304 | return 'localStorage' in window && window['localStorage'] != null; |
1305 | } catch (e) { | |
1306 | return false; | |
ce40b580 | 1307 | } */ |
ff0010c1 | 1308 | } |
5c7c7da9 AD |
1309 | |
1310 | function catSelectOnChange(elem) { | |
1311 | try { | |
1312 | var value = elem[elem.selectedIndex].value; | |
1313 | var def = elem.getAttribute('default'); | |
1314 | ||
1315 | if (value == "ADD_CAT") { | |
1316 | ||
1317 | if (def) | |
1318 | dropboxSelect(elem, def); | |
1319 | else | |
1320 | elem.selectedIndex = 0; | |
1321 | ||
1322 | quickAddCat(elem); | |
1323 | } | |
1324 | ||
1325 | } catch (e) { | |
1326 | exception_error("catSelectOnChange", e); | |
1327 | } | |
1328 | } | |
1329 | ||
c00907f2 | 1330 | function quickAddCat(elem) { |
5c7c7da9 AD |
1331 | try { |
1332 | var cat = prompt(__("Please enter category title:")); | |
1333 | ||
1334 | if (cat) { | |
1335 | ||
1336 | var query = "?op=rpc&subop=quickAddCat&cat=" + param_escape(cat); | |
1337 | ||
c00907f2 AD |
1338 | notify_progress("Loading, please wait...", true); |
1339 | ||
5c7c7da9 AD |
1340 | new Ajax.Request("backend.php", { |
1341 | parameters: query, | |
1342 | onComplete: function (transport) { | |
1343 | var response = transport.responseXML; | |
c00907f2 AD |
1344 | var select = response.getElementsByTagName("select")[0]; |
1345 | var options = select.getElementsByTagName("option"); | |
5c7c7da9 | 1346 | |
c00907f2 | 1347 | dropbox_replace_options(elem, options); |
5c7c7da9 | 1348 | |
c00907f2 | 1349 | notify(''); |
5c7c7da9 AD |
1350 | |
1351 | } }); | |
1352 | ||
1353 | } | |
1354 | ||
1355 | } catch (e) { | |
1356 | exception_error("quickAddCat", e); | |
1357 | } | |
1358 | } | |
8801fb01 AD |
1359 | |
1360 | function genUrlChangeKey(feed, is_cat) { | |
1361 | ||
1362 | try { | |
1363 | var ok = confirm(__("Generate new syndication address for this feed?")); | |
1364 | ||
1365 | if (ok) { | |
1366 | ||
1367 | notify_progress("Trying to change address...", true); | |
1368 | ||
1369 | var query = "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed) + | |
1370 | "&is_cat=" + param_escape(is_cat); | |
1371 | ||
1372 | new Ajax.Request("backend.php", { | |
1373 | parameters: query, | |
1374 | onComplete: function(transport) { | |
1375 | var new_link = transport.responseXML.getElementsByTagName("link")[0]; | |
1376 | ||
1377 | var e = $('gen_feed_url'); | |
1378 | ||
1379 | if (new_link) { | |
1380 | ||
1381 | new_link = new_link.firstChild.nodeValue; | |
1382 | ||
1383 | e.innerHTML = e.innerHTML.replace(/\&key=.*$/, | |
1384 | "&key=" + new_link); | |
1385 | ||
1386 | e.href = e.href.replace(/\&key=.*$/, | |
1387 | "&key=" + new_link); | |
1388 | ||
1389 | new Effect.Highlight(e); | |
1390 | ||
1391 | notify(''); | |
1392 | ||
1393 | } else { | |
1394 | notify_error("Could not change feed URL."); | |
1395 | } | |
1396 | } }); | |
1397 | } | |
1398 | } catch (e) { | |
1399 | exception_error("genUrlChangeKey", e); | |
1400 | } | |
1401 | return false; | |
1402 | } | |
1403 | ||
1c31e190 AD |
1404 | function labelSelectOnChange(elem) { |
1405 | try { | |
1406 | var value = elem[elem.selectedIndex].value; | |
1407 | var def = elem.getAttribute('default'); | |
1408 | ||
1409 | if (value == "ADD_LABEL") { | |
1410 | ||
1411 | if (def) | |
1412 | dropboxSelect(elem, def); | |
1413 | else | |
1414 | elem.selectedIndex = 0; | |
1415 | ||
1416 | addLabel(elem, function(transport) { | |
1c31e190 | 1417 | |
10249c41 | 1418 | try { |
1c31e190 | 1419 | |
10249c41 AD |
1420 | var response = transport.responseXML; |
1421 | var select = response.getElementsByTagName("select")[0]; | |
1422 | var options = select.getElementsByTagName("option"); | |
1423 | ||
1424 | dropbox_replace_options(elem, options); | |
1425 | ||
1426 | notify(''); | |
1427 | } catch (e) { | |
1428 | exception_error("addLabel", e); | |
1429 | } | |
1c31e190 AD |
1430 | }); |
1431 | } | |
1432 | ||
1433 | } catch (e) { | |
10249c41 | 1434 | exception_error("labelSelectOnChange", e); |
1c31e190 AD |
1435 | } |
1436 | } | |
1437 | ||
10249c41 AD |
1438 | function dropbox_replace_options(elem, options) { |
1439 | ||
1440 | try { | |
1441 | while (elem.hasChildNodes()) | |
1442 | elem.removeChild(elem.firstChild); | |
1443 | ||
1444 | var sel_idx = -1; | |
1445 | ||
1446 | for (var i = 0; i < options.length; i++) { | |
1447 | var text = options[i].firstChild.nodeValue; | |
1448 | var value = options[i].getAttribute("value"); | |
11eb3f4e AD |
1449 | |
1450 | if (value == undefined) value = text; | |
1451 | ||
10249c41 | 1452 | var issel = options[i].getAttribute("selected") == "1"; |
c00907f2 AD |
1453 | |
1454 | var option = new Option(text, value, issel); | |
1455 | ||
1456 | if (options[i].getAttribute("disabled")) | |
1457 | option.setAttribute("disabled", true); | |
1458 | ||
1459 | elem.insert(option); | |
1460 | ||
10249c41 AD |
1461 | if (issel) sel_idx = i; |
1462 | } | |
1c31e190 | 1463 | |
10249c41 AD |
1464 | // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true) |
1465 | if (sel_idx >= 0) elem.selectedIndex = sel_idx; | |
1466 | ||
1467 | } catch (e) { | |
1468 | exception_error("dropbox_replace_options", e); | |
1469 | } | |
1470 | } | |
e69fb880 AD |
1471 | |
1472 | // mode = all, none, invert | |
1473 | function selectTableRows(id, mode) { | |
1474 | try { | |
1475 | var rows = $(id).rows; | |
1476 | ||
1477 | for (var i = 0; i < rows.length; i++) { | |
1478 | var row = rows[i]; | |
1479 | var cb = false; | |
1480 | ||
1481 | if (row.id && row.className) { | |
1482 | var bare_id = row.id.replace(/^[A-Z]*?-/, ""); | |
1483 | var inputs = rows[i].getElementsByTagName("input"); | |
1484 | ||
1485 | for (var j = 0; j < inputs.length; j++) { | |
1486 | var input = inputs[j]; | |
1487 | ||
1488 | if (input.getAttribute("type") == "checkbox" && | |
1489 | input.id.match(bare_id)) { | |
1490 | ||
1491 | cb = input; | |
1492 | break; | |
1493 | } | |
1494 | } | |
1495 | ||
1496 | if (cb) { | |
ca8e3d75 | 1497 | var issel = row.hasClassName("Selected"); |
e69fb880 AD |
1498 | |
1499 | if (mode == "all" && !issel) { | |
ca8e3d75 | 1500 | row.addClassName("Selected"); |
e69fb880 AD |
1501 | cb.checked = true; |
1502 | } else if (mode == "none" && issel) { | |
ca8e3d75 | 1503 | row.removeClassName("Selected"); |
e69fb880 AD |
1504 | cb.checked = false; |
1505 | } else if (mode == "invert") { | |
1506 | ||
1507 | if (issel) { | |
ca8e3d75 | 1508 | row.removeClassName("Selected"); |
e69fb880 AD |
1509 | cb.checked = false; |
1510 | } else { | |
ca8e3d75 | 1511 | row.addClassName("Selected"); |
e69fb880 AD |
1512 | cb.checked = true; |
1513 | } | |
1514 | } | |
1515 | } | |
1516 | } | |
1517 | } | |
1518 | ||
1519 | } catch (e) { | |
1520 | exception_error("selectTableRows", e); | |
1521 | ||
1522 | } | |
1523 | } | |
1524 | ||
1525 | function getSelectedTableRowIds(id) { | |
1526 | var rows = []; | |
1527 | ||
1528 | try { | |
1529 | var elem_rows = $(id).rows; | |
1530 | ||
1531 | for (i = 0; i < elem_rows.length; i++) { | |
ca8e3d75 | 1532 | if (elem_rows[i].hasClassName("Selected")) { |
e69fb880 AD |
1533 | var bare_id = elem_rows[i].id.replace(/^[A-Z]*?-/, ""); |
1534 | rows.push(bare_id); | |
1535 | } | |
1536 | } | |
1537 | ||
1538 | } catch (e) { | |
1539 | exception_error("getSelectedTableRowIds", e); | |
1540 | } | |
1541 | ||
1542 | return rows; | |
1543 | } | |
1544 |