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