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