]> git.wh0rd.org - tt-rss.git/blob - prefs.js
add persistent storage for toolbar view options, bump schema
[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 active_tab = id;
1223
1224 } catch (e) {
1225 exception_error("selectTab", e);
1226 }
1227 }
1228
1229 function backend_sanity_check_callback() {
1230
1231 if (xmlhttp.readyState == 4) {
1232
1233 try {
1234
1235 if (!xmlhttp.responseXML) {
1236 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp.responseText);
1237 return;
1238 }
1239
1240 var reply = xmlhttp.responseXML.firstChild.firstChild;
1241
1242 if (!reply) {
1243 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp.responseText);
1244 return;
1245 }
1246
1247 var error_code = reply.getAttribute("error-code");
1248
1249 if (error_code && error_code != 0) {
1250 return fatalError(error_code, reply.getAttribute("error-msg"));
1251 }
1252
1253 debug("sanity check ok");
1254
1255 var params = reply.nextSibling;
1256
1257 if (params) {
1258 debug('reading init-params...');
1259 var param = params.firstChild;
1260
1261 while (param) {
1262 var k = param.getAttribute("key");
1263 var v = param.getAttribute("value");
1264 debug(k + " => " + v);
1265 init_params[k] = v;
1266 param = param.nextSibling;
1267 }
1268 }
1269
1270 init_second_stage();
1271
1272 } catch (e) {
1273 exception_error("backend_sanity_check_callback", e);
1274 }
1275 }
1276 }
1277
1278 function init_second_stage() {
1279
1280 try {
1281 active_tab = getInitParam("prefs_active_tab");
1282 if (!active_tab) active_tab = "genConfig";
1283
1284 document.onkeydown = pref_hotkey_handler;
1285
1286 var tab = getURLParam('tab');
1287
1288 caller_subop = getURLParam('subop');
1289
1290 if (tab) {
1291 active_tab = tab;
1292 }
1293
1294 if (navigator.userAgent.match("Opera")) {
1295 setTimeout("selectTab()", 500);
1296 } else {
1297 selectTab(active_tab);
1298 }
1299 notify("");
1300 } catch (e) {
1301 exception_error("init_second_stage", e);
1302 }
1303 }
1304
1305 function init() {
1306
1307 try {
1308
1309 if (arguments.callee.done) return;
1310 arguments.callee.done = true;
1311
1312 if (getURLParam('debug')) {
1313 document.getElementById('debug_output').style.display = 'block';
1314 debug('debug mode activated');
1315 }
1316
1317 // IE kludge
1318 if (!xmlhttp) {
1319 document.getElementById("prefContent").innerHTML =
1320 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1321 "to function properly. Your browser doesn't seem to support it.";
1322 return;
1323 }
1324
1325 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
1326 xmlhttp.onreadystatechange=backend_sanity_check_callback;
1327 xmlhttp.send(null);
1328
1329 } catch (e) {
1330 exception_error("init", e);
1331 }
1332 }
1333
1334 function categorizeSelectedFeeds() {
1335
1336 if (!xmlhttp_ready(xmlhttp)) {
1337 printLockingError();
1338 return
1339 }
1340
1341 var sel_rows = getSelectedFeeds();
1342
1343 var cat_sel = document.getElementById("sfeed_set_fcat");
1344 var cat_id = cat_sel[cat_sel.selectedIndex].value;
1345
1346 if (sel_rows.length > 0) {
1347
1348 notify_progress("Changing category of selected feeds...");
1349
1350 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
1351 param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
1352 xmlhttp.onreadystatechange=feedlist_callback;
1353 xmlhttp.send(null);
1354
1355 } else {
1356
1357 alert(__("No feeds are selected."));
1358
1359 }
1360
1361 }
1362
1363 function validatePrefsReset() {
1364 return confirm(__("Reset to defaults?"));
1365 }
1366
1367 function browseFeeds(limit) {
1368
1369 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=browse", true);
1370 xmlhttp.onreadystatechange=infobox_callback;
1371 xmlhttp.send(null);
1372
1373 }
1374
1375 function feedBrowserSubscribe() {
1376 try {
1377
1378 var selected = getSelectedFeedsFromBrowser();
1379
1380 if (selected.length > 0) {
1381 closeInfoBox();
1382 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=massSubscribe&ids="+
1383 param_escape(selected.toString()), true);
1384 xmlhttp.onreadystatechange=feedlist_callback;
1385 xmlhttp.send(null);
1386 } else {
1387 alert("No feeds are selected.");
1388 }
1389
1390 } catch (e) {
1391 exception_error("feedBrowserSubscribe", e);
1392 }
1393 }
1394
1395 function updateBigFeedBrowser(limit) {
1396
1397 if (!xmlhttp_ready(xmlhttp)) {
1398 printLockingError();
1399 return
1400 }
1401
1402 // p_notify("Loading, please wait...");
1403
1404 var query = "backend.php?op=pref-feed-browser";
1405
1406 var limit_sel = document.getElementById("feedBrowserLimit");
1407
1408 if (limit_sel) {
1409 var limit = limit_sel[limit_sel.selectedIndex].value;
1410 query = query + "&limit=" + param_escape(limit);
1411 }
1412
1413 xmlhttp.open("GET", query, true);
1414 xmlhttp.onreadystatechange=feed_browser_callback;
1415 xmlhttp.send(null);
1416 }
1417
1418 function browserToggleExpand(id) {
1419 try {
1420 /* if (feed_to_expand && feed_to_expand != id) {
1421 var d = document.getElementById("BRDET-" + feed_to_expand);
1422 d.style.display = "none";
1423 } */
1424
1425 if (!xmlhttp_ready(xmlhttp)) {
1426 printLockingError();
1427 return
1428 }
1429
1430 var d = document.getElementById("BRDET-" + id);
1431
1432 if (d.style.display == "block") {
1433 d.style.display = "none";
1434
1435 } else {
1436
1437 feed_to_expand = id;
1438
1439 d.style.display = "block";
1440 d.innerHTML = "Loading, please wait...";
1441
1442 xmlhttp.open("GET", "backend.php?op=pref-feed-browser&subop=details&id="
1443 + param_escape(id), true);
1444 xmlhttp.onreadystatechange=expand_feed_callback;
1445 xmlhttp.send(null);
1446 }
1447
1448 } catch (e) {
1449 exception_error("browserExpand", e);
1450 }
1451 }
1452
1453 function selectPrefRows(kind, select) {
1454
1455 if (kind) {
1456 var opbarid = false;
1457 var nchk = false;
1458 var nrow = false;
1459 var lname = false;
1460
1461 if (kind == "feed") {
1462 opbarid = "feedOpToolbar";
1463 nrow = "FEEDR-";
1464 nchk = "FRCHK-";
1465 lname = "prefFeedList";
1466 } else if (kind == "fcat") {
1467 opbarid = "catOpToolbar";
1468 nrow = "FCATR-";
1469 nchk = "FCCHK-";
1470 lname = "prefFeedCatList";
1471 } else if (kind == "filter") {
1472 opbarid = "filterOpToolbar";
1473 nrow = "FILRR-";
1474 nchk = "FICHK-";
1475 lname = "prefFilterList";
1476 } else if (kind == "label") {
1477 opbarid = "labelOpToolbar";
1478 nrow = "LILRR-";
1479 nchk = "LICHK-";
1480 lname = "prefLabelList";
1481 } else if (kind == "user") {
1482 opbarid = "userOpToolbar";
1483 nrow = "UMRR-";
1484 nchk = "UMCHK-";
1485 lname = "prefUserList";
1486 }
1487
1488 if (opbarid) {
1489 selectTableRowsByIdPrefix(lname, nrow, nchk, select);
1490 disableContainerChildren(opbarid, !select);
1491 }
1492
1493 }
1494 }
1495
1496
1497 function toggleSelectPrefRow(sender, kind) {
1498
1499 toggleSelectRow(sender);
1500
1501 if (kind) {
1502 var opbarid = false;
1503 var nsel = -1;
1504
1505 if (kind == "feed") {
1506 opbarid = "feedOpToolbar";
1507 nsel = getSelectedFeeds();
1508 } else if (kind == "fcat") {
1509 opbarid = "catOpToolbar";
1510 nsel = getSelectedFeedCats();
1511 } else if (kind == "filter") {
1512 opbarid = "filterOpToolbar";
1513 nsel = getSelectedFilters();
1514 } else if (kind == "label") {
1515 opbarid = "labelOpToolbar";
1516 nsel = getSelectedLabels();
1517 } else if (kind == "user") {
1518 opbarid = "userOpToolbar";
1519 nsel = getSelectedUsers();
1520 }
1521
1522 if (opbarid && nsel != -1) {
1523 disableContainerChildren(opbarid, nsel == false);
1524 }
1525
1526 }
1527 }
1528
1529 function toggleSelectFBListRow(sender) {
1530 toggleSelectListRow(sender);
1531 disableContainerChildren("fbrOpToolbar", getSelectedFeedsFromBrowser() == 0);
1532 }
1533
1534 var seq = "";
1535
1536 function pref_hotkey_handler(e) {
1537 try {
1538
1539 var keycode;
1540
1541 if (!hotkeys_enabled) return;
1542
1543 if (window.event) {
1544 keycode = window.event.keyCode;
1545 } else if (e) {
1546 keycode = e.which;
1547 }
1548
1549 if (keycode == 13 || keycode == 27) {
1550 seq = "";
1551 } else {
1552 seq = seq + "" + keycode;
1553 }
1554
1555
1556 if (document.getElementById("piggie")) {
1557
1558 if (seq.match("807371717369")) {
1559 seq = "";
1560 localPiggieFunction(true);
1561 } else {
1562 localPiggieFunction(false);
1563 }
1564 }
1565
1566 } catch (e) {
1567 exception_error("pref_hotkey_handler", e);
1568 }
1569 }
1570
1571 function userSwitch() {
1572 var chooser = document.getElementById("userSwitch");
1573 var user = chooser[chooser.selectedIndex].value;
1574 window.location = "prefs.php?swu=" + user;
1575 }
1576
1577 function editFeedCats() {
1578 if (!xmlhttp_ready(xmlhttp)) {
1579 printLockingError();
1580 return
1581 }
1582
1583 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
1584 xmlhttp.onreadystatechange=infobox_callback;
1585 xmlhttp.send(null);
1586 }
1587
1588 function showFeedsWithErrors() {
1589 displayDlg('feedUpdateErrors');
1590 }
1591
1592 function changeUserPassword() {
1593
1594 try {
1595
1596 if (!xmlhttp_ready(xmlhttp)) {
1597 printLockingError();
1598 return false;
1599 }
1600
1601 var query = Form.serialize("change_pass_form");
1602
1603 notify_progress("Trying to change password...");
1604
1605 xmlhttp.open("POST", "backend.php", true);
1606 xmlhttp.onreadystatechange=changepass_callback;
1607 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1608 xmlhttp.send(query);
1609
1610 } catch (e) {
1611 exception_error("changeUserPassword", e);
1612 }
1613
1614 return false;
1615 }
1616
1617 function changeUserEmail() {
1618
1619 try {
1620
1621 if (!xmlhttp_ready(xmlhttp)) {
1622 printLockingError();
1623 return false;
1624 }
1625
1626 var query = Form.serialize("change_email_form");
1627
1628 notify_progress("Trying to change e-mail...");
1629
1630 xmlhttp.open("POST", "backend.php", true);
1631 xmlhttp.onreadystatechange=notify_callback;
1632 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1633 xmlhttp.send(query);
1634
1635 } catch (e) {
1636 exception_error("changeUserPassword", e);
1637 }
1638
1639 return false;
1640
1641 }