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