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