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