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