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