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