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