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