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