]> git.wh0rd.org - tt-rss.git/blob - prefs.js
add index on ttrss_entries(date_entered), bump schema
[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 new Effect.Highlight(link);
30
31 notify_info("Address changed.");
32 } else {
33 notify_error("Could not change address.");
34 }
35
36 } else {
37 notify_error("Could not change address.");
38 }
39 } catch (e) {
40 exception_error("replace_pubkey_callback", e);
41 }
42 }
43 }
44
45 function expand_feed_callback() {
46 if (xmlhttp.readyState == 4) {
47 try {
48 var container = document.getElementById("BRDET-" + feed_to_expand);
49 container.innerHTML=xmlhttp.responseText;
50 // container.style.display = "block";
51 Effect.Appear(container, {duration : 0.5});
52 } catch (e) {
53 exception_error("expand_feed_callback", e);
54 }
55 }
56 }
57
58 function feedlist_callback() {
59 if (xmlhttp.readyState == 4) {
60 try {
61 var container = document.getElementById('prefContent');
62 container.innerHTML=xmlhttp.responseText;
63 selectTab("feedConfig", true);
64
65 if (caller_subop) {
66 var tuple = caller_subop.split(":");
67 if (tuple[0] == 'editFeed') {
68 window.setTimeout('editFeed('+tuple[1]+')', 100);
69 }
70
71 caller_subop = false;
72 }
73 if (typeof correctPNG != 'undefined') {
74 correctPNG();
75 }
76 notify("");
77 } catch (e) {
78 exception_error("feedlist_callback", e);
79 }
80 }
81 }
82
83 /* stub for subscription dialog */
84
85 function dlg_frefresh_callback() {
86 if (xmlhttp.readyState == 4) {
87 // setTimeout("updateFeedList()", 500);
88
89 try {
90 var container = document.getElementById('prefContent');
91 container.innerHTML=xmlhttp.responseText;
92 selectTab("feedConfig", true);
93
94 if (caller_subop) {
95 var tuple = caller_subop.split(":");
96 if (tuple[0] == 'editFeed') {
97 window.setTimeout('editFeed('+tuple[1]+')', 100);
98 }
99
100 caller_subop = false;
101 }
102 if (typeof correctPNG != 'undefined') {
103 correctPNG();
104 }
105 notify("");
106 } catch (e) {
107 exception_error("feedlist_callback", e);
108 }
109 }
110 }
111
112 function filterlist_callback() {
113 var container = document.getElementById('prefContent');
114 if (xmlhttp.readyState == 4) {
115 container.innerHTML=xmlhttp.responseText;
116 if (typeof correctPNG != 'undefined') {
117 correctPNG();
118 }
119 notify("");
120 }
121 }
122
123 function labellist_callback() {
124 var container = document.getElementById('prefContent');
125 if (xmlhttp.readyState == 4) {
126 closeInfoBox();
127 container.innerHTML=xmlhttp.responseText;
128 if (active_label) {
129 var row = document.getElementById("LILRR-" + active_label);
130 if (row) {
131 if (!row.className.match("Selected")) {
132 row.className = row.className + "Selected";
133 }
134 }
135 var checkbox = document.getElementById("LICHK-" + active_label);
136
137 if (checkbox) {
138 checkbox.checked = true;
139 }
140 }
141 if (typeof correctPNG != 'undefined') {
142 correctPNG();
143 }
144 notify("");
145 }
146 }
147
148 function feed_browser_callback() {
149 var container = document.getElementById('prefContent');
150 if (xmlhttp.readyState == 4) {
151 container.innerHTML=xmlhttp.responseText;
152 notify("");
153 }
154 }
155
156 function userlist_callback() {
157 var container = document.getElementById('prefContent');
158 if (xmlhttp.readyState == 4) {
159 container.innerHTML=xmlhttp.responseText;
160 notify("");
161 }
162 }
163
164 function prefslist_callback() {
165 var container = document.getElementById('prefContent');
166 if (xmlhttp.readyState == 4) {
167
168 container.innerHTML=xmlhttp.responseText;
169
170 notify("");
171 }
172 }
173
174 function gethelp_callback() {
175 var container = document.getElementById('prefHelpBox');
176 if (xmlhttp.readyState == 4) {
177
178 container.innerHTML = xmlhttp.responseText;
179 container.style.display = "block";
180
181 }
182 }
183
184 function notify_callback() {
185 if (xmlhttp.readyState == 4) {
186 notify_info(xmlhttp.responseText);
187 }
188 }
189
190 function prefs_reset_callback() {
191 if (xmlhttp.readyState == 4) {
192 notify_info(xmlhttp.responseText);
193 selectTab();
194 }
195 }
196
197
198 function changepass_callback() {
199 try {
200 if (xmlhttp.readyState == 4) {
201
202 if (xmlhttp.responseText.indexOf("ERROR: ") == 0) {
203 notify_error(xmlhttp.responseText.replace("ERROR: ", ""));
204 } else {
205 notify_info(xmlhttp.responseText);
206 var warn = document.getElementById("default_pass_warning");
207 if (warn) warn.style.display = "none";
208 }
209
210 document.forms['change_pass_form'].reset();
211
212 }
213 } catch (e) {
214 exception_error("changepass_callback", e);
215 }
216 }
217
218 function infobox_feed_cat_callback() {
219 if (xmlhttp.readyState == 4) {
220 try {
221
222 infobox_callback();
223
224 if (document.getElementById("prefFeedCatList")) {
225 var elems = document.getElementById("prefFeedCatList").getElementsByTagName("SPAN");
226
227 for (var i = 0; i < elems.length; i++) {
228 if (elems[i].id && elems[i].id.match("FCATT-")) {
229 var cat_id = elems[i].id.replace("FCATT-", "");
230
231 new Ajax.InPlaceEditor(elems[i],
232 'backend.php?op=pref-feeds&subop=editCats&action=save&cid=' + cat_id);
233 }
234 }
235 }
236
237 } catch (e) {
238 exception_error("infobox_feed_cat_callback", e);
239 }
240 }
241 }
242
243 function updateFeedList(sort_key) {
244
245 if (!xmlhttp_ready(xmlhttp)) {
246 printLockingError();
247 return
248 }
249
250 var feed_search = document.getElementById("feed_search");
251 var search = "";
252 if (feed_search) { search = feed_search.value; }
253
254 var slat = document.getElementById("show_last_article_times");
255
256 var slat_checked = false;
257 if (slat) {
258 slat_checked = slat.checked;
259 }
260
261 xmlhttp.open("GET", "backend.php?op=pref-feeds" +
262 "&sort=" + param_escape(sort_key) +
263 "&slat=" + param_escape(slat_checked) +
264 "&search=" + param_escape(search), true);
265 xmlhttp.onreadystatechange=feedlist_callback;
266 xmlhttp.send(null);
267
268 }
269
270 function updateUsersList(sort_key) {
271
272 if (!xmlhttp_ready(xmlhttp)) {
273 printLockingError();
274 return
275 }
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 var url = "backend.php?op=help&tid=" + param_escape(topic_id);
785
786 var w = window.open(url, "ttrss_help",
787 "status=0,toolbar=0,location=0,width=400,height=450,menubar=0");
788
789 }
790
791 function labelEditCancel() {
792
793 if (!xmlhttp_ready(xmlhttp)) {
794 printLockingError();
795 return
796 }
797
798 document.getElementById("label_create_btn").disabled = false;
799
800 active_label = false;
801
802 selectPrefRows('label', false); // cleanup feed selection
803 closeInfoBox();
804
805 return false;
806 }
807
808 function userEditCancel() {
809
810 if (!xmlhttp_ready(xmlhttp)) {
811 printLockingError();
812 return
813 }
814
815 selectPrefRows('user', false); // cleanup feed selection
816 closeInfoBox();
817
818 return false;
819 }
820
821 function filterEditCancel() {
822
823 if (!xmlhttp_ready(xmlhttp)) {
824 printLockingError();
825 return
826 }
827
828 document.getElementById("create_filter_btn").disabled = false;
829
830 selectPrefRows('filter', false); // cleanup feed selection
831 closeInfoBox();
832
833 return false;
834 }
835
836 function labelEditSave() {
837
838 var label = active_label;
839
840 if (!xmlhttp_ready(xmlhttp)) {
841 printLockingError();
842 return
843 }
844
845 /* if (!is_opera()) {
846
847 var sql_exp = document.forms["label_edit_form"].sql_exp.value;
848 var description = document.forms["label_edit_form"].description.value;
849
850 if (sql_exp.length == 0) {
851 alert("SQL Expression cannot be blank.");
852 return false;
853 }
854
855 if (description.length == 0) {
856 alert("Caption field cannot be blank.");
857 return false;
858 }
859 } */
860
861 closeInfoBox();
862
863 notify_progress("Saving label...");
864
865 active_label = false;
866
867 query = Form.serialize("label_edit_form");
868
869 xmlhttp.open("GET", "backend.php?" + query, true);
870 xmlhttp.onreadystatechange=labellist_callback;
871 xmlhttp.send(null);
872
873 return false;
874 }
875
876 function userEditSave() {
877
878 if (!xmlhttp_ready(xmlhttp)) {
879 printLockingError();
880 return
881 }
882
883 var login = document.forms["user_edit_form"].login.value;
884
885 if (login.length == 0) {
886 alert(__("Login field cannot be blank."));
887 return;
888 }
889
890 notify_progress("Saving user...");
891
892 closeInfoBox();
893
894 var query = Form.serialize("user_edit_form");
895
896 xmlhttp.open("GET", "backend.php?" + query, true);
897 xmlhttp.onreadystatechange=userlist_callback;
898 xmlhttp.send(null);
899
900 return false;
901 }
902
903
904 function filterEditSave() {
905
906 if (!xmlhttp_ready(xmlhttp)) {
907 printLockingError();
908 return
909 }
910
911 /* if (!is_opera()) {
912 var reg_exp = document.forms["filter_edit_form"].reg_exp.value;
913
914 if (reg_exp.length == 0) {
915 alert("Filter expression field cannot be blank.");
916 return;
917 }
918 } */
919
920 notify_progress("Saving filter...");
921
922 var query = Form.serialize("filter_edit_form");
923
924 closeInfoBox();
925
926 document.getElementById("create_filter_btn").disabled = false;
927
928 xmlhttp.open("GET", "backend.php?" + query, true);
929 xmlhttp.onreadystatechange=filterlist_callback;
930 xmlhttp.send(null);
931
932 return false;
933 }
934
935 function editSelectedLabel() {
936 var rows = getSelectedLabels();
937
938 if (rows.length == 0) {
939 alert(__("No labels are selected."));
940 return;
941 }
942
943 if (rows.length > 1) {
944 alert(__("Please select only one label."));
945 return;
946 }
947
948 notify("");
949
950 editLabel(rows[0]);
951
952 }
953
954 function editSelectedUser() {
955 var rows = getSelectedUsers();
956
957 if (rows.length == 0) {
958 alert(__("No users are selected."));
959 return;
960 }
961
962 if (rows.length > 1) {
963 alert(__("Please select only one user."));
964 return;
965 }
966
967 notify("");
968
969 editUser(rows[0]);
970 }
971
972 function resetSelectedUserPass() {
973 var rows = getSelectedUsers();
974
975 if (rows.length == 0) {
976 alert(__("No users are selected."));
977 return;
978 }
979
980 if (rows.length > 1) {
981 alert(__("Please select only one user."));
982 return;
983 }
984
985 var ok = confirm(__("Reset password of selected user?"));
986
987 if (ok) {
988 notify_progress("Resetting password for selected user...");
989
990 var id = rows[0];
991
992 xmlhttp.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
993 param_escape(id), true);
994 xmlhttp.onreadystatechange=userlist_callback;
995 xmlhttp.send(null);
996 }
997 }
998
999 function selectedUserDetails() {
1000
1001 if (!xmlhttp_ready(xmlhttp)) {
1002 printLockingError();
1003 return
1004 }
1005
1006 var rows = getSelectedUsers();
1007
1008 if (rows.length == 0) {
1009 alert(__("No users are selected."));
1010 return;
1011 }
1012
1013 if (rows.length > 1) {
1014 alert(__("Please select only one user."));
1015 return;
1016 }
1017
1018 notify_progress("Loading, please wait...");
1019
1020 var id = rows[0];
1021
1022 xmlhttp.open("GET", "backend.php?op=user-details&id=" + id, true);
1023 xmlhttp.onreadystatechange=infobox_callback;
1024 xmlhttp.send(null);
1025
1026 }
1027
1028 function selectedFeedDetails() {
1029
1030 if (!xmlhttp_ready(xmlhttp)) {
1031 printLockingError();
1032 return
1033 }
1034
1035 var rows = getSelectedFeeds();
1036
1037 if (rows.length == 0) {
1038 alert(__("No feeds are selected."));
1039 return;
1040 }
1041
1042 if (rows.length > 1) {
1043 alert(__("Please select only one feed."));
1044 return;
1045 }
1046
1047 // var id = rows[0];
1048
1049 notify("");
1050
1051 xmlhttp.open("GET", "backend.php?op=feed-details&id=" +
1052 param_escape(rows.toString()), true);
1053 xmlhttp.onreadystatechange=infobox_callback;
1054 xmlhttp.send(null);
1055
1056 }
1057
1058 function editSelectedFilter() {
1059 var rows = getSelectedFilters();
1060
1061 if (rows.length == 0) {
1062 alert(__("No filters are selected."));
1063 return;
1064 }
1065
1066 if (rows.length > 1) {
1067 alert(__("Please select only one filter."));
1068 return;
1069 }
1070
1071 notify("");
1072
1073 editFilter(rows[0]);
1074
1075 }
1076
1077
1078 function editSelectedFeed() {
1079 var rows = getSelectedFeeds();
1080
1081 if (rows.length == 0) {
1082 alert(__("No feeds are selected."));
1083 return;
1084 }
1085
1086 if (rows.length > 1) {
1087 alert(__("Please select one feed."));
1088 return;
1089 }
1090
1091 notify("");
1092
1093 editFeed(rows[0]);
1094
1095 }
1096
1097 function editSelectedFeedCat() {
1098 var rows = getSelectedFeedCats();
1099
1100 if (rows.length == 0) {
1101 alert(__("No categories are selected."));
1102 return;
1103 }
1104
1105 if (rows.length > 1) {
1106 alert(__("Please select only one category."));
1107 return;
1108 }
1109
1110 notify("");
1111
1112 editFeedCat(rows[0]);
1113
1114 }
1115
1116 function localPiggieFunction(enable) {
1117 if (enable) {
1118 debug("I LOVEDED IT!");
1119 var piggie = document.getElementById("piggie");
1120
1121 Element.show(piggie);
1122 Position.Center(piggie);
1123 Effect.Puff(piggie);
1124
1125 }
1126 }
1127
1128 function validateOpmlImport() {
1129
1130 var opml_file = document.getElementById("opml_file");
1131
1132 if (opml_file.value.length == 0) {
1133 alert(__("No OPML file to upload."));
1134 return false;
1135 } else {
1136 return true;
1137 }
1138 }
1139
1140 function updateFilterList(sort_key) {
1141
1142 if (!xmlhttp_ready(xmlhttp)) {
1143 printLockingError();
1144 return
1145 }
1146
1147 xmlhttp.open("GET", "backend.php?op=pref-filters&sort=" +
1148 param_escape(sort_key), true);
1149 xmlhttp.onreadystatechange=filterlist_callback;
1150 xmlhttp.send(null);
1151
1152 }
1153
1154 function updateLabelList(sort_key) {
1155
1156 if (!xmlhttp_ready(xmlhttp)) {
1157 printLockingError();
1158 return
1159 }
1160
1161 xmlhttp.open("GET", "backend.php?op=pref-labels&sort=" +
1162 param_escape(sort_key), true);
1163 xmlhttp.onreadystatechange=labellist_callback;
1164 xmlhttp.send(null);
1165 }
1166
1167 function updatePrefsList() {
1168
1169 if (!xmlhttp_ready(xmlhttp)) {
1170 printLockingError();
1171 return
1172 }
1173
1174 xmlhttp.open("GET", "backend.php?op=pref-prefs", true);
1175 xmlhttp.onreadystatechange=prefslist_callback;
1176 xmlhttp.send(null);
1177
1178 }
1179
1180 function selectTab(id, noupdate, subop) {
1181
1182 // alert(id);
1183
1184 if (!id) id = active_tab;
1185
1186 try {
1187
1188 if (!xmlhttp_ready(xmlhttp)) {
1189 printLockingError();
1190 return
1191 }
1192
1193 try {
1194 var c = document.getElementById('prefContent');
1195 c.scrollTop = 0;
1196 } catch (e) { };
1197
1198 if (!noupdate) {
1199
1200 debug("selectTab: " + id + "(NU: " + noupdate + ")");
1201
1202 notify_progress("Loading, please wait...");
1203
1204 // close active infobox if needed
1205 closeInfoBox();
1206
1207 // clean up all current selections, just in case
1208 active_feed_cat = false;
1209 active_label = false;
1210
1211 // Effect.Fade("prefContent", {duration: 1, to: 0.01,
1212 // queue: { position:'end', scope: 'FEED_TAB', limit: 1 } } );
1213
1214 if (id == "feedConfig") {
1215 updateFeedList();
1216 } else if (id == "filterConfig") {
1217 updateFilterList();
1218 } else if (id == "labelConfig") {
1219 updateLabelList();
1220 } else if (id == "genConfig") {
1221 updatePrefsList();
1222 } else if (id == "userConfig") {
1223 updateUsersList();
1224 } else if (id == "feedBrowser") {
1225 updateBigFeedBrowser();
1226 }
1227 }
1228
1229 var tab = document.getElementById(active_tab + "Tab");
1230
1231 if (tab) {
1232 if (tab.className.match("Selected")) {
1233 tab.className = "prefsTab";
1234 }
1235 }
1236
1237 tab = document.getElementById(id + "Tab");
1238
1239 if (tab) {
1240 if (!tab.className.match("Selected")) {
1241 tab.className = tab.className + "Selected";
1242 }
1243 }
1244
1245 active_tab = id;
1246
1247 } catch (e) {
1248 exception_error("selectTab", e);
1249 }
1250 }
1251
1252 function backend_sanity_check_callback() {
1253
1254 if (xmlhttp.readyState == 4) {
1255
1256 try {
1257
1258 if (sanity_check_done) {
1259 fatalError(11, "Sanity check request received twice. This can indicate "+
1260 "presence of Firebug or some other disrupting extension. "+
1261 "Please disable it and try again.");
1262 return;
1263 }
1264
1265 if (!xmlhttp.responseXML) {
1266 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp.responseText);
1267 return;
1268 }
1269
1270 var reply = xmlhttp.responseXML.firstChild.firstChild;
1271
1272 if (!reply) {
1273 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp.responseText);
1274 return;
1275 }
1276
1277 var error_code = reply.getAttribute("error-code");
1278
1279 if (error_code && error_code != 0) {
1280 return fatalError(error_code, reply.getAttribute("error-msg"));
1281 }
1282
1283 debug("sanity check ok");
1284
1285 var params = reply.nextSibling;
1286
1287 if (params) {
1288 debug('reading init-params...');
1289 var param = params.firstChild;
1290
1291 while (param) {
1292 var k = param.getAttribute("key");
1293 var v = param.getAttribute("value");
1294 debug(k + " => " + v);
1295 init_params[k] = v;
1296 param = param.nextSibling;
1297 }
1298 }
1299
1300 sanity_check_done = true;
1301
1302 init_second_stage();
1303
1304 } catch (e) {
1305 exception_error("backend_sanity_check_callback", e);
1306 }
1307 }
1308 }
1309
1310 function init_second_stage() {
1311
1312 try {
1313 active_tab = getInitParam("prefs_active_tab");
1314 if (!active_tab || active_tab == '0') active_tab = "genConfig";
1315
1316 document.onkeydown = pref_hotkey_handler;
1317
1318 var tab = getURLParam('tab');
1319
1320 caller_subop = getURLParam('subop');
1321
1322 if (tab) {
1323 active_tab = tab;
1324 }
1325
1326 if (navigator.userAgent.match("Opera")) {
1327 setTimeout("selectTab()", 500);
1328 } else {
1329 selectTab(active_tab);
1330 }
1331 notify("");
1332 } catch (e) {
1333 exception_error("init_second_stage", e);
1334 }
1335 }
1336
1337 function init() {
1338
1339 try {
1340
1341 if (arguments.callee.done) return;
1342 arguments.callee.done = true;
1343
1344 if (getURLParam('debug')) {
1345 document.getElementById('debug_output').style.display = 'block';
1346 debug('debug mode activated');
1347 }
1348
1349 // IE kludge
1350 if (!xmlhttp) {
1351 document.getElementById("prefContent").innerHTML =
1352 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1353 "to function properly. Your browser doesn't seem to support it.";
1354 return;
1355 }
1356
1357 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
1358 xmlhttp.onreadystatechange=backend_sanity_check_callback;
1359 xmlhttp.send(null);
1360
1361 } catch (e) {
1362 exception_error("init", e);
1363 }
1364 }
1365
1366 function categorizeSelectedFeeds() {
1367
1368 if (!xmlhttp_ready(xmlhttp)) {
1369 printLockingError();
1370 return
1371 }
1372
1373 var sel_rows = getSelectedFeeds();
1374
1375 var cat_sel = document.getElementById("sfeed_set_fcat");
1376 var cat_id = cat_sel[cat_sel.selectedIndex].value;
1377
1378 if (sel_rows.length > 0) {
1379
1380 notify_progress("Changing category of selected feeds...");
1381
1382 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
1383 param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
1384 xmlhttp.onreadystatechange=feedlist_callback;
1385 xmlhttp.send(null);
1386
1387 } else {
1388
1389 alert(__("No feeds are selected."));
1390
1391 }
1392
1393 }
1394
1395 function validatePrefsReset() {
1396 try {
1397 var ok = confirm(__("Reset to defaults?"));
1398
1399 if (ok) {
1400
1401 var query = Form.serialize("pref_prefs_form");
1402 query = query + "&subop=reset-config";
1403 debug(query);
1404
1405 xmlhttp.open("POST", "backend.php", true);
1406 xmlhttp.onreadystatechange=prefs_reset_callback;
1407 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1408 xmlhttp.send(query);
1409 }
1410
1411 } catch (e) {
1412 exception_error("validatePrefsSave", e);
1413 }
1414
1415 return false;
1416
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 var query = "backend.php?op=pref-feed-browser";
1455
1456 var limit_sel = document.getElementById("feedBrowserLimit");
1457
1458 if (limit_sel) {
1459 var limit = limit_sel[limit_sel.selectedIndex].value;
1460 query = query + "&limit=" + param_escape(limit);
1461 }
1462
1463 xmlhttp.open("GET", query, true);
1464 xmlhttp.onreadystatechange=feed_browser_callback;
1465 xmlhttp.send(null);
1466 }
1467
1468 function browserToggleExpand(id) {
1469 try {
1470 /* if (feed_to_expand && feed_to_expand != id) {
1471 var d = document.getElementById("BRDET-" + feed_to_expand);
1472 d.style.display = "none";
1473 } */
1474
1475 if (!xmlhttp_ready(xmlhttp)) {
1476 printLockingError();
1477 return
1478 }
1479
1480 /* if (feed_to_expand && id != feed_to_expand) {
1481 Effect.Fade('BRDET-' + feed_to_expand, {duration : 0.5});
1482 } */
1483
1484 var d = document.getElementById("BRDET-" + id);
1485
1486 if (Element.visible(d)) {
1487 Effect.Fade(d, {duration : 0.5});
1488 } else {
1489 feed_to_expand = id;
1490
1491 xmlhttp.open("GET", "backend.php?op=pref-feed-browser&subop=details&id="
1492 + param_escape(id), true);
1493 xmlhttp.onreadystatechange=expand_feed_callback;
1494 xmlhttp.send(null);
1495 }
1496
1497 } catch (e) {
1498 exception_error("browserToggleExpand", e);
1499 }
1500 }
1501
1502 function selectPrefRows(kind, select) {
1503
1504 if (kind) {
1505 var opbarid = false;
1506 var nchk = false;
1507 var nrow = false;
1508 var lname = false;
1509
1510 if (kind == "feed") {
1511 opbarid = "feedOpToolbar";
1512 nrow = "FEEDR-";
1513 nchk = "FRCHK-";
1514 lname = "prefFeedList";
1515 } else if (kind == "fcat") {
1516 opbarid = "catOpToolbar";
1517 nrow = "FCATR-";
1518 nchk = "FCCHK-";
1519 lname = "prefFeedCatList";
1520 } else if (kind == "filter") {
1521 opbarid = "filterOpToolbar";
1522 nrow = "FILRR-";
1523 nchk = "FICHK-";
1524 lname = "prefFilterList";
1525 } else if (kind == "label") {
1526 opbarid = "labelOpToolbar";
1527 nrow = "LILRR-";
1528 nchk = "LICHK-";
1529 lname = "prefLabelList";
1530 } else if (kind == "user") {
1531 opbarid = "userOpToolbar";
1532 nrow = "UMRR-";
1533 nchk = "UMCHK-";
1534 lname = "prefUserList";
1535 }
1536
1537 if (opbarid) {
1538 selectTableRowsByIdPrefix(lname, nrow, nchk, select);
1539 disableContainerChildren(opbarid, !select);
1540 }
1541
1542 }
1543 }
1544
1545
1546 function toggleSelectPrefRow(sender, kind) {
1547
1548 toggleSelectRow(sender);
1549
1550 if (kind) {
1551 var opbarid = false;
1552 var nsel = -1;
1553
1554 if (kind == "feed") {
1555 opbarid = "feedOpToolbar";
1556 nsel = getSelectedFeeds();
1557 } else if (kind == "fcat") {
1558 opbarid = "catOpToolbar";
1559 nsel = getSelectedFeedCats();
1560 } else if (kind == "filter") {
1561 opbarid = "filterOpToolbar";
1562 nsel = getSelectedFilters();
1563 } else if (kind == "label") {
1564 opbarid = "labelOpToolbar";
1565 nsel = getSelectedLabels();
1566 } else if (kind == "user") {
1567 opbarid = "userOpToolbar";
1568 nsel = getSelectedUsers();
1569 }
1570
1571 if (opbarid && nsel != -1) {
1572 disableContainerChildren(opbarid, nsel == false);
1573 }
1574
1575 }
1576 }
1577
1578 function toggleSelectFBListRow(sender) {
1579 toggleSelectListRow(sender);
1580 disableContainerChildren("fbrOpToolbar", getSelectedFeedsFromBrowser() == 0);
1581 }
1582
1583 var seq = "";
1584
1585 function pref_hotkey_handler(e) {
1586 try {
1587
1588 var keycode;
1589
1590 if (!hotkeys_enabled) return;
1591
1592 if (window.event) {
1593 keycode = window.event.keyCode;
1594 } else if (e) {
1595 keycode = e.which;
1596 }
1597
1598 if (keycode == 13 || keycode == 27) {
1599 seq = "";
1600 } else {
1601 seq = seq + "" + keycode;
1602 }
1603
1604
1605 if (document.getElementById("piggie")) {
1606
1607 if (seq.match("807371717369")) {
1608 seq = "";
1609 localPiggieFunction(true);
1610 } else {
1611 localPiggieFunction(false);
1612 }
1613 }
1614
1615 } catch (e) {
1616 exception_error("pref_hotkey_handler", e);
1617 }
1618 }
1619
1620 function editFeedCats() {
1621 if (!xmlhttp_ready(xmlhttp)) {
1622 printLockingError();
1623 return
1624 }
1625
1626 document.getElementById("subscribe_to_feed_btn").disabled = true;
1627
1628 try {
1629 document.getElementById("top25_feeds_btn").disabled = true;
1630 } catch (e) {
1631 // this button is not always available, no-op if not found
1632 }
1633
1634 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
1635 xmlhttp.onreadystatechange=infobox_feed_cat_callback;
1636 xmlhttp.send(null);
1637 }
1638
1639 function showFeedsWithErrors() {
1640 displayDlg('feedUpdateErrors');
1641 }
1642
1643 function changeUserPassword() {
1644
1645 try {
1646
1647 if (!xmlhttp_ready(xmlhttp)) {
1648 printLockingError();
1649 return false;
1650 }
1651
1652 var f = document.forms["change_pass_form"];
1653
1654 if (f) {
1655 if (f.OLD_PASSWORD.value == "") {
1656 new Effect.Highlight(f.OLD_PASSWORD);
1657 notify_error("Old password cannot be blank.");
1658 return false;
1659 }
1660
1661 if (f.NEW_PASSWORD.value == "") {
1662 new Effect.Highlight(f.NEW_PASSWORD);
1663 notify_error("New password cannot be blank.");
1664 return false;
1665 }
1666
1667 if (f.CONFIRM_PASSWORD.value == "") {
1668 new Effect.Highlight(f.CONFIRM_PASSWORD);
1669 notify_error("Entered passwords do not match.");
1670 return false;
1671 }
1672
1673 if (f.CONFIRM_PASSWORD.value != f.NEW_PASSWORD.value) {
1674 new Effect.Highlight(f.CONFIRM_PASSWORD);
1675 new Effect.Highlight(f.NEW_PASSWORD);
1676 notify_error("Entered passwords do not match.");
1677 return false;
1678 }
1679
1680 }
1681
1682 var query = Form.serialize("change_pass_form");
1683
1684 notify_progress("Trying to change password...");
1685
1686 xmlhttp.open("POST", "backend.php", true);
1687 xmlhttp.onreadystatechange=changepass_callback;
1688 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1689 xmlhttp.send(query);
1690
1691 } catch (e) {
1692 exception_error("changeUserPassword", e);
1693 }
1694
1695 return false;
1696 }
1697
1698 function changeUserEmail() {
1699
1700 try {
1701
1702 if (!xmlhttp_ready(xmlhttp)) {
1703 printLockingError();
1704 return false;
1705 }
1706
1707 var query = Form.serialize("change_email_form");
1708
1709 notify_progress("Trying to change e-mail...");
1710
1711 xmlhttp.open("POST", "backend.php", true);
1712 xmlhttp.onreadystatechange=notify_callback;
1713 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1714 xmlhttp.send(query);
1715
1716 } catch (e) {
1717 exception_error("changeUserPassword", e);
1718 }
1719
1720 return false;
1721
1722 }
1723
1724 function feedlistToggleSLAT() {
1725 notify_progress("Loading, please wait...");
1726 updateFeedList()
1727 }
1728
1729 function pubRegenKey() {
1730
1731 if (!xmlhttp_ready(xmlhttp)) {
1732 printLockingError();
1733 return false;
1734 }
1735
1736 var ok = confirm(__("Replace current publishing address with a new one?"));
1737
1738 if (ok) {
1739
1740 notify_progress("Trying to change address...");
1741
1742 xmlhttp.open("GET", "backend.php?op=rpc&subop=regenPubKey");
1743 xmlhttp.onreadystatechange=replace_pubkey_callback;
1744 xmlhttp.send(null);
1745 }
1746
1747 return false;
1748 }
1749
1750 function validatePrefsSave() {
1751 try {
1752
1753 var ok = confirm(__("Save current configuration?"));
1754
1755 if (ok) {
1756
1757 var query = Form.serialize("pref_prefs_form");
1758 query = query + "&subop=save-config";
1759 debug(query);
1760
1761 xmlhttp.open("POST", "backend.php", true);
1762 xmlhttp.onreadystatechange=notify_callback;
1763 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1764 xmlhttp.send(query);
1765 }
1766
1767 } catch (e) {
1768 exception_error("validatePrefsSave", e);
1769 }
1770
1771 return false;
1772 }