]>
git.wh0rd.org - tt-rss.git/blob - prefs.js
2 This program is Copyright (c) 2003-2005 Andrew Dolgov <cthulhoo@gmail.com>
3 Licensed under GPL v.2 or (at your preference) any later version.
8 var active_feed
= false;
9 var active_feed_cat
= false;
10 var active_filter
= false;
11 var active_label
= false;
12 var active_user
= false;
14 var active_tab
= false;
17 /*@if (@_jscript_version >= 5)
18 // JScript gives us Conditional compilation, we can cope with old IE versions.
19 // and security blocked creation of the objects.
21 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
24 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
31 if (!xmlhttp
&& typeof XMLHttpRequest
!='undefined') {
32 xmlhttp
= new XMLHttpRequest();
35 function feedlist_callback() {
36 var container
= document
.getElementById('prefContent');
37 if (xmlhttp
.readyState
== 4) {
38 container
.innerHTML
=xmlhttp
.responseText
;
40 var row
= document
.getElementById("FEEDR-" + active_feed
);
42 if (!row
.className
.match("Selected")) {
43 row
.className
= row
.className
+ "Selected";
46 var checkbox
= document
.getElementById("FRCHK-" + active_feed
);
48 checkbox
.checked
= true;
55 function filterlist_callback() {
56 var container
= document
.getElementById('prefContent');
57 if (xmlhttp
.readyState
== 4) {
59 container
.innerHTML
=xmlhttp
.responseText
;
62 var row
= document
.getElementById("FILRR-" + active_filter
);
64 if (!row
.className
.match("Selected")) {
65 row
.className
= row
.className
+ "Selected";
68 var checkbox
= document
.getElementById("FICHK-" + active_filter
);
71 checkbox
.checked
= true;
78 function labellist_callback() {
79 var container
= document
.getElementById('prefContent');
80 if (xmlhttp
.readyState
== 4) {
81 container
.innerHTML
=xmlhttp
.responseText
;
84 var row
= document
.getElementById("LILRR-" + active_label
);
86 if (!row
.className
.match("Selected")) {
87 row
.className
= row
.className
+ "Selected";
90 var checkbox
= document
.getElementById("LICHK-" + active_label
);
93 checkbox
.checked
= true;
100 function userlist_callback() {
101 var container
= document
.getElementById('prefContent');
102 if (xmlhttp
.readyState
== 4) {
103 container
.innerHTML
=xmlhttp
.responseText
;
106 var row
= document
.getElementById("UMRR-" + active_user
);
108 if (!row
.className
.match("Selected")) {
109 row
.className
= row
.className
+ "Selected";
112 var checkbox
= document
.getElementById("UMCHK-" + active_user
);
115 checkbox
.checked
= true;
123 function infobox_callback() {
124 if (xmlhttp
.readyState
== 4) {
125 var box
= document
.getElementById('infoBox');
126 var shadow
= document
.getElementById('infoBoxShadow');
129 box
.innerHTML
=xmlhttp
.responseText
;
131 shadow
.style
.display
= "block";
133 box
.style
.display
= "block";
140 function prefslist_callback() {
141 var container
= document
.getElementById('prefContent');
142 if (xmlhttp
.readyState
== 4) {
144 container
.innerHTML
=xmlhttp
.responseText
;
150 function gethelp_callback() {
151 var container
= document
.getElementById('prefHelpBox');
152 if (xmlhttp
.readyState
== 4) {
154 container
.innerHTML
= xmlhttp
.responseText
;
155 container
.style
.display
= "block";
161 function notify_callback() {
162 var container
= document
.getElementById('notify');
163 if (xmlhttp
.readyState
== 4) {
164 container
.innerHTML
=xmlhttp
.responseText
;
168 function updateFeedList(sort_key
) {
170 if (!xmlhttp_ready(xmlhttp
)) {
175 // document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
177 p_notify("Loading, please wait...");
179 xmlhttp
.open("GET", "backend.php?op=pref-feeds" +
180 "&sort=" + param_escape(sort_key
), true);
181 xmlhttp
.onreadystatechange
=feedlist_callback
;
186 function updateUsersList() {
188 if (!xmlhttp_ready(xmlhttp
)) {
193 // document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
195 p_notify("Loading, please wait...");
197 xmlhttp
.open("GET", "backend.php?op=pref-users", true);
198 xmlhttp
.onreadystatechange
=userlist_callback
;
203 function toggleSelectRow(sender
) {
204 var parent_row
= sender
.parentNode
.parentNode
;
206 if (sender
.checked
) {
207 if (!parent_row
.className
.match("Selected")) {
208 parent_row
.className
= parent_row
.className
+ "Selected";
211 if (parent_row
.className
.match("Selected")) {
212 parent_row
.className
= parent_row
.className
.replace("Selected", "");
217 function addLabel() {
219 if (!xmlhttp_ready(xmlhttp
)) {
224 var sqlexp
= document
.getElementById("ladd_expr");
226 if (sqlexp
.value
.length
== 0) {
227 notify("Missing SQL expression.");
229 notify("Adding label...");
231 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=add&exp=" +
232 param_escape(sqlexp
.value
), true);
234 xmlhttp
.onreadystatechange
=labellist_callback
;
242 function addFilter() {
244 if (!xmlhttp_ready(xmlhttp
)) {
249 var regexp
= document
.getElementById("fadd_regexp");
250 var match
= document
.getElementById("fadd_match");
251 var feed
= document
.getElementById("fadd_feed");
253 if (regexp
.value
.length
== 0) {
254 notify("Missing filter expression.");
256 notify("Adding filter...");
258 var v_match
= match
[match
.selectedIndex
].text
;
260 var feed_id
= feed
[feed
.selectedIndex
].id
;
262 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=add®exp=" +
263 param_escape(regexp
.value
) + "&match=" + v_match
+
264 "&fid=" + param_escape(feed_id
), true);
266 xmlhttp
.onreadystatechange
=filterlist_callback
;
276 if (!xmlhttp_ready(xmlhttp
)) {
281 var link
= document
.getElementById("fadd_link");
283 if (link
.value
.length
== 0) {
284 notify("Missing feed URL.");
286 notify("Adding feed...");
288 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
289 param_escape(link
.value
), true);
290 xmlhttp
.onreadystatechange
=feedlist_callback
;
299 function addFeedCat() {
301 if (!xmlhttp_ready(xmlhttp
)) {
306 var cat
= document
.getElementById("fadd_cat");
308 if (cat
.value
.length
== 0) {
309 notify("Missing feed category.");
311 notify("Adding feed category...");
313 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=addCat&cat=" +
314 param_escape(cat
.value
), true);
315 xmlhttp
.onreadystatechange
=feedlist_callback
;
325 if (!xmlhttp_ready(xmlhttp
)) {
330 var sqlexp
= document
.getElementById("uadd_box");
332 if (sqlexp
.value
.length
== 0) {
333 notify("Missing user login.");
335 notify("Adding user...");
337 xmlhttp
.open("GET", "backend.php?op=pref-users&subop=add&login=" +
338 param_escape(sqlexp
.value
), true);
340 xmlhttp
.onreadystatechange
=userlist_callback
;
348 function editLabel(id
) {
350 if (!xmlhttp_ready(xmlhttp
)) {
357 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=edit&id=" +
358 param_escape(id
), true);
359 xmlhttp
.onreadystatechange
=labellist_callback
;
364 function editUser(id
) {
366 if (!xmlhttp_ready(xmlhttp
)) {
373 xmlhttp
.open("GET", "backend.php?op=pref-users&subop=edit&id=" +
374 param_escape(id
), true);
375 xmlhttp
.onreadystatechange
=userlist_callback
;
380 function editFilter(id
) {
382 if (!xmlhttp_ready(xmlhttp
)) {
389 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=edit&id=" +
390 param_escape(id
), true);
391 xmlhttp
.onreadystatechange
=filterlist_callback
;
396 function editFeed(feed
) {
398 // notify("Editing feed...");
400 if (!xmlhttp_ready(xmlhttp
)) {
407 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=edit&id=" +
408 param_escape(feed
), true);
409 xmlhttp
.onreadystatechange
=feedlist_callback
;
414 function editFeedCat(cat
) {
416 if (!xmlhttp_ready(xmlhttp
)) {
421 active_feed_cat
= cat
;
423 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=editCat&id=" +
424 param_escape(cat
), true);
425 xmlhttp
.onreadystatechange
=feedlist_callback
;
430 function getSelectedLabels() {
431 return getSelectedTableRowIds("prefLabelList", "LILRR");
434 function getSelectedUsers() {
435 return getSelectedTableRowIds("prefUserList", "UMRR");
438 function getSelectedFeeds() {
439 return getSelectedTableRowIds("prefFeedList", "FEEDR");
442 function getSelectedFilters() {
443 return getSelectedTableRowIds("prefFilterList", "FILRR");
446 function getSelectedFeedCats() {
447 return getSelectedTableRowIds("prefFeedCatList", "FCATR");
451 function readSelectedFeeds() {
453 if (!xmlhttp_ready(xmlhttp
)) {
458 var sel_rows
= getSelectedFeeds();
460 if (sel_rows
.length
> 0) {
462 notify("Marking selected feeds as read...");
464 xmlhttp
.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
465 param_escape(sel_rows
.toString()), true);
466 xmlhttp
.onreadystatechange
=notify_callback
;
471 notify("Please select some feeds first.");
476 function unreadSelectedFeeds() {
478 if (!xmlhttp_ready(xmlhttp
)) {
483 var sel_rows
= getSelectedFeeds();
485 if (sel_rows
.length
> 0) {
487 notify("Marking selected feeds as unread...");
489 xmlhttp
.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
490 param_escape(sel_rows
.toString()), true);
491 xmlhttp
.onreadystatechange
=notify_callback
;
496 notify("Please select some feeds first.");
501 function removeSelectedLabels() {
503 if (!xmlhttp_ready(xmlhttp
)) {
508 var sel_rows
= getSelectedLabels();
510 if (sel_rows
.length
> 0) {
512 notify("Removing selected labels...");
514 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
515 param_escape(sel_rows
.toString()), true);
516 xmlhttp
.onreadystatechange
=labellist_callback
;
520 notify("Please select some labels first.");
524 function removeSelectedUsers() {
526 if (!xmlhttp_ready(xmlhttp
)) {
531 var sel_rows
= getSelectedUsers();
533 if (sel_rows
.length
> 0) {
535 notify("Removing selected users...");
537 xmlhttp
.open("GET", "backend.php?op=pref-users&subop=remove&ids="+
538 param_escape(sel_rows
.toString()), true);
539 xmlhttp
.onreadystatechange
=userlist_callback
;
543 notify("Please select some labels first.");
547 function removeSelectedFilters() {
549 if (!xmlhttp_ready(xmlhttp
)) {
554 var sel_rows
= getSelectedFilters();
556 if (sel_rows
.length
> 0) {
558 notify("Removing selected filters...");
560 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
561 param_escape(sel_rows
.toString()), true);
562 xmlhttp
.onreadystatechange
=filterlist_callback
;
566 notify("Please select some filters first.");
571 function removeSelectedFeeds() {
573 if (!xmlhttp_ready(xmlhttp
)) {
578 var sel_rows
= getSelectedFeeds();
580 if (sel_rows
.length
> 0) {
582 notify("Removing selected feeds...");
584 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
585 param_escape(sel_rows
.toString()), true);
586 xmlhttp
.onreadystatechange
=feedlist_callback
;
591 notify("Please select some feeds first.");
597 function removeSelectedFeedCats() {
599 if (!xmlhttp_ready(xmlhttp
)) {
604 var sel_rows
= getSelectedFeedCats();
606 if (sel_rows
.length
> 0) {
608 notify("Removing selected categories...");
610 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=removeCats&ids="+
611 param_escape(sel_rows
.toString()), true);
612 xmlhttp
.onreadystatechange
=feedlist_callback
;
617 notify("Please select some feeds first.");
623 function feedEditCancel() {
625 if (!xmlhttp_ready(xmlhttp
)) {
632 notify("Operation cancelled.");
634 xmlhttp
.open("GET", "backend.php?op=pref-feeds", true);
635 xmlhttp
.onreadystatechange
=feedlist_callback
;
640 function feedCatEditCancel() {
642 if (!xmlhttp_ready(xmlhttp
)) {
647 active_feed_cat
= false;
649 notify("Operation cancelled.");
651 xmlhttp
.open("GET", "backend.php?op=pref-feeds", true);
652 xmlhttp
.onreadystatechange
=feedlist_callback
;
657 function feedEditSave() {
659 var feed
= active_feed
;
661 if (!xmlhttp_ready(xmlhttp
)) {
666 var link
= document
.getElementById("iedit_link").value
;
667 var title
= document
.getElementById("iedit_title").value
;
668 var upd_intl
= document
.getElementById("iedit_updintl").value
;
669 var purge_intl
= document
.getElementById("iedit_purgintl").value
;
670 var fcat
= document
.getElementById("iedit_fcat");
672 var fcat_id
= fcat
[fcat
.selectedIndex
].id
;
674 // notify("Saving feed.");
676 /* if (upd_intl < 0) {
677 notify("Update interval must be >= 0 (0 = default)");
681 if (purge_intl < 0) {
682 notify("Purge days must be >= 0 (0 = default)");
686 if (link
.length
== 0) {
687 notify("Feed link cannot be blank.");
691 if (title
.length
== 0) {
692 notify("Feed title cannot be blank.");
700 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=editSave&id=" +
701 feed
+ "&l=" + param_escape(link
) + "&t=" + param_escape(title
) +
702 "&ui=" + param_escape(upd_intl
) + "&pi=" + param_escape(purge_intl
) +
703 "&catid=" + param_escape(fcat_id
), true);
704 xmlhttp
.onreadystatechange
=feedlist_callback
;
709 function labelTest() {
711 var sqlexp
= document
.getElementById("iedit_expr").value
;
712 var descr
= document
.getElementById("iedit_descr").value
;
714 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=test&expr=" +
715 param_escape(sqlexp
) + "&descr=" + param_escape(descr
), true);
717 xmlhttp
.onreadystatechange
=infobox_callback
;
722 function labelEditCancel() {
724 if (!xmlhttp_ready(xmlhttp
)) {
729 active_label
= false;
731 notify("Operation cancelled.");
733 xmlhttp
.open("GET", "backend.php?op=pref-labels", true);
734 xmlhttp
.onreadystatechange
=labellist_callback
;
739 function userEditCancel() {
741 if (!xmlhttp_ready(xmlhttp
)) {
748 notify("Operation cancelled.");
750 xmlhttp
.open("GET", "backend.php?op=pref-users", true);
751 xmlhttp
.onreadystatechange
=userlist_callback
;
756 function filterEditCancel() {
758 if (!xmlhttp_ready(xmlhttp
)) {
763 active_filter
= false;
765 notify("Operation cancelled.");
767 xmlhttp
.open("GET", "backend.php?op=pref-filters", true);
768 xmlhttp
.onreadystatechange
=filterlist_callback
;
773 function labelEditSave() {
775 var label
= active_label
;
777 if (!xmlhttp_ready(xmlhttp
)) {
782 var sqlexp
= document
.getElementById("iedit_expr").value
;
783 var descr
= document
.getElementById("iedit_descr").value
;
785 // notify("Saving label " + sqlexp + ": " + descr);
787 if (sqlexp
.length
== 0) {
788 notify("SQL expression cannot be blank.");
792 if (descr
.length
== 0) {
793 notify("Caption cannot be blank.");
799 active_label
= false;
801 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=editSave&id=" +
802 label
+ "&s=" + param_escape(sqlexp
) + "&d=" + param_escape(descr
),
805 xmlhttp
.onreadystatechange
=labellist_callback
;
810 function userEditSave() {
812 var user
= active_user
;
814 if (!xmlhttp_ready(xmlhttp
)) {
819 var login
= document
.getElementById("iedit_ulogin").value
;
820 var level
= document
.getElementById("iedit_ulevel").value
;
822 if (login
.length
== 0) {
823 notify("Login cannot be blank.");
827 if (level
.length
== 0) {
828 notify("User level cannot be blank.");
836 xmlhttp
.open("GET", "backend.php?op=pref-users&subop=editSave&id=" +
837 user
+ "&l=" + param_escape(login
) + "&al=" + param_escape(level
),
840 xmlhttp
.onreadystatechange
=userlist_callback
;
846 function filterEditSave() {
848 var filter
= active_filter
;
850 if (!xmlhttp_ready(xmlhttp
)) {
855 var regexp
= document
.getElementById("iedit_regexp").value
;
856 var descr
= document
.getElementById("iedit_descr").value
;
857 var match
= document
.getElementById("iedit_match");
859 var v_match
= match
[match
.selectedIndex
].text
;
861 var feed
= document
.getElementById("iedit_feed");
862 var feed_id
= feed
[feed
.selectedIndex
].id
;
864 // notify("Saving filter " + filter + ": " + regexp + ", " + descr + ", " + match);
866 if (regexp
.length
== 0) {
867 notify("Filter expression cannot be blank.");
871 active_filter
= false;
873 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=editSave&id=" +
874 filter
+ "&r=" + param_escape(regexp
) + "&d=" + param_escape(descr
) +
875 "&m=" + param_escape(v_match
) + "&fid=" + param_escape(feed_id
), true);
879 xmlhttp
.onreadystatechange
=filterlist_callback
;
884 function editSelectedLabel() {
885 var rows
= getSelectedLabels();
887 if (rows
.length
== 0) {
888 notify("No labels are selected.");
892 if (rows
.length
> 1) {
893 notify("Please select one label.");
903 function editSelectedUser() {
904 var rows
= getSelectedUsers();
906 if (rows
.length
== 0) {
907 notify("No users are selected.");
911 if (rows
.length
> 1) {
912 notify("Please select one user.");
921 function resetSelectedUserPass() {
922 var rows
= getSelectedUsers();
924 if (rows
.length
== 0) {
925 notify("No users are selected.");
929 if (rows
.length
> 1) {
930 notify("Please select one user.");
934 notify("Resetting password for selected user...");
938 xmlhttp
.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
939 param_escape(id
), true);
940 xmlhttp
.onreadystatechange
=userlist_callback
;
945 function selectedUserDetails() {
947 if (!xmlhttp_ready(xmlhttp
)) {
952 var rows
= getSelectedUsers();
954 if (rows
.length
== 0) {
955 notify("No users are selected.");
959 if (rows
.length
> 1) {
960 notify("Please select one user.");
968 xmlhttp
.open("GET", "backend.php?op=user-details&id=" + id
, true);
969 xmlhttp
.onreadystatechange
=infobox_callback
;
974 function selectedFeedDetails() {
976 if (!xmlhttp_ready(xmlhttp
)) {
981 var rows
= getSelectedFeeds();
983 if (rows
.length
== 0) {
984 notify("No feeds are selected.");
988 if (rows
.length
> 1) {
989 notify("Please select one feed.");
997 xmlhttp
.open("GET", "backend.php?op=feed-details&id=" + id
, true);
998 xmlhttp
.onreadystatechange
=infobox_callback
;
1003 function editSelectedFilter() {
1004 var rows
= getSelectedFilters();
1006 if (rows
.length
== 0) {
1007 notify("No filters are selected.");
1011 if (rows
.length
> 1) {
1012 notify("Please select one filter.");
1018 editFilter(rows
[0]);
1023 function editSelectedFeed() {
1024 var rows
= getSelectedFeeds();
1026 if (rows
.length
== 0) {
1027 notify("No feeds are selected.");
1031 if (rows
.length
> 1) {
1032 notify("Please select one feed.");
1042 function editSelectedFeedCat() {
1043 var rows
= getSelectedFeedCats();
1045 if (rows
.length
== 0) {
1046 notify("No categories are selected.");
1050 if (rows
.length
> 1) {
1051 notify("Please select one category.");
1057 editFeedCat(rows
[0]);
1061 function localPiggieFunction(enable
) {
1063 piggie
.style
.display
= "block";
1065 notify("I loveded it!!!");
1067 piggie
.style
.display
= "none";
1072 function validateOpmlImport() {
1074 var opml_file
= document
.getElementById("opml_file");
1076 if (opml_file
.value
.length
== 0) {
1077 notify("Please select OPML file to upload.");
1084 function updateFilterList() {
1086 if (!xmlhttp_ready(xmlhttp
)) {
1087 printLockingError();
1091 // document.getElementById("prefContent").innerHTML = "Loading filters, please wait...";
1093 p_notify("Loading, please wait...");
1095 xmlhttp
.open("GET", "backend.php?op=pref-filters", true);
1096 xmlhttp
.onreadystatechange
=filterlist_callback
;
1101 function updateLabelList() {
1103 if (!xmlhttp_ready(xmlhttp
)) {
1104 printLockingError();
1108 p_notify("Loading, please wait...");
1110 // document.getElementById("prefContent").innerHTML = "Loading labels, please wait...";
1112 xmlhttp
.open("GET", "backend.php?op=pref-labels", true);
1113 xmlhttp
.onreadystatechange
=labellist_callback
;
1117 function updatePrefsList() {
1119 if (!xmlhttp_ready(xmlhttp
)) {
1120 printLockingError();
1124 p_notify("Loading, please wait...");
1126 xmlhttp
.open("GET", "backend.php?op=pref-prefs", true);
1127 xmlhttp
.onreadystatechange
=prefslist_callback
;
1132 function selectTab(id
) {
1134 if (!xmlhttp_ready(xmlhttp
)) {
1135 printLockingError();
1139 if (id
== "feedConfig") {
1141 } else if (id
== "filterConfig") {
1143 } else if (id
== "labelConfig") {
1145 } else if (id
== "genConfig") {
1147 } else if (id
== "userConfig") {
1151 var tab
= document
.getElementById(active_tab
+ "Tab");
1154 if (tab
.className
.match("Selected")) {
1155 tab
.className
= "prefsTab";
1159 tab
= document
.getElementById(id
+ "Tab");
1162 if (!tab
.className
.match("Selected")) {
1163 tab
.className
= tab
.className
+ "Selected";
1176 document
.getElementById("prefContent").innerHTML
=
1177 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1178 "to function properly. Your browser doesn't seem to support it.";
1182 selectTab("genConfig");
1184 document
.onkeydown
= hotkey_handler
;
1190 var help_topic_id = false;
1192 function do_dispOptionHelp() {
1194 if (!xmlhttp_ready(xmlhttp))
1197 xmlhttp.open("GET", "backend.php?op=pref-prefs&subop=getHelp&pn=" +
1198 param_escape(help_topic_id), true);
1199 xmlhttp.onreadystatechange=gethelp_callback;
1204 function dispOptionHelp(event, sender) {
1206 help_topic_id = sender.id;
1208 // document.setTimeout("do_dispOptionHelp()", 100);
1212 function closeInfoBox() {
1213 var box
= document
.getElementById('infoBox');
1214 var shadow
= document
.getElementById('infoBoxShadow');
1217 shadow
.style
.display
= "none";
1219 box
.style
.display
= "none";