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