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