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