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