]> git.wh0rd.org - tt-rss.git/blob - prefs.js
rework filter editor/add infobox layout, misc fixes
[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 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
688 xmlhttp.onreadystatechange=labellist_callback;
689 xmlhttp.send(null);
690
691 }
692
693 function userEditCancel() {
694
695 if (!xmlhttp_ready(xmlhttp)) {
696 printLockingError();
697 return
698 }
699
700 selectPrefRows('user', false); // cleanup feed selection
701 closeInfoBox();
702 }
703
704 function filterEditCancel() {
705
706 if (!xmlhttp_ready(xmlhttp)) {
707 printLockingError();
708 return
709 }
710
711 document.getElementById("create_filter_btn").disabled = false;
712
713 selectPrefRows('filter', false); // cleanup feed selection
714 closeInfoBox();
715 }
716
717 function labelEditSave() {
718
719 var label = active_label;
720
721 if (!xmlhttp_ready(xmlhttp)) {
722 printLockingError();
723 return
724 }
725
726 var sql_exp = document.forms["label_edit_form"].sql_exp.value;
727 var description = document.forms["label_edit_form"].description.value;
728
729 if (sql_exp.length == 0) {
730 alert("SQL Expression cannot be blank.");
731 return;
732 }
733
734 if (description.length == 0) {
735 alert("Caption field cannot be blank.");
736 return;
737 }
738
739 notify("Saving label...");
740
741 active_label = false;
742
743 query = Form.serialize("label_edit_form");
744
745 xmlhttp.open("GET", "backend.php?" + query, true);
746
747 xmlhttp.onreadystatechange=labellist_callback;
748 xmlhttp.send(null);
749
750 }
751
752 function userEditSave() {
753
754 if (!xmlhttp_ready(xmlhttp)) {
755 printLockingError();
756 return
757 }
758
759 var login = document.forms["user_edit_form"].login.value;
760
761 if (login.length == 0) {
762 alert("Login field cannot be blank.");
763 return;
764 }
765
766 notify("Saving user...");
767
768 closeInfoBox();
769
770 var query = Form.serialize("user_edit_form");
771
772 xmlhttp.open("GET", "backend.php?" + query, true);
773 xmlhttp.onreadystatechange=userlist_callback;
774 xmlhttp.send(null);
775 }
776
777
778 function filterEditSave() {
779
780 if (!xmlhttp_ready(xmlhttp)) {
781 printLockingError();
782 return
783 }
784
785 var reg_exp = document.forms["filter_edit_form"].reg_exp.value;
786
787 if (reg_exp.length == 0) {
788 alert("Filter expression field cannot be blank.");
789 return;
790 }
791
792 notify("Saving filter...");
793
794 var query = Form.serialize("filter_edit_form");
795
796 closeInfoBox();
797
798 document.getElementById("create_filter_btn").disabled = false;
799
800 xmlhttp.open("GET", "backend.php?" + query, true);
801 xmlhttp.onreadystatechange=filterlist_callback;
802 xmlhttp.send(null);
803
804 }
805
806 function editSelectedLabel() {
807 var rows = getSelectedLabels();
808
809 if (rows.length == 0) {
810 alert("No labels are selected.");
811 return;
812 }
813
814 if (rows.length > 1) {
815 alert("Please select only one label.");
816 return;
817 }
818
819 notify("");
820
821 editLabel(rows[0]);
822
823 }
824
825 function editSelectedUser() {
826 var rows = getSelectedUsers();
827
828 if (rows.length == 0) {
829 alert("No users are selected.");
830 return;
831 }
832
833 if (rows.length > 1) {
834 alert("Please select only one user.");
835 return;
836 }
837
838 notify("");
839
840 editUser(rows[0]);
841 }
842
843 function resetSelectedUserPass() {
844 var rows = getSelectedUsers();
845
846 if (rows.length == 0) {
847 alert("No users are selected.");
848 return;
849 }
850
851 if (rows.length > 1) {
852 alert("Please select only one user.");
853 return;
854 }
855
856 var ok = confirm("Reset password of selected user?");
857
858 if (ok) {
859 notify("Resetting password for selected user...");
860
861 var id = rows[0];
862
863 xmlhttp.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
864 param_escape(id), true);
865 xmlhttp.onreadystatechange=userlist_callback;
866 xmlhttp.send(null);
867 }
868 }
869
870 function selectedUserDetails() {
871
872 if (!xmlhttp_ready(xmlhttp)) {
873 printLockingError();
874 return
875 }
876
877 var rows = getSelectedUsers();
878
879 if (rows.length == 0) {
880 alert("No users are selected.");
881 return;
882 }
883
884 if (rows.length > 1) {
885 alert("Please select only one user.");
886 return;
887 }
888
889 var id = rows[0];
890
891 notify("");
892
893 xmlhttp.open("GET", "backend.php?op=user-details&id=" + id, true);
894 xmlhttp.onreadystatechange=infobox_callback;
895 xmlhttp.send(null);
896
897 }
898
899 function selectedFeedDetails() {
900
901 if (!xmlhttp_ready(xmlhttp)) {
902 printLockingError();
903 return
904 }
905
906 var rows = getSelectedFeeds();
907
908 if (rows.length == 0) {
909 alert("No feeds are selected.");
910 return;
911 }
912
913 if (rows.length > 1) {
914 notify("Please select only one feed.");
915 return;
916 }
917
918 // var id = rows[0];
919
920 notify("");
921
922 xmlhttp.open("GET", "backend.php?op=feed-details&id=" +
923 param_escape(rows.toString()), true);
924 xmlhttp.onreadystatechange=infobox_callback;
925 xmlhttp.send(null);
926
927 }
928
929 function editSelectedFilter() {
930 var rows = getSelectedFilters();
931
932 if (rows.length == 0) {
933 alert("No filters are selected.");
934 return;
935 }
936
937 if (rows.length > 1) {
938 alert("Please select only one filter.");
939 return;
940 }
941
942 notify("");
943
944 editFilter(rows[0]);
945
946 }
947
948
949 function editSelectedFeed() {
950 var rows = getSelectedFeeds();
951
952 if (rows.length == 0) {
953 notify("No feeds are selected.");
954 return;
955 }
956
957 if (rows.length > 1) {
958 notify("Please select one feed.");
959 return;
960 }
961
962 notify("");
963
964 editFeed(rows[0]);
965
966 }
967
968 function editSelectedFeedCat() {
969 var rows = getSelectedFeedCats();
970
971 if (rows.length == 0) {
972 alert("No categories are selected.");
973 return;
974 }
975
976 if (rows.length > 1) {
977 alert("Please select only one category.");
978 return;
979 }
980
981 notify("");
982
983 editFeedCat(rows[0]);
984
985 }
986
987 function piggie_callback() {
988 var piggie = document.getElementById("piggie");
989
990 piggie.style.top = piggie_top;
991 piggie.style.backgroundColor = "white";
992 piggie.style.borderWidth = "1px";
993
994 if (piggie_fwd && piggie_top < 0) {
995 setTimeout("piggie_callback()", 50);
996 piggie_top = piggie_top + 10;
997 } else if (piggie_fwd && piggie_top >= 0) {
998 piggie_fwd = false;
999 setTimeout("piggie_callback()", 50);
1000 } else if (!piggie_fwd && piggie_top > -400) {
1001 setTimeout("piggie_callback()", 50);
1002 piggie_top = piggie_top - 10;
1003 } else if (!piggie_fwd && piggie_top <= -400) {
1004 piggie.style.display = "none";
1005 piggie_fwd = true;
1006 }
1007 }
1008
1009 var piggie_opacity = 0;
1010
1011 function piggie2_callback() {
1012 var piggie = document.getElementById("piggie");
1013 piggie.style.top = 0;
1014 piggie.style.opacity = piggie_opacity;
1015 piggie.style.backgroundColor = "transparent";
1016 piggie.style.borderWidth = "0px";
1017
1018 if (piggie_fwd && piggie_opacity < 1) {
1019 setTimeout("piggie2_callback()", 50);
1020 piggie_opacity = piggie_opacity + 0.03;
1021 } else if (piggie_fwd && piggie_opacity >= 1) {
1022 piggie_fwd = false;
1023 setTimeout("piggie2_callback()", 50);
1024 } else if (!piggie_fwd && piggie_opacity > 0) {
1025 setTimeout("piggie2_callback()", 50);
1026 piggie_opacity = piggie_opacity - 0.03;
1027 } else if (!piggie_fwd && piggie_opacity <= 0) {
1028 piggie.style.display = "none";
1029 piggie_fwd = true;
1030 }
1031 }
1032
1033 function localPiggieFunction(enable) {
1034 if (enable) {
1035 var piggie = document.getElementById("piggie");
1036 piggie.style.display = "block";
1037
1038 if (navigator.userAgent.match("Gecko") && Math.random(1) > 0.5) {
1039 piggie2_callback();
1040 } else {
1041 piggie_callback();
1042 }
1043 }
1044 }
1045
1046 function validateOpmlImport() {
1047
1048 var opml_file = document.getElementById("opml_file");
1049
1050 if (opml_file.value.length == 0) {
1051 alert("No OPML file to upload.");
1052 return false;
1053 } else {
1054 return true;
1055 }
1056 }
1057
1058 function updateFilterList() {
1059
1060 if (!xmlhttp_ready(xmlhttp)) {
1061 printLockingError();
1062 return
1063 }
1064
1065 // document.getElementById("prefContent").innerHTML = "Loading filters, please wait...";
1066
1067 // p_notify("Loading, please wait...");
1068
1069 xmlhttp.open("GET", "backend.php?op=pref-filters", true);
1070 xmlhttp.onreadystatechange=filterlist_callback;
1071 xmlhttp.send(null);
1072
1073 }
1074
1075 function updateLabelList() {
1076
1077 if (!xmlhttp_ready(xmlhttp)) {
1078 printLockingError();
1079 return
1080 }
1081
1082 // p_notify("Loading, please wait...");
1083
1084 // document.getElementById("prefContent").innerHTML = "Loading labels, please wait...";
1085
1086 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
1087 xmlhttp.onreadystatechange=labellist_callback;
1088 xmlhttp.send(null);
1089 }
1090
1091 function updatePrefsList() {
1092
1093 if (!xmlhttp_ready(xmlhttp)) {
1094 printLockingError();
1095 return
1096 }
1097
1098 // p_notify("Loading, please wait...");
1099
1100 xmlhttp.open("GET", "backend.php?op=pref-prefs", true);
1101 xmlhttp.onreadystatechange=prefslist_callback;
1102 xmlhttp.send(null);
1103
1104 }
1105
1106 function selectTab(id, noupdate) {
1107
1108 // alert(id);
1109
1110 if (!xmlhttp_ready(xmlhttp)) {
1111 printLockingError();
1112 return
1113 }
1114
1115 if (!noupdate) {
1116
1117 notify("Loading, please wait...", true);
1118
1119 // close active infobox if needed
1120 closeInfoBox();
1121
1122 // clean up all current selections, just in case
1123 active_feed_cat = false;
1124 active_label = false;
1125
1126 if (id == "feedConfig") {
1127 updateFeedList();
1128 } else if (id == "filterConfig") {
1129 updateFilterList();
1130 } else if (id == "labelConfig") {
1131 updateLabelList();
1132 } else if (id == "genConfig") {
1133 updatePrefsList();
1134 } else if (id == "userConfig") {
1135 updateUsersList();
1136 } else if (id == "feedBrowser") {
1137 updateBigFeedBrowser();
1138 }
1139 }
1140
1141 var tab = document.getElementById(active_tab + "Tab");
1142
1143 if (tab) {
1144 if (tab.className.match("Selected")) {
1145 tab.className = "prefsTab";
1146 }
1147 }
1148
1149 tab = document.getElementById(id + "Tab");
1150
1151 if (tab) {
1152 if (!tab.className.match("Selected")) {
1153 tab.className = tab.className + "Selected";
1154 }
1155 }
1156
1157 active_tab = id;
1158
1159 setCookie('ttrss_pref_acttab', active_tab);
1160
1161 }
1162
1163 function init() {
1164
1165 try {
1166
1167 if (arguments.callee.done) return;
1168 arguments.callee.done = true;
1169
1170 // IE kludge
1171 if (!xmlhttp) {
1172 document.getElementById("prefContent").innerHTML =
1173 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1174 "to function properly. Your browser doesn't seem to support it.";
1175 return;
1176 }
1177
1178 active_tab = getCookie("ttrss_pref_acttab");
1179 if (!active_tab) active_tab = "genConfig";
1180 selectTab(active_tab);
1181
1182 document.onkeydown = hotkey_handler;
1183 notify("");
1184 } catch (e) {
1185 exception_error("init", e);
1186 }
1187 }
1188
1189 function categorizeSelectedFeeds() {
1190
1191 if (!xmlhttp_ready(xmlhttp)) {
1192 printLockingError();
1193 return
1194 }
1195
1196 var sel_rows = getSelectedFeeds();
1197
1198 var cat_sel = document.getElementById("sfeed_set_fcat");
1199 var cat_id = cat_sel[cat_sel.selectedIndex].value;
1200
1201 if (sel_rows.length > 0) {
1202
1203 notify("Changing category of selected feeds...");
1204
1205 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
1206 param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
1207 xmlhttp.onreadystatechange=feedlist_callback;
1208 xmlhttp.send(null);
1209
1210 } else {
1211
1212 alert("No feeds are selected.");
1213
1214 }
1215
1216 }
1217
1218 function validatePrefsReset() {
1219 return confirm("Reset to defaults?");
1220 }
1221
1222 function browseFeeds(limit) {
1223
1224 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=browse", true);
1225 xmlhttp.onreadystatechange=infobox_callback;
1226 xmlhttp.send(null);
1227
1228 }
1229
1230 function feedBrowserSubscribe() {
1231 try {
1232
1233 var selected = getSelectedFeedsFromBrowser();
1234
1235 if (selected.length > 0) {
1236 closeInfoBox();
1237 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=massSubscribe&ids="+
1238 param_escape(selected.toString()), true);
1239 xmlhttp.onreadystatechange=feedlist_callback;
1240 xmlhttp.send(null);
1241 } else {
1242 alert("No feeds are selected.");
1243 }
1244
1245 } catch (e) {
1246 exception_error("feedBrowserSubscribe", e);
1247 }
1248 }
1249
1250 function updateBigFeedBrowser(limit) {
1251
1252 if (!xmlhttp_ready(xmlhttp)) {
1253 printLockingError();
1254 return
1255 }
1256
1257 // p_notify("Loading, please wait...");
1258
1259 var query = "backend.php?op=pref-feed-browser";
1260
1261 var limit_sel = document.getElementById("feedBrowserLimit");
1262
1263 if (limit_sel) {
1264 var limit = limit_sel[limit_sel.selectedIndex].value;
1265 query = query + "&limit=" + param_escape(limit);
1266 }
1267
1268 xmlhttp.open("GET", query, true);
1269 xmlhttp.onreadystatechange=feed_browser_callback;
1270 xmlhttp.send(null);
1271 }
1272
1273 function browserToggleExpand(id) {
1274 try {
1275 /* if (feed_to_expand && feed_to_expand != id) {
1276 var d = document.getElementById("BRDET-" + feed_to_expand);
1277 d.style.display = "none";
1278 } */
1279
1280 if (!xmlhttp_ready(xmlhttp)) {
1281 printLockingError();
1282 return
1283 }
1284
1285 var d = document.getElementById("BRDET-" + id);
1286
1287 if (d.style.display == "block") {
1288 d.style.display = "none";
1289
1290 } else {
1291
1292 feed_to_expand = id;
1293
1294 d.style.display = "block";
1295 d.innerHTML = "Loading, please wait...";
1296
1297 xmlhttp.open("GET", "backend.php?op=pref-feed-browser&subop=details&id="
1298 + param_escape(id), true);
1299 xmlhttp.onreadystatechange=expand_feed_callback;
1300 xmlhttp.send(null);
1301 }
1302
1303 } catch (e) {
1304 exception_error("browserExpand", e);
1305 }
1306 }
1307
1308 function validateNewPassword(form) {
1309 if (form.OLD_PASSWORD.value == "") {
1310 alert("Old password cannot be blank");
1311 return false;
1312 }
1313 if (form.NEW_PASSWORD.value == "") {
1314 alert("New password cannot be blank");
1315 return false;
1316 }
1317 return true;
1318 }
1319
1320 function selectPrefRows(kind, select) {
1321
1322 if (kind) {
1323 var opbarid = false;
1324 var nchk = false;
1325 var nrow = false;
1326 var lname = false;
1327
1328 if (kind == "feed") {
1329 opbarid = "feedOpToolbar";
1330 nrow = "FEEDR-";
1331 nchk = "FRCHK-";
1332 lname = "prefFeedList";
1333 } else if (kind == "fcat") {
1334 opbarid = "catOpToolbar";
1335 nrow = "FCATR-";
1336 nchk = "FCHK-";
1337 lname = "prefFeedCatList";
1338 } else if (kind == "filter") {
1339 opbarid = "filterOpToolbar";
1340 nrow = "FILRR-";
1341 nchk = "FICHK-";
1342 lname = "prefFilterList";
1343 } else if (kind == "label") {
1344 opbarid = "labelOpToolbar";
1345 nrow = "LILRR-";
1346 nchk = "LCHK-";
1347 lname = "prefLabelList";
1348 } else if (kind == "user") {
1349 opbarid = "userOpToolbar";
1350 nrow = "UMRR-";
1351 nchk = "UMCHK-";
1352 lname = "prefUserList";
1353 }
1354
1355 if (opbarid) {
1356 selectTableRowsByIdPrefix(lname, nrow, nchk, select);
1357 disableContainerChildren(opbarid, !select);
1358 }
1359
1360 }
1361 }
1362
1363
1364 function toggleSelectPrefRow(sender, kind) {
1365
1366 toggleSelectRow(sender);
1367
1368 if (kind) {
1369 var opbarid = false;
1370 var nsel = -1;
1371
1372 if (kind == "feed") {
1373 opbarid = "feedOpToolbar";
1374 nsel = getSelectedFeeds();
1375 } else if (kind == "fcat") {
1376 opbarid = "catOpToolbar";
1377 nsel = getSelectedFeedCats();
1378 } else if (kind == "filter") {
1379 opbarid = "filterOpToolbar";
1380 nsel = getSelectedFilters();
1381 } else if (kind == "label") {
1382 opbarid = "labelOpToolbar";
1383 nsel = getSelectedLabels();
1384 } else if (kind == "user") {
1385 opbarid = "userOpToolbar";
1386 nsel = getSelectedUsers();
1387 }
1388
1389 if (opbarid && nsel != -1) {
1390 disableContainerChildren(opbarid, nsel == false);
1391 }
1392
1393 }
1394 }
1395
1396 function toggleSelectFBListRow(sender) {
1397 toggleSelectListRow(sender);
1398 disableContainerChildren("fbrOpToolbar", getSelectedFeedsFromBrowser() == 0);
1399 }