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