]> git.wh0rd.org - tt-rss.git/blob - prefs.js
parse_counters: enable feed icons on the fly
[tt-rss.git] / prefs.js
1 var xmlhttp = false;
2
3 var active_feed_cat = false;
4 var active_label = false;
5 var active_tab = false;
6 var feed_to_expand = false;
7
8 var piggie_top = -400;
9 var piggie_fwd = true;
10
11 var xmlhttp = Ajax.getTransport();
12
13 var init_params = new Array();
14
15 var caller_subop = false;
16
17 var sanity_check_done = false;
18
19 function replace_pubkey_callback() {
20 if (xmlhttp.readyState == 4) {
21 try {
22 var link = document.getElementById("pubGenAddress");
23
24 if (xmlhttp.responseXML) {
25
26 var new_link = xmlhttp.responseXML.getElementsByTagName("link")[0];
27
28 if (new_link) {
29 link.href = new_link.firstChild.nodeValue;
30 link.innerHTML = new_link.firstChild.nodeValue;
31
32 notify_info("Address changed.");
33 } else {
34 notify_error("Could not change address.");
35 }
36
37 } else {
38 notify_error("Could not change address.");
39 }
40 } catch (e) {
41 exception_error("replace_pubkey_callback", e);
42 }
43 }
44 }
45
46 function expand_feed_callback() {
47 if (xmlhttp.readyState == 4) {
48 try {
49 var container = document.getElementById("BRDET-" + feed_to_expand);
50 container.innerHTML=xmlhttp.responseText;
51 // container.style.display = "block";
52 // p_notify("");
53 Effect.Appear(container, {duration : 0.5});
54 } catch (e) {
55 exception_error("expand_feed_callback", e);
56 }
57 }
58 }
59
60 function feedlist_callback() {
61 if (xmlhttp.readyState == 4) {
62 try {
63 var container = document.getElementById('prefContent');
64 container.innerHTML=xmlhttp.responseText;
65 selectTab("feedConfig", true);
66
67 if (caller_subop) {
68 var tuple = caller_subop.split(":");
69 if (tuple[0] == 'editFeed') {
70 window.setTimeout('editFeed('+tuple[1]+')', 100);
71 }
72
73 caller_subop = false;
74 }
75 if (typeof correctPNG != 'undefined') {
76 correctPNG();
77 }
78 notify("");
79 } catch (e) {
80 exception_error("feedlist_callback", e);
81 }
82 }
83 }
84
85 /* stub for subscription dialog */
86
87 function dlg_frefresh_callback() {
88 if (xmlhttp.readyState == 4) {
89 // setTimeout("updateFeedList()", 500);
90
91 try {
92 var container = document.getElementById('prefContent');
93 container.innerHTML=xmlhttp.responseText;
94 selectTab("feedConfig", true);
95
96 if (caller_subop) {
97 var tuple = caller_subop.split(":");
98 if (tuple[0] == 'editFeed') {
99 window.setTimeout('editFeed('+tuple[1]+')', 100);
100 }
101
102 caller_subop = false;
103 }
104 if (typeof correctPNG != 'undefined') {
105 correctPNG();
106 }
107 notify("");
108 } catch (e) {
109 exception_error("feedlist_callback", e);
110 }
111 }
112 }
113
114 function filterlist_callback() {
115 var container = document.getElementById('prefContent');
116 if (xmlhttp.readyState == 4) {
117 container.innerHTML=xmlhttp.responseText;
118 if (typeof correctPNG != 'undefined') {
119 correctPNG();
120 }
121 notify("");
122 }
123 }
124
125 function labellist_callback() {
126 var container = document.getElementById('prefContent');
127 if (xmlhttp.readyState == 4) {
128 closeInfoBox();
129 container.innerHTML=xmlhttp.responseText;
130 if (active_label) {
131 var row = document.getElementById("LILRR-" + active_label);
132 if (row) {
133 if (!row.className.match("Selected")) {
134 row.className = row.className + "Selected";
135 }
136 }
137 var checkbox = document.getElementById("LICHK-" + active_label);
138
139 if (checkbox) {
140 checkbox.checked = true;
141 }
142 }
143 if (typeof correctPNG != 'undefined') {
144 correctPNG();
145 }
146 notify("");
147 }
148 }
149
150 function labeltest_callback() {
151 var container = document.getElementById('label_test_result');
152 if (xmlhttp.readyState == 4) {
153 container.innerHTML=xmlhttp.responseText;
154 notify("");
155 }
156 }
157
158 function feed_browser_callback() {
159 var container = document.getElementById('prefContent');
160 if (xmlhttp.readyState == 4) {
161 container.innerHTML=xmlhttp.responseText;
162 notify("");
163 }
164 }
165
166 function userlist_callback() {
167 var container = document.getElementById('prefContent');
168 if (xmlhttp.readyState == 4) {
169 container.innerHTML=xmlhttp.responseText;
170 notify("");
171 }
172 }
173
174 function prefslist_callback() {
175 var container = document.getElementById('prefContent');
176 if (xmlhttp.readyState == 4) {
177
178 container.innerHTML=xmlhttp.responseText;
179
180 notify("");
181 }
182 }
183
184 function gethelp_callback() {
185 var container = document.getElementById('prefHelpBox');
186 if (xmlhttp.readyState == 4) {
187
188 container.innerHTML = xmlhttp.responseText;
189 container.style.display = "block";
190
191 }
192 }
193
194 function notify_callback() {
195 if (xmlhttp.readyState == 4) {
196 notify_info(xmlhttp.responseText);
197 }
198 }
199
200
201 function changepass_callback() {
202 try {
203 if (xmlhttp.readyState == 4) {
204
205 if (xmlhttp.responseText.indexOf("ERROR: ") == 0) {
206 notify_error(xmlhttp.responseText.replace("ERROR: ", ""));
207 } else {
208 notify_info(xmlhttp.responseText);
209 var warn = document.getElementById("default_pass_warning");
210 if (warn) warn.style.display = "none";
211 }
212
213 document.forms['change_pass_form'].reset();
214
215 }
216 } catch (e) {
217 exception_error("changepass_callback", e);
218 }
219 }
220
221 function updateFeedList(sort_key) {
222
223 if (!xmlhttp_ready(xmlhttp)) {
224 printLockingError();
225 return
226 }
227
228 // document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
229
230 // p_notify("Loading, please wait...");
231
232 var feed_search = document.getElementById("feed_search");
233 var search = "";
234 if (feed_search) { search = feed_search.value; }
235
236 var slat = document.getElementById("show_last_article_times");
237
238 var slat_checked = false;
239 if (slat) {
240 slat_checked = slat.checked;
241 }
242
243 xmlhttp.open("GET", "backend.php?op=pref-feeds" +
244 "&sort=" + param_escape(sort_key) +
245 "&slat=" + param_escape(slat_checked) +
246 "&search=" + param_escape(search), true);
247 xmlhttp.onreadystatechange=feedlist_callback;
248 xmlhttp.send(null);
249
250 }
251
252 function updateUsersList(sort_key) {
253
254 if (!xmlhttp_ready(xmlhttp)) {
255 printLockingError();
256 return
257 }
258
259 // document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
260
261 // p_notify("Loading, please wait...");
262
263 xmlhttp.open("GET", "backend.php?op=pref-users&sort="
264 + param_escape(sort_key), true);
265 xmlhttp.onreadystatechange=userlist_callback;
266 xmlhttp.send(null);
267
268 }
269
270 function addLabel() {
271
272 if (!xmlhttp_ready(xmlhttp)) {
273 printLockingError();
274 return
275 }
276
277 var form = document.forms['label_edit_form'];
278
279 var sql_exp = form.sql_exp.value;
280 var description = form.description.value;
281
282 if (sql_exp == "") {
283 alert(__("Can't create label: missing SQL expression."));
284 return false;
285 }
286
287 if (description == "") {
288 alert(__("Can't create label: missing caption."));
289 return false;
290 }
291
292 var query = Form.serialize("label_edit_form");
293
294 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=add&" + query, true);
295 xmlhttp.onreadystatechange=infobox_submit_callback;
296 xmlhttp.send(null);
297 }
298
299 function addFeed() {
300
301 if (!xmlhttp_ready(xmlhttp)) {
302 printLockingError();
303 return
304 }
305
306 var link = document.getElementById("fadd_link");
307
308 if (link.value.length == 0) {
309 alert(__("Error: No feed URL given."));
310 } else if (!isValidURL(link.value)) {
311 alert(__("Error: Invalid feed URL."));
312 } else {
313 notify_progress("Adding feed...");
314
315 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&from=tt-rss&feed_url=" +
316 param_escape(link.value), true);
317 xmlhttp.onreadystatechange=feedlist_callback;
318 xmlhttp.send(null);
319
320 link.value = "";
321
322 }
323
324 }
325
326 function addFeedCat() {
327
328 if (!xmlhttp_ready(xmlhttp)) {
329 printLockingError();
330 return
331 }
332
333 var cat = document.getElementById("fadd_cat");
334
335 if (cat.value.length == 0) {
336 alert(__("Can't add category: no name specified."));
337 } else {
338 notify_progress("Adding feed category...");
339
340 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=add&cat=" +
341 param_escape(cat.value), true);
342 xmlhttp.onreadystatechange=infobox_callback;
343 xmlhttp.send(null);
344
345 link.value = "";
346
347 }
348
349 }
350 function addUser() {
351
352 if (!xmlhttp_ready(xmlhttp)) {
353 printLockingError();
354 return
355 }
356
357 var sqlexp = document.getElementById("uadd_box");
358
359 if (sqlexp.value.length == 0) {
360 alert(__("Can't add user: no login specified."));
361 } else {
362 notify_progress("Adding user...");
363
364 xmlhttp.open("GET", "backend.php?op=pref-users&subop=add&login=" +
365 param_escape(sqlexp.value), true);
366
367 xmlhttp.onreadystatechange=userlist_callback;
368 xmlhttp.send(null);
369
370 sqlexp.value = "";
371 }
372
373 }
374
375 function editLabel(id) {
376
377 if (!xmlhttp_ready(xmlhttp)) {
378 printLockingError();
379 return
380 }
381
382 notify_progress("Loading, please wait...");
383
384 document.getElementById("label_create_btn").disabled = true;
385
386 active_label = id;
387
388 selectTableRowsByIdPrefix('prefLabelList', 'LILRR-', 'LICHK-', false);
389 selectTableRowById('LILRR-'+id, 'LICHK-'+id, true);
390
391 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=edit&id=" +
392 param_escape(id), true);
393 xmlhttp.onreadystatechange=infobox_callback;
394 xmlhttp.send(null);
395
396 }
397
398 function editUser(id) {
399
400 if (!xmlhttp_ready(xmlhttp)) {
401 printLockingError();
402 return
403 }
404
405 notify_progress("Loading, please wait...");
406
407 selectTableRowsByIdPrefix('prefUserList', 'UMRR-', 'UMCHK-', false);
408 selectTableRowById('UMRR-'+id, 'UMCHK-'+id, true);
409
410 xmlhttp.open("GET", "backend.php?op=pref-users&subop=edit&id=" +
411 param_escape(id), true);
412 xmlhttp.onreadystatechange=infobox_callback;
413 xmlhttp.send(null);
414
415 }
416
417 function editFilter(id) {
418
419 if (!xmlhttp_ready(xmlhttp)) {
420 printLockingError();
421 return
422 }
423
424 notify_progress("Loading, please wait...");
425
426 document.getElementById("create_filter_btn").disabled = true;
427
428 selectTableRowsByIdPrefix('prefFilterList', 'FILRR-', 'FICHK-', false);
429 selectTableRowById('FILRR-'+id, 'FICHK-'+id, true);
430
431 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=edit&id=" + param_escape(id), true);
432 xmlhttp.onreadystatechange=infobox_callback;
433 xmlhttp.send(null);
434 }
435
436 function editFeed(feed) {
437
438 // notify("Editing feed...");
439
440 if (!xmlhttp_ready(xmlhttp)) {
441 printLockingError();
442 return
443 }
444
445 notify_progress("Loading, please wait...");
446
447 document.getElementById("subscribe_to_feed_btn").disabled = true;
448
449 try {
450 document.getElementById("top25_feeds_btn").disabled = true;
451 } catch (e) {
452 // this button is not always available, no-op if not found
453 }
454
455 // clean selection from all rows & select row being edited
456 selectTableRowsByIdPrefix('prefFeedList', 'FEEDR-', 'FRCHK-', false);
457 selectTableRowById('FEEDR-'+feed, 'FRCHK-'+feed, true);
458
459 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
460 param_escape(feed), true);
461
462 xmlhttp.onreadystatechange=infobox_callback;
463 xmlhttp.send(null);
464
465 }
466
467 function editFeedCat(cat) {
468
469 if (!xmlhttp_ready(xmlhttp)) {
470 printLockingError();
471 return
472 }
473
474 notify_progress("Loading, please wait...");
475
476 active_feed_cat = cat;
477
478 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=edit&id=" +
479 param_escape(cat), true);
480 xmlhttp.onreadystatechange=infobox_callback;
481 xmlhttp.send(null);
482
483 }
484
485 function getSelectedLabels() {
486 return getSelectedTableRowIds("prefLabelList", "LILRR");
487 }
488
489 function getSelectedUsers() {
490 return getSelectedTableRowIds("prefUserList", "UMRR");
491 }
492
493 function getSelectedFeeds() {
494 return getSelectedTableRowIds("prefFeedList", "FEEDR");
495 }
496
497 function getSelectedFilters() {
498 return getSelectedTableRowIds("prefFilterList", "FILRR");
499 }
500
501 function getSelectedFeedCats() {
502 return getSelectedTableRowIds("prefFeedCatList", "FCATR");
503 }
504
505 function getSelectedFeedsFromBrowser() {
506
507 var list = document.getElementById("browseFeedList");
508 if (!list) list = document.getElementById("browseBigFeedList");
509
510 var selected = new Array();
511
512 for (i = 0; i < list.childNodes.length; i++) {
513 var child = list.childNodes[i];
514 if (child.id && child.id.match("FBROW-")) {
515 var id = child.id.replace("FBROW-", "");
516
517 var cb = document.getElementById("FBCHK-" + id);
518
519 if (cb.checked) {
520 selected.push(id);
521 }
522 }
523 }
524
525 return selected;
526 }
527
528 function removeSelectedLabels() {
529
530 if (!xmlhttp_ready(xmlhttp)) {
531 printLockingError();
532 return
533 }
534
535 var sel_rows = getSelectedLabels();
536
537 if (sel_rows.length > 0) {
538
539 var ok = confirm(__("Remove selected labels?"));
540
541 if (ok) {
542 notify_progress("Removing selected labels...");
543
544 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
545 param_escape(sel_rows.toString()), true);
546 xmlhttp.onreadystatechange=labellist_callback;
547 xmlhttp.send(null);
548 }
549 } else {
550 alert(__("No labels are selected."));
551 }
552
553 return false;
554 }
555
556 function removeSelectedUsers() {
557
558 if (!xmlhttp_ready(xmlhttp)) {
559 printLockingError();
560 return
561 }
562
563 var sel_rows = getSelectedUsers();
564
565 if (sel_rows.length > 0) {
566
567 var ok = confirm(__("Remove selected users?"));
568
569 if (ok) {
570 notify_progress("Removing selected users...");
571
572 xmlhttp.open("GET", "backend.php?op=pref-users&subop=remove&ids="+
573 param_escape(sel_rows.toString()), true);
574 xmlhttp.onreadystatechange=userlist_callback;
575 xmlhttp.send(null);
576 }
577
578 } else {
579 alert(__("No users are selected."));
580 }
581
582 return false;
583 }
584
585 function removeSelectedFilters() {
586
587 if (!xmlhttp_ready(xmlhttp)) {
588 printLockingError();
589 return
590 }
591
592 var sel_rows = getSelectedFilters();
593
594 if (sel_rows.length > 0) {
595
596 var ok = confirm(__("Remove selected filters?"));
597
598 if (ok) {
599 notify_progress("Removing selected filters...");
600
601 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
602 param_escape(sel_rows.toString()), true);
603 xmlhttp.onreadystatechange=filterlist_callback;
604 xmlhttp.send(null);
605 }
606 } else {
607 alert(__("No filters are selected."));
608 }
609
610 return false;
611 }
612
613
614 function removeSelectedFeeds() {
615
616 if (!xmlhttp_ready(xmlhttp)) {
617 printLockingError();
618 return
619 }
620
621 var sel_rows = getSelectedFeeds();
622
623 if (sel_rows.length > 0) {
624
625 var ok = confirm(__("Unsubscribe from selected feeds?"));
626
627 if (ok) {
628
629 notify_progress("Unsubscribing from selected feeds...");
630
631 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
632 param_escape(sel_rows.toString()), true);
633 xmlhttp.onreadystatechange=feedlist_callback;
634 xmlhttp.send(null);
635 }
636
637 } else {
638
639 alert(__("No feeds are selected."));
640
641 }
642
643 return false;
644 }
645
646 function removeSelectedFeedCats() {
647
648 if (!xmlhttp_ready(xmlhttp)) {
649 printLockingError();
650 return
651 }
652
653 var sel_rows = getSelectedFeedCats();
654
655 if (sel_rows.length > 0) {
656
657 var ok = confirm(__("Remove selected categories?"));
658
659 if (ok) {
660 notify_progress("Removing selected categories...");
661
662 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=remove&ids="+
663 param_escape(sel_rows.toString()), true);
664 xmlhttp.onreadystatechange=infobox_callback;
665 xmlhttp.send(null);
666 }
667
668 } else {
669
670 alert(__("No categories are selected."));
671
672 }
673
674 return false;
675 }
676
677 function feedEditCancel() {
678
679 if (!xmlhttp_ready(xmlhttp)) {
680 printLockingError();
681 return
682 }
683
684 document.getElementById("subscribe_to_feed_btn").disabled = false;
685
686 try {
687 document.getElementById("top25_feeds_btn").disabled = false;
688 } catch (e) {
689 // this button is not always available, no-op if not found
690 }
691
692 closeInfoBox();
693
694 selectPrefRows('feed', false); // cleanup feed selection
695
696 return false;
697 }
698
699 function feedCatEditCancel() {
700
701 if (!xmlhttp_ready(xmlhttp)) {
702 printLockingError();
703 return
704 }
705
706 active_feed_cat = false;
707
708 // notify("Operation cancelled.");
709
710 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
711 xmlhttp.onreadystatechange=infobox_callback;
712 xmlhttp.send(null);
713
714 return false;
715 }
716
717 function feedEditSave() {
718
719 try {
720
721 if (!xmlhttp_ready(xmlhttp)) {
722 printLockingError();
723 return
724 }
725
726 // FIXME: add parameter validation
727
728 var query = Form.serialize("edit_feed_form");
729
730 notify_progress("Saving feed...");
731
732 xmlhttp.open("POST", "backend.php", true);
733 xmlhttp.onreadystatechange=feedlist_callback;
734 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
735 xmlhttp.send(query);
736
737 closeInfoBox();
738
739 return false;
740
741 } catch (e) {
742 exception_error("feedEditSave", e);
743 }
744 }
745
746 function feedCatEditSave() {
747
748 if (!xmlhttp_ready(xmlhttp)) {
749 printLockingError();
750 return
751 }
752
753 notify_progress("Saving category...");
754
755 var query = Form.serialize("feed_cat_edit_form");
756
757 xmlhttp.open("GET", "backend.php?" + query, true);
758 xmlhttp.onreadystatechange=infobox_callback;
759 xmlhttp.send(null);
760
761 active_feed_cat = false;
762
763 return false;
764 }
765
766
767 function labelTest() {
768
769 var container = document.getElementById('label_test_result');
770 container.style.display = "block";
771 container.innerHTML = "<p>Loading, please wait...</p>";
772
773 var form = document.forms['label_edit_form'];
774
775 var sql_exp = form.sql_exp.value;
776 var description = form.description.value;
777
778 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=test&expr=" +
779 param_escape(sql_exp) + "&descr=" + param_escape(description), true);
780
781 xmlhttp.onreadystatechange=labeltest_callback;
782 xmlhttp.send(null);
783
784 return false;
785 }
786
787 function displayHelpInfobox(topic_id) {
788
789 /* if (!xmlhttp_ready(xmlhttp)) {
790 printLockingError();
791 return
792 }
793
794 notify_progress("Loading help...");
795
796 xmlhttp.open("GET", "backend.php?op=help&tid=" +
797 param_escape(topic_id), true);
798
799 xmlhttp.onreadystatechange=helpbox_callback;
800 xmlhttp.send(null); */
801
802 var url = "backend.php?op=help&tid=" + param_escape(topic_id);
803
804 var w = window.open(url, "ttrss_help",
805 "status=0,toolbar=0,location=0,width=400,height=450,menubar=0");
806
807 }
808
809 function labelEditCancel() {
810
811 if (!xmlhttp_ready(xmlhttp)) {
812 printLockingError();
813 return
814 }
815
816 document.getElementById("label_create_btn").disabled = false;
817
818 active_label = false;
819
820 selectPrefRows('label', false); // cleanup feed selection
821 closeInfoBox();
822
823 return false;
824 }
825
826 function userEditCancel() {
827
828 if (!xmlhttp_ready(xmlhttp)) {
829 printLockingError();
830 return
831 }
832
833 selectPrefRows('user', false); // cleanup feed selection
834 closeInfoBox();
835
836 return false;
837 }
838
839 function filterEditCancel() {
840
841 if (!xmlhttp_ready(xmlhttp)) {
842 printLockingError();
843 return
844 }
845
846 document.getElementById("create_filter_btn").disabled = false;
847
848 selectPrefRows('filter', false); // cleanup feed selection
849 closeInfoBox();
850
851 return false;
852 }
853
854 function labelEditSave() {
855
856 var label = active_label;
857
858 if (!xmlhttp_ready(xmlhttp)) {
859 printLockingError();
860 return
861 }
862
863 /* if (!is_opera()) {
864
865 var sql_exp = document.forms["label_edit_form"].sql_exp.value;
866 var description = document.forms["label_edit_form"].description.value;
867
868 if (sql_exp.length == 0) {
869 alert("SQL Expression cannot be blank.");
870 return false;
871 }
872
873 if (description.length == 0) {
874 alert("Caption field cannot be blank.");
875 return false;
876 }
877 } */
878
879 closeInfoBox();
880
881 notify_progress("Saving label...");
882
883 active_label = false;
884
885 query = Form.serialize("label_edit_form");
886
887 xmlhttp.open("GET", "backend.php?" + query, true);
888 xmlhttp.onreadystatechange=labellist_callback;
889 xmlhttp.send(null);
890
891 return false;
892 }
893
894 function userEditSave() {
895
896 if (!xmlhttp_ready(xmlhttp)) {
897 printLockingError();
898 return
899 }
900
901 var login = document.forms["user_edit_form"].login.value;
902
903 if (login.length == 0) {
904 alert(__("Login field cannot be blank."));
905 return;
906 }
907
908 notify_progress("Saving user...");
909
910 closeInfoBox();
911
912 var query = Form.serialize("user_edit_form");
913
914 xmlhttp.open("GET", "backend.php?" + query, true);
915 xmlhttp.onreadystatechange=userlist_callback;
916 xmlhttp.send(null);
917
918 return false;
919 }
920
921
922 function filterEditSave() {
923
924 if (!xmlhttp_ready(xmlhttp)) {
925 printLockingError();
926 return
927 }
928
929 /* if (!is_opera()) {
930 var reg_exp = document.forms["filter_edit_form"].reg_exp.value;
931
932 if (reg_exp.length == 0) {
933 alert("Filter expression field cannot be blank.");
934 return;
935 }
936 } */
937
938 notify_progress("Saving filter...");
939
940 var query = Form.serialize("filter_edit_form");
941
942 closeInfoBox();
943
944 document.getElementById("create_filter_btn").disabled = false;
945
946 xmlhttp.open("GET", "backend.php?" + query, true);
947 xmlhttp.onreadystatechange=filterlist_callback;
948 xmlhttp.send(null);
949
950 return false;
951 }
952
953 function editSelectedLabel() {
954 var rows = getSelectedLabels();
955
956 if (rows.length == 0) {
957 alert(__("No labels are selected."));
958 return;
959 }
960
961 if (rows.length > 1) {
962 alert(__("Please select only one label."));
963 return;
964 }
965
966 notify("");
967
968 editLabel(rows[0]);
969
970 }
971
972 function editSelectedUser() {
973 var rows = getSelectedUsers();
974
975 if (rows.length == 0) {
976 alert(__("No users are selected."));
977 return;
978 }
979
980 if (rows.length > 1) {
981 alert(__("Please select only one user."));
982 return;
983 }
984
985 notify("");
986
987 editUser(rows[0]);
988 }
989
990 function resetSelectedUserPass() {
991 var rows = getSelectedUsers();
992
993 if (rows.length == 0) {
994 alert(__("No users are selected."));
995 return;
996 }
997
998 if (rows.length > 1) {
999 alert(__("Please select only one user."));
1000 return;
1001 }
1002
1003 var ok = confirm(__("Reset password of selected user?"));
1004
1005 if (ok) {
1006 notify_progress("Resetting password for selected user...");
1007
1008 var id = rows[0];
1009
1010 xmlhttp.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
1011 param_escape(id), true);
1012 xmlhttp.onreadystatechange=userlist_callback;
1013 xmlhttp.send(null);
1014 }
1015 }
1016
1017 function selectedUserDetails() {
1018
1019 if (!xmlhttp_ready(xmlhttp)) {
1020 printLockingError();
1021 return
1022 }
1023
1024 var rows = getSelectedUsers();
1025
1026 if (rows.length == 0) {
1027 alert(__("No users are selected."));
1028 return;
1029 }
1030
1031 if (rows.length > 1) {
1032 alert(__("Please select only one user."));
1033 return;
1034 }
1035
1036 notify_progress("Loading, please wait...");
1037
1038 var id = rows[0];
1039
1040 xmlhttp.open("GET", "backend.php?op=user-details&id=" + id, true);
1041 xmlhttp.onreadystatechange=infobox_callback;
1042 xmlhttp.send(null);
1043
1044 }
1045
1046 function selectedFeedDetails() {
1047
1048 if (!xmlhttp_ready(xmlhttp)) {
1049 printLockingError();
1050 return
1051 }
1052
1053 var rows = getSelectedFeeds();
1054
1055 if (rows.length == 0) {
1056 alert(__("No feeds are selected."));
1057 return;
1058 }
1059
1060 if (rows.length > 1) {
1061 alert(__("Please select only one feed."));
1062 return;
1063 }
1064
1065 // var id = rows[0];
1066
1067 notify("");
1068
1069 xmlhttp.open("GET", "backend.php?op=feed-details&id=" +
1070 param_escape(rows.toString()), true);
1071 xmlhttp.onreadystatechange=infobox_callback;
1072 xmlhttp.send(null);
1073
1074 }
1075
1076 function editSelectedFilter() {
1077 var rows = getSelectedFilters();
1078
1079 if (rows.length == 0) {
1080 alert(__("No filters are selected."));
1081 return;
1082 }
1083
1084 if (rows.length > 1) {
1085 alert(__("Please select only one filter."));
1086 return;
1087 }
1088
1089 notify("");
1090
1091 editFilter(rows[0]);
1092
1093 }
1094
1095
1096 function editSelectedFeed() {
1097 var rows = getSelectedFeeds();
1098
1099 if (rows.length == 0) {
1100 alert(__("No feeds are selected."));
1101 return;
1102 }
1103
1104 if (rows.length > 1) {
1105 alert(__("Please select one feed."));
1106 return;
1107 }
1108
1109 notify("");
1110
1111 editFeed(rows[0]);
1112
1113 }
1114
1115 function editSelectedFeedCat() {
1116 var rows = getSelectedFeedCats();
1117
1118 if (rows.length == 0) {
1119 alert(__("No categories are selected."));
1120 return;
1121 }
1122
1123 if (rows.length > 1) {
1124 alert(__("Please select only one category."));
1125 return;
1126 }
1127
1128 notify("");
1129
1130 editFeedCat(rows[0]);
1131
1132 }
1133
1134 function piggie_callback() {
1135 var piggie = document.getElementById("piggie");
1136
1137 piggie.style.top = piggie_top;
1138 piggie.style.backgroundColor = "white";
1139 piggie.style.borderWidth = "1px";
1140
1141 if (piggie_fwd && piggie_top < 0) {
1142 setTimeout("piggie_callback()", 50);
1143 piggie_top = piggie_top + 10;
1144 } else if (piggie_fwd && piggie_top >= 0) {
1145 piggie_fwd = false;
1146 setTimeout("piggie_callback()", 50);
1147 } else if (!piggie_fwd && piggie_top > -400) {
1148 setTimeout("piggie_callback()", 50);
1149 piggie_top = piggie_top - 10;
1150 } else if (!piggie_fwd && piggie_top <= -400) {
1151 piggie.style.display = "none";
1152 piggie_fwd = true;
1153 }
1154 }
1155
1156 var piggie_opacity = 0;
1157
1158 function piggie2_callback() {
1159 var piggie = document.getElementById("piggie");
1160 piggie.style.top = 0;
1161 piggie.style.opacity = piggie_opacity;
1162 piggie.style.backgroundColor = "transparent";
1163 piggie.style.borderWidth = "0px";
1164
1165 if (piggie_fwd && piggie_opacity < 1) {
1166 setTimeout("piggie2_callback()", 50);
1167 piggie_opacity = piggie_opacity + 0.03;
1168 } else if (piggie_fwd && piggie_opacity >= 1) {
1169 piggie_fwd = false;
1170 setTimeout("piggie2_callback()", 50);
1171 } else if (!piggie_fwd && piggie_opacity > 0) {
1172 setTimeout("piggie2_callback()", 50);
1173 piggie_opacity = piggie_opacity - 0.03;
1174 } else if (!piggie_fwd && piggie_opacity <= 0) {
1175 piggie.style.display = "none";
1176 piggie_fwd = true;
1177 }
1178 }
1179
1180 function localPiggieFunction(enable) {
1181 if (enable) {
1182 debug("I LOVEDED IT!");
1183 var piggie = document.getElementById("piggie");
1184 piggie.style.display = "block";
1185
1186 if (navigator.userAgent.match("Gecko") && Math.random(1) > 0.5) {
1187 piggie2_callback();
1188 } else {
1189 piggie_callback();
1190 }
1191 }
1192 }
1193
1194 function validateOpmlImport() {
1195
1196 var opml_file = document.getElementById("opml_file");
1197
1198 if (opml_file.value.length == 0) {
1199 alert(__("No OPML file to upload."));
1200 return false;
1201 } else {
1202 return true;
1203 }
1204 }
1205
1206 function updateFilterList(sort_key) {
1207
1208 if (!xmlhttp_ready(xmlhttp)) {
1209 printLockingError();
1210 return
1211 }
1212
1213 // document.getElementById("prefContent").innerHTML = "Loading filters, please wait...";
1214
1215 // p_notify("Loading, please wait...");
1216
1217 xmlhttp.open("GET", "backend.php?op=pref-filters&sort=" +
1218 param_escape(sort_key), true);
1219 xmlhttp.onreadystatechange=filterlist_callback;
1220 xmlhttp.send(null);
1221
1222 }
1223
1224 function updateLabelList(sort_key) {
1225
1226 if (!xmlhttp_ready(xmlhttp)) {
1227 printLockingError();
1228 return
1229 }
1230
1231 // p_notify("Loading, please wait...");
1232
1233 // document.getElementById("prefContent").innerHTML = "Loading labels, please wait...";
1234
1235 xmlhttp.open("GET", "backend.php?op=pref-labels&sort=" +
1236 param_escape(sort_key), true);
1237 xmlhttp.onreadystatechange=labellist_callback;
1238 xmlhttp.send(null);
1239 }
1240
1241 function updatePrefsList() {
1242
1243 if (!xmlhttp_ready(xmlhttp)) {
1244 printLockingError();
1245 return
1246 }
1247
1248 // p_notify("Loading, please wait...");
1249
1250 xmlhttp.open("GET", "backend.php?op=pref-prefs", true);
1251 xmlhttp.onreadystatechange=prefslist_callback;
1252 xmlhttp.send(null);
1253
1254 }
1255
1256 function selectTab(id, noupdate, subop) {
1257
1258 // alert(id);
1259
1260 if (!id) id = active_tab;
1261
1262 try {
1263
1264 if (!xmlhttp_ready(xmlhttp)) {
1265 printLockingError();
1266 return
1267 }
1268
1269 try {
1270 var c = document.getElementById('prefContent');
1271 c.scrollTop = 0;
1272 } catch (e) { };
1273
1274 if (!noupdate) {
1275
1276 debug("selectTab: " + id + "(NU: " + noupdate + ")");
1277
1278 notify_progress("Loading, please wait...");
1279
1280 // close active infobox if needed
1281 closeInfoBox();
1282
1283 // clean up all current selections, just in case
1284 active_feed_cat = false;
1285 active_label = false;
1286
1287 if (id == "feedConfig") {
1288 updateFeedList();
1289 } else if (id == "filterConfig") {
1290 updateFilterList();
1291 } else if (id == "labelConfig") {
1292 updateLabelList();
1293 } else if (id == "genConfig") {
1294 updatePrefsList();
1295 } else if (id == "userConfig") {
1296 updateUsersList();
1297 } else if (id == "feedBrowser") {
1298 updateBigFeedBrowser();
1299 }
1300 }
1301
1302 var tab = document.getElementById(active_tab + "Tab");
1303
1304 if (tab) {
1305 if (tab.className.match("Selected")) {
1306 tab.className = "prefsTab";
1307 }
1308 }
1309
1310 tab = document.getElementById(id + "Tab");
1311
1312 if (tab) {
1313 if (!tab.className.match("Selected")) {
1314 tab.className = tab.className + "Selected";
1315 }
1316 }
1317
1318 active_tab = id;
1319
1320 } catch (e) {
1321 exception_error("selectTab", e);
1322 }
1323 }
1324
1325 function backend_sanity_check_callback() {
1326
1327 if (xmlhttp.readyState == 4) {
1328
1329 try {
1330
1331 if (sanity_check_done) {
1332 fatalError(11, "Sanity check request received twice. This can indicate "+
1333 "presence of Firebug or some other disrupting extension. "+
1334 "Please disable it and try again.");
1335 return;
1336 }
1337
1338 if (!xmlhttp.responseXML) {
1339 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp.responseText);
1340 return;
1341 }
1342
1343 var reply = xmlhttp.responseXML.firstChild.firstChild;
1344
1345 if (!reply) {
1346 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp.responseText);
1347 return;
1348 }
1349
1350 var error_code = reply.getAttribute("error-code");
1351
1352 if (error_code && error_code != 0) {
1353 return fatalError(error_code, reply.getAttribute("error-msg"));
1354 }
1355
1356 debug("sanity check ok");
1357
1358 var params = reply.nextSibling;
1359
1360 if (params) {
1361 debug('reading init-params...');
1362 var param = params.firstChild;
1363
1364 while (param) {
1365 var k = param.getAttribute("key");
1366 var v = param.getAttribute("value");
1367 debug(k + " => " + v);
1368 init_params[k] = v;
1369 param = param.nextSibling;
1370 }
1371 }
1372
1373 sanity_check_done = true;
1374
1375 init_second_stage();
1376
1377 } catch (e) {
1378 exception_error("backend_sanity_check_callback", e);
1379 }
1380 }
1381 }
1382
1383 function init_second_stage() {
1384
1385 try {
1386 active_tab = getInitParam("prefs_active_tab");
1387 if (!active_tab || active_tab == '0') active_tab = "genConfig";
1388
1389 document.onkeydown = pref_hotkey_handler;
1390
1391 var tab = getURLParam('tab');
1392
1393 caller_subop = getURLParam('subop');
1394
1395 if (tab) {
1396 active_tab = tab;
1397 }
1398
1399 if (navigator.userAgent.match("Opera")) {
1400 setTimeout("selectTab()", 500);
1401 } else {
1402 selectTab(active_tab);
1403 }
1404 notify("");
1405 } catch (e) {
1406 exception_error("init_second_stage", e);
1407 }
1408 }
1409
1410 function init() {
1411
1412 try {
1413
1414 if (arguments.callee.done) return;
1415 arguments.callee.done = true;
1416
1417 if (getURLParam('debug')) {
1418 document.getElementById('debug_output').style.display = 'block';
1419 debug('debug mode activated');
1420 }
1421
1422 // IE kludge
1423 if (!xmlhttp) {
1424 document.getElementById("prefContent").innerHTML =
1425 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1426 "to function properly. Your browser doesn't seem to support it.";
1427 return;
1428 }
1429
1430 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
1431 xmlhttp.onreadystatechange=backend_sanity_check_callback;
1432 xmlhttp.send(null);
1433
1434 } catch (e) {
1435 exception_error("init", e);
1436 }
1437 }
1438
1439 function categorizeSelectedFeeds() {
1440
1441 if (!xmlhttp_ready(xmlhttp)) {
1442 printLockingError();
1443 return
1444 }
1445
1446 var sel_rows = getSelectedFeeds();
1447
1448 var cat_sel = document.getElementById("sfeed_set_fcat");
1449 var cat_id = cat_sel[cat_sel.selectedIndex].value;
1450
1451 if (sel_rows.length > 0) {
1452
1453 notify_progress("Changing category of selected feeds...");
1454
1455 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
1456 param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
1457 xmlhttp.onreadystatechange=feedlist_callback;
1458 xmlhttp.send(null);
1459
1460 } else {
1461
1462 alert(__("No feeds are selected."));
1463
1464 }
1465
1466 }
1467
1468 function validatePrefsReset() {
1469 return confirm(__("Reset to defaults?"));
1470 }
1471
1472 function browseFeeds(limit) {
1473
1474 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=browse", true);
1475 xmlhttp.onreadystatechange=infobox_callback;
1476 xmlhttp.send(null);
1477
1478 }
1479
1480 function feedBrowserSubscribe() {
1481 try {
1482
1483 var selected = getSelectedFeedsFromBrowser();
1484
1485 if (selected.length > 0) {
1486 closeInfoBox();
1487 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=massSubscribe&ids="+
1488 param_escape(selected.toString()), true);
1489 xmlhttp.onreadystatechange=feedlist_callback;
1490 xmlhttp.send(null);
1491 } else {
1492 alert(__("No feeds are selected."));
1493 }
1494
1495 } catch (e) {
1496 exception_error("feedBrowserSubscribe", e);
1497 }
1498 }
1499
1500 function updateBigFeedBrowser(limit) {
1501
1502 if (!xmlhttp_ready(xmlhttp)) {
1503 printLockingError();
1504 return
1505 }
1506
1507 // p_notify("Loading, please wait...");
1508
1509 var query = "backend.php?op=pref-feed-browser";
1510
1511 var limit_sel = document.getElementById("feedBrowserLimit");
1512
1513 if (limit_sel) {
1514 var limit = limit_sel[limit_sel.selectedIndex].value;
1515 query = query + "&limit=" + param_escape(limit);
1516 }
1517
1518 xmlhttp.open("GET", query, true);
1519 xmlhttp.onreadystatechange=feed_browser_callback;
1520 xmlhttp.send(null);
1521 }
1522
1523 function browserToggleExpand(id) {
1524 try {
1525 /* if (feed_to_expand && feed_to_expand != id) {
1526 var d = document.getElementById("BRDET-" + feed_to_expand);
1527 d.style.display = "none";
1528 } */
1529
1530 if (!xmlhttp_ready(xmlhttp)) {
1531 printLockingError();
1532 return
1533 }
1534
1535 /* if (feed_to_expand && id != feed_to_expand) {
1536 Effect.Fade('BRDET-' + feed_to_expand, {duration : 0.5});
1537 } */
1538
1539 var d = document.getElementById("BRDET-" + id);
1540
1541 if (Element.visible(d)) {
1542 Effect.Fade(d, {duration : 0.5});
1543 } else {
1544 feed_to_expand = id;
1545
1546 xmlhttp.open("GET", "backend.php?op=pref-feed-browser&subop=details&id="
1547 + param_escape(id), true);
1548 xmlhttp.onreadystatechange=expand_feed_callback;
1549 xmlhttp.send(null);
1550 }
1551
1552 } catch (e) {
1553 exception_error("browserToggleExpand", e);
1554 }
1555 }
1556
1557 function selectPrefRows(kind, select) {
1558
1559 if (kind) {
1560 var opbarid = false;
1561 var nchk = false;
1562 var nrow = false;
1563 var lname = false;
1564
1565 if (kind == "feed") {
1566 opbarid = "feedOpToolbar";
1567 nrow = "FEEDR-";
1568 nchk = "FRCHK-";
1569 lname = "prefFeedList";
1570 } else if (kind == "fcat") {
1571 opbarid = "catOpToolbar";
1572 nrow = "FCATR-";
1573 nchk = "FCCHK-";
1574 lname = "prefFeedCatList";
1575 } else if (kind == "filter") {
1576 opbarid = "filterOpToolbar";
1577 nrow = "FILRR-";
1578 nchk = "FICHK-";
1579 lname = "prefFilterList";
1580 } else if (kind == "label") {
1581 opbarid = "labelOpToolbar";
1582 nrow = "LILRR-";
1583 nchk = "LICHK-";
1584 lname = "prefLabelList";
1585 } else if (kind == "user") {
1586 opbarid = "userOpToolbar";
1587 nrow = "UMRR-";
1588 nchk = "UMCHK-";
1589 lname = "prefUserList";
1590 }
1591
1592 if (opbarid) {
1593 selectTableRowsByIdPrefix(lname, nrow, nchk, select);
1594 disableContainerChildren(opbarid, !select);
1595 }
1596
1597 }
1598 }
1599
1600
1601 function toggleSelectPrefRow(sender, kind) {
1602
1603 toggleSelectRow(sender);
1604
1605 if (kind) {
1606 var opbarid = false;
1607 var nsel = -1;
1608
1609 if (kind == "feed") {
1610 opbarid = "feedOpToolbar";
1611 nsel = getSelectedFeeds();
1612 } else if (kind == "fcat") {
1613 opbarid = "catOpToolbar";
1614 nsel = getSelectedFeedCats();
1615 } else if (kind == "filter") {
1616 opbarid = "filterOpToolbar";
1617 nsel = getSelectedFilters();
1618 } else if (kind == "label") {
1619 opbarid = "labelOpToolbar";
1620 nsel = getSelectedLabels();
1621 } else if (kind == "user") {
1622 opbarid = "userOpToolbar";
1623 nsel = getSelectedUsers();
1624 }
1625
1626 if (opbarid && nsel != -1) {
1627 disableContainerChildren(opbarid, nsel == false);
1628 }
1629
1630 }
1631 }
1632
1633 function toggleSelectFBListRow(sender) {
1634 toggleSelectListRow(sender);
1635 disableContainerChildren("fbrOpToolbar", getSelectedFeedsFromBrowser() == 0);
1636 }
1637
1638 var seq = "";
1639
1640 function pref_hotkey_handler(e) {
1641 try {
1642
1643 var keycode;
1644
1645 if (!hotkeys_enabled) return;
1646
1647 if (window.event) {
1648 keycode = window.event.keyCode;
1649 } else if (e) {
1650 keycode = e.which;
1651 }
1652
1653 if (keycode == 13 || keycode == 27) {
1654 seq = "";
1655 } else {
1656 seq = seq + "" + keycode;
1657 }
1658
1659
1660 if (document.getElementById("piggie")) {
1661
1662 if (seq.match("807371717369")) {
1663 seq = "";
1664 localPiggieFunction(true);
1665 } else {
1666 localPiggieFunction(false);
1667 }
1668 }
1669
1670 } catch (e) {
1671 exception_error("pref_hotkey_handler", e);
1672 }
1673 }
1674
1675 function userSwitch() {
1676 var chooser = document.getElementById("userSwitch");
1677 var user = chooser[chooser.selectedIndex].value;
1678 window.location = "prefs.php?swu=" + user;
1679 }
1680
1681 function editFeedCats() {
1682 if (!xmlhttp_ready(xmlhttp)) {
1683 printLockingError();
1684 return
1685 }
1686
1687 document.getElementById("subscribe_to_feed_btn").disabled = true;
1688
1689 try {
1690 document.getElementById("top25_feeds_btn").disabled = true;
1691 } catch (e) {
1692 // this button is not always available, no-op if not found
1693 }
1694
1695 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
1696 xmlhttp.onreadystatechange=infobox_callback;
1697 xmlhttp.send(null);
1698 }
1699
1700 function showFeedsWithErrors() {
1701 displayDlg('feedUpdateErrors');
1702 }
1703
1704 function changeUserPassword() {
1705
1706 try {
1707
1708 if (!xmlhttp_ready(xmlhttp)) {
1709 printLockingError();
1710 return false;
1711 }
1712
1713 var query = Form.serialize("change_pass_form");
1714
1715 notify_progress("Trying to change password...");
1716
1717 xmlhttp.open("POST", "backend.php", true);
1718 xmlhttp.onreadystatechange=changepass_callback;
1719 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1720 xmlhttp.send(query);
1721
1722 } catch (e) {
1723 exception_error("changeUserPassword", e);
1724 }
1725
1726 return false;
1727 }
1728
1729 function changeUserEmail() {
1730
1731 try {
1732
1733 if (!xmlhttp_ready(xmlhttp)) {
1734 printLockingError();
1735 return false;
1736 }
1737
1738 var query = Form.serialize("change_email_form");
1739
1740 notify_progress("Trying to change e-mail...");
1741
1742 xmlhttp.open("POST", "backend.php", true);
1743 xmlhttp.onreadystatechange=notify_callback;
1744 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1745 xmlhttp.send(query);
1746
1747 } catch (e) {
1748 exception_error("changeUserPassword", e);
1749 }
1750
1751 return false;
1752
1753 }
1754
1755 function feedlistToggleSLAT() {
1756 notify_progress("Loading, please wait...");
1757 updateFeedList()
1758 }
1759
1760 function pubRegenKey() {
1761
1762 if (!xmlhttp_ready(xmlhttp)) {
1763 printLockingError();
1764 return false;
1765 }
1766
1767 var ok = confirm(__("Replace current publishing address with a new one?"));
1768
1769 if (ok) {
1770
1771 notify_progress("Trying to change address...");
1772
1773 xmlhttp.open("GET", "backend.php?op=rpc&subop=regenPubKey");
1774 xmlhttp.onreadystatechange=replace_pubkey_callback;
1775 xmlhttp.send(null);
1776 }
1777
1778 return false;
1779 }