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