]>
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_filter
= false;
10 var active_label
= false;
11 var active_user
= false;
13 var active_tab
= false;
16 /*@if (@_jscript_version >= 5)
17 // JScript gives us Conditional compilation, we can cope with old IE versions.
18 // and security blocked creation of the objects.
20 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
23 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
30 if (!xmlhttp
&& typeof XMLHttpRequest
!='undefined') {
31 xmlhttp
= new XMLHttpRequest();
34 function feedlist_callback() {
35 var container
= document
.getElementById('prefContent');
36 if (xmlhttp
.readyState
== 4) {
37 container
.innerHTML
=xmlhttp
.responseText
;
39 var row
= document
.getElementById("FEEDR-" + active_feed
);
41 if (!row
.className
.match("Selected")) {
42 row
.className
= row
.className
+ "Selected";
45 var checkbox
= document
.getElementById("FRCHK-" + active_feed
);
47 checkbox
.checked
= true;
54 function filterlist_callback() {
55 var container
= document
.getElementById('prefContent');
56 if (xmlhttp
.readyState
== 4) {
58 container
.innerHTML
=xmlhttp
.responseText
;
61 var row
= document
.getElementById("FILRR-" + active_filter
);
63 if (!row
.className
.match("Selected")) {
64 row
.className
= row
.className
+ "Selected";
67 var checkbox
= document
.getElementById("FICHK-" + active_filter
);
70 checkbox
.checked
= true;
77 function labellist_callback() {
78 var container
= document
.getElementById('prefContent');
79 if (xmlhttp
.readyState
== 4) {
80 container
.innerHTML
=xmlhttp
.responseText
;
83 var row
= document
.getElementById("LILRR-" + active_label
);
85 if (!row
.className
.match("Selected")) {
86 row
.className
= row
.className
+ "Selected";
89 var checkbox
= document
.getElementById("LICHK-" + active_label
);
92 checkbox
.checked
= true;
99 function userlist_callback() {
100 var container
= document
.getElementById('prefContent');
101 if (xmlhttp
.readyState
== 4) {
102 container
.innerHTML
=xmlhttp
.responseText
;
105 var row
= document
.getElementById("UMRR-" + active_user
);
107 if (!row
.className
.match("Selected")) {
108 row
.className
= row
.className
+ "Selected";
111 var checkbox
= document
.getElementById("UMCHK-" + active_user
);
114 checkbox
.checked
= true;
122 function userdetails_callback() {
123 var container
= document
.getElementById('prefUserDetails');
124 if (xmlhttp
.readyState
== 4) {
125 container
.innerHTML
=xmlhttp
.responseText
;
126 container
.style
.display
= "block";
131 function prefslist_callback() {
132 var container
= document
.getElementById('prefContent');
133 if (xmlhttp
.readyState
== 4) {
135 container
.innerHTML
=xmlhttp
.responseText
;
141 function gethelp_callback() {
142 var container
= document
.getElementById('prefHelpBox');
143 if (xmlhttp
.readyState
== 4) {
145 container
.innerHTML
= xmlhttp
.responseText
;
146 container
.style
.display
= "block";
152 function notify_callback() {
153 var container
= document
.getElementById('notify');
154 if (xmlhttp
.readyState
== 4) {
155 container
.innerHTML
=xmlhttp
.responseText
;
160 function updateFeedList() {
162 if (!xmlhttp_ready(xmlhttp
)) {
167 // document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
169 p_notify("Loading, please wait...");
171 xmlhttp
.open("GET", "backend.php?op=pref-feeds", true);
172 xmlhttp
.onreadystatechange
=feedlist_callback
;
177 function updateUsersList() {
179 if (!xmlhttp_ready(xmlhttp
)) {
184 // document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
186 p_notify("Loading, please wait...");
188 xmlhttp
.open("GET", "backend.php?op=pref-users", true);
189 xmlhttp
.onreadystatechange
=userlist_callback
;
194 function toggleSelectRow(sender
) {
195 var parent_row
= sender
.parentNode
.parentNode
;
197 if (sender
.checked
) {
198 if (!parent_row
.className
.match("Selected")) {
199 parent_row
.className
= parent_row
.className
+ "Selected";
202 if (parent_row
.className
.match("Selected")) {
203 parent_row
.className
= parent_row
.className
.replace("Selected", "");
208 function addLabel() {
210 if (!xmlhttp_ready(xmlhttp
)) {
215 var sqlexp
= document
.getElementById("ladd_expr");
217 if (sqlexp
.value
.length
== 0) {
218 notify("Missing SQL expression.");
220 notify("Adding label...");
222 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=add&exp=" +
223 param_escape(sqlexp
.value
), true);
225 xmlhttp
.onreadystatechange
=labellist_callback
;
233 function addFilter() {
235 if (!xmlhttp_ready(xmlhttp
)) {
240 var regexp
= document
.getElementById("fadd_regexp");
241 var match
= document
.getElementById("fadd_match");
243 if (regexp
.value
.length
== 0) {
244 notify("Missing filter expression.");
246 notify("Adding filter...");
248 var v_match
= match
[match
.selectedIndex
].text
;
250 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=add®exp=" +
251 param_escape(regexp
.value
) + "&match=" + v_match
, true);
253 xmlhttp
.onreadystatechange
=filterlist_callback
;
263 if (!xmlhttp_ready(xmlhttp
)) {
268 var link
= document
.getElementById("fadd_link");
270 if (link
.value
.length
== 0) {
271 notify("Missing feed URL.");
273 notify("Adding feed...");
275 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
276 param_escape(link
.value
), true);
277 xmlhttp
.onreadystatechange
=feedlist_callback
;
288 if (!xmlhttp_ready(xmlhttp
)) {
293 var sqlexp
= document
.getElementById("uadd_box");
295 if (sqlexp
.value
.length
== 0) {
296 notify("Missing user login.");
298 notify("Adding user...");
300 xmlhttp
.open("GET", "backend.php?op=pref-users&subop=add&login=" +
301 param_escape(sqlexp
.value
), true);
303 xmlhttp
.onreadystatechange
=userlist_callback
;
311 function editLabel(id
) {
313 if (!xmlhttp_ready(xmlhttp
)) {
320 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=edit&id=" +
321 param_escape(id
), true);
322 xmlhttp
.onreadystatechange
=labellist_callback
;
327 function editUser(id
) {
329 if (!xmlhttp_ready(xmlhttp
)) {
336 xmlhttp
.open("GET", "backend.php?op=pref-users&subop=edit&id=" +
337 param_escape(id
), true);
338 xmlhttp
.onreadystatechange
=userlist_callback
;
343 function editFilter(id
) {
345 if (!xmlhttp_ready(xmlhttp
)) {
352 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=edit&id=" +
353 param_escape(id
), true);
354 xmlhttp
.onreadystatechange
=filterlist_callback
;
359 function editFeed(feed
) {
361 // notify("Editing feed...");
363 if (!xmlhttp_ready(xmlhttp
)) {
370 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=edit&id=" +
371 param_escape(feed
), true);
372 xmlhttp
.onreadystatechange
=feedlist_callback
;
377 function getSelectedLabels() {
379 var content
= document
.getElementById("prefLabelList");
381 var sel_rows
= new Array();
383 for (i
= 0; i
< content
.rows
.length
; i
++) {
384 if (content
.rows
[i
].className
.match("Selected")) {
385 var row_id
= content
.rows
[i
].id
.replace("LILRR-", "");
386 sel_rows
.push(row_id
);
393 function getSelectedUsers() {
395 var content
= document
.getElementById("prefUserList");
397 var sel_rows
= new Array();
399 for (i
= 0; i
< content
.rows
.length
; i
++) {
400 if (content
.rows
[i
].className
.match("Selected")) {
401 var row_id
= content
.rows
[i
].id
.replace("UMRR-", "");
402 sel_rows
.push(row_id
);
410 function getSelectedFilters() {
412 var content
= document
.getElementById("prefFilterList");
414 var sel_rows
= new Array();
416 for (i
= 0; i
< content
.rows
.length
; i
++) {
417 if (content
.rows
[i
].className
.match("Selected")) {
418 var row_id
= content
.rows
[i
].id
.replace("FILRR-", "");
419 sel_rows
.push(row_id
);
426 function getSelectedFeeds() {
428 var content
= document
.getElementById("prefFeedList");
430 var sel_rows
= new Array();
432 for (i
= 0; i
< content
.rows
.length
; i
++) {
433 if (content
.rows
[i
].className
.match("Selected")) {
434 var row_id
= content
.rows
[i
].id
.replace("FEEDR-", "");
435 sel_rows
.push(row_id
);
442 function readSelectedFeeds() {
444 if (!xmlhttp_ready(xmlhttp
)) {
449 var sel_rows
= getSelectedFeeds();
451 if (sel_rows
.length
> 0) {
453 notify("Marking selected feeds as read...");
455 xmlhttp
.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
456 param_escape(sel_rows
.toString()), true);
457 xmlhttp
.onreadystatechange
=notify_callback
;
462 notify("Please select some feeds first.");
467 function unreadSelectedFeeds() {
469 if (!xmlhttp_ready(xmlhttp
)) {
474 var sel_rows
= getSelectedFeeds();
476 if (sel_rows
.length
> 0) {
478 notify("Marking selected feeds as unread...");
480 xmlhttp
.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
481 param_escape(sel_rows
.toString()), true);
482 xmlhttp
.onreadystatechange
=notify_callback
;
487 notify("Please select some feeds first.");
492 function removeSelectedLabels() {
494 if (!xmlhttp_ready(xmlhttp
)) {
499 var sel_rows
= getSelectedLabels();
501 if (sel_rows
.length
> 0) {
503 notify("Removing selected labels...");
505 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
506 param_escape(sel_rows
.toString()), true);
507 xmlhttp
.onreadystatechange
=labellist_callback
;
511 notify("Please select some labels first.");
515 function removeSelectedUsers() {
517 if (!xmlhttp_ready(xmlhttp
)) {
522 var sel_rows
= getSelectedUsers();
524 if (sel_rows
.length
> 0) {
526 notify("Removing selected users...");
528 xmlhttp
.open("GET", "backend.php?op=pref-users&subop=remove&ids="+
529 param_escape(sel_rows
.toString()), true);
530 xmlhttp
.onreadystatechange
=userlist_callback
;
534 notify("Please select some labels first.");
538 function removeSelectedFilters() {
540 if (!xmlhttp_ready(xmlhttp
)) {
545 var sel_rows
= getSelectedFilters();
547 if (sel_rows
.length
> 0) {
549 notify("Removing selected filters...");
551 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
552 param_escape(sel_rows
.toString()), true);
553 xmlhttp
.onreadystatechange
=filterlist_callback
;
557 notify("Please select some filters first.");
562 function removeSelectedFeeds() {
564 if (!xmlhttp_ready(xmlhttp
)) {
569 var sel_rows
= getSelectedFeeds();
571 if (sel_rows
.length
> 0) {
573 notify("Removing selected feeds...");
575 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
576 param_escape(sel_rows
.toString()), true);
577 xmlhttp
.onreadystatechange
=feedlist_callback
;
582 notify("Please select some feeds first.");
588 function feedEditCancel() {
590 if (!xmlhttp_ready(xmlhttp
)) {
597 notify("Operation cancelled.");
599 xmlhttp
.open("GET", "backend.php?op=pref-feeds", true);
600 xmlhttp
.onreadystatechange
=feedlist_callback
;
605 function feedEditSave() {
607 var feed
= active_feed
;
609 if (!xmlhttp_ready(xmlhttp
)) {
614 var link
= document
.getElementById("iedit_link").value
;
615 var title
= document
.getElementById("iedit_title").value
;
616 var upd_intl
= document
.getElementById("iedit_updintl").value
;
617 var purge_intl
= document
.getElementById("iedit_purgintl").value
;
619 // notify("Saving feed.");
621 /* if (upd_intl < 0) {
622 notify("Update interval must be >= 0 (0 = default)");
626 if (purge_intl < 0) {
627 notify("Purge days must be >= 0 (0 = default)");
631 if (link
.length
== 0) {
632 notify("Feed link cannot be blank.");
636 if (title
.length
== 0) {
637 notify("Feed title cannot be blank.");
643 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=editSave&id=" +
644 feed
+ "&l=" + param_escape(link
) + "&t=" + param_escape(title
) +
645 "&ui=" + param_escape(upd_intl
) + "&pi=" + param_escape(purge_intl
), true);
646 xmlhttp
.onreadystatechange
=feedlist_callback
;
651 function labelEditCancel() {
653 if (!xmlhttp_ready(xmlhttp
)) {
658 active_label
= false;
660 notify("Operation cancelled.");
662 xmlhttp
.open("GET", "backend.php?op=pref-labels", true);
663 xmlhttp
.onreadystatechange
=labellist_callback
;
668 function userEditCancel() {
670 if (!xmlhttp_ready(xmlhttp
)) {
677 notify("Operation cancelled.");
679 xmlhttp
.open("GET", "backend.php?op=pref-users", true);
680 xmlhttp
.onreadystatechange
=userlist_callback
;
685 function filterEditCancel() {
687 if (!xmlhttp_ready(xmlhttp
)) {
692 active_filter
= false;
694 notify("Operation cancelled.");
696 xmlhttp
.open("GET", "backend.php?op=pref-filters", true);
697 xmlhttp
.onreadystatechange
=filterlist_callback
;
702 function labelEditSave() {
704 var label
= active_label
;
706 if (!xmlhttp_ready(xmlhttp
)) {
711 var sqlexp
= document
.getElementById("iedit_expr").value
;
712 var descr
= document
.getElementById("iedit_descr").value
;
714 // notify("Saving label " + sqlexp + ": " + descr);
716 if (sqlexp
.length
== 0) {
717 notify("SQL expression cannot be blank.");
721 if (descr
.length
== 0) {
722 notify("Caption cannot be blank.");
726 active_label
= false;
728 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=editSave&id=" +
729 label
+ "&s=" + param_escape(sqlexp
) + "&d=" + param_escape(descr
),
732 xmlhttp
.onreadystatechange
=labellist_callback
;
737 function userEditSave() {
739 var user
= active_user
;
741 if (!xmlhttp_ready(xmlhttp
)) {
746 var login
= document
.getElementById("iedit_ulogin").value
;
747 var level
= document
.getElementById("iedit_ulevel").value
;
749 if (login
.length
== 0) {
750 notify("Login cannot be blank.");
754 if (level
.length
== 0) {
755 notify("User level cannot be blank.");
761 xmlhttp
.open("GET", "backend.php?op=pref-users&subop=editSave&id=" +
762 user
+ "&l=" + param_escape(login
) + "&al=" + param_escape(level
),
765 xmlhttp
.onreadystatechange
=labellist_callback
;
771 function filterEditSave() {
773 var filter
= active_filter
;
775 if (!xmlhttp_ready(xmlhttp
)) {
780 var regexp
= document
.getElementById("iedit_regexp").value
;
781 var descr
= document
.getElementById("iedit_descr").value
;
782 var match
= document
.getElementById("iedit_match");
784 var v_match
= match
[match
.selectedIndex
].text
;
786 // notify("Saving filter " + filter + ": " + regexp + ", " + descr + ", " + match);
788 if (regexp
.length
== 0) {
789 notify("Filter expression cannot be blank.");
793 active_filter
= false;
795 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=editSave&id=" +
796 filter
+ "&r=" + param_escape(regexp
) + "&d=" + param_escape(descr
) +
797 "&m=" + param_escape(v_match
), true);
799 xmlhttp
.onreadystatechange
=filterlist_callback
;
804 function editSelectedLabel() {
805 var rows
= getSelectedLabels();
807 if (rows
.length
== 0) {
808 notify("No labels are selected.");
812 if (rows
.length
> 1) {
813 notify("Please select one label.");
821 function editSelectedUser() {
822 var rows
= getSelectedUsers();
824 if (rows
.length
== 0) {
825 notify("No users are selected.");
829 if (rows
.length
> 1) {
830 notify("Please select one user.");
837 function resetSelectedUserPass() {
838 var rows
= getSelectedUsers();
840 if (rows
.length
== 0) {
841 notify("No users are selected.");
845 if (rows
.length
> 1) {
846 notify("Please select one user.");
850 notify("Resetting password for selected user...");
854 xmlhttp
.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
855 param_escape(id
), true);
856 xmlhttp
.onreadystatechange
=userlist_callback
;
861 function selectedUserDetails() {
863 if (!xmlhttp_ready(xmlhttp
)) {
868 var rows
= getSelectedUsers();
870 if (rows
.length
== 0) {
871 notify("No users are selected.");
875 if (rows
.length
> 1) {
876 notify("Please select one user.");
882 xmlhttp
.open("GET", "backend.php?op=user-details&id=" + id
, true);
883 xmlhttp
.onreadystatechange
=userdetails_callback
;
888 function editSelectedFilter() {
889 var rows
= getSelectedFilters();
891 if (rows
.length
== 0) {
892 notify("No filters are selected.");
896 if (rows
.length
> 1) {
897 notify("Please select one filter.");
906 function editSelectedFeed() {
907 var rows
= getSelectedFeeds();
909 if (rows
.length
== 0) {
910 notify("No feeds are selected.");
914 if (rows
.length
> 1) {
915 notify("Please select one feed.");
923 function localPiggieFunction(enable
) {
925 piggie
.style
.display
= "block";
927 notify("I loveded it!!!");
929 piggie
.style
.display
= "none";
934 function validateOpmlImport() {
936 var opml_file
= document
.getElementById("opml_file");
938 if (opml_file
.value
.length
== 0) {
939 notify("Please select OPML file to upload.");
946 function updateFilterList() {
948 if (!xmlhttp_ready(xmlhttp
)) {
953 // document.getElementById("prefContent").innerHTML = "Loading filters, please wait...";
955 p_notify("Loading, please wait...");
957 xmlhttp
.open("GET", "backend.php?op=pref-filters", true);
958 xmlhttp
.onreadystatechange
=filterlist_callback
;
963 function updateLabelList() {
965 if (!xmlhttp_ready(xmlhttp
)) {
970 p_notify("Loading, please wait...");
972 // document.getElementById("prefContent").innerHTML = "Loading labels, please wait...";
974 xmlhttp
.open("GET", "backend.php?op=pref-labels", true);
975 xmlhttp
.onreadystatechange
=labellist_callback
;
979 function updatePrefsList() {
981 if (!xmlhttp_ready(xmlhttp
)) {
986 p_notify("Loading, please wait...");
988 xmlhttp
.open("GET", "backend.php?op=pref-prefs", true);
989 xmlhttp
.onreadystatechange
=prefslist_callback
;
994 function selectTab(id
) {
996 if (id
== "feedConfig") {
998 } else if (id
== "filterConfig") {
1000 } else if (id
== "labelConfig") {
1002 } else if (id
== "genConfig") {
1004 } else if (id
== "userConfig") {
1008 var tab
= document
.getElementById(active_tab
+ "Tab");
1011 if (tab
.className
.match("Selected")) {
1012 tab
.className
= "prefsTab";
1016 tab
= document
.getElementById(id
+ "Tab");
1019 if (!tab
.className
.match("Selected")) {
1020 tab
.className
= tab
.className
+ "Selected";
1033 document
.getElementById("prefContent").innerHTML
=
1034 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1035 "to function properly. Your browser doesn't seem to support it.";
1039 selectTab("genConfig");
1041 document
.onkeydown
= hotkey_handler
;
1047 var help_topic_id = false;
1049 function do_dispOptionHelp() {
1051 if (!xmlhttp_ready(xmlhttp))
1054 xmlhttp.open("GET", "backend.php?op=pref-prefs&subop=getHelp&pn=" +
1055 param_escape(help_topic_id), true);
1056 xmlhttp.onreadystatechange=gethelp_callback;
1061 function dispOptionHelp(event, sender) {
1063 help_topic_id = sender.id;
1065 // document.setTimeout("do_dispOptionHelp()", 100);
1069 function closeUserDetails() {
1070 var d
= document
.getElementById('prefUserDetails');
1071 d
.style
.display
= "none";