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