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