]> git.wh0rd.org - tt-rss.git/blob - prefs.js
fix broken piggie
[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 debug("I LOVEDED IT!");
1062 var piggie = document.getElementById("piggie");
1063 piggie.style.display = "block";
1064
1065 if (navigator.userAgent.match("Gecko") && Math.random(1) > 0.5) {
1066 piggie2_callback();
1067 } else {
1068 piggie_callback();
1069 }
1070 }
1071 }
1072
1073 function validateOpmlImport() {
1074
1075 var opml_file = document.getElementById("opml_file");
1076
1077 if (opml_file.value.length == 0) {
1078 alert("No OPML file to upload.");
1079 return false;
1080 } else {
1081 return true;
1082 }
1083 }
1084
1085 function updateFilterList() {
1086
1087 if (!xmlhttp_ready(xmlhttp)) {
1088 printLockingError();
1089 return
1090 }
1091
1092 // document.getElementById("prefContent").innerHTML = "Loading filters, please wait...";
1093
1094 // p_notify("Loading, please wait...");
1095
1096 xmlhttp.open("GET", "backend.php?op=pref-filters", true);
1097 xmlhttp.onreadystatechange=filterlist_callback;
1098 xmlhttp.send(null);
1099
1100 }
1101
1102 function updateLabelList() {
1103
1104 if (!xmlhttp_ready(xmlhttp)) {
1105 printLockingError();
1106 return
1107 }
1108
1109 // p_notify("Loading, please wait...");
1110
1111 // document.getElementById("prefContent").innerHTML = "Loading labels, please wait...";
1112
1113 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
1114 xmlhttp.onreadystatechange=labellist_callback;
1115 xmlhttp.send(null);
1116 }
1117
1118 function updatePrefsList() {
1119
1120 if (!xmlhttp_ready(xmlhttp)) {
1121 printLockingError();
1122 return
1123 }
1124
1125 // p_notify("Loading, please wait...");
1126
1127 xmlhttp.open("GET", "backend.php?op=pref-prefs", true);
1128 xmlhttp.onreadystatechange=prefslist_callback;
1129 xmlhttp.send(null);
1130
1131 }
1132
1133 function selectTab(id, noupdate) {
1134
1135 // alert(id);
1136
1137 if (!id) id = active_tab;
1138
1139 try {
1140
1141 if (!xmlhttp_ready(xmlhttp)) {
1142 printLockingError();
1143 return
1144 }
1145
1146 if (!noupdate) {
1147
1148 debug("selectTab: " + id + "(NU: " + noupdate + ")");
1149
1150 notify("Loading, please wait...", true);
1151
1152 // close active infobox if needed
1153 closeInfoBox();
1154
1155 // clean up all current selections, just in case
1156 active_feed_cat = false;
1157 active_label = false;
1158
1159 if (id == "feedConfig") {
1160 updateFeedList();
1161 } else if (id == "filterConfig") {
1162 updateFilterList();
1163 } else if (id == "labelConfig") {
1164 updateLabelList();
1165 } else if (id == "genConfig") {
1166 updatePrefsList();
1167 } else if (id == "userConfig") {
1168 updateUsersList();
1169 } else if (id == "feedBrowser") {
1170 updateBigFeedBrowser();
1171 }
1172 }
1173
1174 var tab = document.getElementById(active_tab + "Tab");
1175
1176 if (tab) {
1177 if (tab.className.match("Selected")) {
1178 tab.className = "prefsTab";
1179 }
1180 }
1181
1182 tab = document.getElementById(id + "Tab");
1183
1184 if (tab) {
1185 if (!tab.className.match("Selected")) {
1186 tab.className = tab.className + "Selected";
1187 }
1188 }
1189
1190 if (active_tab != id) {
1191 storeInitParam("prefs_active_tab", id);
1192 }
1193
1194 active_tab = id;
1195
1196 } catch (e) {
1197 exception_error("selectTab", e);
1198 }
1199 }
1200
1201 function backend_sanity_check_callback() {
1202
1203 if (xmlhttp.readyState == 4) {
1204
1205 try {
1206
1207 if (!xmlhttp.responseXML) {
1208 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp.responseText);
1209 return;
1210 }
1211
1212 var reply = xmlhttp.responseXML.firstChild.firstChild;
1213
1214 if (!reply) {
1215 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp.responseText);
1216 return;
1217 }
1218
1219 var error_code = reply.getAttribute("error-code");
1220
1221 if (error_code && error_code != 0) {
1222 return fatalError(error_code, reply.getAttribute("error-msg"));
1223 }
1224
1225 debug("sanity check ok");
1226
1227 var params = reply.nextSibling;
1228
1229 if (params) {
1230 debug('reading init-params...');
1231 var param = params.firstChild;
1232
1233 while (param) {
1234 var k = param.getAttribute("key");
1235 var v = param.getAttribute("value");
1236 debug(k + " => " + v);
1237 init_params[k] = v;
1238 param = param.nextSibling;
1239 }
1240 }
1241
1242 init_second_stage();
1243
1244 } catch (e) {
1245 exception_error("backend_sanity_check_callback", e);
1246 }
1247 }
1248 }
1249
1250 function init_second_stage() {
1251
1252 try {
1253 active_tab = getInitParam("prefs_active_tab");
1254 if (!active_tab) active_tab = "genConfig";
1255
1256 document.onkeydown = pref_hotkey_handler;
1257
1258 if (navigator.userAgent.match("Opera")) {
1259 setTimeout("selectTab()", 500);
1260 } else {
1261 selectTab(active_tab);
1262 }
1263 notify("");
1264 } catch (e) {
1265 exception_error("init_second_stage", e);
1266 }
1267 }
1268
1269 function init() {
1270
1271 try {
1272
1273 if (arguments.callee.done) return;
1274 arguments.callee.done = true;
1275
1276 if (getURLParam('debug')) {
1277 document.getElementById('debug_output').style.display = 'block';
1278 debug('debug mode activated');
1279 }
1280
1281 // IE kludge
1282 if (!xmlhttp) {
1283 document.getElementById("prefContent").innerHTML =
1284 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1285 "to function properly. Your browser doesn't seem to support it.";
1286 return;
1287 }
1288
1289 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
1290 xmlhttp.onreadystatechange=backend_sanity_check_callback;
1291 xmlhttp.send(null);
1292
1293 } catch (e) {
1294 exception_error("init", e);
1295 }
1296 }
1297
1298 function categorizeSelectedFeeds() {
1299
1300 if (!xmlhttp_ready(xmlhttp)) {
1301 printLockingError();
1302 return
1303 }
1304
1305 var sel_rows = getSelectedFeeds();
1306
1307 var cat_sel = document.getElementById("sfeed_set_fcat");
1308 var cat_id = cat_sel[cat_sel.selectedIndex].value;
1309
1310 if (sel_rows.length > 0) {
1311
1312 notify("Changing category of selected feeds...");
1313
1314 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
1315 param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
1316 xmlhttp.onreadystatechange=feedlist_callback;
1317 xmlhttp.send(null);
1318
1319 } else {
1320
1321 alert("No feeds are selected.");
1322
1323 }
1324
1325 }
1326
1327 function validatePrefsReset() {
1328 return confirm("Reset to defaults?");
1329 }
1330
1331 function browseFeeds(limit) {
1332
1333 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=browse", true);
1334 xmlhttp.onreadystatechange=infobox_callback;
1335 xmlhttp.send(null);
1336
1337 }
1338
1339 function feedBrowserSubscribe() {
1340 try {
1341
1342 var selected = getSelectedFeedsFromBrowser();
1343
1344 if (selected.length > 0) {
1345 closeInfoBox();
1346 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=massSubscribe&ids="+
1347 param_escape(selected.toString()), true);
1348 xmlhttp.onreadystatechange=feedlist_callback;
1349 xmlhttp.send(null);
1350 } else {
1351 alert("No feeds are selected.");
1352 }
1353
1354 } catch (e) {
1355 exception_error("feedBrowserSubscribe", e);
1356 }
1357 }
1358
1359 function updateBigFeedBrowser(limit) {
1360
1361 if (!xmlhttp_ready(xmlhttp)) {
1362 printLockingError();
1363 return
1364 }
1365
1366 // p_notify("Loading, please wait...");
1367
1368 var query = "backend.php?op=pref-feed-browser";
1369
1370 var limit_sel = document.getElementById("feedBrowserLimit");
1371
1372 if (limit_sel) {
1373 var limit = limit_sel[limit_sel.selectedIndex].value;
1374 query = query + "&limit=" + param_escape(limit);
1375 }
1376
1377 xmlhttp.open("GET", query, true);
1378 xmlhttp.onreadystatechange=feed_browser_callback;
1379 xmlhttp.send(null);
1380 }
1381
1382 function browserToggleExpand(id) {
1383 try {
1384 /* if (feed_to_expand && feed_to_expand != id) {
1385 var d = document.getElementById("BRDET-" + feed_to_expand);
1386 d.style.display = "none";
1387 } */
1388
1389 if (!xmlhttp_ready(xmlhttp)) {
1390 printLockingError();
1391 return
1392 }
1393
1394 var d = document.getElementById("BRDET-" + id);
1395
1396 if (d.style.display == "block") {
1397 d.style.display = "none";
1398
1399 } else {
1400
1401 feed_to_expand = id;
1402
1403 d.style.display = "block";
1404 d.innerHTML = "Loading, please wait...";
1405
1406 xmlhttp.open("GET", "backend.php?op=pref-feed-browser&subop=details&id="
1407 + param_escape(id), true);
1408 xmlhttp.onreadystatechange=expand_feed_callback;
1409 xmlhttp.send(null);
1410 }
1411
1412 } catch (e) {
1413 exception_error("browserExpand", e);
1414 }
1415 }
1416
1417 function validateNewPassword(form) {
1418 if (form.OLD_PASSWORD.value == "") {
1419 alert("Old password cannot be blank");
1420 return false;
1421 }
1422 if (form.NEW_PASSWORD.value == "") {
1423 alert("New password cannot be blank");
1424 return false;
1425 }
1426 return true;
1427 }
1428
1429 function selectPrefRows(kind, select) {
1430
1431 if (kind) {
1432 var opbarid = false;
1433 var nchk = false;
1434 var nrow = false;
1435 var lname = false;
1436
1437 if (kind == "feed") {
1438 opbarid = "feedOpToolbar";
1439 nrow = "FEEDR-";
1440 nchk = "FRCHK-";
1441 lname = "prefFeedList";
1442 } else if (kind == "fcat") {
1443 opbarid = "catOpToolbar";
1444 nrow = "FCATR-";
1445 nchk = "FCHK-";
1446 lname = "prefFeedCatList";
1447 } else if (kind == "filter") {
1448 opbarid = "filterOpToolbar";
1449 nrow = "FILRR-";
1450 nchk = "FICHK-";
1451 lname = "prefFilterList";
1452 } else if (kind == "label") {
1453 opbarid = "labelOpToolbar";
1454 nrow = "LILRR-";
1455 nchk = "LCHK-";
1456 lname = "prefLabelList";
1457 } else if (kind == "user") {
1458 opbarid = "userOpToolbar";
1459 nrow = "UMRR-";
1460 nchk = "UMCHK-";
1461 lname = "prefUserList";
1462 }
1463
1464 if (opbarid) {
1465 selectTableRowsByIdPrefix(lname, nrow, nchk, select);
1466 disableContainerChildren(opbarid, !select);
1467 }
1468
1469 }
1470 }
1471
1472
1473 function toggleSelectPrefRow(sender, kind) {
1474
1475 toggleSelectRow(sender);
1476
1477 if (kind) {
1478 var opbarid = false;
1479 var nsel = -1;
1480
1481 if (kind == "feed") {
1482 opbarid = "feedOpToolbar";
1483 nsel = getSelectedFeeds();
1484 } else if (kind == "fcat") {
1485 opbarid = "catOpToolbar";
1486 nsel = getSelectedFeedCats();
1487 } else if (kind == "filter") {
1488 opbarid = "filterOpToolbar";
1489 nsel = getSelectedFilters();
1490 } else if (kind == "label") {
1491 opbarid = "labelOpToolbar";
1492 nsel = getSelectedLabels();
1493 } else if (kind == "user") {
1494 opbarid = "userOpToolbar";
1495 nsel = getSelectedUsers();
1496 }
1497
1498 if (opbarid && nsel != -1) {
1499 disableContainerChildren(opbarid, nsel == false);
1500 }
1501
1502 }
1503 }
1504
1505 function toggleSelectFBListRow(sender) {
1506 toggleSelectListRow(sender);
1507 disableContainerChildren("fbrOpToolbar", getSelectedFeedsFromBrowser() == 0);
1508 }
1509
1510 var seq = "";
1511
1512 function pref_hotkey_handler(e) {
1513 try {
1514
1515 var keycode;
1516
1517 if (!hotkeys_enabled) return;
1518
1519 if (window.event) {
1520 keycode = window.event.keyCode;
1521 } else if (e) {
1522 keycode = e.which;
1523 }
1524
1525 if (keycode == 13 || keycode == 27) {
1526 seq = "";
1527 } else {
1528 seq = seq + "" + keycode;
1529 }
1530
1531
1532 if (document.getElementById("piggie")) {
1533
1534 if (seq.match("807371717369")) {
1535 seq = "";
1536 localPiggieFunction(true);
1537 } else {
1538 localPiggieFunction(false);
1539 }
1540 }
1541
1542 } catch (e) {
1543 exception_error("pref_hotkey_handler", e);
1544 }
1545 }
1546
1547