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