]>
Commit | Line | Data |
---|---|---|
1 | var loading_progress = 0; | |
2 | var sanity_check_done = false; | |
3 | var init_params = {}; | |
4 | var _label_base_index = -1024; | |
5 | var notify_hide_timerid = false; | |
6 | ||
7 | Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap( | |
8 | function (callOriginal, options) { | |
9 | ||
10 | if (getInitParam("csrf_token") != undefined) { | |
11 | Object.extend(options, options || { }); | |
12 | ||
13 | if (Object.isString(options.parameters)) | |
14 | options.parameters = options.parameters.toQueryParams(); | |
15 | else if (Object.isHash(options.parameters)) | |
16 | options.parameters = options.parameters.toObject(); | |
17 | ||
18 | options.parameters["csrf_token"] = getInitParam("csrf_token"); | |
19 | } | |
20 | ||
21 | return callOriginal(options); | |
22 | } | |
23 | ); | |
24 | ||
25 | /* add method to remove element from array */ | |
26 | ||
27 | Array.prototype.remove = function(s) { | |
28 | for (var i=0; i < this.length; i++) { | |
29 | if (s == this[i]) this.splice(i, 1); | |
30 | } | |
31 | }; | |
32 | ||
33 | /* create console.log if it doesn't exist */ | |
34 | ||
35 | if (!window.console) console = {}; | |
36 | console.log = console.log || function(msg) { }; | |
37 | console.warn = console.warn || function(msg) { }; | |
38 | console.error = console.error || function(msg) { }; | |
39 | ||
40 | function exception_error(location, e, ext_info) { | |
41 | var msg = format_exception_error(location, e); | |
42 | ||
43 | if (!ext_info) ext_info = false; | |
44 | ||
45 | try { | |
46 | ||
47 | if (ext_info) { | |
48 | if (ext_info.responseText) { | |
49 | ext_info = ext_info.responseText; | |
50 | } | |
51 | } | |
52 | ||
53 | var content = "<div class=\"fatalError\">" + | |
54 | "<pre>" + msg + "</pre>"; | |
55 | ||
56 | content += "<form name=\"exceptionForm\" id=\"exceptionForm\" target=\"_blank\" "+ | |
57 | "action=\"http://tt-rss.org/report.php\" method=\"POST\">"; | |
58 | ||
59 | content += "<textarea style=\"display : none\" name=\"message\">" + msg + "</textarea>"; | |
60 | content += "<textarea style=\"display : none\" name=\"params\">N/A</textarea>"; | |
61 | ||
62 | if (ext_info) { | |
63 | content += "<div><b>Additional information:</b></div>" + | |
64 | "<textarea name=\"xinfo\" readonly=\"1\">" + ext_info + "</textarea>"; | |
65 | } | |
66 | ||
67 | content += "<div><b>Stack trace:</b></div>" + | |
68 | "<textarea name=\"stack\" readonly=\"1\">" + e.stack + "</textarea>"; | |
69 | ||
70 | content += "</form>"; | |
71 | ||
72 | content += "</div>"; | |
73 | ||
74 | content += "<div class='dlgButtons'>"; | |
75 | ||
76 | content += "<button dojoType=\"dijit.form.Button\""+ | |
77 | "onclick=\"dijit.byId('exceptionDlg').report()\">" + | |
78 | __('Report to tt-rss.org') + "</button> "; | |
79 | content += "<button dojoType=\"dijit.form.Button\" "+ | |
80 | "onclick=\"dijit.byId('exceptionDlg').hide()\">" + | |
81 | __('Close') + "</button>"; | |
82 | content += "</div>"; | |
83 | ||
84 | if (dijit.byId("exceptionDlg")) | |
85 | dijit.byId("exceptionDlg").destroyRecursive(); | |
86 | ||
87 | var dialog = new dijit.Dialog({ | |
88 | id: "exceptionDlg", | |
89 | title: "Unhandled exception", | |
90 | style: "width: 600px", | |
91 | report: function() { | |
92 | if (confirm(__("Are you sure to report this exception to tt-rss.org? The report will include your browser information. Your IP would be saved in the database."))) { | |
93 | ||
94 | document.forms['exceptionForm'].params.value = $H({ | |
95 | browserName: navigator.appName, | |
96 | browserVersion: navigator.appVersion, | |
97 | browserPlatform: navigator.platform, | |
98 | browserCookies: navigator.cookieEnabled, | |
99 | }).toQueryString(); | |
100 | ||
101 | document.forms['exceptionForm'].submit(); | |
102 | ||
103 | } | |
104 | }, | |
105 | content: content}); | |
106 | ||
107 | dialog.show(); | |
108 | ||
109 | } catch (e) { | |
110 | alert(msg); | |
111 | } | |
112 | ||
113 | } | |
114 | ||
115 | function format_exception_error(location, e) { | |
116 | var msg; | |
117 | ||
118 | if (e.fileName) { | |
119 | var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1); | |
120 | ||
121 | msg = "Exception: " + e.name + ", " + e.message + | |
122 | "\nFunction: " + location + "()" + | |
123 | "\nLocation: " + base_fname + ":" + e.lineNumber; | |
124 | ||
125 | } else if (e.description) { | |
126 | msg = "Exception: " + e.description + "\nFunction: " + location + "()"; | |
127 | } else { | |
128 | msg = "Exception: " + e + "\nFunction: " + location + "()"; | |
129 | } | |
130 | ||
131 | console.error("EXCEPTION: " + msg); | |
132 | ||
133 | return msg; | |
134 | } | |
135 | ||
136 | function param_escape(arg) { | |
137 | if (typeof encodeURIComponent != 'undefined') | |
138 | return encodeURIComponent(arg); | |
139 | else | |
140 | return escape(arg); | |
141 | } | |
142 | ||
143 | function param_unescape(arg) { | |
144 | if (typeof decodeURIComponent != 'undefined') | |
145 | return decodeURIComponent(arg); | |
146 | else | |
147 | return unescape(arg); | |
148 | } | |
149 | ||
150 | ||
151 | function hide_notify() { | |
152 | Element.hide('notify'); | |
153 | } | |
154 | ||
155 | function notify_real(msg, no_hide, n_type) { | |
156 | ||
157 | var n = $("notify"); | |
158 | ||
159 | if (!n) return; | |
160 | ||
161 | if (notify_hide_timerid) { | |
162 | window.clearTimeout(notify_hide_timerid); | |
163 | } | |
164 | ||
165 | if (msg == "") { | |
166 | if (Element.visible(n)) { | |
167 | notify_hide_timerid = window.setTimeout("hide_notify()", 0); | |
168 | } | |
169 | return; | |
170 | } else { | |
171 | Element.show(n); | |
172 | } | |
173 | ||
174 | /* types: | |
175 | ||
176 | 1 - generic | |
177 | 2 - progress | |
178 | 3 - error | |
179 | 4 - info | |
180 | ||
181 | */ | |
182 | ||
183 | msg = "<span class=\"msg\"> " + __(msg) + "</span>"; | |
184 | ||
185 | if (n_type == 1) { | |
186 | n.className = "notify"; | |
187 | } else if (n_type == 2) { | |
188 | n.className = "notify progress"; | |
189 | msg = "<span><img src='images/indicator_white.gif'></span>" + msg; | |
190 | no_hide = true; | |
191 | } else if (n_type == 3) { | |
192 | n.className = "notify error"; | |
193 | msg = "<span><img src='images/sign_excl.svg'></span>" + msg; | |
194 | } else if (n_type == 4) { | |
195 | n.className = "notify info"; | |
196 | msg = "<span><img src='images/sign_info.svg'></span>" + msg; | |
197 | } | |
198 | ||
199 | msg += " <span><img src=\"images/close_notify.svg\" class=\"close\" title=\"" + | |
200 | __("Click to close") + "\" onclick=\"notify('')\"></span>"; | |
201 | ||
202 | // msg = "<img src='images/live_com_loading.gif'> " + msg; | |
203 | ||
204 | n.innerHTML = msg; | |
205 | ||
206 | if (!no_hide) { | |
207 | notify_hide_timerid = window.setTimeout("hide_notify()", 5*1000); | |
208 | } | |
209 | } | |
210 | ||
211 | function notify(msg, no_hide) { | |
212 | notify_real(msg, no_hide, 1); | |
213 | } | |
214 | ||
215 | function notify_progress(msg, no_hide) { | |
216 | notify_real(msg, no_hide, 2); | |
217 | } | |
218 | ||
219 | function notify_error(msg, no_hide) { | |
220 | notify_real(msg, no_hide, 3); | |
221 | ||
222 | } | |
223 | ||
224 | function notify_info(msg, no_hide) { | |
225 | notify_real(msg, no_hide, 4); | |
226 | } | |
227 | ||
228 | function setCookie(name, value, lifetime, path, domain, secure) { | |
229 | ||
230 | var d = false; | |
231 | ||
232 | if (lifetime) { | |
233 | d = new Date(); | |
234 | d.setTime(d.getTime() + (lifetime * 1000)); | |
235 | } | |
236 | ||
237 | console.log("setCookie: " + name + " => " + value + ": " + d); | |
238 | ||
239 | int_setCookie(name, value, d, path, domain, secure); | |
240 | ||
241 | } | |
242 | ||
243 | function int_setCookie(name, value, expires, path, domain, secure) { | |
244 | document.cookie= name + "=" + escape(value) + | |
245 | ((expires) ? "; expires=" + expires.toGMTString() : "") + | |
246 | ((path) ? "; path=" + path : "") + | |
247 | ((domain) ? "; domain=" + domain : "") + | |
248 | ((secure) ? "; secure" : ""); | |
249 | } | |
250 | ||
251 | function delCookie(name, path, domain) { | |
252 | if (getCookie(name)) { | |
253 | document.cookie = name + "=" + | |
254 | ((path) ? ";path=" + path : "") + | |
255 | ((domain) ? ";domain=" + domain : "" ) + | |
256 | ";expires=Thu, 01-Jan-1970 00:00:01 GMT"; | |
257 | } | |
258 | } | |
259 | ||
260 | ||
261 | function getCookie(name) { | |
262 | ||
263 | var dc = document.cookie; | |
264 | var prefix = name + "="; | |
265 | var begin = dc.indexOf("; " + prefix); | |
266 | if (begin == -1) { | |
267 | begin = dc.indexOf(prefix); | |
268 | if (begin != 0) return null; | |
269 | } | |
270 | else { | |
271 | begin += 2; | |
272 | } | |
273 | var end = document.cookie.indexOf(";", begin); | |
274 | if (end == -1) { | |
275 | end = dc.length; | |
276 | } | |
277 | return unescape(dc.substring(begin + prefix.length, end)); | |
278 | } | |
279 | ||
280 | function gotoPreferences() { | |
281 | document.location.href = "prefs.php"; | |
282 | } | |
283 | ||
284 | function gotoLogout() { | |
285 | document.location.href = "backend.php?op=logout"; | |
286 | } | |
287 | ||
288 | function gotoMain() { | |
289 | document.location.href = "index.php"; | |
290 | } | |
291 | ||
292 | /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj | |
293 | * * @author Sundar Dorai-Raj | |
294 | * * Email: sdoraira@vt.edu | |
295 | * * This program is free software; you can redistribute it and/or | |
296 | * * modify it under the terms of the GNU General Public License | |
297 | * * as published by the Free Software Foundation; either version 2 | |
298 | * * of the License, or (at your option) any later version, | |
299 | * * provided that any use properly credits the author. | |
300 | * * This program is distributed in the hope that it will be useful, | |
301 | * * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
302 | * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
303 | * * GNU General Public License for more details at http://www.gnu.org * * */ | |
304 | ||
305 | var numbers=".0123456789"; | |
306 | function isNumeric(x) { | |
307 | // is x a String or a character? | |
308 | if(x.length>1) { | |
309 | // remove negative sign | |
310 | x=Math.abs(x)+""; | |
311 | for(var j=0;j<x.length;j++) { | |
312 | // call isNumeric recursively for each character | |
313 | number=isNumeric(x.substring(j,j+1)); | |
314 | if(!number) return number; | |
315 | } | |
316 | return number; | |
317 | } | |
318 | else { | |
319 | // if x is number return true | |
320 | if(numbers.indexOf(x)>=0) return true; | |
321 | return false; | |
322 | } | |
323 | } | |
324 | ||
325 | ||
326 | function toggleSelectRowById(sender, id) { | |
327 | var row = $(id); | |
328 | return toggleSelectRow(sender, row); | |
329 | } | |
330 | ||
331 | function toggleSelectListRow(sender) { | |
332 | var row = sender.parentNode; | |
333 | return toggleSelectRow(sender, row); | |
334 | } | |
335 | ||
336 | /* this is for dijit Checkbox */ | |
337 | function toggleSelectListRow2(sender) { | |
338 | var row = sender.domNode.parentNode; | |
339 | return toggleSelectRow(sender, row); | |
340 | } | |
341 | ||
342 | /* this is for dijit Checkbox */ | |
343 | function toggleSelectRow2(sender, row, is_cdm) { | |
344 | ||
345 | if (!row) | |
346 | if (!is_cdm) | |
347 | row = sender.domNode.parentNode.parentNode; | |
348 | else | |
349 | row = sender.domNode.parentNode.parentNode.parentNode; // oh ffs | |
350 | ||
351 | if (sender.checked && !row.hasClassName('Selected')) | |
352 | row.addClassName('Selected'); | |
353 | else | |
354 | row.removeClassName('Selected'); | |
355 | ||
356 | if (typeof updateSelectedPrompt != undefined) | |
357 | updateSelectedPrompt(); | |
358 | } | |
359 | ||
360 | ||
361 | function toggleSelectRow(sender, row) { | |
362 | ||
363 | if (!row) row = sender.parentNode.parentNode; | |
364 | ||
365 | if (sender.checked && !row.hasClassName('Selected')) | |
366 | row.addClassName('Selected'); | |
367 | else | |
368 | row.removeClassName('Selected'); | |
369 | ||
370 | if (typeof updateSelectedPrompt != undefined) | |
371 | updateSelectedPrompt(); | |
372 | } | |
373 | ||
374 | function checkboxToggleElement(elem, id) { | |
375 | if (elem.checked) { | |
376 | Effect.Appear(id, {duration : 0.5}); | |
377 | } else { | |
378 | Effect.Fade(id, {duration : 0.5}); | |
379 | } | |
380 | } | |
381 | ||
382 | function dropboxSelect(e, v) { | |
383 | for (var i = 0; i < e.length; i++) { | |
384 | if (e[i].value == v) { | |
385 | e.selectedIndex = i; | |
386 | break; | |
387 | } | |
388 | } | |
389 | } | |
390 | ||
391 | function getURLParam(param){ | |
392 | return String(window.location.href).parseQuery()[param]; | |
393 | } | |
394 | ||
395 | function closeInfoBox(cleanup) { | |
396 | try { | |
397 | dialog = dijit.byId("infoBox"); | |
398 | ||
399 | if (dialog) dialog.hide(); | |
400 | ||
401 | } catch (e) { | |
402 | //exception_error("closeInfoBox", e); | |
403 | } | |
404 | return false; | |
405 | } | |
406 | ||
407 | ||
408 | function displayDlg(title, id, param, callback) { | |
409 | ||
410 | notify_progress("Loading, please wait...", true); | |
411 | ||
412 | var query = "?op=dlg&method=" + | |
413 | param_escape(id) + "¶m=" + param_escape(param); | |
414 | ||
415 | new Ajax.Request("backend.php", { | |
416 | parameters: query, | |
417 | onComplete: function (transport) { | |
418 | infobox_callback2(transport, title); | |
419 | if (callback) callback(transport); | |
420 | } }); | |
421 | ||
422 | return false; | |
423 | } | |
424 | ||
425 | function infobox_callback2(transport, title) { | |
426 | try { | |
427 | var dialog = false; | |
428 | ||
429 | if (dijit.byId("infoBox")) { | |
430 | dialog = dijit.byId("infoBox"); | |
431 | } | |
432 | ||
433 | //console.log("infobox_callback2"); | |
434 | notify(''); | |
435 | ||
436 | var content = transport.responseText; | |
437 | ||
438 | if (!dialog) { | |
439 | dialog = new dijit.Dialog({ | |
440 | title: title, | |
441 | id: 'infoBox', | |
442 | style: "width: 600px", | |
443 | onCancel: function() { | |
444 | return true; | |
445 | }, | |
446 | onExecute: function() { | |
447 | return true; | |
448 | }, | |
449 | onClose: function() { | |
450 | return true; | |
451 | }, | |
452 | content: content}); | |
453 | } else { | |
454 | dialog.attr('title', title); | |
455 | dialog.attr('content', content); | |
456 | } | |
457 | ||
458 | dialog.show(); | |
459 | ||
460 | notify(""); | |
461 | } catch (e) { | |
462 | exception_error("infobox_callback2", e); | |
463 | } | |
464 | } | |
465 | ||
466 | function filterCR(e, f) | |
467 | { | |
468 | var key; | |
469 | ||
470 | if(window.event) | |
471 | key = window.event.keyCode; //IE | |
472 | else | |
473 | key = e.which; //firefox | |
474 | ||
475 | if (key == 13) { | |
476 | if (typeof f != 'undefined') { | |
477 | f(); | |
478 | return false; | |
479 | } else { | |
480 | return false; | |
481 | } | |
482 | } else { | |
483 | return true; | |
484 | } | |
485 | } | |
486 | ||
487 | function getInitParam(key) { | |
488 | return init_params[key]; | |
489 | } | |
490 | ||
491 | function setInitParam(key, value) { | |
492 | init_params[key] = value; | |
493 | } | |
494 | ||
495 | function fatalError(code, msg, ext_info) { | |
496 | try { | |
497 | ||
498 | if (code == 6) { | |
499 | window.location.href = "index.php"; | |
500 | } else if (code == 5) { | |
501 | window.location.href = "public.php?op=dbupdate"; | |
502 | } else { | |
503 | ||
504 | if (msg == "") msg = "Unknown error"; | |
505 | ||
506 | if (ext_info) { | |
507 | if (ext_info.responseText) { | |
508 | ext_info = ext_info.responseText; | |
509 | } | |
510 | } | |
511 | ||
512 | if (ERRORS && ERRORS[code] && !msg) { | |
513 | msg = ERRORS[code]; | |
514 | } | |
515 | ||
516 | var content = "<div><b>Error code:</b> " + code + "</div>" + | |
517 | "<p>" + msg + "</p>"; | |
518 | ||
519 | if (ext_info) { | |
520 | content = content + "<div><b>Additional information:</b></div>" + | |
521 | "<textarea style='width: 100%' readonly=\"1\">" + | |
522 | ext_info + "</textarea>"; | |
523 | } | |
524 | ||
525 | var dialog = new dijit.Dialog({ | |
526 | title: "Fatal error", | |
527 | style: "width: 600px", | |
528 | content: content}); | |
529 | ||
530 | dialog.show(); | |
531 | ||
532 | } | |
533 | ||
534 | return false; | |
535 | ||
536 | } catch (e) { | |
537 | exception_error("fatalError", e); | |
538 | } | |
539 | } | |
540 | ||
541 | function filterDlgCheckAction(sender) { | |
542 | ||
543 | try { | |
544 | ||
545 | var action = sender.value; | |
546 | ||
547 | var action_param = $("filterDlg_paramBox"); | |
548 | ||
549 | if (!action_param) { | |
550 | console.log("filterDlgCheckAction: can't find action param box!"); | |
551 | return; | |
552 | } | |
553 | ||
554 | // if selected action supports parameters, enable params field | |
555 | if (action == 4 || action == 6 || action == 7) { | |
556 | new Effect.Appear(action_param, {duration : 0.5}); | |
557 | if (action != 7) { | |
558 | Element.show(dijit.byId("filterDlg_actionParam").domNode); | |
559 | Element.hide(dijit.byId("filterDlg_actionParamLabel").domNode); | |
560 | } else { | |
561 | Element.show(dijit.byId("filterDlg_actionParamLabel").domNode); | |
562 | Element.hide(dijit.byId("filterDlg_actionParam").domNode); | |
563 | } | |
564 | } else { | |
565 | Element.hide(action_param); | |
566 | } | |
567 | ||
568 | } catch (e) { | |
569 | exception_error("filterDlgCheckAction", e); | |
570 | } | |
571 | ||
572 | } | |
573 | ||
574 | ||
575 | function explainError(code) { | |
576 | return displayDlg(__("Error explained"), "explainError", code); | |
577 | } | |
578 | ||
579 | function loading_set_progress(p) { | |
580 | try { | |
581 | loading_progress += p; | |
582 | ||
583 | if (dijit.byId("loading_bar")) | |
584 | dijit.byId("loading_bar").update({progress: loading_progress}); | |
585 | ||
586 | if (loading_progress >= 90) | |
587 | remove_splash(); | |
588 | ||
589 | } catch (e) { | |
590 | exception_error("loading_set_progress", e); | |
591 | } | |
592 | } | |
593 | ||
594 | function remove_splash() { | |
595 | ||
596 | if (Element.visible("overlay")) { | |
597 | console.log("about to remove splash, OMG!"); | |
598 | Element.hide("overlay"); | |
599 | console.log("removed splash!"); | |
600 | } | |
601 | } | |
602 | ||
603 | function transport_error_check(transport) { | |
604 | try { | |
605 | if (transport.responseXML) { | |
606 | var error = transport.responseXML.getElementsByTagName("error")[0]; | |
607 | ||
608 | if (error) { | |
609 | var code = error.getAttribute("error-code"); | |
610 | var msg = error.getAttribute("error-msg"); | |
611 | if (code != 0) { | |
612 | fatalError(code, msg); | |
613 | return false; | |
614 | } | |
615 | } | |
616 | } | |
617 | } catch (e) { | |
618 | exception_error("check_for_error_xml", e); | |
619 | } | |
620 | return true; | |
621 | } | |
622 | ||
623 | function strip_tags(s) { | |
624 | return s.replace(/<\/?[^>]+(>|$)/g, ""); | |
625 | } | |
626 | ||
627 | function truncate_string(s, length) { | |
628 | if (!length) length = 30; | |
629 | var tmp = s.substring(0, length); | |
630 | if (s.length > length) tmp += "…"; | |
631 | return tmp; | |
632 | } | |
633 | ||
634 | function hotkey_prefix_timeout() { | |
635 | try { | |
636 | ||
637 | var date = new Date(); | |
638 | var ts = Math.round(date.getTime() / 1000); | |
639 | ||
640 | if (hotkey_prefix_pressed && ts - hotkey_prefix_pressed >= 5) { | |
641 | console.log("hotkey_prefix seems to be stuck, aborting"); | |
642 | hotkey_prefix_pressed = false; | |
643 | hotkey_prefix = false; | |
644 | Element.hide('cmdline'); | |
645 | } | |
646 | ||
647 | setTimeout("hotkey_prefix_timeout()", 1000); | |
648 | ||
649 | } catch (e) { | |
650 | exception_error("hotkey_prefix_timeout", e); | |
651 | } | |
652 | } | |
653 | ||
654 | function uploadIconHandler(rc) { | |
655 | try { | |
656 | switch (rc) { | |
657 | case 0: | |
658 | notify_info("Upload complete."); | |
659 | if (inPreferences()) { | |
660 | updateFeedList(); | |
661 | } else { | |
662 | setTimeout('updateFeedList(false, false)', 50); | |
663 | } | |
664 | break; | |
665 | case 1: | |
666 | notify_error("Upload failed: icon is too big."); | |
667 | break; | |
668 | case 2: | |
669 | notify_error("Upload failed."); | |
670 | break; | |
671 | } | |
672 | ||
673 | } catch (e) { | |
674 | exception_error("uploadIconHandler", e); | |
675 | } | |
676 | } | |
677 | ||
678 | function removeFeedIcon(id) { | |
679 | ||
680 | try { | |
681 | ||
682 | if (confirm(__("Remove stored feed icon?"))) { | |
683 | var query = "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape(id); | |
684 | ||
685 | console.log(query); | |
686 | ||
687 | notify_progress("Removing feed icon...", true); | |
688 | ||
689 | new Ajax.Request("backend.php", { | |
690 | parameters: query, | |
691 | onComplete: function(transport) { | |
692 | notify_info("Feed icon removed."); | |
693 | if (inPreferences()) { | |
694 | updateFeedList(); | |
695 | } else { | |
696 | setTimeout('updateFeedList(false, false)', 50); | |
697 | } | |
698 | } }); | |
699 | } | |
700 | ||
701 | return false; | |
702 | } catch (e) { | |
703 | exception_error("removeFeedIcon", e); | |
704 | } | |
705 | } | |
706 | ||
707 | function uploadFeedIcon() { | |
708 | ||
709 | try { | |
710 | ||
711 | var file = $("icon_file"); | |
712 | ||
713 | if (file.value.length == 0) { | |
714 | alert(__("Please select an image file to upload.")); | |
715 | } else { | |
716 | if (confirm(__("Upload new icon for this feed?"))) { | |
717 | notify_progress("Uploading, please wait...", true); | |
718 | return true; | |
719 | } | |
720 | } | |
721 | ||
722 | return false; | |
723 | ||
724 | } catch (e) { | |
725 | exception_error("uploadFeedIcon", e); | |
726 | } | |
727 | } | |
728 | ||
729 | function addLabel(select, callback) { | |
730 | ||
731 | try { | |
732 | ||
733 | var caption = prompt(__("Please enter label caption:"), ""); | |
734 | ||
735 | if (caption != undefined) { | |
736 | ||
737 | if (caption == "") { | |
738 | alert(__("Can't create label: missing caption.")); | |
739 | return false; | |
740 | } | |
741 | ||
742 | var query = "?op=pref-labels&method=add&caption=" + | |
743 | param_escape(caption); | |
744 | ||
745 | if (select) | |
746 | query += "&output=select"; | |
747 | ||
748 | notify_progress("Loading, please wait...", true); | |
749 | ||
750 | if (inPreferences() && !select) active_tab = "labelConfig"; | |
751 | ||
752 | new Ajax.Request("backend.php", { | |
753 | parameters: query, | |
754 | onComplete: function(transport) { | |
755 | if (callback) { | |
756 | callback(transport); | |
757 | } else if (inPreferences()) { | |
758 | updateLabelList(); | |
759 | } else { | |
760 | updateFeedList(); | |
761 | } | |
762 | } }); | |
763 | ||
764 | } | |
765 | ||
766 | } catch (e) { | |
767 | exception_error("addLabel", e); | |
768 | } | |
769 | } | |
770 | ||
771 | function quickAddFeed() { | |
772 | try { | |
773 | var query = "backend.php?op=feeds&method=quickAddFeed"; | |
774 | ||
775 | // overlapping widgets | |
776 | if (dijit.byId("batchSubDlg")) dijit.byId("batchSubDlg").destroyRecursive(); | |
777 | if (dijit.byId("feedAddDlg")) dijit.byId("feedAddDlg").destroyRecursive(); | |
778 | ||
779 | var dialog = new dijit.Dialog({ | |
780 | id: "feedAddDlg", | |
781 | title: __("Subscribe to Feed"), | |
782 | style: "width: 600px", | |
783 | execute: function() { | |
784 | if (this.validate()) { | |
785 | console.log(dojo.objectToQuery(this.attr('value'))); | |
786 | ||
787 | var feed_url = this.attr('value').feed; | |
788 | ||
789 | Element.show("feed_add_spinner"); | |
790 | ||
791 | new Ajax.Request("backend.php", { | |
792 | parameters: dojo.objectToQuery(this.attr('value')), | |
793 | onComplete: function(transport) { | |
794 | try { | |
795 | ||
796 | var reply = JSON.parse(transport.responseText); | |
797 | ||
798 | var rc = reply['result']; | |
799 | ||
800 | notify(''); | |
801 | Element.hide("feed_add_spinner"); | |
802 | ||
803 | console.log(rc); | |
804 | ||
805 | switch (parseInt(rc['code'])) { | |
806 | case 1: | |
807 | dialog.hide(); | |
808 | notify_info(__("Subscribed to %s").replace("%s", feed_url)); | |
809 | ||
810 | updateFeedList(); | |
811 | break; | |
812 | case 2: | |
813 | alert(__("Specified URL seems to be invalid.")); | |
814 | break; | |
815 | case 3: | |
816 | alert(__("Specified URL doesn't seem to contain any feeds.")); | |
817 | break; | |
818 | case 4: | |
819 | feeds = rc['feeds']; | |
820 | ||
821 | var select = dijit.byId("feedDlg_feedContainerSelect"); | |
822 | ||
823 | while (select.getOptions().length > 0) | |
824 | select.removeOption(0); | |
825 | ||
826 | select.addOption({value: '', label: __("Expand to select feed")}); | |
827 | ||
828 | var count = 0; | |
829 | for (var feedUrl in feeds) { | |
830 | select.addOption({value: feedUrl, label: feeds[feedUrl]}); | |
831 | count++; | |
832 | } | |
833 | ||
834 | Effect.Appear('feedDlg_feedsContainer', {duration : 0.5}); | |
835 | ||
836 | break; | |
837 | case 5: | |
838 | alert(__("Couldn't download the specified URL: %s"). | |
839 | replace("%s", rc['message'])); | |
840 | break; | |
841 | case 6: | |
842 | alert(__("XML validation failed: %s"). | |
843 | replace("%s", rc['message'])); | |
844 | break; | |
845 | break; | |
846 | case 0: | |
847 | alert(__("You are already subscribed to this feed.")); | |
848 | break; | |
849 | } | |
850 | ||
851 | } catch (e) { | |
852 | exception_error("subscribeToFeed", e, transport); | |
853 | } | |
854 | ||
855 | } }); | |
856 | ||
857 | } | |
858 | }, | |
859 | href: query}); | |
860 | ||
861 | dialog.show(); | |
862 | } catch (e) { | |
863 | exception_error("quickAddFeed", e); | |
864 | } | |
865 | } | |
866 | ||
867 | function createNewRuleElement(parentNode, replaceNode) { | |
868 | try { | |
869 | var form = document.forms["filter_new_rule_form"]; | |
870 | ||
871 | form.reg_exp.value = form.reg_exp.value.replace(/(<([^>]+)>)/ig,""); | |
872 | ||
873 | var query = "backend.php?op=pref-filters&method=printrulename&rule="+ | |
874 | param_escape(dojo.formToJson(form)); | |
875 | ||
876 | console.log(query); | |
877 | ||
878 | new Ajax.Request("backend.php", { | |
879 | parameters: query, | |
880 | onComplete: function (transport) { | |
881 | try { | |
882 | var li = dojo.create("li"); | |
883 | ||
884 | var cb = dojo.create("input", { type: "checkbox" }, li); | |
885 | ||
886 | new dijit.form.CheckBox({ | |
887 | onChange: function() { | |
888 | toggleSelectListRow2(this) }, | |
889 | }, cb); | |
890 | ||
891 | dojo.create("input", { type: "hidden", | |
892 | name: "rule[]", | |
893 | value: dojo.formToJson(form) }, li); | |
894 | ||
895 | dojo.create("span", { | |
896 | onclick: function() { | |
897 | dijit.byId('filterEditDlg').editRule(this); | |
898 | }, | |
899 | innerHTML: transport.responseText }, li); | |
900 | ||
901 | if (replaceNode) { | |
902 | parentNode.replaceChild(li, replaceNode); | |
903 | } else { | |
904 | parentNode.appendChild(li); | |
905 | } | |
906 | } catch (e) { | |
907 | exception_error("createNewRuleElement", e); | |
908 | } | |
909 | } }); | |
910 | } catch (e) { | |
911 | exception_error("createNewRuleElement", e); | |
912 | } | |
913 | } | |
914 | ||
915 | function createNewActionElement(parentNode, replaceNode) { | |
916 | try { | |
917 | var form = document.forms["filter_new_action_form"]; | |
918 | ||
919 | if (form.action_id.value == 7) { | |
920 | form.action_param.value = form.action_param_label.value; | |
921 | } | |
922 | ||
923 | var query = "backend.php?op=pref-filters&method=printactionname&action="+ | |
924 | param_escape(dojo.formToJson(form)); | |
925 | ||
926 | console.log(query); | |
927 | ||
928 | new Ajax.Request("backend.php", { | |
929 | parameters: query, | |
930 | onComplete: function (transport) { | |
931 | try { | |
932 | var li = dojo.create("li"); | |
933 | ||
934 | var cb = dojo.create("input", { type: "checkbox" }, li); | |
935 | ||
936 | new dijit.form.CheckBox({ | |
937 | onChange: function() { | |
938 | toggleSelectListRow2(this) }, | |
939 | }, cb); | |
940 | ||
941 | dojo.create("input", { type: "hidden", | |
942 | name: "action[]", | |
943 | value: dojo.formToJson(form) }, li); | |
944 | ||
945 | dojo.create("span", { | |
946 | onclick: function() { | |
947 | dijit.byId('filterEditDlg').editAction(this); | |
948 | }, | |
949 | innerHTML: transport.responseText }, li); | |
950 | ||
951 | if (replaceNode) { | |
952 | parentNode.replaceChild(li, replaceNode); | |
953 | } else { | |
954 | parentNode.appendChild(li); | |
955 | } | |
956 | ||
957 | } catch (e) { | |
958 | exception_error("createNewActionElement", e); | |
959 | } | |
960 | } }); | |
961 | } catch (e) { | |
962 | exception_error("createNewActionElement", e); | |
963 | } | |
964 | } | |
965 | ||
966 | ||
967 | function addFilterRule(replaceNode, ruleStr) { | |
968 | try { | |
969 | if (dijit.byId("filterNewRuleDlg")) | |
970 | dijit.byId("filterNewRuleDlg").destroyRecursive(); | |
971 | ||
972 | var query = "backend.php?op=pref-filters&method=newrule&rule=" + | |
973 | param_escape(ruleStr); | |
974 | ||
975 | var rule_dlg = new dijit.Dialog({ | |
976 | id: "filterNewRuleDlg", | |
977 | title: ruleStr ? __("Edit rule") : __("Add rule"), | |
978 | style: "width: 600px", | |
979 | execute: function() { | |
980 | if (this.validate()) { | |
981 | createNewRuleElement($("filterDlg_Matches"), replaceNode); | |
982 | this.hide(); | |
983 | } | |
984 | }, | |
985 | href: query}); | |
986 | ||
987 | rule_dlg.show(); | |
988 | } catch (e) { | |
989 | exception_error("addFilterRule", e); | |
990 | } | |
991 | } | |
992 | ||
993 | function addFilterAction(replaceNode, actionStr) { | |
994 | try { | |
995 | if (dijit.byId("filterNewActionDlg")) | |
996 | dijit.byId("filterNewActionDlg").destroyRecursive(); | |
997 | ||
998 | var query = "backend.php?op=pref-filters&method=newaction&action=" + | |
999 | param_escape(actionStr); | |
1000 | ||
1001 | var rule_dlg = new dijit.Dialog({ | |
1002 | id: "filterNewActionDlg", | |
1003 | title: actionStr ? __("Edit action") : __("Add action"), | |
1004 | style: "width: 600px", | |
1005 | execute: function() { | |
1006 | if (this.validate()) { | |
1007 | createNewActionElement($("filterDlg_Actions"), replaceNode); | |
1008 | this.hide(); | |
1009 | } | |
1010 | }, | |
1011 | href: query}); | |
1012 | ||
1013 | rule_dlg.show(); | |
1014 | } catch (e) { | |
1015 | exception_error("addFilterAction", e); | |
1016 | } | |
1017 | } | |
1018 | ||
1019 | function quickAddFilter() { | |
1020 | try { | |
1021 | var query = ""; | |
1022 | if (!inPreferences()) { | |
1023 | query = "backend.php?op=pref-filters&method=newfilter&feed=" + | |
1024 | param_escape(getActiveFeedId()) + "&is_cat=" + | |
1025 | param_escape(activeFeedIsCat()); | |
1026 | } else { | |
1027 | query = "backend.php?op=pref-filters&method=newfilter"; | |
1028 | } | |
1029 | ||
1030 | console.log(query); | |
1031 | ||
1032 | if (dijit.byId("feedEditDlg")) | |
1033 | dijit.byId("feedEditDlg").destroyRecursive(); | |
1034 | ||
1035 | if (dijit.byId("filterEditDlg")) | |
1036 | dijit.byId("filterEditDlg").destroyRecursive(); | |
1037 | ||
1038 | dialog = new dijit.Dialog({ | |
1039 | id: "filterEditDlg", | |
1040 | title: __("Create Filter"), | |
1041 | style: "width: 600px", | |
1042 | test: function() { | |
1043 | var query = "backend.php?" + dojo.formToQuery("filter_new_form") + "&savemode=test"; | |
1044 | ||
1045 | if (dijit.byId("filterTestDlg")) | |
1046 | dijit.byId("filterTestDlg").destroyRecursive(); | |
1047 | ||
1048 | var test_dlg = new dijit.Dialog({ | |
1049 | id: "filterTestDlg", | |
1050 | title: "Test Filter", | |
1051 | style: "width: 600px", | |
1052 | href: query}); | |
1053 | ||
1054 | test_dlg.show(); | |
1055 | }, | |
1056 | selectRules: function(select) { | |
1057 | $$("#filterDlg_Matches input[type=checkbox]").each(function(e) { | |
1058 | e.checked = select; | |
1059 | if (select) | |
1060 | e.parentNode.addClassName("Selected"); | |
1061 | else | |
1062 | e.parentNode.removeClassName("Selected"); | |
1063 | }); | |
1064 | }, | |
1065 | selectActions: function(select) { | |
1066 | $$("#filterDlg_Actions input[type=checkbox]").each(function(e) { | |
1067 | e.checked = select; | |
1068 | ||
1069 | if (select) | |
1070 | e.parentNode.addClassName("Selected"); | |
1071 | else | |
1072 | e.parentNode.removeClassName("Selected"); | |
1073 | ||
1074 | }); | |
1075 | }, | |
1076 | editRule: function(e) { | |
1077 | var li = e.parentNode; | |
1078 | var rule = li.getElementsByTagName("INPUT")[1].value; | |
1079 | addFilterRule(li, rule); | |
1080 | }, | |
1081 | editAction: function(e) { | |
1082 | var li = e.parentNode; | |
1083 | var action = li.getElementsByTagName("INPUT")[1].value; | |
1084 | addFilterAction(li, action); | |
1085 | }, | |
1086 | addAction: function() { addFilterAction(); }, | |
1087 | addRule: function() { addFilterRule(); }, | |
1088 | deleteAction: function() { | |
1089 | $$("#filterDlg_Actions li.[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) }); | |
1090 | }, | |
1091 | deleteRule: function() { | |
1092 | $$("#filterDlg_Matches li.[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) }); | |
1093 | }, | |
1094 | execute: function() { | |
1095 | if (this.validate()) { | |
1096 | ||
1097 | var query = dojo.formToQuery("filter_new_form"); | |
1098 | ||
1099 | console.log(query); | |
1100 | ||
1101 | new Ajax.Request("backend.php", { | |
1102 | parameters: query, | |
1103 | onComplete: function (transport) { | |
1104 | if (inPreferences()) { | |
1105 | updateFilterList(); | |
1106 | } | |
1107 | ||
1108 | dialog.hide(); | |
1109 | } }); | |
1110 | } | |
1111 | }, | |
1112 | href: query}); | |
1113 | ||
1114 | if (!inPreferences()) { | |
1115 | var lh = dojo.connect(dialog, "onLoad", function(){ | |
1116 | dojo.disconnect(lh); | |
1117 | ||
1118 | var query = "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId(); | |
1119 | ||
1120 | new Ajax.Request("backend.php", { | |
1121 | parameters: query, | |
1122 | onComplete: function(transport) { | |
1123 | var reply = JSON.parse(transport.responseText); | |
1124 | ||
1125 | var title = false; | |
1126 | ||
1127 | if (reply && reply) title = reply.title; | |
1128 | ||
1129 | if (title || getActiveFeedId() || activeFeedIsCat()) { | |
1130 | ||
1131 | console.log(title + " " + getActiveFeedId()); | |
1132 | ||
1133 | var feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) : | |
1134 | getActiveFeedId(); | |
1135 | ||
1136 | var rule = { reg_exp: title, feed_id: feed_id, filter_type: 1 }; | |
1137 | ||
1138 | addFilterRule(null, dojo.toJson(rule)); | |
1139 | } | |
1140 | ||
1141 | } }); | |
1142 | ||
1143 | }); | |
1144 | } | |
1145 | ||
1146 | dialog.show(); | |
1147 | ||
1148 | } catch (e) { | |
1149 | exception_error("quickAddFilter", e); | |
1150 | } | |
1151 | } | |
1152 | ||
1153 | function resetPubSub(feed_id, title) { | |
1154 | ||
1155 | var msg = __("Reset subscription? Tiny Tiny RSS will try to subscribe to the notification hub again on next feed update.").replace("%s", title); | |
1156 | ||
1157 | if (title == undefined || confirm(msg)) { | |
1158 | notify_progress("Loading, please wait..."); | |
1159 | ||
1160 | var query = "?op=pref-feeds&quiet=1&method=resetPubSub&ids=" + feed_id; | |
1161 | ||
1162 | new Ajax.Request("backend.php", { | |
1163 | parameters: query, | |
1164 | onComplete: function(transport) { | |
1165 | dijit.byId("pubsubReset_Btn").attr('disabled', true); | |
1166 | notify_info("Subscription reset."); | |
1167 | } }); | |
1168 | } | |
1169 | ||
1170 | return false; | |
1171 | } | |
1172 | ||
1173 | ||
1174 | function unsubscribeFeed(feed_id, title) { | |
1175 | ||
1176 | var msg = __("Unsubscribe from %s?").replace("%s", title); | |
1177 | ||
1178 | if (title == undefined || confirm(msg)) { | |
1179 | notify_progress("Removing feed..."); | |
1180 | ||
1181 | var query = "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id; | |
1182 | ||
1183 | new Ajax.Request("backend.php", { | |
1184 | parameters: query, | |
1185 | onComplete: function(transport) { | |
1186 | ||
1187 | if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").hide(); | |
1188 | ||
1189 | if (inPreferences()) { | |
1190 | updateFeedList(); | |
1191 | } else { | |
1192 | if (feed_id == getActiveFeedId()) | |
1193 | setTimeout("viewfeed(-5)", 100); | |
1194 | ||
1195 | if (feed_id < 0) updateFeedList(); | |
1196 | } | |
1197 | ||
1198 | } }); | |
1199 | } | |
1200 | ||
1201 | return false; | |
1202 | } | |
1203 | ||
1204 | ||
1205 | function backend_sanity_check_callback(transport) { | |
1206 | ||
1207 | try { | |
1208 | ||
1209 | if (sanity_check_done) { | |
1210 | fatalError(11, "Sanity check request received twice. This can indicate "+ | |
1211 | "presence of Firebug or some other disrupting extension. "+ | |
1212 | "Please disable it and try again."); | |
1213 | return; | |
1214 | } | |
1215 | ||
1216 | var reply = JSON.parse(transport.responseText); | |
1217 | ||
1218 | if (!reply) { | |
1219 | fatalError(3, "Sanity check: invalid RPC reply", transport.responseText); | |
1220 | return; | |
1221 | } | |
1222 | ||
1223 | var error_code = reply['error']['code']; | |
1224 | ||
1225 | if (error_code && error_code != 0) { | |
1226 | return fatalError(error_code, reply['error']['message']); | |
1227 | } | |
1228 | ||
1229 | console.log("sanity check ok"); | |
1230 | ||
1231 | var params = reply['init-params']; | |
1232 | ||
1233 | if (params) { | |
1234 | console.log('reading init-params...'); | |
1235 | ||
1236 | if (params) { | |
1237 | for (k in params) { | |
1238 | var v = params[k]; | |
1239 | console.log("IP: " + k + " => " + v); | |
1240 | ||
1241 | if (k == "label_base_index") _label_base_index = parseInt(v); | |
1242 | } | |
1243 | } | |
1244 | ||
1245 | init_params = params; | |
1246 | } | |
1247 | ||
1248 | sanity_check_done = true; | |
1249 | ||
1250 | init_second_stage(); | |
1251 | ||
1252 | } catch (e) { | |
1253 | exception_error("backend_sanity_check_callback", e, transport); | |
1254 | } | |
1255 | } | |
1256 | ||
1257 | /*function has_local_storage() { | |
1258 | try { | |
1259 | return 'sessionStorage' in window && window['sessionStorage'] != null; | |
1260 | } catch (e) { | |
1261 | return false; | |
1262 | } | |
1263 | } */ | |
1264 | ||
1265 | function catSelectOnChange(elem) { | |
1266 | try { | |
1267 | /* var value = elem[elem.selectedIndex].value; | |
1268 | var def = elem.getAttribute('default'); | |
1269 | ||
1270 | if (value == "ADD_CAT") { | |
1271 | ||
1272 | if (def) | |
1273 | dropboxSelect(elem, def); | |
1274 | else | |
1275 | elem.selectedIndex = 0; | |
1276 | ||
1277 | quickAddCat(elem); | |
1278 | } */ | |
1279 | ||
1280 | } catch (e) { | |
1281 | exception_error("catSelectOnChange", e); | |
1282 | } | |
1283 | } | |
1284 | ||
1285 | function quickAddCat(elem) { | |
1286 | try { | |
1287 | var cat = prompt(__("Please enter category title:")); | |
1288 | ||
1289 | if (cat) { | |
1290 | ||
1291 | var query = "?op=rpc&method=quickAddCat&cat=" + param_escape(cat); | |
1292 | ||
1293 | notify_progress("Loading, please wait...", true); | |
1294 | ||
1295 | new Ajax.Request("backend.php", { | |
1296 | parameters: query, | |
1297 | onComplete: function (transport) { | |
1298 | var response = transport.responseXML; | |
1299 | var select = response.getElementsByTagName("select")[0]; | |
1300 | var options = select.getElementsByTagName("option"); | |
1301 | ||
1302 | dropbox_replace_options(elem, options); | |
1303 | ||
1304 | notify(''); | |
1305 | ||
1306 | } }); | |
1307 | ||
1308 | } | |
1309 | ||
1310 | } catch (e) { | |
1311 | exception_error("quickAddCat", e); | |
1312 | } | |
1313 | } | |
1314 | ||
1315 | function genUrlChangeKey(feed, is_cat) { | |
1316 | ||
1317 | try { | |
1318 | var ok = confirm(__("Generate new syndication address for this feed?")); | |
1319 | ||
1320 | if (ok) { | |
1321 | ||
1322 | notify_progress("Trying to change address...", true); | |
1323 | ||
1324 | var query = "?op=pref-feeds&method=regenFeedKey&id=" + param_escape(feed) + | |
1325 | "&is_cat=" + param_escape(is_cat); | |
1326 | ||
1327 | new Ajax.Request("backend.php", { | |
1328 | parameters: query, | |
1329 | onComplete: function(transport) { | |
1330 | var reply = JSON.parse(transport.responseText); | |
1331 | var new_link = reply.link; | |
1332 | ||
1333 | var e = $('gen_feed_url'); | |
1334 | ||
1335 | if (new_link) { | |
1336 | ||
1337 | e.innerHTML = e.innerHTML.replace(/\&key=.*$/, | |
1338 | "&key=" + new_link); | |
1339 | ||
1340 | e.href = e.href.replace(/\&key=.*$/, | |
1341 | "&key=" + new_link); | |
1342 | ||
1343 | new Effect.Highlight(e); | |
1344 | ||
1345 | notify(''); | |
1346 | ||
1347 | } else { | |
1348 | notify_error("Could not change feed URL."); | |
1349 | } | |
1350 | } }); | |
1351 | } | |
1352 | } catch (e) { | |
1353 | exception_error("genUrlChangeKey", e); | |
1354 | } | |
1355 | return false; | |
1356 | } | |
1357 | ||
1358 | function labelSelectOnChange(elem) { | |
1359 | try { | |
1360 | /* var value = elem[elem.selectedIndex].value; | |
1361 | var def = elem.getAttribute('default'); | |
1362 | ||
1363 | if (value == "ADD_LABEL") { | |
1364 | ||
1365 | if (def) | |
1366 | dropboxSelect(elem, def); | |
1367 | else | |
1368 | elem.selectedIndex = 0; | |
1369 | ||
1370 | addLabel(elem, function(transport) { | |
1371 | ||
1372 | try { | |
1373 | ||
1374 | var response = transport.responseXML; | |
1375 | var select = response.getElementsByTagName("select")[0]; | |
1376 | var options = select.getElementsByTagName("option"); | |
1377 | ||
1378 | dropbox_replace_options(elem, options); | |
1379 | ||
1380 | notify(''); | |
1381 | } catch (e) { | |
1382 | exception_error("addLabel", e); | |
1383 | } | |
1384 | }); | |
1385 | } */ | |
1386 | ||
1387 | } catch (e) { | |
1388 | exception_error("labelSelectOnChange", e); | |
1389 | } | |
1390 | } | |
1391 | ||
1392 | function dropbox_replace_options(elem, options) { | |
1393 | ||
1394 | try { | |
1395 | while (elem.hasChildNodes()) | |
1396 | elem.removeChild(elem.firstChild); | |
1397 | ||
1398 | var sel_idx = -1; | |
1399 | ||
1400 | for (var i = 0; i < options.length; i++) { | |
1401 | var text = options[i].firstChild.nodeValue; | |
1402 | var value = options[i].getAttribute("value"); | |
1403 | ||
1404 | if (value == undefined) value = text; | |
1405 | ||
1406 | var issel = options[i].getAttribute("selected") == "1"; | |
1407 | ||
1408 | var option = new Option(text, value, issel); | |
1409 | ||
1410 | if (options[i].getAttribute("disabled")) | |
1411 | option.setAttribute("disabled", true); | |
1412 | ||
1413 | elem.insert(option); | |
1414 | ||
1415 | if (issel) sel_idx = i; | |
1416 | } | |
1417 | ||
1418 | // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true) | |
1419 | if (sel_idx >= 0) elem.selectedIndex = sel_idx; | |
1420 | ||
1421 | } catch (e) { | |
1422 | exception_error("dropbox_replace_options", e); | |
1423 | } | |
1424 | } | |
1425 | ||
1426 | // mode = all, none, invert | |
1427 | function selectTableRows(id, mode) { | |
1428 | try { | |
1429 | var rows = $(id).rows; | |
1430 | ||
1431 | for (var i = 0; i < rows.length; i++) { | |
1432 | var row = rows[i]; | |
1433 | var cb = false; | |
1434 | var dcb = false; | |
1435 | ||
1436 | if (row.id && row.className) { | |
1437 | var bare_id = row.id.replace(/^[A-Z]*?-/, ""); | |
1438 | var inputs = rows[i].getElementsByTagName("input"); | |
1439 | ||
1440 | for (var j = 0; j < inputs.length; j++) { | |
1441 | var input = inputs[j]; | |
1442 | ||
1443 | if (input.getAttribute("type") == "checkbox" && | |
1444 | input.id.match(bare_id)) { | |
1445 | ||
1446 | cb = input; | |
1447 | dcb = dijit.getEnclosingWidget(cb); | |
1448 | break; | |
1449 | } | |
1450 | } | |
1451 | ||
1452 | if (cb || dcb) { | |
1453 | var issel = row.hasClassName("Selected"); | |
1454 | ||
1455 | if (mode == "all" && !issel) { | |
1456 | row.addClassName("Selected"); | |
1457 | cb.checked = true; | |
1458 | if (dcb) dcb.set("checked", true); | |
1459 | } else if (mode == "none" && issel) { | |
1460 | row.removeClassName("Selected"); | |
1461 | cb.checked = false; | |
1462 | if (dcb) dcb.set("checked", false); | |
1463 | ||
1464 | } else if (mode == "invert") { | |
1465 | ||
1466 | if (issel) { | |
1467 | row.removeClassName("Selected"); | |
1468 | cb.checked = false; | |
1469 | if (dcb) dcb.set("checked", false); | |
1470 | } else { | |
1471 | row.addClassName("Selected"); | |
1472 | cb.checked = true; | |
1473 | if (dcb) dcb.set("checked", true); | |
1474 | } | |
1475 | } | |
1476 | } | |
1477 | } | |
1478 | } | |
1479 | ||
1480 | } catch (e) { | |
1481 | exception_error("selectTableRows", e); | |
1482 | ||
1483 | } | |
1484 | } | |
1485 | ||
1486 | function getSelectedTableRowIds(id) { | |
1487 | var rows = []; | |
1488 | ||
1489 | try { | |
1490 | var elem_rows = $(id).rows; | |
1491 | ||
1492 | for (var i = 0; i < elem_rows.length; i++) { | |
1493 | if (elem_rows[i].hasClassName("Selected")) { | |
1494 | var bare_id = elem_rows[i].id.replace(/^[A-Z]*?-/, ""); | |
1495 | rows.push(bare_id); | |
1496 | } | |
1497 | } | |
1498 | ||
1499 | } catch (e) { | |
1500 | exception_error("getSelectedTableRowIds", e); | |
1501 | } | |
1502 | ||
1503 | return rows; | |
1504 | } | |
1505 | ||
1506 | function editFeed(feed, event) { | |
1507 | try { | |
1508 | if (feed <= 0) | |
1509 | return alert(__("You can't edit this kind of feed.")); | |
1510 | ||
1511 | var query = "backend.php?op=pref-feeds&method=editfeed&id=" + | |
1512 | param_escape(feed); | |
1513 | ||
1514 | console.log(query); | |
1515 | ||
1516 | if (dijit.byId("filterEditDlg")) | |
1517 | dijit.byId("filterEditDlg").destroyRecursive(); | |
1518 | ||
1519 | if (dijit.byId("feedEditDlg")) | |
1520 | dijit.byId("feedEditDlg").destroyRecursive(); | |
1521 | ||
1522 | dialog = new dijit.Dialog({ | |
1523 | id: "feedEditDlg", | |
1524 | title: __("Edit Feed"), | |
1525 | style: "width: 600px", | |
1526 | execute: function() { | |
1527 | if (this.validate()) { | |
1528 | // console.log(dojo.objectToQuery(this.attr('value'))); | |
1529 | ||
1530 | notify_progress("Saving data...", true); | |
1531 | ||
1532 | new Ajax.Request("backend.php", { | |
1533 | parameters: dojo.objectToQuery(dialog.attr('value')), | |
1534 | onComplete: function(transport) { | |
1535 | dialog.hide(); | |
1536 | notify(''); | |
1537 | updateFeedList(); | |
1538 | }}); | |
1539 | } | |
1540 | }, | |
1541 | href: query}); | |
1542 | ||
1543 | dialog.show(); | |
1544 | ||
1545 | } catch (e) { | |
1546 | exception_error("editFeed", e); | |
1547 | } | |
1548 | } | |
1549 | ||
1550 | function feedBrowser() { | |
1551 | try { | |
1552 | var query = "backend.php?op=feeds&method=feedBrowser"; | |
1553 | ||
1554 | if (dijit.byId("feedAddDlg")) | |
1555 | dijit.byId("feedAddDlg").hide(); | |
1556 | ||
1557 | if (dijit.byId("feedBrowserDlg")) | |
1558 | dijit.byId("feedBrowserDlg").destroyRecursive(); | |
1559 | ||
1560 | var dialog = new dijit.Dialog({ | |
1561 | id: "feedBrowserDlg", | |
1562 | title: __("More Feeds"), | |
1563 | style: "width: 600px", | |
1564 | getSelectedFeedIds: function() { | |
1565 | var list = $$("#browseFeedList li[id*=FBROW]"); | |
1566 | var selected = new Array(); | |
1567 | ||
1568 | list.each(function(child) { | |
1569 | var id = child.id.replace("FBROW-", ""); | |
1570 | ||
1571 | if (child.hasClassName('Selected')) { | |
1572 | selected.push(id); | |
1573 | } | |
1574 | }); | |
1575 | ||
1576 | return selected; | |
1577 | }, | |
1578 | getSelectedFeeds: function() { | |
1579 | var list = $$("#browseFeedList li.Selected"); | |
1580 | var selected = new Array(); | |
1581 | ||
1582 | list.each(function(child) { | |
1583 | var title = child.getElementsBySelector("span.fb_feedTitle")[0].innerHTML; | |
1584 | var url = child.getElementsBySelector("a.fb_feedUrl")[0].href; | |
1585 | ||
1586 | selected.push([title,url]); | |
1587 | ||
1588 | }); | |
1589 | ||
1590 | return selected; | |
1591 | }, | |
1592 | ||
1593 | subscribe: function() { | |
1594 | var mode = this.attr('value').mode; | |
1595 | var selected = []; | |
1596 | ||
1597 | if (mode == "1") | |
1598 | selected = this.getSelectedFeeds(); | |
1599 | else | |
1600 | selected = this.getSelectedFeedIds(); | |
1601 | ||
1602 | if (selected.length > 0) { | |
1603 | dijit.byId("feedBrowserDlg").hide(); | |
1604 | ||
1605 | notify_progress("Loading, please wait...", true); | |
1606 | ||
1607 | // we use dojo.toJson instead of JSON.stringify because | |
1608 | // it somehow escapes everything TWICE, at least in Chrome 9 | |
1609 | ||
1610 | var query = "?op=rpc&method=massSubscribe&payload="+ | |
1611 | param_escape(dojo.toJson(selected)) + "&mode=" + param_escape(mode); | |
1612 | ||
1613 | console.log(query); | |
1614 | ||
1615 | new Ajax.Request("backend.php", { | |
1616 | parameters: query, | |
1617 | onComplete: function(transport) { | |
1618 | notify(''); | |
1619 | updateFeedList(); | |
1620 | } }); | |
1621 | ||
1622 | } else { | |
1623 | alert(__("No feeds are selected.")); | |
1624 | } | |
1625 | ||
1626 | }, | |
1627 | update: function() { | |
1628 | var query = dojo.objectToQuery(dialog.attr('value')); | |
1629 | ||
1630 | Element.show('feed_browser_spinner'); | |
1631 | ||
1632 | new Ajax.Request("backend.php", { | |
1633 | parameters: query, | |
1634 | onComplete: function(transport) { | |
1635 | notify(''); | |
1636 | ||
1637 | Element.hide('feed_browser_spinner'); | |
1638 | ||
1639 | var c = $("browseFeedList"); | |
1640 | ||
1641 | var reply = JSON.parse(transport.responseText); | |
1642 | ||
1643 | var r = reply['content']; | |
1644 | var mode = reply['mode']; | |
1645 | ||
1646 | if (c && r) { | |
1647 | c.innerHTML = r; | |
1648 | } | |
1649 | ||
1650 | dojo.parser.parse("browseFeedList"); | |
1651 | ||
1652 | if (mode == 2) { | |
1653 | Element.show(dijit.byId('feed_archive_remove').domNode); | |
1654 | } else { | |
1655 | Element.hide(dijit.byId('feed_archive_remove').domNode); | |
1656 | } | |
1657 | ||
1658 | } }); | |
1659 | }, | |
1660 | removeFromArchive: function() { | |
1661 | var selected = this.getSelectedFeedIds(); | |
1662 | ||
1663 | if (selected.length > 0) { | |
1664 | ||
1665 | var pr = __("Remove selected feeds from the archive? Feeds with stored articles will not be removed."); | |
1666 | ||
1667 | if (confirm(pr)) { | |
1668 | Element.show('feed_browser_spinner'); | |
1669 | ||
1670 | var query = "?op=rpc&method=remarchive&ids=" + | |
1671 | param_escape(selected.toString());; | |
1672 | ||
1673 | new Ajax.Request("backend.php", { | |
1674 | parameters: query, | |
1675 | onComplete: function(transport) { | |
1676 | dialog.update(); | |
1677 | } }); | |
1678 | } | |
1679 | } | |
1680 | }, | |
1681 | execute: function() { | |
1682 | if (this.validate()) { | |
1683 | this.subscribe(); | |
1684 | } | |
1685 | }, | |
1686 | href: query}); | |
1687 | ||
1688 | dialog.show(); | |
1689 | ||
1690 | } catch (e) { | |
1691 | exception_error("editFeed", e); | |
1692 | } | |
1693 | } | |
1694 | ||
1695 | function showFeedsWithErrors() { | |
1696 | try { | |
1697 | var query = "backend.php?op=pref-feeds&method=feedsWithErrors"; | |
1698 | ||
1699 | if (dijit.byId("errorFeedsDlg")) | |
1700 | dijit.byId("errorFeedsDlg").destroyRecursive(); | |
1701 | ||
1702 | dialog = new dijit.Dialog({ | |
1703 | id: "errorFeedsDlg", | |
1704 | title: __("Feeds with update errors"), | |
1705 | style: "width: 600px", | |
1706 | getSelectedFeeds: function() { | |
1707 | return getSelectedTableRowIds("prefErrorFeedList"); | |
1708 | }, | |
1709 | removeSelected: function() { | |
1710 | var sel_rows = this.getSelectedFeeds(); | |
1711 | ||
1712 | console.log(sel_rows); | |
1713 | ||
1714 | if (sel_rows.length > 0) { | |
1715 | var ok = confirm(__("Remove selected feeds?")); | |
1716 | ||
1717 | if (ok) { | |
1718 | notify_progress("Removing selected feeds...", true); | |
1719 | ||
1720 | var query = "?op=pref-feeds&method=remove&ids="+ | |
1721 | param_escape(sel_rows.toString()); | |
1722 | ||
1723 | new Ajax.Request("backend.php", { | |
1724 | parameters: query, | |
1725 | onComplete: function(transport) { | |
1726 | notify(''); | |
1727 | dialog.hide(); | |
1728 | updateFeedList(); | |
1729 | } }); | |
1730 | } | |
1731 | ||
1732 | } else { | |
1733 | alert(__("No feeds are selected.")); | |
1734 | } | |
1735 | }, | |
1736 | execute: function() { | |
1737 | if (this.validate()) { | |
1738 | } | |
1739 | }, | |
1740 | href: query}); | |
1741 | ||
1742 | dialog.show(); | |
1743 | ||
1744 | } catch (e) { | |
1745 | exception_error("showFeedsWithErrors", e); | |
1746 | } | |
1747 | ||
1748 | } | |
1749 | ||
1750 | /* new support functions for SelectByTag */ | |
1751 | ||
1752 | function get_all_tags(selObj){ | |
1753 | try { | |
1754 | if( !selObj ) return ""; | |
1755 | ||
1756 | var result = ""; | |
1757 | var len = selObj.options.length; | |
1758 | ||
1759 | for (var i=0; i < len; i++){ | |
1760 | if (selObj.options[i].selected) { | |
1761 | result += selObj[i].value + "%2C"; // is really a comma | |
1762 | } | |
1763 | } | |
1764 | ||
1765 | if (result.length > 0){ | |
1766 | result = result.substr(0, result.length-3); // remove trailing %2C | |
1767 | } | |
1768 | ||
1769 | return(result); | |
1770 | ||
1771 | } catch (e) { | |
1772 | exception_error("get_all_tags", e); | |
1773 | } | |
1774 | } | |
1775 | ||
1776 | function get_radio_checked(radioObj) { | |
1777 | try { | |
1778 | if (!radioObj) return ""; | |
1779 | ||
1780 | var len = radioObj.length; | |
1781 | ||
1782 | if (len == undefined){ | |
1783 | if(radioObj.checked){ | |
1784 | return(radioObj.value); | |
1785 | } else { | |
1786 | return(""); | |
1787 | } | |
1788 | } | |
1789 | ||
1790 | for( var i=0; i < len; i++ ){ | |
1791 | if( radioObj[i].checked ){ | |
1792 | return( radioObj[i].value); | |
1793 | } | |
1794 | } | |
1795 | ||
1796 | } catch (e) { | |
1797 | exception_error("get_radio_checked", e); | |
1798 | } | |
1799 | return(""); | |
1800 | } | |
1801 | ||
1802 | function get_timestamp() { | |
1803 | var date = new Date(); | |
1804 | return Math.round(date.getTime() / 1000); | |
1805 | } | |
1806 | ||
1807 | function helpDialog(topic) { | |
1808 | try { | |
1809 | var query = "backend.php?op=backend&method=help&topic=" + param_escape(topic); | |
1810 | ||
1811 | if (dijit.byId("helpDlg")) | |
1812 | dijit.byId("helpDlg").destroyRecursive(); | |
1813 | ||
1814 | dialog = new dijit.Dialog({ | |
1815 | id: "helpDlg", | |
1816 | title: __("Help"), | |
1817 | style: "width: 600px", | |
1818 | href: query, | |
1819 | }); | |
1820 | ||
1821 | dialog.show(); | |
1822 | ||
1823 | } catch (e) { | |
1824 | exception_error("helpDialog", e); | |
1825 | } | |
1826 | } | |
1827 | ||
1828 | function htmlspecialchars_decode (string, quote_style) { | |
1829 | // http://kevin.vanzonneveld.net | |
1830 | // + original by: Mirek Slugen | |
1831 | // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | |
1832 | // + bugfixed by: Mateusz "loonquawl" Zalega | |
1833 | // + input by: ReverseSyntax | |
1834 | // + input by: Slawomir Kaniecki | |
1835 | // + input by: Scott Cariss | |
1836 | // + input by: Francois | |
1837 | // + bugfixed by: Onno Marsman | |
1838 | // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | |
1839 | // + bugfixed by: Brett Zamir (http://brett-zamir.me) | |
1840 | // + input by: Ratheous | |
1841 | // + input by: Mailfaker (http://www.weedem.fr/) | |
1842 | // + reimplemented by: Brett Zamir (http://brett-zamir.me) | |
1843 | // + bugfixed by: Brett Zamir (http://brett-zamir.me) | |
1844 | // * example 1: htmlspecialchars_decode("<p>this -> "</p>", 'ENT_NOQUOTES'); | |
1845 | // * returns 1: '<p>this -> "</p>' | |
1846 | // * example 2: htmlspecialchars_decode("&quot;"); | |
1847 | // * returns 2: '"' | |
1848 | var optTemp = 0, | |
1849 | i = 0, | |
1850 | noquotes = false; | |
1851 | if (typeof quote_style === 'undefined') { | |
1852 | quote_style = 2; | |
1853 | } | |
1854 | string = string.toString().replace(/</g, '<').replace(/>/g, '>'); | |
1855 | var OPTS = { | |
1856 | 'ENT_NOQUOTES': 0, | |
1857 | 'ENT_HTML_QUOTE_SINGLE': 1, | |
1858 | 'ENT_HTML_QUOTE_DOUBLE': 2, | |
1859 | 'ENT_COMPAT': 2, | |
1860 | 'ENT_QUOTES': 3, | |
1861 | 'ENT_IGNORE': 4 | |
1862 | }; | |
1863 | if (quote_style === 0) { | |
1864 | noquotes = true; | |
1865 | } | |
1866 | if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags | |
1867 | quote_style = [].concat(quote_style); | |
1868 | for (i = 0; i < quote_style.length; i++) { | |
1869 | // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4 | |
1870 | if (OPTS[quote_style[i]] === 0) { | |
1871 | noquotes = true; | |
1872 | } else if (OPTS[quote_style[i]]) { | |
1873 | optTemp = optTemp | OPTS[quote_style[i]]; | |
1874 | } | |
1875 | } | |
1876 | quote_style = optTemp; | |
1877 | } | |
1878 | if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) { | |
1879 | string = string.replace(/�*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should | |
1880 | // string = string.replace(/'|�*27;/g, "'"); // This would also be useful here, but not a part of PHP | |
1881 | } | |
1882 | if (!noquotes) { | |
1883 | string = string.replace(/"/g, '"'); | |
1884 | } | |
1885 | // Put this in last place to avoid escape being double-decoded | |
1886 | string = string.replace(/&/g, '&'); | |
1887 | ||
1888 | return string; | |
1889 | } | |
1890 | ||
1891 | ||
1892 | function label_to_feed_id(label) { | |
1893 | return _label_base_index - 1 - Math.abs(label); | |
1894 | } | |
1895 | ||
1896 | function feed_to_label_id(feed) { | |
1897 | return _label_base_index - 1 + Math.abs(feed); | |
1898 | } | |
1899 |