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