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