]> git.wh0rd.org - tt-rss.git/blob - prefs.js
create label now uses dialog, code cleanups
[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 var sql_exp = document.forms["label_edit_form"].sql_exp.value;
733 var description = document.forms["label_edit_form"].description.value;
734
735 if (sql_exp.length == 0) {
736 alert("SQL Expression cannot be blank.");
737 return;
738 }
739
740 if (description.length == 0) {
741 alert("Caption field cannot be blank.");
742 return;
743 }
744
745 closeInfoBox();
746
747 notify("Saving label...");
748
749 active_label = false;
750
751 query = Form.serialize("label_edit_form");
752
753 xmlhttp.open("GET", "backend.php?" + query, true);
754 xmlhttp.onreadystatechange=labellist_callback;
755 xmlhttp.send(null);
756
757 return false;
758 }
759
760 function userEditSave() {
761
762 if (!xmlhttp_ready(xmlhttp)) {
763 printLockingError();
764 return
765 }
766
767 var login = document.forms["user_edit_form"].login.value;
768
769 if (login.length == 0) {
770 alert("Login field cannot be blank.");
771 return;
772 }
773
774 notify("Saving user...");
775
776 closeInfoBox();
777
778 var query = Form.serialize("user_edit_form");
779
780 xmlhttp.open("GET", "backend.php?" + query, true);
781 xmlhttp.onreadystatechange=userlist_callback;
782 xmlhttp.send(null);
783
784 return false;
785 }
786
787
788 function filterEditSave() {
789
790 if (!xmlhttp_ready(xmlhttp)) {
791 printLockingError();
792 return
793 }
794
795 var reg_exp = document.forms["filter_edit_form"].reg_exp.value;
796
797 if (reg_exp.length == 0) {
798 alert("Filter expression field cannot be blank.");
799 return;
800 }
801
802 notify("Saving filter...");
803
804 var query = Form.serialize("filter_edit_form");
805
806 closeInfoBox();
807
808 document.getElementById("create_filter_btn").disabled = false;
809
810 xmlhttp.open("GET", "backend.php?" + query, true);
811 xmlhttp.onreadystatechange=filterlist_callback;
812 xmlhttp.send(null);
813
814 return false;
815 }
816
817 function editSelectedLabel() {
818 var rows = getSelectedLabels();
819
820 if (rows.length == 0) {
821 alert("No labels are selected.");
822 return;
823 }
824
825 if (rows.length > 1) {
826 alert("Please select only one label.");
827 return;
828 }
829
830 notify("");
831
832 editLabel(rows[0]);
833
834 }
835
836 function editSelectedUser() {
837 var rows = getSelectedUsers();
838
839 if (rows.length == 0) {
840 alert("No users are selected.");
841 return;
842 }
843
844 if (rows.length > 1) {
845 alert("Please select only one user.");
846 return;
847 }
848
849 notify("");
850
851 editUser(rows[0]);
852 }
853
854 function resetSelectedUserPass() {
855 var rows = getSelectedUsers();
856
857 if (rows.length == 0) {
858 alert("No users are selected.");
859 return;
860 }
861
862 if (rows.length > 1) {
863 alert("Please select only one user.");
864 return;
865 }
866
867 var ok = confirm("Reset password of selected user?");
868
869 if (ok) {
870 notify("Resetting password for selected user...");
871
872 var id = rows[0];
873
874 xmlhttp.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
875 param_escape(id), true);
876 xmlhttp.onreadystatechange=userlist_callback;
877 xmlhttp.send(null);
878 }
879 }
880
881 function selectedUserDetails() {
882
883 if (!xmlhttp_ready(xmlhttp)) {
884 printLockingError();
885 return
886 }
887
888 var rows = getSelectedUsers();
889
890 if (rows.length == 0) {
891 alert("No users are selected.");
892 return;
893 }
894
895 if (rows.length > 1) {
896 alert("Please select only one user.");
897 return;
898 }
899
900 var id = rows[0];
901
902 notify("");
903
904 xmlhttp.open("GET", "backend.php?op=user-details&id=" + id, true);
905 xmlhttp.onreadystatechange=infobox_callback;
906 xmlhttp.send(null);
907
908 }
909
910 function selectedFeedDetails() {
911
912 if (!xmlhttp_ready(xmlhttp)) {
913 printLockingError();
914 return
915 }
916
917 var rows = getSelectedFeeds();
918
919 if (rows.length == 0) {
920 alert("No feeds are selected.");
921 return;
922 }
923
924 if (rows.length > 1) {
925 notify("Please select only one feed.");
926 return;
927 }
928
929 // var id = rows[0];
930
931 notify("");
932
933 xmlhttp.open("GET", "backend.php?op=feed-details&id=" +
934 param_escape(rows.toString()), true);
935 xmlhttp.onreadystatechange=infobox_callback;
936 xmlhttp.send(null);
937
938 }
939
940 function editSelectedFilter() {
941 var rows = getSelectedFilters();
942
943 if (rows.length == 0) {
944 alert("No filters are selected.");
945 return;
946 }
947
948 if (rows.length > 1) {
949 alert("Please select only one filter.");
950 return;
951 }
952
953 notify("");
954
955 editFilter(rows[0]);
956
957 }
958
959
960 function editSelectedFeed() {
961 var rows = getSelectedFeeds();
962
963 if (rows.length == 0) {
964 notify("No feeds are selected.");
965 return;
966 }
967
968 if (rows.length > 1) {
969 notify("Please select one feed.");
970 return;
971 }
972
973 notify("");
974
975 editFeed(rows[0]);
976
977 }
978
979 function editSelectedFeedCat() {
980 var rows = getSelectedFeedCats();
981
982 if (rows.length == 0) {
983 alert("No categories are selected.");
984 return;
985 }
986
987 if (rows.length > 1) {
988 alert("Please select only one category.");
989 return;
990 }
991
992 notify("");
993
994 editFeedCat(rows[0]);
995
996 }
997
998 function piggie_callback() {
999 var piggie = document.getElementById("piggie");
1000
1001 piggie.style.top = piggie_top;
1002 piggie.style.backgroundColor = "white";
1003 piggie.style.borderWidth = "1px";
1004
1005 if (piggie_fwd && piggie_top < 0) {
1006 setTimeout("piggie_callback()", 50);
1007 piggie_top = piggie_top + 10;
1008 } else if (piggie_fwd && piggie_top >= 0) {
1009 piggie_fwd = false;
1010 setTimeout("piggie_callback()", 50);
1011 } else if (!piggie_fwd && piggie_top > -400) {
1012 setTimeout("piggie_callback()", 50);
1013 piggie_top = piggie_top - 10;
1014 } else if (!piggie_fwd && piggie_top <= -400) {
1015 piggie.style.display = "none";
1016 piggie_fwd = true;
1017 }
1018 }
1019
1020 var piggie_opacity = 0;
1021
1022 function piggie2_callback() {
1023 var piggie = document.getElementById("piggie");
1024 piggie.style.top = 0;
1025 piggie.style.opacity = piggie_opacity;
1026 piggie.style.backgroundColor = "transparent";
1027 piggie.style.borderWidth = "0px";
1028
1029 if (piggie_fwd && piggie_opacity < 1) {
1030 setTimeout("piggie2_callback()", 50);
1031 piggie_opacity = piggie_opacity + 0.03;
1032 } else if (piggie_fwd && piggie_opacity >= 1) {
1033 piggie_fwd = false;
1034 setTimeout("piggie2_callback()", 50);
1035 } else if (!piggie_fwd && piggie_opacity > 0) {
1036 setTimeout("piggie2_callback()", 50);
1037 piggie_opacity = piggie_opacity - 0.03;
1038 } else if (!piggie_fwd && piggie_opacity <= 0) {
1039 piggie.style.display = "none";
1040 piggie_fwd = true;
1041 }
1042 }
1043
1044 function localPiggieFunction(enable) {
1045 if (enable) {
1046 debug("I LOVEDED IT!");
1047 var piggie = document.getElementById("piggie");
1048 piggie.style.display = "block";
1049
1050 if (navigator.userAgent.match("Gecko") && Math.random(1) > 0.5) {
1051 piggie2_callback();
1052 } else {
1053 piggie_callback();
1054 }
1055 }
1056 }
1057
1058 function validateOpmlImport() {
1059
1060 var opml_file = document.getElementById("opml_file");
1061
1062 if (opml_file.value.length == 0) {
1063 alert("No OPML file to upload.");
1064 return false;
1065 } else {
1066 return true;
1067 }
1068 }
1069
1070 function updateFilterList() {
1071
1072 if (!xmlhttp_ready(xmlhttp)) {
1073 printLockingError();
1074 return
1075 }
1076
1077 // document.getElementById("prefContent").innerHTML = "Loading filters, please wait...";
1078
1079 // p_notify("Loading, please wait...");
1080
1081 xmlhttp.open("GET", "backend.php?op=pref-filters", true);
1082 xmlhttp.onreadystatechange=filterlist_callback;
1083 xmlhttp.send(null);
1084
1085 }
1086
1087 function updateLabelList() {
1088
1089 if (!xmlhttp_ready(xmlhttp)) {
1090 printLockingError();
1091 return
1092 }
1093
1094 // p_notify("Loading, please wait...");
1095
1096 // document.getElementById("prefContent").innerHTML = "Loading labels, please wait...";
1097
1098 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
1099 xmlhttp.onreadystatechange=labellist_callback;
1100 xmlhttp.send(null);
1101 }
1102
1103 function updatePrefsList() {
1104
1105 if (!xmlhttp_ready(xmlhttp)) {
1106 printLockingError();
1107 return
1108 }
1109
1110 // p_notify("Loading, please wait...");
1111
1112 xmlhttp.open("GET", "backend.php?op=pref-prefs", true);
1113 xmlhttp.onreadystatechange=prefslist_callback;
1114 xmlhttp.send(null);
1115
1116 }
1117
1118 function selectTab(id, noupdate) {
1119
1120 // alert(id);
1121
1122 if (!id) id = active_tab;
1123
1124 try {
1125
1126 if (!xmlhttp_ready(xmlhttp)) {
1127 printLockingError();
1128 return
1129 }
1130
1131 if (!noupdate) {
1132
1133 debug("selectTab: " + id + "(NU: " + noupdate + ")");
1134
1135 notify("Loading, please wait...", true);
1136
1137 // close active infobox if needed
1138 closeInfoBox();
1139
1140 // clean up all current selections, just in case
1141 active_feed_cat = false;
1142 active_label = false;
1143
1144 if (id == "feedConfig") {
1145 updateFeedList();
1146 } else if (id == "filterConfig") {
1147 updateFilterList();
1148 } else if (id == "labelConfig") {
1149 updateLabelList();
1150 } else if (id == "genConfig") {
1151 updatePrefsList();
1152 } else if (id == "userConfig") {
1153 updateUsersList();
1154 } else if (id == "feedBrowser") {
1155 updateBigFeedBrowser();
1156 }
1157 }
1158
1159 var tab = document.getElementById(active_tab + "Tab");
1160
1161 if (tab) {
1162 if (tab.className.match("Selected")) {
1163 tab.className = "prefsTab";
1164 }
1165 }
1166
1167 tab = document.getElementById(id + "Tab");
1168
1169 if (tab) {
1170 if (!tab.className.match("Selected")) {
1171 tab.className = tab.className + "Selected";
1172 }
1173 }
1174
1175 if (active_tab != id) {
1176 storeInitParam("prefs_active_tab", id);
1177 }
1178
1179 active_tab = id;
1180
1181 } catch (e) {
1182 exception_error("selectTab", e);
1183 }
1184 }
1185
1186 function backend_sanity_check_callback() {
1187
1188 if (xmlhttp.readyState == 4) {
1189
1190 try {
1191
1192 if (!xmlhttp.responseXML) {
1193 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp.responseText);
1194 return;
1195 }
1196
1197 var reply = xmlhttp.responseXML.firstChild.firstChild;
1198
1199 if (!reply) {
1200 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp.responseText);
1201 return;
1202 }
1203
1204 var error_code = reply.getAttribute("error-code");
1205
1206 if (error_code && error_code != 0) {
1207 return fatalError(error_code, reply.getAttribute("error-msg"));
1208 }
1209
1210 debug("sanity check ok");
1211
1212 var params = reply.nextSibling;
1213
1214 if (params) {
1215 debug('reading init-params...');
1216 var param = params.firstChild;
1217
1218 while (param) {
1219 var k = param.getAttribute("key");
1220 var v = param.getAttribute("value");
1221 debug(k + " => " + v);
1222 init_params[k] = v;
1223 param = param.nextSibling;
1224 }
1225 }
1226
1227 init_second_stage();
1228
1229 } catch (e) {
1230 exception_error("backend_sanity_check_callback", e);
1231 }
1232 }
1233 }
1234
1235 function init_second_stage() {
1236
1237 try {
1238 active_tab = getInitParam("prefs_active_tab");
1239 if (!active_tab) active_tab = "genConfig";
1240
1241 document.onkeydown = pref_hotkey_handler;
1242
1243 if (navigator.userAgent.match("Opera")) {
1244 setTimeout("selectTab()", 500);
1245 } else {
1246 selectTab(active_tab);
1247 }
1248 notify("");
1249 } catch (e) {
1250 exception_error("init_second_stage", e);
1251 }
1252 }
1253
1254 function init() {
1255
1256 try {
1257
1258 if (arguments.callee.done) return;
1259 arguments.callee.done = true;
1260
1261 if (getURLParam('debug')) {
1262 document.getElementById('debug_output').style.display = 'block';
1263 debug('debug mode activated');
1264 }
1265
1266 // IE kludge
1267 if (!xmlhttp) {
1268 document.getElementById("prefContent").innerHTML =
1269 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1270 "to function properly. Your browser doesn't seem to support it.";
1271 return;
1272 }
1273
1274 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
1275 xmlhttp.onreadystatechange=backend_sanity_check_callback;
1276 xmlhttp.send(null);
1277
1278 } catch (e) {
1279 exception_error("init", e);
1280 }
1281 }
1282
1283 function categorizeSelectedFeeds() {
1284
1285 if (!xmlhttp_ready(xmlhttp)) {
1286 printLockingError();
1287 return
1288 }
1289
1290 var sel_rows = getSelectedFeeds();
1291
1292 var cat_sel = document.getElementById("sfeed_set_fcat");
1293 var cat_id = cat_sel[cat_sel.selectedIndex].value;
1294
1295 if (sel_rows.length > 0) {
1296
1297 notify("Changing category of selected feeds...");
1298
1299 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
1300 param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
1301 xmlhttp.onreadystatechange=feedlist_callback;
1302 xmlhttp.send(null);
1303
1304 } else {
1305
1306 alert("No feeds are selected.");
1307
1308 }
1309
1310 }
1311
1312 function validatePrefsReset() {
1313 return confirm("Reset to defaults?");
1314 }
1315
1316 function browseFeeds(limit) {
1317
1318 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=browse", true);
1319 xmlhttp.onreadystatechange=infobox_callback;
1320 xmlhttp.send(null);
1321
1322 }
1323
1324 function feedBrowserSubscribe() {
1325 try {
1326
1327 var selected = getSelectedFeedsFromBrowser();
1328
1329 if (selected.length > 0) {
1330 closeInfoBox();
1331 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=massSubscribe&ids="+
1332 param_escape(selected.toString()), true);
1333 xmlhttp.onreadystatechange=feedlist_callback;
1334 xmlhttp.send(null);
1335 } else {
1336 alert("No feeds are selected.");
1337 }
1338
1339 } catch (e) {
1340 exception_error("feedBrowserSubscribe", e);
1341 }
1342 }
1343
1344 function updateBigFeedBrowser(limit) {
1345
1346 if (!xmlhttp_ready(xmlhttp)) {
1347 printLockingError();
1348 return
1349 }
1350
1351 // p_notify("Loading, please wait...");
1352
1353 var query = "backend.php?op=pref-feed-browser";
1354
1355 var limit_sel = document.getElementById("feedBrowserLimit");
1356
1357 if (limit_sel) {
1358 var limit = limit_sel[limit_sel.selectedIndex].value;
1359 query = query + "&limit=" + param_escape(limit);
1360 }
1361
1362 xmlhttp.open("GET", query, true);
1363 xmlhttp.onreadystatechange=feed_browser_callback;
1364 xmlhttp.send(null);
1365 }
1366
1367 function browserToggleExpand(id) {
1368 try {
1369 /* if (feed_to_expand && feed_to_expand != id) {
1370 var d = document.getElementById("BRDET-" + feed_to_expand);
1371 d.style.display = "none";
1372 } */
1373
1374 if (!xmlhttp_ready(xmlhttp)) {
1375 printLockingError();
1376 return
1377 }
1378
1379 var d = document.getElementById("BRDET-" + id);
1380
1381 if (d.style.display == "block") {
1382 d.style.display = "none";
1383
1384 } else {
1385
1386 feed_to_expand = id;
1387
1388 d.style.display = "block";
1389 d.innerHTML = "Loading, please wait...";
1390
1391 xmlhttp.open("GET", "backend.php?op=pref-feed-browser&subop=details&id="
1392 + param_escape(id), true);
1393 xmlhttp.onreadystatechange=expand_feed_callback;
1394 xmlhttp.send(null);
1395 }
1396
1397 } catch (e) {
1398 exception_error("browserExpand", e);
1399 }
1400 }
1401
1402 function validateNewPassword(form) {
1403 if (form.OLD_PASSWORD.value == "") {
1404 alert("Old password cannot be blank");
1405 return false;
1406 }
1407 if (form.NEW_PASSWORD.value == "") {
1408 alert("New password cannot be blank");
1409 return false;
1410 }
1411 return true;
1412 }
1413
1414 function selectPrefRows(kind, select) {
1415
1416 if (kind) {
1417 var opbarid = false;
1418 var nchk = false;
1419 var nrow = false;
1420 var lname = false;
1421
1422 if (kind == "feed") {
1423 opbarid = "feedOpToolbar";
1424 nrow = "FEEDR-";
1425 nchk = "FRCHK-";
1426 lname = "prefFeedList";
1427 } else if (kind == "fcat") {
1428 opbarid = "catOpToolbar";
1429 nrow = "FCATR-";
1430 nchk = "FCHK-";
1431 lname = "prefFeedCatList";
1432 } else if (kind == "filter") {
1433 opbarid = "filterOpToolbar";
1434 nrow = "FILRR-";
1435 nchk = "FICHK-";
1436 lname = "prefFilterList";
1437 } else if (kind == "label") {
1438 opbarid = "labelOpToolbar";
1439 nrow = "LILRR-";
1440 nchk = "LICHK-";
1441 lname = "prefLabelList";
1442 } else if (kind == "user") {
1443 opbarid = "userOpToolbar";
1444 nrow = "UMRR-";
1445 nchk = "UMCHK-";
1446 lname = "prefUserList";
1447 }
1448
1449 if (opbarid) {
1450 selectTableRowsByIdPrefix(lname, nrow, nchk, select);
1451 disableContainerChildren(opbarid, !select);
1452 }
1453
1454 }
1455 }
1456
1457
1458 function toggleSelectPrefRow(sender, kind) {
1459
1460 toggleSelectRow(sender);
1461
1462 if (kind) {
1463 var opbarid = false;
1464 var nsel = -1;
1465
1466 if (kind == "feed") {
1467 opbarid = "feedOpToolbar";
1468 nsel = getSelectedFeeds();
1469 } else if (kind == "fcat") {
1470 opbarid = "catOpToolbar";
1471 nsel = getSelectedFeedCats();
1472 } else if (kind == "filter") {
1473 opbarid = "filterOpToolbar";
1474 nsel = getSelectedFilters();
1475 } else if (kind == "label") {
1476 opbarid = "labelOpToolbar";
1477 nsel = getSelectedLabels();
1478 } else if (kind == "user") {
1479 opbarid = "userOpToolbar";
1480 nsel = getSelectedUsers();
1481 }
1482
1483 if (opbarid && nsel != -1) {
1484 disableContainerChildren(opbarid, nsel == false);
1485 }
1486
1487 }
1488 }
1489
1490 function toggleSelectFBListRow(sender) {
1491 toggleSelectListRow(sender);
1492 disableContainerChildren("fbrOpToolbar", getSelectedFeedsFromBrowser() == 0);
1493 }
1494
1495 var seq = "";
1496
1497 function pref_hotkey_handler(e) {
1498 try {
1499
1500 var keycode;
1501
1502 if (!hotkeys_enabled) return;
1503
1504 if (window.event) {
1505 keycode = window.event.keyCode;
1506 } else if (e) {
1507 keycode = e.which;
1508 }
1509
1510 if (keycode == 13 || keycode == 27) {
1511 seq = "";
1512 } else {
1513 seq = seq + "" + keycode;
1514 }
1515
1516
1517 if (document.getElementById("piggie")) {
1518
1519 if (seq.match("807371717369")) {
1520 seq = "";
1521 localPiggieFunction(true);
1522 } else {
1523 localPiggieFunction(false);
1524 }
1525 }
1526
1527 } catch (e) {
1528 exception_error("pref_hotkey_handler", e);
1529 }
1530 }
1531
1532