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