]>
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 infobox_callback() {
123 var container
= document
.getElementById('infoBox');
124 if (xmlhttp
.readyState
== 4) {
126 container
.innerHTML
=xmlhttp
.responseText
;
127 container
.style
.display
= "block";
133 function prefslist_callback() {
134 var container
= document
.getElementById('prefContent');
135 if (xmlhttp
.readyState
== 4) {
137 container
.innerHTML
=xmlhttp
.responseText
;
143 function gethelp_callback() {
144 var container
= document
.getElementById('prefHelpBox');
145 if (xmlhttp
.readyState
== 4) {
147 container
.innerHTML
= xmlhttp
.responseText
;
148 container
.style
.display
= "block";
154 function notify_callback() {
155 var container
= document
.getElementById('notify');
156 if (xmlhttp
.readyState
== 4) {
157 container
.innerHTML
=xmlhttp
.responseText
;
162 function updateFeedList() {
164 if (!xmlhttp_ready(xmlhttp
)) {
169 // document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
171 p_notify("Loading, please wait...");
173 xmlhttp
.open("GET", "backend.php?op=pref-feeds", true);
174 xmlhttp
.onreadystatechange
=feedlist_callback
;
179 function updateUsersList() {
181 if (!xmlhttp_ready(xmlhttp
)) {
186 // document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
188 p_notify("Loading, please wait...");
190 xmlhttp
.open("GET", "backend.php?op=pref-users", true);
191 xmlhttp
.onreadystatechange
=userlist_callback
;
196 function toggleSelectRow(sender
) {
197 var parent_row
= sender
.parentNode
.parentNode
;
199 if (sender
.checked
) {
200 if (!parent_row
.className
.match("Selected")) {
201 parent_row
.className
= parent_row
.className
+ "Selected";
204 if (parent_row
.className
.match("Selected")) {
205 parent_row
.className
= parent_row
.className
.replace("Selected", "");
210 function addLabel() {
212 if (!xmlhttp_ready(xmlhttp
)) {
217 var sqlexp
= document
.getElementById("ladd_expr");
219 if (sqlexp
.value
.length
== 0) {
220 notify("Missing SQL expression.");
222 notify("Adding label...");
224 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=add&exp=" +
225 param_escape(sqlexp
.value
), true);
227 xmlhttp
.onreadystatechange
=labellist_callback
;
235 function addFilter() {
237 if (!xmlhttp_ready(xmlhttp
)) {
242 var regexp
= document
.getElementById("fadd_regexp");
243 var match
= document
.getElementById("fadd_match");
245 if (regexp
.value
.length
== 0) {
246 notify("Missing filter expression.");
248 notify("Adding filter...");
250 var v_match
= match
[match
.selectedIndex
].text
;
252 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=add®exp=" +
253 param_escape(regexp
.value
) + "&match=" + v_match
, true);
255 xmlhttp
.onreadystatechange
=filterlist_callback
;
265 if (!xmlhttp_ready(xmlhttp
)) {
270 var link
= document
.getElementById("fadd_link");
272 if (link
.value
.length
== 0) {
273 notify("Missing feed URL.");
275 notify("Adding feed...");
277 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
278 param_escape(link
.value
), true);
279 xmlhttp
.onreadystatechange
=feedlist_callback
;
290 if (!xmlhttp_ready(xmlhttp
)) {
295 var sqlexp
= document
.getElementById("uadd_box");
297 if (sqlexp
.value
.length
== 0) {
298 notify("Missing user login.");
300 notify("Adding user...");
302 xmlhttp
.open("GET", "backend.php?op=pref-users&subop=add&login=" +
303 param_escape(sqlexp
.value
), true);
305 xmlhttp
.onreadystatechange
=userlist_callback
;
313 function editLabel(id
) {
315 if (!xmlhttp_ready(xmlhttp
)) {
322 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=edit&id=" +
323 param_escape(id
), true);
324 xmlhttp
.onreadystatechange
=labellist_callback
;
329 function editUser(id
) {
331 if (!xmlhttp_ready(xmlhttp
)) {
338 xmlhttp
.open("GET", "backend.php?op=pref-users&subop=edit&id=" +
339 param_escape(id
), true);
340 xmlhttp
.onreadystatechange
=userlist_callback
;
345 function editFilter(id
) {
347 if (!xmlhttp_ready(xmlhttp
)) {
354 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=edit&id=" +
355 param_escape(id
), true);
356 xmlhttp
.onreadystatechange
=filterlist_callback
;
361 function editFeed(feed
) {
363 // notify("Editing feed...");
365 if (!xmlhttp_ready(xmlhttp
)) {
372 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=edit&id=" +
373 param_escape(feed
), true);
374 xmlhttp
.onreadystatechange
=feedlist_callback
;
379 function getSelectedLabels() {
381 var content
= document
.getElementById("prefLabelList");
383 var sel_rows
= new Array();
385 for (i
= 0; i
< content
.rows
.length
; i
++) {
386 if (content
.rows
[i
].className
.match("Selected")) {
387 var row_id
= content
.rows
[i
].id
.replace("LILRR-", "");
388 sel_rows
.push(row_id
);
395 function getSelectedUsers() {
397 var content
= document
.getElementById("prefUserList");
399 var sel_rows
= new Array();
401 for (i
= 0; i
< content
.rows
.length
; i
++) {
402 if (content
.rows
[i
].className
.match("Selected")) {
403 var row_id
= content
.rows
[i
].id
.replace("UMRR-", "");
404 sel_rows
.push(row_id
);
412 function getSelectedFilters() {
414 var content
= document
.getElementById("prefFilterList");
416 var sel_rows
= new Array();
418 for (i
= 0; i
< content
.rows
.length
; i
++) {
419 if (content
.rows
[i
].className
.match("Selected")) {
420 var row_id
= content
.rows
[i
].id
.replace("FILRR-", "");
421 sel_rows
.push(row_id
);
428 function getSelectedFeeds() {
430 var content
= document
.getElementById("prefFeedList");
432 var sel_rows
= new Array();
434 for (i
= 0; i
< content
.rows
.length
; i
++) {
435 if (content
.rows
[i
].className
.match("Selected")) {
436 var row_id
= content
.rows
[i
].id
.replace("FEEDR-", "");
437 sel_rows
.push(row_id
);
444 function readSelectedFeeds() {
446 if (!xmlhttp_ready(xmlhttp
)) {
451 var sel_rows
= getSelectedFeeds();
453 if (sel_rows
.length
> 0) {
455 notify("Marking selected feeds as read...");
457 xmlhttp
.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
458 param_escape(sel_rows
.toString()), true);
459 xmlhttp
.onreadystatechange
=notify_callback
;
464 notify("Please select some feeds first.");
469 function unreadSelectedFeeds() {
471 if (!xmlhttp_ready(xmlhttp
)) {
476 var sel_rows
= getSelectedFeeds();
478 if (sel_rows
.length
> 0) {
480 notify("Marking selected feeds as unread...");
482 xmlhttp
.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
483 param_escape(sel_rows
.toString()), true);
484 xmlhttp
.onreadystatechange
=notify_callback
;
489 notify("Please select some feeds first.");
494 function removeSelectedLabels() {
496 if (!xmlhttp_ready(xmlhttp
)) {
501 var sel_rows
= getSelectedLabels();
503 if (sel_rows
.length
> 0) {
505 notify("Removing selected labels...");
507 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
508 param_escape(sel_rows
.toString()), true);
509 xmlhttp
.onreadystatechange
=labellist_callback
;
513 notify("Please select some labels first.");
517 function removeSelectedUsers() {
519 if (!xmlhttp_ready(xmlhttp
)) {
524 var sel_rows
= getSelectedUsers();
526 if (sel_rows
.length
> 0) {
528 notify("Removing selected users...");
530 xmlhttp
.open("GET", "backend.php?op=pref-users&subop=remove&ids="+
531 param_escape(sel_rows
.toString()), true);
532 xmlhttp
.onreadystatechange
=userlist_callback
;
536 notify("Please select some labels first.");
540 function removeSelectedFilters() {
542 if (!xmlhttp_ready(xmlhttp
)) {
547 var sel_rows
= getSelectedFilters();
549 if (sel_rows
.length
> 0) {
551 notify("Removing selected filters...");
553 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
554 param_escape(sel_rows
.toString()), true);
555 xmlhttp
.onreadystatechange
=filterlist_callback
;
559 notify("Please select some filters first.");
564 function removeSelectedFeeds() {
566 if (!xmlhttp_ready(xmlhttp
)) {
571 var sel_rows
= getSelectedFeeds();
573 if (sel_rows
.length
> 0) {
575 notify("Removing selected feeds...");
577 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
578 param_escape(sel_rows
.toString()), true);
579 xmlhttp
.onreadystatechange
=feedlist_callback
;
584 notify("Please select some feeds first.");
590 function feedEditCancel() {
592 if (!xmlhttp_ready(xmlhttp
)) {
599 notify("Operation cancelled.");
601 xmlhttp
.open("GET", "backend.php?op=pref-feeds", true);
602 xmlhttp
.onreadystatechange
=feedlist_callback
;
607 function feedEditSave() {
609 var feed
= active_feed
;
611 if (!xmlhttp_ready(xmlhttp
)) {
616 var link
= document
.getElementById("iedit_link").value
;
617 var title
= document
.getElementById("iedit_title").value
;
618 var upd_intl
= document
.getElementById("iedit_updintl").value
;
619 var purge_intl
= document
.getElementById("iedit_purgintl").value
;
621 // notify("Saving feed.");
623 /* if (upd_intl < 0) {
624 notify("Update interval must be >= 0 (0 = default)");
628 if (purge_intl < 0) {
629 notify("Purge days must be >= 0 (0 = default)");
633 if (link
.length
== 0) {
634 notify("Feed link cannot be blank.");
638 if (title
.length
== 0) {
639 notify("Feed title cannot be blank.");
645 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=editSave&id=" +
646 feed
+ "&l=" + param_escape(link
) + "&t=" + param_escape(title
) +
647 "&ui=" + param_escape(upd_intl
) + "&pi=" + param_escape(purge_intl
), true);
648 xmlhttp
.onreadystatechange
=feedlist_callback
;
653 function labelEditCancel() {
655 if (!xmlhttp_ready(xmlhttp
)) {
660 active_label
= false;
662 notify("Operation cancelled.");
664 xmlhttp
.open("GET", "backend.php?op=pref-labels", true);
665 xmlhttp
.onreadystatechange
=labellist_callback
;
670 function userEditCancel() {
672 if (!xmlhttp_ready(xmlhttp
)) {
679 notify("Operation cancelled.");
681 xmlhttp
.open("GET", "backend.php?op=pref-users", true);
682 xmlhttp
.onreadystatechange
=userlist_callback
;
687 function filterEditCancel() {
689 if (!xmlhttp_ready(xmlhttp
)) {
694 active_filter
= false;
696 notify("Operation cancelled.");
698 xmlhttp
.open("GET", "backend.php?op=pref-filters", true);
699 xmlhttp
.onreadystatechange
=filterlist_callback
;
704 function labelEditSave() {
706 var label
= active_label
;
708 if (!xmlhttp_ready(xmlhttp
)) {
713 var sqlexp
= document
.getElementById("iedit_expr").value
;
714 var descr
= document
.getElementById("iedit_descr").value
;
716 // notify("Saving label " + sqlexp + ": " + descr);
718 if (sqlexp
.length
== 0) {
719 notify("SQL expression cannot be blank.");
723 if (descr
.length
== 0) {
724 notify("Caption cannot be blank.");
728 active_label
= false;
730 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=editSave&id=" +
731 label
+ "&s=" + param_escape(sqlexp
) + "&d=" + param_escape(descr
),
734 xmlhttp
.onreadystatechange
=labellist_callback
;
739 function userEditSave() {
741 var user
= active_user
;
743 if (!xmlhttp_ready(xmlhttp
)) {
748 var login
= document
.getElementById("iedit_ulogin").value
;
749 var level
= document
.getElementById("iedit_ulevel").value
;
751 if (login
.length
== 0) {
752 notify("Login cannot be blank.");
756 if (level
.length
== 0) {
757 notify("User level cannot be blank.");
763 xmlhttp
.open("GET", "backend.php?op=pref-users&subop=editSave&id=" +
764 user
+ "&l=" + param_escape(login
) + "&al=" + param_escape(level
),
767 xmlhttp
.onreadystatechange
=labellist_callback
;
773 function filterEditSave() {
775 var filter
= active_filter
;
777 if (!xmlhttp_ready(xmlhttp
)) {
782 var regexp
= document
.getElementById("iedit_regexp").value
;
783 var descr
= document
.getElementById("iedit_descr").value
;
784 var match
= document
.getElementById("iedit_match");
786 var v_match
= match
[match
.selectedIndex
].text
;
788 // notify("Saving filter " + filter + ": " + regexp + ", " + descr + ", " + match);
790 if (regexp
.length
== 0) {
791 notify("Filter expression cannot be blank.");
795 active_filter
= false;
797 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=editSave&id=" +
798 filter
+ "&r=" + param_escape(regexp
) + "&d=" + param_escape(descr
) +
799 "&m=" + param_escape(v_match
), true);
801 xmlhttp
.onreadystatechange
=filterlist_callback
;
806 function editSelectedLabel() {
807 var rows
= getSelectedLabels();
809 if (rows
.length
== 0) {
810 notify("No labels are selected.");
814 if (rows
.length
> 1) {
815 notify("Please select one label.");
823 function editSelectedUser() {
824 var rows
= getSelectedUsers();
826 if (rows
.length
== 0) {
827 notify("No users are selected.");
831 if (rows
.length
> 1) {
832 notify("Please select one user.");
839 function resetSelectedUserPass() {
840 var rows
= getSelectedUsers();
842 if (rows
.length
== 0) {
843 notify("No users are selected.");
847 if (rows
.length
> 1) {
848 notify("Please select one user.");
852 notify("Resetting password for selected user...");
856 xmlhttp
.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
857 param_escape(id
), true);
858 xmlhttp
.onreadystatechange
=userlist_callback
;
863 function selectedUserDetails() {
865 if (!xmlhttp_ready(xmlhttp
)) {
870 var rows
= getSelectedUsers();
872 if (rows
.length
== 0) {
873 notify("No users are selected.");
877 if (rows
.length
> 1) {
878 notify("Please select one user.");
884 xmlhttp
.open("GET", "backend.php?op=user-details&id=" + id
, true);
885 xmlhttp
.onreadystatechange
=infobox_callback
;
890 function selectedFeedDetails() {
892 if (!xmlhttp_ready(xmlhttp
)) {
897 var rows
= getSelectedFeeds();
899 if (rows
.length
== 0) {
900 notify("No feeds are selected.");
904 if (rows
.length
> 1) {
905 notify("Please select one feed.");
911 xmlhttp
.open("GET", "backend.php?op=feed-details&id=" + id
, true);
912 xmlhttp
.onreadystatechange
=infobox_callback
;
917 function editSelectedFilter() {
918 var rows
= getSelectedFilters();
920 if (rows
.length
== 0) {
921 notify("No filters are selected.");
925 if (rows
.length
> 1) {
926 notify("Please select one filter.");
935 function editSelectedFeed() {
936 var rows
= getSelectedFeeds();
938 if (rows
.length
== 0) {
939 notify("No feeds are selected.");
943 if (rows
.length
> 1) {
944 notify("Please select one feed.");
952 function localPiggieFunction(enable
) {
954 piggie
.style
.display
= "block";
956 notify("I loveded it!!!");
958 piggie
.style
.display
= "none";
963 function validateOpmlImport() {
965 var opml_file
= document
.getElementById("opml_file");
967 if (opml_file
.value
.length
== 0) {
968 notify("Please select OPML file to upload.");
975 function updateFilterList() {
977 if (!xmlhttp_ready(xmlhttp
)) {
982 // document.getElementById("prefContent").innerHTML = "Loading filters, please wait...";
984 p_notify("Loading, please wait...");
986 xmlhttp
.open("GET", "backend.php?op=pref-filters", true);
987 xmlhttp
.onreadystatechange
=filterlist_callback
;
992 function updateLabelList() {
994 if (!xmlhttp_ready(xmlhttp
)) {
999 p_notify("Loading, please wait...");
1001 // document.getElementById("prefContent").innerHTML = "Loading labels, please wait...";
1003 xmlhttp
.open("GET", "backend.php?op=pref-labels", true);
1004 xmlhttp
.onreadystatechange
=labellist_callback
;
1008 function updatePrefsList() {
1010 if (!xmlhttp_ready(xmlhttp
)) {
1011 printLockingError();
1015 p_notify("Loading, please wait...");
1017 xmlhttp
.open("GET", "backend.php?op=pref-prefs", true);
1018 xmlhttp
.onreadystatechange
=prefslist_callback
;
1023 function selectTab(id
) {
1025 if (!xmlhttp_ready(xmlhttp
)) {
1026 printLockingError();
1030 if (id
== "feedConfig") {
1032 } else if (id
== "filterConfig") {
1034 } else if (id
== "labelConfig") {
1036 } else if (id
== "genConfig") {
1038 } else if (id
== "userConfig") {
1042 var tab
= document
.getElementById(active_tab
+ "Tab");
1045 if (tab
.className
.match("Selected")) {
1046 tab
.className
= "prefsTab";
1050 tab
= document
.getElementById(id
+ "Tab");
1053 if (!tab
.className
.match("Selected")) {
1054 tab
.className
= tab
.className
+ "Selected";
1067 document
.getElementById("prefContent").innerHTML
=
1068 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1069 "to function properly. Your browser doesn't seem to support it.";
1073 selectTab("genConfig");
1075 document
.onkeydown
= hotkey_handler
;
1081 var help_topic_id = false;
1083 function do_dispOptionHelp() {
1085 if (!xmlhttp_ready(xmlhttp))
1088 xmlhttp.open("GET", "backend.php?op=pref-prefs&subop=getHelp&pn=" +
1089 param_escape(help_topic_id), true);
1090 xmlhttp.onreadystatechange=gethelp_callback;
1095 function dispOptionHelp(event, sender) {
1097 help_topic_id = sender.id;
1099 // document.setTimeout("do_dispOptionHelp()", 100);
1103 function closeInfoBox() {
1104 var d
= document
.getElementById('infoBox');
1105 d
.style
.display
= "none";