]> git.wh0rd.org - tt-rss.git/blob - prefs.js
properly select next unread feed in feedlist when catching up
[tt-rss.git] / prefs.js
1 var xmlhttp = false;
2
3 var active_feed_cat = false;
4 var active_tab = false;
5 var feed_to_expand = false;
6
7 var xmlhttp = Ajax.getTransport();
8
9 var init_params = new Array();
10
11 var caller_subop = false;
12 var sanity_check_done = false;
13 var hotkey_prefix = false;
14
15 function infobox_callback() {
16 if (xmlhttp.readyState == 4) {
17 infobox_callback2(xmlhttp);
18 }
19 }
20
21 function infobox_submit_callback() {
22 if (xmlhttp.readyState == 4) {
23 infobox_submit_callback2(xmlhttp);
24 }
25 }
26
27
28 function replace_pubkey_callback() {
29 if (xmlhttp.readyState == 4) {
30 try {
31 var link = document.getElementById("pubGenAddress");
32
33 if (xmlhttp.responseXML) {
34
35 var new_link = xmlhttp.responseXML.getElementsByTagName("link")[0];
36
37 if (new_link) {
38 link.href = new_link.firstChild.nodeValue;
39 //link.innerHTML = new_link.firstChild.nodeValue;
40
41 new Effect.Highlight(link);
42
43 notify_info("Published feed URL changed.");
44 } else {
45 notify_error("Could not change feed URL.");
46 }
47
48 } else {
49 notify_error("Could not change feed URL.");
50 }
51 } catch (e) {
52 exception_error("replace_pubkey_callback", e);
53 }
54 }
55 }
56
57 function expand_feed_callback() {
58 if (xmlhttp.readyState == 4) {
59 try {
60 var container = document.getElementById("BRDET-" + feed_to_expand);
61 container.innerHTML=xmlhttp.responseText;
62 // container.style.display = "block";
63 Effect.Appear(container, {duration : 0.5});
64 notify('');
65 } catch (e) {
66 exception_error("expand_feed_callback", e);
67 }
68 }
69 }
70
71 function feedlist_callback() {
72 if (xmlhttp.readyState == 4) {
73 try {
74 var container = document.getElementById('prefContent');
75 container.innerHTML=xmlhttp.responseText;
76 selectTab("feedConfig", true);
77
78 if (caller_subop) {
79 var tuple = caller_subop.split(":");
80 if (tuple[0] == 'editFeed') {
81 window.setTimeout('editFeed('+tuple[1]+')', 100);
82 }
83
84 caller_subop = false;
85 }
86 if (typeof correctPNG != 'undefined') {
87 correctPNG();
88 }
89 notify("");
90 remove_splash();
91
92 } catch (e) {
93 exception_error("feedlist_callback", e);
94 }
95 }
96 }
97
98 /* stub for subscription dialog */
99
100 function dlg_frefresh_callback(transport) {
101
102 try {
103 var container = document.getElementById('prefContent');
104 container.innerHTML=transport.responseText;
105 selectTab("feedConfig", true);
106
107 if (caller_subop) {
108 var tuple = caller_subop.split(":");
109 if (tuple[0] == 'editFeed') {
110 window.setTimeout('editFeed('+tuple[1]+')', 100);
111 }
112
113 caller_subop = false;
114 }
115 if (typeof correctPNG != 'undefined') {
116 correctPNG();
117 }
118 notify("");
119 } catch (e) {
120 exception_error("feedlist_callback", e);
121 }
122
123 }
124
125 function filterlist_callback() {
126 var container = document.getElementById('prefContent');
127 if (xmlhttp.readyState == 4) {
128 container.innerHTML=xmlhttp.responseText;
129 if (typeof correctPNG != 'undefined') {
130 correctPNG();
131 }
132 notify("");
133 remove_splash();
134 }
135 }
136
137 function labellist_callback() {
138
139 try {
140
141 var container = document.getElementById('prefContent');
142 if (xmlhttp.readyState == 4) {
143 closeInfoBox();
144 container.innerHTML=xmlhttp.responseText;
145
146 if (document.getElementById("prefLabelList")) {
147 var elems = document.getElementById("prefLabelList").getElementsByTagName("SPAN");
148
149 for (var i = 0; i < elems.length; i++) {
150 if (elems[i].id && elems[i].id.match("LILT-")) {
151
152 var id = elems[i].id.replace("LILT-", "");
153 new Ajax.InPlaceEditor(elems[i],
154 'backend.php?op=pref-labels&subop=save&id=' + id,
155 {cols: 20, rows: 1});
156 }
157 }
158 }
159
160 if (typeof correctPNG != 'undefined') {
161 correctPNG();
162 }
163 notify("");
164 remove_splash();
165 }
166
167 } catch (e) {
168 exception_error("labellist_callback", e);
169 }
170 }
171
172 function feed_browser_callback() {
173 var container = document.getElementById('prefContent');
174 if (xmlhttp.readyState == 4) {
175 container.innerHTML=xmlhttp.responseText;
176 notify("");
177 remove_splash();
178 }
179 }
180
181 function userlist_callback() {
182 var container = document.getElementById('prefContent');
183 if (xmlhttp.readyState == 4) {
184 container.innerHTML=xmlhttp.responseText;
185 notify("");
186 remove_splash();
187 }
188 }
189
190 function prefslist_callback() {
191 var container = document.getElementById('prefContent');
192 if (xmlhttp.readyState == 4) {
193 container.innerHTML=xmlhttp.responseText;
194 notify("");
195 remove_splash();
196 }
197 }
198
199 function gethelp_callback() {
200 var container = document.getElementById('prefHelpBox');
201 if (xmlhttp.readyState == 4) {
202
203 container.innerHTML = xmlhttp.responseText;
204 container.style.display = "block";
205
206 }
207 }
208
209 function notify_callback() {
210 if (xmlhttp.readyState == 4) {
211 notify_info(xmlhttp.responseText);
212 }
213 }
214
215 function prefs_reset_callback() {
216 if (xmlhttp.readyState == 4) {
217 notify_info(xmlhttp.responseText);
218 selectTab();
219 }
220 }
221
222
223 function changepass_callback() {
224 try {
225 if (xmlhttp.readyState == 4) {
226
227 if (xmlhttp.responseText.indexOf("ERROR: ") == 0) {
228 notify_error(xmlhttp.responseText.replace("ERROR: ", ""));
229 } else {
230 notify_info(xmlhttp.responseText);
231 var warn = document.getElementById("default_pass_warning");
232 if (warn) warn.style.display = "none";
233 }
234
235 document.forms['change_pass_form'].reset();
236
237 }
238 } catch (e) {
239 exception_error("changepass_callback", e);
240 }
241 }
242
243 function init_cat_inline_editor() {
244 try {
245
246 if (document.getElementById("prefFeedCatList")) {
247 var elems = document.getElementById("prefFeedCatList").getElementsByTagName("SPAN");
248
249 for (var i = 0; i < elems.length; i++) {
250 if (elems[i].id && elems[i].id.match("FCATT-")) {
251 var cat_id = elems[i].id.replace("FCATT-", "");
252 new Ajax.InPlaceEditor(elems[i],
253 'backend.php?op=pref-feeds&subop=editCats&action=save&cid=' + cat_id);
254 }
255 }
256 }
257
258 } catch (e) {
259 exception_error("init_cat_inline_editor", e);
260 }
261 }
262
263 function infobox_feed_cat_callback() {
264 if (xmlhttp.readyState == 4) {
265 try {
266
267 infobox_callback();
268 init_cat_inline_editor();
269
270 } catch (e) {
271 exception_error("infobox_feed_cat_callback", e);
272 }
273 }
274 }
275
276 function updateFeedList(sort_key) {
277
278 if (!xmlhttp_ready(xmlhttp)) {
279 printLockingError();
280 return
281 }
282
283 var feed_search = document.getElementById("feed_search");
284 var search = "";
285 if (feed_search) { search = feed_search.value; }
286
287 var slat = document.getElementById("show_last_article_times");
288
289 var slat_checked = false;
290 if (slat) {
291 slat_checked = slat.checked;
292 }
293
294 xmlhttp.open("GET", "backend.php?op=pref-feeds" +
295 "&sort=" + param_escape(sort_key) +
296 "&slat=" + param_escape(slat_checked) +
297 "&search=" + param_escape(search), true);
298 xmlhttp.onreadystatechange=feedlist_callback;
299 xmlhttp.send(null);
300
301 }
302
303 function updateUsersList(sort_key) {
304
305 if (!xmlhttp_ready(xmlhttp)) {
306 printLockingError();
307 return
308 }
309
310 var user_search = document.getElementById("user_search");
311 var search = "";
312 if (user_search) { search = user_search.value; }
313
314 xmlhttp.open("GET", "backend.php?op=pref-users&sort="
315 + param_escape(sort_key) +
316 "&search=" + param_escape(search), true);
317 xmlhttp.onreadystatechange=userlist_callback;
318 xmlhttp.send(null);
319
320 }
321
322 function addLabel() {
323
324 try {
325
326 if (!xmlhttp_ready(xmlhttp)) {
327 printLockingError();
328 return
329 }
330
331 var caption = prompt(__("Please enter label caption:"), "");
332
333 if (caption == null) {
334 return false;
335 }
336
337 if (caption == "") {
338 alert(__("Can't create label: missing caption."));
339 return false;
340 }
341
342 // we can be called from some other tab
343 active_tab = "labelConfig";
344
345 var query = "caption=" + param_escape(caption);
346
347 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=add&" + query, true);
348 xmlhttp.onreadystatechange=infobox_submit_callback;
349 xmlhttp.send(null);
350
351 } catch (e) {
352 exception_error("addLabel", e);
353 }
354 }
355
356 function addFeed() {
357
358 if (!xmlhttp_ready(xmlhttp)) {
359 printLockingError();
360 return
361 }
362
363 var link = document.getElementById("fadd_link");
364
365 if (link.value.length == 0) {
366 alert(__("Error: No feed URL given."));
367 } else if (!isValidURL(link.value)) {
368 alert(__("Error: Invalid feed URL."));
369 } else {
370 notify_progress("Adding feed...");
371
372 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&from=tt-rss&feed_url=" +
373 param_escape(link.value), true);
374 xmlhttp.onreadystatechange=feedlist_callback;
375 xmlhttp.send(null);
376
377 link.value = "";
378
379 }
380
381 }
382
383 function addFeedCat() {
384
385 if (!xmlhttp_ready(xmlhttp)) {
386 printLockingError();
387 return
388 }
389
390 var cat = document.getElementById("fadd_cat");
391
392 if (cat.value.length == 0) {
393 alert(__("Can't add category: no name specified."));
394 } else {
395 notify_progress("Adding feed category...");
396
397 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=add&cat=" +
398 param_escape(cat.value), true);
399 xmlhttp.onreadystatechange=infobox_feed_cat_callback;
400 xmlhttp.send(null);
401
402 link.value = "";
403
404 }
405
406 }
407 function addUser() {
408
409 if (!xmlhttp_ready(xmlhttp)) {
410 printLockingError();
411 return
412 }
413
414 var sqlexp = document.getElementById("uadd_box");
415
416 if (sqlexp.value.length == 0) {
417 alert(__("Can't add user: no login specified."));
418 } else {
419 notify_progress("Adding user...");
420
421 xmlhttp.open("GET", "backend.php?op=pref-users&subop=add&login=" +
422 param_escape(sqlexp.value), true);
423
424 xmlhttp.onreadystatechange=userlist_callback;
425 xmlhttp.send(null);
426
427 sqlexp.value = "";
428 }
429
430 }
431
432 function editUser(id) {
433
434 if (!xmlhttp_ready(xmlhttp)) {
435 printLockingError();
436 return
437 }
438
439 disableHotkeys();
440
441 notify_progress("Loading, please wait...");
442
443 selectTableRowsByIdPrefix('prefUserList', 'UMRR-', 'UMCHK-', false);
444 selectTableRowById('UMRR-'+id, 'UMCHK-'+id, true);
445
446 xmlhttp.open("GET", "backend.php?op=pref-users&subop=edit&id=" +
447 param_escape(id), true);
448 xmlhttp.onreadystatechange=infobox_callback;
449 xmlhttp.send(null);
450
451 }
452
453 function editFilter(id) {
454
455 if (!xmlhttp_ready(xmlhttp)) {
456 printLockingError();
457 return
458 }
459
460 disableHotkeys();
461
462 notify_progress("Loading, please wait...");
463
464 // document.getElementById("create_filter_btn").disabled = true;
465
466 selectTableRowsByIdPrefix('prefFilterList', 'FILRR-', 'FICHK-', false);
467 selectTableRowById('FILRR-'+id, 'FICHK-'+id, true);
468
469 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=edit&id=" + param_escape(id), true);
470 xmlhttp.onreadystatechange=infobox_callback;
471 xmlhttp.send(null);
472 }
473
474 function editFeed(feed) {
475
476 // notify("Editing feed...");
477
478 if (!xmlhttp_ready(xmlhttp)) {
479 printLockingError();
480 return
481 }
482
483 disableHotkeys();
484
485 notify_progress("Loading, please wait...");
486
487 /* document.getElementById("subscribe_to_feed_btn").disabled = true;
488
489 try {
490 document.getElementById("top25_feeds_btn").disabled = true;
491 } catch (e) {
492 // this button is not always available, no-op if not found
493 } */
494
495 // clean selection from all rows & select row being edited
496 selectTableRowsByIdPrefix('prefFeedList', 'FEEDR-', 'FRCHK-', false);
497 selectTableRowById('FEEDR-'+feed, 'FRCHK-'+feed, true);
498
499 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
500 param_escape(feed), true);
501
502 xmlhttp.onreadystatechange=infobox_callback;
503 xmlhttp.send(null);
504
505 }
506
507 function editFeedCat(cat) {
508
509 if (!xmlhttp_ready(xmlhttp)) {
510 printLockingError();
511 return
512 }
513
514 disableHotkeys();
515
516 notify_progress("Loading, please wait...");
517
518 active_feed_cat = cat;
519
520 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=edit&id=" +
521 param_escape(cat), true);
522 xmlhttp.onreadystatechange=infobox_callback;
523 xmlhttp.send(null);
524
525 }
526
527 function getSelectedLabels() {
528 return getSelectedTableRowIds("prefLabelList", "LILRR");
529 }
530
531 function getSelectedUsers() {
532 return getSelectedTableRowIds("prefUserList", "UMRR");
533 }
534
535 function getSelectedFeeds() {
536 return getSelectedTableRowIds("prefFeedList", "FEEDR");
537 }
538
539 function getSelectedFilters() {
540 return getSelectedTableRowIds("prefFilterList", "FILRR");
541 }
542
543 function getSelectedFeedCats() {
544 return getSelectedTableRowIds("prefFeedCatList", "FCATR");
545 }
546
547 function getSelectedFeedsFromBrowser() {
548
549 var list = document.getElementById("browseFeedList");
550 if (!list) list = document.getElementById("browseBigFeedList");
551
552 var selected = new Array();
553
554 for (i = 0; i < list.childNodes.length; i++) {
555 var child = list.childNodes[i];
556 if (child.id && child.id.match("FBROW-")) {
557 var id = child.id.replace("FBROW-", "");
558
559 var cb = document.getElementById("FBCHK-" + id);
560
561 if (cb.checked) {
562 selected.push(id);
563 }
564 }
565 }
566
567 return selected;
568 }
569
570 function removeSelectedLabels() {
571
572 if (!xmlhttp_ready(xmlhttp)) {
573 printLockingError();
574 return
575 }
576
577 var sel_rows = getSelectedLabels();
578
579 if (sel_rows.length > 0) {
580
581 var ok = confirm(__("Remove selected labels?"));
582
583 if (ok) {
584 notify_progress("Removing selected labels...");
585
586 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
587 param_escape(sel_rows.toString()), true);
588 xmlhttp.onreadystatechange=labellist_callback;
589 xmlhttp.send(null);
590 }
591 } else {
592 alert(__("No labels are selected."));
593 }
594
595 return false;
596 }
597
598 function removeSelectedUsers() {
599
600 if (!xmlhttp_ready(xmlhttp)) {
601 printLockingError();
602 return
603 }
604
605 var sel_rows = getSelectedUsers();
606
607 if (sel_rows.length > 0) {
608
609 var ok = confirm(__("Remove selected users?"));
610
611 if (ok) {
612 notify_progress("Removing selected users...");
613
614 xmlhttp.open("GET", "backend.php?op=pref-users&subop=remove&ids="+
615 param_escape(sel_rows.toString()), true);
616 xmlhttp.onreadystatechange=userlist_callback;
617 xmlhttp.send(null);
618 }
619
620 } else {
621 alert(__("No users are selected."));
622 }
623
624 return false;
625 }
626
627 function removeSelectedFilters() {
628
629 if (!xmlhttp_ready(xmlhttp)) {
630 printLockingError();
631 return
632 }
633
634 var sel_rows = getSelectedFilters();
635
636 if (sel_rows.length > 0) {
637
638 var ok = confirm(__("Remove selected filters?"));
639
640 if (ok) {
641 notify_progress("Removing selected filters...");
642
643 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
644 param_escape(sel_rows.toString()), true);
645 xmlhttp.onreadystatechange=filterlist_callback;
646 xmlhttp.send(null);
647 }
648 } else {
649 alert(__("No filters are selected."));
650 }
651
652 return false;
653 }
654
655
656 function removeSelectedFeeds() {
657
658 if (!xmlhttp_ready(xmlhttp)) {
659 printLockingError();
660 return
661 }
662
663 var sel_rows = getSelectedFeeds();
664
665 if (sel_rows.length > 0) {
666
667 var ok = confirm(__("Unsubscribe from selected feeds?"));
668
669 if (ok) {
670
671 notify_progress("Unsubscribing from selected feeds...");
672
673 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
674 param_escape(sel_rows.toString()), true);
675 xmlhttp.onreadystatechange=feedlist_callback;
676 xmlhttp.send(null);
677 }
678
679 } else {
680
681 alert(__("No feeds are selected."));
682
683 }
684
685 return false;
686 }
687
688 function clearSelectedFeeds() {
689
690 if (!xmlhttp_ready(xmlhttp)) {
691 printLockingError();
692 return
693 }
694
695 var sel_rows = getSelectedFeeds();
696
697 if (sel_rows.length > 1) {
698 alert(__("Please select only one feed."));
699 return;
700 }
701
702 if (sel_rows.length > 0) {
703
704 var ok = confirm(__("Erase all non-starred articles in selected feed?"));
705
706 if (ok) {
707 notify_progress("Clearing selected feed...");
708 clearFeedArticles(sel_rows[0]);
709 }
710
711 } else {
712
713 alert(__("No feeds are selected."));
714
715 }
716
717 return false;
718 }
719
720 function purgeSelectedFeeds() {
721
722 if (!xmlhttp_ready(xmlhttp)) {
723 printLockingError();
724 return
725 }
726
727 var sel_rows = getSelectedFeeds();
728
729 if (sel_rows.length > 0) {
730
731 var pr = prompt(__("How many days of articles to keep (0 - use default)?"), "0");
732
733 if (pr != undefined) {
734 notify_progress("Purging selected feed...");
735
736 var query = "backend.php?op=rpc&subop=purge&ids="+
737 param_escape(sel_rows.toString()) + "&days=" + pr;
738
739 debug(query);
740
741 new Ajax.Request(query, {
742 onComplete: function(transport) {
743 notify('');
744 } });
745 }
746
747 } else {
748
749 alert(__("No feeds are selected."));
750
751 }
752
753 return false;
754 }
755
756 function removeSelectedFeedCats() {
757
758 if (!xmlhttp_ready(xmlhttp)) {
759 printLockingError();
760 return
761 }
762
763 var sel_rows = getSelectedFeedCats();
764
765 if (sel_rows.length > 0) {
766
767 var ok = confirm(__("Remove selected categories?"));
768
769 if (ok) {
770 notify_progress("Removing selected categories...");
771
772 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=remove&ids="+
773 param_escape(sel_rows.toString()), true);
774 xmlhttp.onreadystatechange=infobox_feed_cat_callback;
775 xmlhttp.send(null);
776 }
777
778 } else {
779
780 alert(__("No categories are selected."));
781
782 }
783
784 return false;
785 }
786
787 function feedEditCancel() {
788
789 if (!xmlhttp_ready(xmlhttp)) {
790 printLockingError();
791 return
792 }
793
794 try {
795 document.getElementById("subscribe_to_feed_btn").disabled = false;
796 document.getElementById("top25_feeds_btn").disabled = false;
797 } catch (e) {
798 // this button is not always available, no-op if not found
799 }
800
801 closeInfoBox();
802
803 selectPrefRows('feed', false); // cleanup feed selection
804
805 return false;
806 }
807
808 function feedCatEditCancel() {
809
810 if (!xmlhttp_ready(xmlhttp)) {
811 printLockingError();
812 return
813 }
814
815 active_feed_cat = false;
816
817 try {
818 document.getElementById("subscribe_to_feed_btn").disabled = false;
819 document.getElementById("top25_feeds_btn").disabled = false;
820 } catch (e) {
821 // this button is not always available, no-op if not found
822 }
823
824 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
825 xmlhttp.onreadystatechange=infobox_callback;
826 xmlhttp.send(null);
827
828 return false;
829 }
830
831 function feedEditSave() {
832
833 try {
834
835 if (!xmlhttp_ready(xmlhttp)) {
836 printLockingError();
837 return
838 }
839
840 // FIXME: add parameter validation
841
842 var query = Form.serialize("edit_feed_form");
843
844 notify_progress("Saving feed...");
845
846 xmlhttp.open("POST", "backend.php", true);
847 xmlhttp.onreadystatechange=feedlist_callback;
848 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
849 xmlhttp.send(query);
850
851 closeInfoBox();
852
853 return false;
854
855 } catch (e) {
856 exception_error("feedEditSave", e);
857 }
858 }
859
860 function userEditCancel() {
861
862 if (!xmlhttp_ready(xmlhttp)) {
863 printLockingError();
864 return
865 }
866
867 selectPrefRows('user', false); // cleanup feed selection
868 closeInfoBox();
869
870 return false;
871 }
872
873 function filterEditCancel() {
874
875 if (!xmlhttp_ready(xmlhttp)) {
876 printLockingError();
877 return
878 }
879
880 try {
881 document.getElementById("create_filter_btn").disabled = false;
882 selectPrefRows('filter', false); // cleanup feed selection
883 } catch (e) { }
884
885 closeInfoBox();
886
887 return false;
888 }
889
890 function userEditSave() {
891
892 if (!xmlhttp_ready(xmlhttp)) {
893 printLockingError();
894 return
895 }
896
897 var login = document.forms["user_edit_form"].login.value;
898
899 if (login.length == 0) {
900 alert(__("Login field cannot be blank."));
901 return;
902 }
903
904 notify_progress("Saving user...");
905
906 closeInfoBox();
907
908 var query = Form.serialize("user_edit_form");
909
910 xmlhttp.open("GET", "backend.php?" + query, true);
911 xmlhttp.onreadystatechange=userlist_callback;
912 xmlhttp.send(null);
913
914 return false;
915 }
916
917
918 function filterEditSave() {
919
920 if (!xmlhttp_ready(xmlhttp)) {
921 printLockingError();
922 return
923 }
924
925 /* if (!is_opera()) {
926 var reg_exp = document.forms["filter_edit_form"].reg_exp.value;
927
928 if (reg_exp.length == 0) {
929 alert("Filter expression field cannot be blank.");
930 return;
931 }
932 } */
933
934 notify_progress("Saving filter...");
935
936 var query = Form.serialize("filter_edit_form");
937
938 closeInfoBox();
939
940 document.getElementById("create_filter_btn").disabled = false;
941
942 xmlhttp.open("GET", "backend.php?" + query, true);
943 xmlhttp.onreadystatechange=filterlist_callback;
944 xmlhttp.send(null);
945
946 return false;
947 }
948
949
950 function editSelectedUser() {
951 var rows = getSelectedUsers();
952
953 if (rows.length == 0) {
954 alert(__("No users are selected."));
955 return;
956 }
957
958 if (rows.length > 1) {
959 alert(__("Please select only one user."));
960 return;
961 }
962
963 notify("");
964
965 editUser(rows[0]);
966 }
967
968 function resetSelectedUserPass() {
969 var rows = getSelectedUsers();
970
971 if (rows.length == 0) {
972 alert(__("No users are selected."));
973 return;
974 }
975
976 if (rows.length > 1) {
977 alert(__("Please select only one user."));
978 return;
979 }
980
981 var ok = confirm(__("Reset password of selected user?"));
982
983 if (ok) {
984 notify_progress("Resetting password for selected user...");
985
986 var id = rows[0];
987
988 xmlhttp.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
989 param_escape(id), true);
990 xmlhttp.onreadystatechange=userlist_callback;
991 xmlhttp.send(null);
992 }
993 }
994
995 function selectedUserDetails() {
996
997 if (!xmlhttp_ready(xmlhttp)) {
998 printLockingError();
999 return
1000 }
1001
1002 var rows = getSelectedUsers();
1003
1004 if (rows.length == 0) {
1005 alert(__("No users are selected."));
1006 return;
1007 }
1008
1009 if (rows.length > 1) {
1010 alert(__("Please select only one user."));
1011 return;
1012 }
1013
1014 notify_progress("Loading, please wait...");
1015
1016 var id = rows[0];
1017
1018 xmlhttp.open("GET", "backend.php?op=pref-users&subop=user-details&id=" + id, true);
1019 xmlhttp.onreadystatechange=infobox_callback;
1020 xmlhttp.send(null);
1021
1022 }
1023
1024 function selectedFeedDetails() {
1025
1026 if (!xmlhttp_ready(xmlhttp)) {
1027 printLockingError();
1028 return
1029 }
1030
1031 var rows = getSelectedFeeds();
1032
1033 if (rows.length == 0) {
1034 alert(__("No feeds are selected."));
1035 return;
1036 }
1037
1038 if (rows.length > 1) {
1039 alert(__("Please select only one feed."));
1040 return;
1041 }
1042
1043 // var id = rows[0];
1044
1045 notify("");
1046
1047 xmlhttp.open("GET", "backend.php?op=feed-details&id=" +
1048 param_escape(rows.toString()), true);
1049 xmlhttp.onreadystatechange=infobox_callback;
1050 xmlhttp.send(null);
1051
1052 }
1053
1054 function editSelectedFilter() {
1055 var rows = getSelectedFilters();
1056
1057 if (rows.length == 0) {
1058 alert(__("No filters are selected."));
1059 return;
1060 }
1061
1062 if (rows.length > 1) {
1063 alert(__("Please select only one filter."));
1064 return;
1065 }
1066
1067 notify("");
1068
1069 editFilter(rows[0]);
1070
1071 }
1072
1073
1074 function editSelectedFeed() {
1075 var rows = getSelectedFeeds();
1076
1077 if (rows.length == 0) {
1078 alert(__("No feeds are selected."));
1079 return;
1080 }
1081
1082 if (rows.length > 1) {
1083 alert(__("Please select one feed."));
1084 return;
1085 }
1086
1087 notify("");
1088
1089 editFeed(rows[0]);
1090
1091 }
1092
1093 function editSelectedFeeds() {
1094
1095 if (!xmlhttp_ready(xmlhttp)) {
1096 printLockingError();
1097 return
1098 }
1099
1100 var rows = getSelectedFeeds();
1101
1102 if (rows.length == 0) {
1103 alert(__("No feeds are selected."));
1104 return;
1105 }
1106
1107 notify("");
1108
1109 disableHotkeys();
1110
1111 notify_progress("Loading, please wait...");
1112
1113 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeeds&ids=" +
1114 param_escape(rows.toString()), true);
1115
1116 xmlhttp.onreadystatechange=infobox_callback;
1117 xmlhttp.send(null);
1118
1119 }
1120
1121 function editSelectedFeedCat() {
1122 var rows = getSelectedFeedCats();
1123
1124 if (rows.length == 0) {
1125 alert(__("No categories are selected."));
1126 return;
1127 }
1128
1129 if (rows.length > 1) {
1130 alert(__("Please select only one category."));
1131 return;
1132 }
1133
1134 notify("");
1135
1136 editFeedCat(rows[0]);
1137
1138 }
1139
1140 function piggie(enable) {
1141 if (enable) {
1142 debug("I LOVEDED IT!");
1143 var piggie = document.getElementById("piggie");
1144
1145 Element.show(piggie);
1146 Position.Center(piggie);
1147 Effect.Puff(piggie);
1148
1149 }
1150 }
1151
1152 function validateOpmlImport() {
1153
1154 var opml_file = document.getElementById("opml_file");
1155
1156 if (opml_file.value.length == 0) {
1157 alert(__("No OPML file to upload."));
1158 return false;
1159 } else {
1160 return true;
1161 }
1162 }
1163
1164 function updateFilterList(sort_key) {
1165
1166 if (!xmlhttp_ready(xmlhttp)) {
1167 printLockingError();
1168 return
1169 }
1170
1171 var filter_search = document.getElementById("filter_search");
1172 var search = "";
1173 if (filter_search) { search = filter_search.value; }
1174
1175 xmlhttp.open("GET", "backend.php?op=pref-filters&sort=" +
1176 param_escape(sort_key) +
1177 "&search=" + param_escape(search), true);
1178 xmlhttp.onreadystatechange=filterlist_callback;
1179 xmlhttp.send(null);
1180
1181 }
1182
1183 function updateLabelList(sort_key) {
1184
1185 if (!xmlhttp_ready(xmlhttp)) {
1186 printLockingError();
1187 return
1188 }
1189
1190 var label_search = document.getElementById("label_search");
1191 var search = "";
1192 if (label_search) { search = label_search.value; }
1193
1194 xmlhttp.open("GET", "backend.php?op=pref-labels&sort=" +
1195 param_escape(sort_key) +
1196 "&search=" + param_escape(search), true);
1197 xmlhttp.onreadystatechange=labellist_callback;
1198 xmlhttp.send(null);
1199 }
1200
1201 function updatePrefsList() {
1202
1203 if (!xmlhttp_ready(xmlhttp)) {
1204 printLockingError();
1205 return
1206 }
1207
1208 xmlhttp.open("GET", "backend.php?op=pref-prefs", true);
1209 xmlhttp.onreadystatechange=prefslist_callback;
1210 xmlhttp.send(null);
1211
1212 }
1213
1214 function selectTab(id, noupdate, subop) {
1215
1216 // alert(id);
1217
1218 if (!id) id = active_tab;
1219
1220 try {
1221
1222 if (!xmlhttp_ready(xmlhttp)) {
1223 printLockingError();
1224 return
1225 }
1226
1227 try {
1228 var c = document.getElementById('prefContent');
1229 c.scrollTop = 0;
1230 } catch (e) { };
1231
1232 if (!noupdate) {
1233
1234 debug("selectTab: " + id + "(NU: " + noupdate + ")");
1235
1236 notify_progress("Loading, please wait...");
1237
1238 // close active infobox if needed
1239 closeInfoBox();
1240
1241 // clean up all current selections, just in case
1242 active_feed_cat = false;
1243
1244 // Effect.Fade("prefContent", {duration: 1, to: 0.01,
1245 // queue: { position:'end', scope: 'FEED_TAB', limit: 1 } } );
1246
1247 if (id == "feedConfig") {
1248 updateFeedList();
1249 } else if (id == "filterConfig") {
1250 updateFilterList();
1251 } else if (id == "labelConfig") {
1252 updateLabelList();
1253 } else if (id == "genConfig") {
1254 updatePrefsList();
1255 } else if (id == "userConfig") {
1256 updateUsersList();
1257 } else if (id == "feedBrowser") {
1258 updateBigFeedBrowser();
1259 }
1260 }
1261
1262 /* clean selection from all tabs */
1263
1264 var tabs_holder = document.getElementById("prefTabs");
1265 var tab = tabs_holder.firstChild;
1266
1267 while (tab) {
1268 if (tab.className && tab.className.match("prefsTabSelected")) {
1269 tab.className = "prefsTab";
1270 }
1271 tab = tab.nextSibling;
1272 }
1273
1274 /* mark new tab as selected */
1275
1276 tab = document.getElementById(id + "Tab");
1277
1278 if (tab) {
1279 if (!tab.className.match("Selected")) {
1280 tab.className = tab.className + "Selected";
1281 }
1282 }
1283
1284 active_tab = id;
1285
1286 } catch (e) {
1287 exception_error("selectTab", e);
1288 }
1289 }
1290
1291 function backend_sanity_check_callback() {
1292
1293 if (xmlhttp.readyState == 4) {
1294
1295 try {
1296
1297 if (sanity_check_done) {
1298 fatalError(11, "Sanity check request received twice. This can indicate "+
1299 "presence of Firebug or some other disrupting extension. "+
1300 "Please disable it and try again.");
1301 return;
1302 }
1303
1304 if (!xmlhttp.responseXML) {
1305 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp.responseText);
1306 return;
1307 }
1308
1309 var reply = xmlhttp.responseXML.firstChild.firstChild;
1310
1311 if (!reply) {
1312 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp.responseText);
1313 return;
1314 }
1315
1316 var error_code = reply.getAttribute("error-code");
1317
1318 if (error_code && error_code != 0) {
1319 return fatalError(error_code, reply.getAttribute("error-msg"));
1320 }
1321
1322 debug("sanity check ok");
1323
1324 var params = reply.nextSibling;
1325
1326 if (params) {
1327 debug('reading init-params...');
1328 var param = params.firstChild;
1329
1330 while (param) {
1331 var k = param.getAttribute("key");
1332 var v = param.getAttribute("value");
1333 debug(k + " => " + v);
1334 init_params[k] = v;
1335 param = param.nextSibling;
1336 }
1337 }
1338
1339 sanity_check_done = true;
1340
1341 init_second_stage();
1342
1343 } catch (e) {
1344 exception_error("backend_sanity_check_callback", e);
1345 }
1346 }
1347 }
1348
1349 function init_second_stage() {
1350
1351 try {
1352 active_tab = getInitParam("prefs_active_tab");
1353 if (!active_tab || active_tab == '0') active_tab = "genConfig";
1354
1355 document.onkeydown = pref_hotkey_handler;
1356
1357 var tab = getURLParam('tab');
1358
1359 caller_subop = getURLParam('subop');
1360
1361 if (tab) {
1362 active_tab = tab;
1363 }
1364
1365 if (navigator.userAgent.match("Opera")) {
1366 setTimeout("selectTab()", 500);
1367 } else {
1368 selectTab(active_tab);
1369 }
1370 notify("");
1371
1372 loading_set_progress(60);
1373
1374 } catch (e) {
1375 exception_error("init_second_stage", e);
1376 }
1377 }
1378
1379 function init() {
1380
1381 try {
1382
1383 if (arguments.callee.done) return;
1384 arguments.callee.done = true;
1385
1386 if (getURLParam('debug')) {
1387 Element.show("debug_output");
1388 debug('debug mode activated');
1389 }
1390
1391 // IE kludge
1392 if (!xmlhttp) {
1393 document.getElementById("prefContent").innerHTML =
1394 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1395 "to function properly. Your browser doesn't seem to support it.";
1396 return;
1397 }
1398
1399 loading_set_progress(30);
1400
1401 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
1402 xmlhttp.onreadystatechange=backend_sanity_check_callback;
1403 xmlhttp.send(null);
1404
1405 } catch (e) {
1406 exception_error("init", e);
1407 }
1408 }
1409
1410 function categorizeSelectedFeeds() {
1411
1412 if (!xmlhttp_ready(xmlhttp)) {
1413 printLockingError();
1414 return
1415 }
1416
1417 var sel_rows = getSelectedFeeds();
1418
1419 var cat_sel = document.getElementById("sfeed_set_fcat");
1420 var cat_id = cat_sel[cat_sel.selectedIndex].value;
1421
1422 if (sel_rows.length > 0) {
1423
1424 notify_progress("Changing category of selected feeds...");
1425
1426 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
1427 param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
1428 xmlhttp.onreadystatechange=feedlist_callback;
1429 xmlhttp.send(null);
1430
1431 } else {
1432
1433 alert(__("No feeds are selected."));
1434
1435 }
1436
1437 }
1438
1439 function validatePrefsReset() {
1440 try {
1441 var ok = confirm(__("Reset to defaults?"));
1442
1443 if (ok) {
1444
1445 var query = Form.serialize("pref_prefs_form");
1446 query = query + "&subop=reset-config";
1447 debug(query);
1448
1449 xmlhttp.open("POST", "backend.php", true);
1450 xmlhttp.onreadystatechange=prefs_reset_callback;
1451 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1452 xmlhttp.send(query);
1453 }
1454
1455 } catch (e) {
1456 exception_error("validatePrefsSave", e);
1457 }
1458
1459 return false;
1460
1461 }
1462
1463 function browseFeeds(limit) {
1464
1465 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=browse", true);
1466 xmlhttp.onreadystatechange=infobox_callback;
1467 xmlhttp.send(null);
1468
1469 }
1470
1471 function feedBrowserSubscribe() {
1472 try {
1473
1474 var selected = getSelectedFeedsFromBrowser();
1475
1476 if (selected.length > 0) {
1477 closeInfoBox();
1478 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=massSubscribe&ids="+
1479 param_escape(selected.toString()), true);
1480 xmlhttp.onreadystatechange=feedlist_callback;
1481 xmlhttp.send(null);
1482 } else {
1483 alert(__("No feeds are selected."));
1484 }
1485
1486 } catch (e) {
1487 exception_error("feedBrowserSubscribe", e);
1488 }
1489 }
1490
1491 function updateBigFeedBrowserBtn() {
1492 notify_progress("Loading, please wait...");
1493 return updateBigFeedBrowser();
1494 }
1495
1496 function updateBigFeedBrowser(limit, from_button) {
1497
1498 if (!xmlhttp_ready(xmlhttp)) {
1499 printLockingError();
1500 return
1501 }
1502
1503 var query = "backend.php?op=pref-feed-browser";
1504
1505 var limit_sel = document.getElementById("feedBrowserLimit");
1506
1507 if (limit_sel) {
1508 var limit = limit_sel[limit_sel.selectedIndex].value;
1509 query = query + "&limit=" + param_escape(limit);
1510 }
1511
1512 var search = document.getElementById("feed_browser_search");
1513
1514 if (search) {
1515 query = query + "&search=" + param_escape(search.value);
1516 }
1517
1518 xmlhttp.open("GET", query, true);
1519 xmlhttp.onreadystatechange=feed_browser_callback;
1520 xmlhttp.send(null);
1521 }
1522
1523 function browserToggleExpand(id) {
1524 try {
1525 /* if (feed_to_expand && feed_to_expand != id) {
1526 var d = document.getElementById("BRDET-" + feed_to_expand);
1527 d.style.display = "none";
1528 } */
1529
1530 if (!xmlhttp_ready(xmlhttp)) {
1531 printLockingError();
1532 return
1533 }
1534
1535 /* if (feed_to_expand && id != feed_to_expand) {
1536 Effect.Fade('BRDET-' + feed_to_expand, {duration : 0.5});
1537 } */
1538
1539 var d = document.getElementById("BRDET-" + id);
1540
1541 notify_progress("Loading, please wait...");
1542
1543 if (Element.visible(d)) {
1544 Effect.Fade(d, {duration : 0.5});
1545 } else {
1546 feed_to_expand = id;
1547
1548 xmlhttp.open("GET", "backend.php?op=pref-feed-browser&subop=details&id="
1549 + param_escape(id), true);
1550 xmlhttp.onreadystatechange=expand_feed_callback;
1551 xmlhttp.send(null);
1552 }
1553
1554 } catch (e) {
1555 exception_error("browserToggleExpand", e);
1556 }
1557 }
1558
1559 function selectPrefRows(kind, select) {
1560
1561 if (kind) {
1562 var opbarid = false;
1563 var nchk = false;
1564 var nrow = false;
1565 var lname = false;
1566
1567 if (kind == "feed") {
1568 opbarid = "feedOpToolbar";
1569 nrow = "FEEDR-";
1570 nchk = "FRCHK-";
1571 lname = "prefFeedList";
1572 } else if (kind == "fcat") {
1573 opbarid = "catOpToolbar";
1574 nrow = "FCATR-";
1575 nchk = "FCCHK-";
1576 lname = "prefFeedCatList";
1577 } else if (kind == "filter") {
1578 opbarid = "filterOpToolbar";
1579 nrow = "FILRR-";
1580 nchk = "FICHK-";
1581 lname = "prefFilterList";
1582 } else if (kind == "label") {
1583 opbarid = "labelOpToolbar";
1584 nrow = "LILRR-";
1585 nchk = "LICHK-";
1586 lname = "prefLabelList";
1587 } else if (kind == "user") {
1588 opbarid = "userOpToolbar";
1589 nrow = "UMRR-";
1590 nchk = "UMCHK-";
1591 lname = "prefUserList";
1592 }
1593
1594 if (opbarid) {
1595 selectTableRowsByIdPrefix(lname, nrow, nchk, select);
1596 disableContainerChildren(opbarid, !select);
1597 }
1598
1599 }
1600 }
1601
1602
1603 function toggleSelectPrefRow(sender, kind) {
1604
1605 toggleSelectRow(sender);
1606
1607 if (kind) {
1608 var opbarid = false;
1609 var nsel = -1;
1610
1611 if (kind == "feed") {
1612 opbarid = "feedOpToolbar";
1613 nsel = getSelectedFeeds();
1614 } else if (kind == "fcat") {
1615 opbarid = "catOpToolbar";
1616 nsel = getSelectedFeedCats();
1617 } else if (kind == "filter") {
1618 opbarid = "filterOpToolbar";
1619 nsel = getSelectedFilters();
1620 } else if (kind == "label") {
1621 opbarid = "labelOpToolbar";
1622 nsel = getSelectedLabels();
1623 } else if (kind == "user") {
1624 opbarid = "userOpToolbar";
1625 nsel = getSelectedUsers();
1626 }
1627
1628 if (opbarid && nsel != -1) {
1629 disableContainerChildren(opbarid, nsel == false);
1630 }
1631
1632 }
1633 }
1634
1635 function toggleSelectFBListRow(sender) {
1636 toggleSelectListRow(sender);
1637 disableContainerChildren("fbrOpToolbar", getSelectedFeedsFromBrowser() == 0);
1638 }
1639
1640 var seq = "";
1641
1642 function pref_hotkey_handler(e) {
1643 try {
1644
1645 var keycode;
1646 var shift_key = false;
1647
1648 try {
1649 shift_key = e.shiftKey;
1650 } catch (e) {
1651
1652 }
1653
1654 if (window.event) {
1655 keycode = window.event.keyCode;
1656 } else if (e) {
1657 keycode = e.which;
1658 }
1659
1660 var keychar = String.fromCharCode(keycode);
1661
1662 if (keycode == 27) { // escape
1663 if (Element.visible("hotkey_help_overlay")) {
1664 Element.hide("hotkey_help_overlay");
1665 }
1666 hotkey_prefix = false;
1667 closeInfoBox();
1668 }
1669
1670 if (!hotkeys_enabled) {
1671 debug("hotkeys disabled");
1672 return;
1673 }
1674
1675 if (keycode == 16) return; // ignore lone shift
1676
1677 if ((keycode == 67 || keycode == 71) && !hotkey_prefix) {
1678 hotkey_prefix = keycode;
1679 debug("KP: PREFIX=" + keycode + " CHAR=" + keychar);
1680 return;
1681 }
1682
1683 if (Element.visible("hotkey_help_overlay")) {
1684 Element.hide("hotkey_help_overlay");
1685 }
1686
1687 if (keycode == 13 || keycode == 27) {
1688 seq = "";
1689 } else {
1690 seq = seq + "" + keycode;
1691 }
1692
1693 /* Global hotkeys */
1694
1695 if (!hotkey_prefix) {
1696
1697 if (keycode == 68 && shift_key) { // d
1698 if (!Element.visible("debug_output")) {
1699 Element.show("debug_output");
1700 debug('debug mode activated');
1701 } else {
1702 Element.hide("debug_output");
1703 }
1704 return;
1705 }
1706
1707 if ((keycode == 191 || keychar == '?') && shift_key) { // ?
1708 if (!Element.visible("hotkey_help_overlay")) {
1709 //Element.show("hotkey_help_overlay");
1710 Effect.Appear("hotkey_help_overlay", {duration : 0.3});
1711 } else {
1712 Element.hide("hotkey_help_overlay");
1713 }
1714 return false;
1715 }
1716
1717 if (keycode == 191 || keychar == '/') { // /
1718 var search_boxes = new Array("label_search",
1719 "feed_search", "filter_search", "user_search", "feed_browser_search");
1720
1721 for (var i = 0; i < search_boxes.length; i++) {
1722 var elem = document.getElementById(search_boxes[i]);
1723 if (elem) {
1724 focus_element(search_boxes[i]);
1725 return false;
1726 }
1727 }
1728 }
1729 }
1730
1731 /* Prefix c */
1732
1733 if (hotkey_prefix == 67) { // c
1734 hotkey_prefix = false;
1735
1736 if (keycode == 70) { // f
1737 displayDlg("quickAddFilter");
1738 return false;
1739 }
1740
1741 if (keycode == 83) { // s
1742 displayDlg("quickAddFeed");
1743 return false;
1744 }
1745
1746 /* if (keycode == 76) { // l
1747 displayDlg("quickAddLabel");
1748 return false;
1749 } */
1750
1751 if (keycode == 85) { // u
1752 // no-op
1753 }
1754
1755 if (keycode == 67) { // c
1756 editFeedCats();
1757 return false;
1758 }
1759
1760 if (keycode == 84 && shift_key) { // T
1761 browseFeeds();
1762 return false;
1763 }
1764
1765 }
1766
1767 /* Prefix g */
1768
1769 if (hotkey_prefix == 71) { // g
1770
1771 hotkey_prefix = false;
1772
1773 if (keycode == 49 && document.getElementById("genConfigTab")) { // 1
1774 selectTab("genConfig");
1775 return false;
1776 }
1777
1778 if (keycode == 50 && document.getElementById("feedConfigTab")) { // 2
1779 selectTab("feedConfig");
1780 return false;
1781 }
1782
1783 if (keycode == 51 && document.getElementById("feedBrowserTab")) { // 3
1784 selectTab("feedBrowser");
1785 return false;
1786 }
1787
1788 if (keycode == 52 && document.getElementById("filterConfigTab")) { // 4
1789 selectTab("filterConfig");
1790 return false;
1791 }
1792
1793 if (keycode == 53 && document.getElementById("labelConfigTab")) { // 5
1794 selectTab("labelConfig");
1795 return false;
1796 }
1797
1798 if (keycode == 54 && document.getElementById("userConfigTab")) { // 6
1799 selectTab("userConfig");
1800 return false;
1801 }
1802
1803 if (keycode == 88) { // x
1804 return gotoMain();
1805 }
1806
1807 }
1808
1809 if (document.getElementById("piggie")) {
1810
1811 if (seq.match("807371717369")) {
1812 seq = "";
1813 piggie(true);
1814 } else {
1815 piggie(false);
1816 }
1817 }
1818
1819 if (hotkey_prefix) {
1820 debug("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar);
1821 } else {
1822 debug("KP: CODE=" + keycode + " CHAR=" + keychar);
1823 }
1824
1825 } catch (e) {
1826 exception_error("pref_hotkey_handler", e);
1827 }
1828 }
1829
1830 function editFeedCats() {
1831 if (!xmlhttp_ready(xmlhttp)) {
1832 printLockingError();
1833 return
1834 }
1835
1836 document.getElementById("subscribe_to_feed_btn").disabled = true;
1837
1838 try {
1839 document.getElementById("top25_feeds_btn").disabled = true;
1840 } catch (e) {
1841 // this button is not always available, no-op if not found
1842 }
1843
1844 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
1845 xmlhttp.onreadystatechange=infobox_feed_cat_callback;
1846 xmlhttp.send(null);
1847 }
1848
1849 function showFeedsWithErrors() {
1850 displayDlg('feedUpdateErrors');
1851 }
1852
1853 function changeUserPassword() {
1854
1855 try {
1856
1857 if (!xmlhttp_ready(xmlhttp)) {
1858 printLockingError();
1859 return false;
1860 }
1861
1862 var f = document.forms["change_pass_form"];
1863
1864 if (f) {
1865 if (f.OLD_PASSWORD.value == "") {
1866 new Effect.Highlight(f.OLD_PASSWORD);
1867 notify_error("Old password cannot be blank.");
1868 return false;
1869 }
1870
1871 if (f.NEW_PASSWORD.value == "") {
1872 new Effect.Highlight(f.NEW_PASSWORD);
1873 notify_error("New password cannot be blank.");
1874 return false;
1875 }
1876
1877 if (f.CONFIRM_PASSWORD.value == "") {
1878 new Effect.Highlight(f.CONFIRM_PASSWORD);
1879 notify_error("Entered passwords do not match.");
1880 return false;
1881 }
1882
1883 if (f.CONFIRM_PASSWORD.value != f.NEW_PASSWORD.value) {
1884 new Effect.Highlight(f.CONFIRM_PASSWORD);
1885 new Effect.Highlight(f.NEW_PASSWORD);
1886 notify_error("Entered passwords do not match.");
1887 return false;
1888 }
1889
1890 }
1891
1892 var query = Form.serialize("change_pass_form");
1893
1894 notify_progress("Trying to change password...");
1895
1896 xmlhttp.open("POST", "backend.php", true);
1897 xmlhttp.onreadystatechange=changepass_callback;
1898 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1899 xmlhttp.send(query);
1900
1901 } catch (e) {
1902 exception_error("changeUserPassword", e);
1903 }
1904
1905 return false;
1906 }
1907
1908 function changeUserEmail() {
1909
1910 try {
1911
1912 if (!xmlhttp_ready(xmlhttp)) {
1913 printLockingError();
1914 return false;
1915 }
1916
1917 var query = Form.serialize("change_email_form");
1918
1919 notify_progress("Trying to change e-mail...");
1920
1921 xmlhttp.open("POST", "backend.php", true);
1922 xmlhttp.onreadystatechange=notify_callback;
1923 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1924 xmlhttp.send(query);
1925
1926 } catch (e) {
1927 exception_error("changeUserPassword", e);
1928 }
1929
1930 return false;
1931
1932 }
1933
1934 function feedlistToggleSLAT() {
1935 notify_progress("Loading, please wait...");
1936 updateFeedList()
1937 }
1938
1939 function pubRegenKey() {
1940
1941 if (!xmlhttp_ready(xmlhttp)) {
1942 printLockingError();
1943 return false;
1944 }
1945
1946 var ok = confirm(__("Replace current publishing address with a new one?"));
1947
1948 if (ok) {
1949
1950 notify_progress("Trying to change address...");
1951
1952 xmlhttp.open("GET", "backend.php?op=rpc&subop=regenPubKey");
1953 xmlhttp.onreadystatechange=replace_pubkey_callback;
1954 xmlhttp.send(null);
1955 }
1956
1957 return false;
1958 }
1959
1960 function pubToClipboard() {
1961
1962 try {
1963
1964 if (!xmlhttp_ready(xmlhttp)) {
1965 printLockingError();
1966 return false;
1967 }
1968
1969 var link = document.getElementById("pubGenAddress");
1970 alert(link.href);
1971
1972 } catch (e) {
1973 exception_error("pubToClipboard", e);
1974 }
1975
1976 return false;
1977 }
1978
1979 function validatePrefsSave() {
1980 try {
1981
1982 var ok = confirm(__("Save current configuration?"));
1983
1984 if (ok) {
1985
1986 var query = Form.serialize("pref_prefs_form");
1987 query = query + "&subop=save-config";
1988 debug(query);
1989
1990 xmlhttp.open("POST", "backend.php", true);
1991 xmlhttp.onreadystatechange=notify_callback;
1992 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1993 xmlhttp.send(query);
1994 }
1995
1996 } catch (e) {
1997 exception_error("validatePrefsSave", e);
1998 }
1999
2000 return false;
2001 }
2002
2003 function feedActionChange() {
2004 try {
2005 var chooser = document.getElementById("feedActionChooser");
2006 var opid = chooser[chooser.selectedIndex].value;
2007
2008 chooser.selectedIndex = 0;
2009 feedActionGo(opid);
2010 } catch (e) {
2011 exception_error("feedActionChange", e);
2012 }
2013 }
2014
2015 function feedActionGo(op) {
2016 try {
2017 if (op == "facEdit") {
2018
2019 var rows = getSelectedFeeds();
2020
2021 if (rows.length > 1) {
2022 editSelectedFeeds();
2023 } else {
2024 editSelectedFeed();
2025 }
2026 }
2027
2028 if (op == "facClear") {
2029 clearSelectedFeeds();
2030 }
2031
2032 if (op == "facPurge") {
2033 purgeSelectedFeeds();
2034 }
2035
2036 if (op == "facEditCats") {
2037 editFeedCats();
2038 }
2039
2040 if (op == "facRescore") {
2041 rescoreSelectedFeeds();
2042 }
2043
2044 if (op == "facUnsubscribe") {
2045 removeSelectedFeeds();
2046 }
2047
2048 } catch (e) {
2049 exception_error("feedActionGo", e);
2050
2051 }
2052 }
2053
2054 function clearFeedArticles(feed_id) {
2055
2056 notify_progress("Clearing feed...");
2057
2058 var query = "backend.php?op=pref-feeds&quiet=1&subop=clear&id=" + feed_id;
2059
2060 new Ajax.Request(query, {
2061 onComplete: function(transport) {
2062 notify('');
2063 } });
2064
2065 return false;
2066 }
2067
2068 function rescoreSelectedFeeds() {
2069
2070 if (!xmlhttp_ready(xmlhttp)) {
2071 printLockingError();
2072 return
2073 }
2074
2075 var sel_rows = getSelectedFeeds();
2076
2077 if (sel_rows.length > 0) {
2078
2079 //var ok = confirm(__("Rescore last 100 articles in selected feeds?"));
2080 var ok = confirm(__("Rescore articles in selected feeds?"));
2081
2082 if (ok) {
2083 notify_progress("Rescoring selected feeds...", true);
2084
2085 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=rescore&quiet=1&ids="+
2086 param_escape(sel_rows.toString()), true);
2087 xmlhttp.onreadystatechange=notify_callback;
2088 xmlhttp.send(null);
2089 }
2090 } else {
2091 alert(__("No feeds are selected."));
2092 }
2093
2094 return false;
2095 }
2096
2097 function rescore_all_feeds() {
2098 var ok = confirm(__("Rescore all articles? This operation may take a lot of time."));
2099
2100 if (ok) {
2101 notify_progress("Rescoring feeds...", true);
2102
2103 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=rescoreAll&quiet=1", true);
2104 xmlhttp.onreadystatechange=notify_callback;
2105 xmlhttp.send(null);
2106 }
2107 }
2108
2109 function removeFilter(id, title) {
2110
2111 if (!xmlhttp_ready(xmlhttp)) {
2112 printLockingError();
2113 return
2114 }
2115
2116 var msg = __("Remove filter %s?").replace("%s", title);
2117
2118 var ok = confirm(msg);
2119
2120 if (ok) {
2121 closeInfoBox();
2122
2123 notify_progress("Removing filter...");
2124
2125 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
2126 param_escape(id), true);
2127 xmlhttp.onreadystatechange=filterlist_callback;
2128 xmlhttp.send(null);
2129 }
2130
2131 return false;
2132 }
2133
2134 function unsubscribeFeed(id, title) {
2135
2136 if (!xmlhttp_ready(xmlhttp)) {
2137 printLockingError();
2138 return
2139 }
2140
2141 var msg = __("Unsubscribe from %s?").replace("%s", title);
2142
2143 var ok = confirm(msg);
2144
2145 if (ok) {
2146 closeInfoBox();
2147
2148 notify_progress("Removing feed...");
2149
2150 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
2151 param_escape(id), true);
2152 xmlhttp.onreadystatechange=filterlist_callback;
2153 xmlhttp.send(null);
2154 }
2155
2156 return false;
2157
2158 return false;
2159
2160 }
2161
2162 function feedsEditSave() {
2163 try {
2164
2165 if (!xmlhttp_ready(xmlhttp)) {
2166 printLockingError();
2167 return
2168 }
2169
2170 var ok = confirm(__("Save changes to selected feeds?"));
2171
2172 if (ok) {
2173
2174 var f = document.forms["batch_edit_feed_form"];
2175
2176 var query = Form.serialize("batch_edit_feed_form");
2177
2178 /* Form.serialize ignores unchecked checkboxes */
2179
2180 if (!query.match("&hidden=") &&
2181 f.hidden.disabled == false) {
2182 query = query + "&hidden=false";
2183 }
2184
2185 if (!query.match("&rtl_content=") &&
2186 f.rtl_content.disabled == false) {
2187 query = query + "&rtl_content=false";
2188 }
2189
2190 if (!query.match("&private=") &&
2191 f.private.disabled == false) {
2192 query = query + "&private=false";
2193 }
2194
2195 if (!query.match("&cache_images=") &&
2196 f.cache_images.disabled == false) {
2197 query = query + "&cache_images=false";
2198 }
2199
2200 if (!query.match("&include_in_digest=") &&
2201 f.include_in_digest.disabled == false) {
2202 query = query + "&include_in_digest=false";
2203 }
2204
2205 closeInfoBox();
2206
2207 notify_progress("Saving feeds...");
2208
2209 xmlhttp.open("POST", "backend.php", true);
2210 xmlhttp.onreadystatechange=feedlist_callback;
2211 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
2212 xmlhttp.send(query);
2213 }
2214
2215 return false;
2216 } catch (e) {
2217 exception_error("feedsEditSave", e);
2218 }
2219 }
2220
2221 function batchFeedsToggleField(cb, elem, label) {
2222 try {
2223 var f = document.forms["batch_edit_feed_form"];
2224 var l = document.getElementById(label);
2225
2226 if (cb.checked) {
2227 f[elem].disabled = false;
2228
2229 if (l) {
2230 l.className = "";
2231 };
2232
2233 // new Effect.Highlight(f[elem], {duration: 1, startcolor: "#fff7d5",
2234 // queue: { position:'end', scope: 'BPEFQ', limit: 1 } } );
2235
2236 } else {
2237 f[elem].disabled = true;
2238
2239 if (l) {
2240 l.className = "insensitive";
2241 };
2242
2243 }
2244 } catch (e) {
2245 exception_error("batchFeedsToggleField", e);
2246 }
2247 }
2248