]>
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
;
104 /* if (active_filter) {
105 var row = document.getElementById("ULRR-" + active_label);
107 if (!row.className.match("Selected")) {
108 row.className = row.className + "Selected";
111 var checkbox = document.getElementById("LICHK-" + active_label);
114 checkbox.checked = true;
121 function prefslist_callback() {
122 var container
= document
.getElementById('prefContent');
123 if (xmlhttp
.readyState
== 4) {
125 container
.innerHTML
=xmlhttp
.responseText
;
131 function gethelp_callback() {
132 var container
= document
.getElementById('prefHelpBox');
133 if (xmlhttp
.readyState
== 4) {
135 container
.innerHTML
= xmlhttp
.responseText
;
136 container
.style
.display
= "block";
142 function notify_callback() {
143 var container
= document
.getElementById('notify');
144 if (xmlhttp
.readyState
== 4) {
145 container
.innerHTML
=xmlhttp
.responseText
;
150 function updateFeedList() {
152 if (!xmlhttp_ready(xmlhttp
)) {
157 // document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
159 p_notify("Loading, please wait...");
161 xmlhttp
.open("GET", "backend.php?op=pref-feeds", true);
162 xmlhttp
.onreadystatechange
=feedlist_callback
;
167 function updateUsersList() {
169 if (!xmlhttp_ready(xmlhttp
)) {
174 // document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
176 p_notify("Loading, please wait...");
178 xmlhttp
.open("GET", "backend.php?op=pref-users", true);
179 xmlhttp
.onreadystatechange
=userlist_callback
;
184 function toggleSelectRow(sender
) {
185 var parent_row
= sender
.parentNode
.parentNode
;
187 if (sender
.checked
) {
188 if (!parent_row
.className
.match("Selected")) {
189 parent_row
.className
= parent_row
.className
+ "Selected";
192 if (parent_row
.className
.match("Selected")) {
193 parent_row
.className
= parent_row
.className
.replace("Selected", "");
198 function addLabel() {
200 if (!xmlhttp_ready(xmlhttp
)) {
205 var sqlexp
= document
.getElementById("ladd_expr");
207 if (sqlexp
.value
.length
== 0) {
208 notify("Missing SQL expression.");
210 notify("Adding label...");
212 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=add&exp=" +
213 param_escape(sqlexp
.value
), true);
215 xmlhttp
.onreadystatechange
=labellist_callback
;
223 function addFilter() {
225 if (!xmlhttp_ready(xmlhttp
)) {
230 var regexp
= document
.getElementById("fadd_regexp");
231 var match
= document
.getElementById("fadd_match");
233 if (regexp
.value
.length
== 0) {
234 notify("Missing filter expression.");
236 notify("Adding filter...");
238 var v_match
= match
[match
.selectedIndex
].text
;
240 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=add®exp=" +
241 param_escape(regexp
.value
) + "&match=" + v_match
, true);
243 xmlhttp
.onreadystatechange
=filterlist_callback
;
253 if (!xmlhttp_ready(xmlhttp
)) {
258 var link
= document
.getElementById("fadd_link");
260 if (link
.value
.length
== 0) {
261 notify("Missing feed URL.");
263 notify("Adding feed...");
265 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
266 param_escape(link
.value
), true);
267 xmlhttp
.onreadystatechange
=feedlist_callback
;
278 if (!xmlhttp_ready(xmlhttp
)) {
283 var sqlexp
= document
.getElementById("uadd_box");
285 if (sqlexp
.value
.length
== 0) {
286 notify("Missing user login.");
288 notify("Adding user...");
290 xmlhttp
.open("GET", "backend.php?op=pref-users&subop=add&login=" +
291 param_escape(sqlexp
.value
), true);
293 xmlhttp
.onreadystatechange
=userlist_callback
;
301 function editLabel(id
) {
303 if (!xmlhttp_ready(xmlhttp
)) {
310 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=edit&id=" +
311 param_escape(id
), true);
312 xmlhttp
.onreadystatechange
=labellist_callback
;
317 function editUser(id
) {
319 if (!xmlhttp_ready(xmlhttp
)) {
326 xmlhttp
.open("GET", "backend.php?op=pref-users&subop=edit&id=" +
327 param_escape(id
), true);
328 xmlhttp
.onreadystatechange
=userlist_callback
;
333 function editFilter(id
) {
335 if (!xmlhttp_ready(xmlhttp
)) {
342 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=edit&id=" +
343 param_escape(id
), true);
344 xmlhttp
.onreadystatechange
=filterlist_callback
;
349 function editFeed(feed
) {
351 // notify("Editing feed...");
353 if (!xmlhttp_ready(xmlhttp
)) {
360 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=edit&id=" +
361 param_escape(feed
), true);
362 xmlhttp
.onreadystatechange
=feedlist_callback
;
367 function getSelectedLabels() {
369 var content
= document
.getElementById("prefLabelList");
371 var sel_rows
= new Array();
373 for (i
= 0; i
< content
.rows
.length
; i
++) {
374 if (content
.rows
[i
].className
.match("Selected")) {
375 var row_id
= content
.rows
[i
].id
.replace("LILRR-", "");
376 sel_rows
.push(row_id
);
383 function getSelectedUsers() {
385 var content
= document
.getElementById("prefUserList");
387 var sel_rows
= new Array();
389 for (i
= 0; i
< content
.rows
.length
; i
++) {
390 if (content
.rows
[i
].className
.match("Selected")) {
391 var row_id
= content
.rows
[i
].id
.replace("UMRR-", "");
392 sel_rows
.push(row_id
);
400 function getSelectedFilters() {
402 var content
= document
.getElementById("prefFilterList");
404 var sel_rows
= new Array();
406 for (i
= 0; i
< content
.rows
.length
; i
++) {
407 if (content
.rows
[i
].className
.match("Selected")) {
408 var row_id
= content
.rows
[i
].id
.replace("FILRR-", "");
409 sel_rows
.push(row_id
);
416 function getSelectedFeeds() {
418 var content
= document
.getElementById("prefFeedList");
420 var sel_rows
= new Array();
422 for (i
= 0; i
< content
.rows
.length
; i
++) {
423 if (content
.rows
[i
].className
.match("Selected")) {
424 var row_id
= content
.rows
[i
].id
.replace("FEEDR-", "");
425 sel_rows
.push(row_id
);
432 function readSelectedFeeds() {
434 if (!xmlhttp_ready(xmlhttp
)) {
439 var sel_rows
= getSelectedFeeds();
441 if (sel_rows
.length
> 0) {
443 notify("Marking selected feeds as read...");
445 xmlhttp
.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
446 param_escape(sel_rows
.toString()), true);
447 xmlhttp
.onreadystatechange
=notify_callback
;
452 notify("Please select some feeds first.");
457 function unreadSelectedFeeds() {
459 if (!xmlhttp_ready(xmlhttp
)) {
464 var sel_rows
= getSelectedFeeds();
466 if (sel_rows
.length
> 0) {
468 notify("Marking selected feeds as unread...");
470 xmlhttp
.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
471 param_escape(sel_rows
.toString()), true);
472 xmlhttp
.onreadystatechange
=notify_callback
;
477 notify("Please select some feeds first.");
482 function removeSelectedLabels() {
484 if (!xmlhttp_ready(xmlhttp
)) {
489 var sel_rows
= getSelectedLabels();
491 if (sel_rows
.length
> 0) {
493 notify("Removing selected labels...");
495 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
496 param_escape(sel_rows
.toString()), true);
497 xmlhttp
.onreadystatechange
=labellist_callback
;
501 notify("Please select some labels first.");
505 function removeSelectedUsers() {
507 if (!xmlhttp_ready(xmlhttp
)) {
512 var sel_rows
= getSelectedUsers();
514 if (sel_rows
.length
> 0) {
516 notify("Removing selected users...");
518 xmlhttp
.open("GET", "backend.php?op=pref-users&subop=remove&ids="+
519 param_escape(sel_rows
.toString()), true);
520 xmlhttp
.onreadystatechange
=userlist_callback
;
524 notify("Please select some labels first.");
528 function removeSelectedFilters() {
530 if (!xmlhttp_ready(xmlhttp
)) {
535 var sel_rows
= getSelectedFilters();
537 if (sel_rows
.length
> 0) {
539 notify("Removing selected filters...");
541 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
542 param_escape(sel_rows
.toString()), true);
543 xmlhttp
.onreadystatechange
=filterlist_callback
;
547 notify("Please select some filters first.");
552 function removeSelectedFeeds() {
554 if (!xmlhttp_ready(xmlhttp
)) {
559 var sel_rows
= getSelectedFeeds();
561 if (sel_rows
.length
> 0) {
563 notify("Removing selected feeds...");
565 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
566 param_escape(sel_rows
.toString()), true);
567 xmlhttp
.onreadystatechange
=feedlist_callback
;
572 notify("Please select some feeds first.");
578 function feedEditCancel() {
580 if (!xmlhttp_ready(xmlhttp
)) {
587 notify("Operation cancelled.");
589 xmlhttp
.open("GET", "backend.php?op=pref-feeds", true);
590 xmlhttp
.onreadystatechange
=feedlist_callback
;
595 function feedEditSave() {
597 var feed
= active_feed
;
599 if (!xmlhttp_ready(xmlhttp
)) {
604 var link
= document
.getElementById("iedit_link").value
;
605 var title
= document
.getElementById("iedit_title").value
;
606 var upd_intl
= document
.getElementById("iedit_updintl").value
;
607 var purge_intl
= document
.getElementById("iedit_purgintl").value
;
609 // notify("Saving feed.");
611 /* if (upd_intl < 0) {
612 notify("Update interval must be >= 0 (0 = default)");
616 if (purge_intl < 0) {
617 notify("Purge days must be >= 0 (0 = default)");
621 if (link
.length
== 0) {
622 notify("Feed link cannot be blank.");
626 if (title
.length
== 0) {
627 notify("Feed title cannot be blank.");
633 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=editSave&id=" +
634 feed
+ "&l=" + param_escape(link
) + "&t=" + param_escape(title
) +
635 "&ui=" + param_escape(upd_intl
) + "&pi=" + param_escape(purge_intl
), true);
636 xmlhttp
.onreadystatechange
=feedlist_callback
;
641 function labelEditCancel() {
643 if (!xmlhttp_ready(xmlhttp
)) {
648 active_label
= false;
650 notify("Operation cancelled.");
652 xmlhttp
.open("GET", "backend.php?op=pref-labels", true);
653 xmlhttp
.onreadystatechange
=labellist_callback
;
658 function userEditCancel() {
660 if (!xmlhttp_ready(xmlhttp
)) {
667 notify("Operation cancelled.");
669 xmlhttp
.open("GET", "backend.php?op=pref-users", true);
670 xmlhttp
.onreadystatechange
=userlist_callback
;
675 function filterEditCancel() {
677 if (!xmlhttp_ready(xmlhttp
)) {
682 active_filter
= false;
684 notify("Operation cancelled.");
686 xmlhttp
.open("GET", "backend.php?op=pref-filters", true);
687 xmlhttp
.onreadystatechange
=filterlist_callback
;
692 function labelEditSave() {
694 var label
= active_label
;
696 if (!xmlhttp_ready(xmlhttp
)) {
701 var sqlexp
= document
.getElementById("iedit_expr").value
;
702 var descr
= document
.getElementById("iedit_descr").value
;
704 // notify("Saving label " + sqlexp + ": " + descr);
706 if (sqlexp
.length
== 0) {
707 notify("SQL expression cannot be blank.");
711 if (descr
.length
== 0) {
712 notify("Caption cannot be blank.");
716 active_label
= false;
718 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=editSave&id=" +
719 label
+ "&s=" + param_escape(sqlexp
) + "&d=" + param_escape(descr
),
722 xmlhttp
.onreadystatechange
=labellist_callback
;
727 function userEditSave() {
729 var user
= active_user
;
731 if (!xmlhttp_ready(xmlhttp
)) {
736 var login
= document
.getElementById("iedit_ulogin").value
;
737 var level
= document
.getElementById("iedit_ulevel").value
;
739 if (login
.length
== 0) {
740 notify("Login cannot be blank.");
744 if (level
.length
== 0) {
745 notify("User level cannot be blank.");
751 xmlhttp
.open("GET", "backend.php?op=pref-users&subop=editSave&id=" +
752 user
+ "&l=" + param_escape(login
) + "&al=" + param_escape(level
),
755 xmlhttp
.onreadystatechange
=labellist_callback
;
761 function filterEditSave() {
763 var filter
= active_filter
;
765 if (!xmlhttp_ready(xmlhttp
)) {
770 var regexp
= document
.getElementById("iedit_regexp").value
;
771 var descr
= document
.getElementById("iedit_descr").value
;
772 var match
= document
.getElementById("iedit_match");
774 var v_match
= match
[match
.selectedIndex
].text
;
776 // notify("Saving filter " + filter + ": " + regexp + ", " + descr + ", " + match);
778 if (regexp
.length
== 0) {
779 notify("Filter expression cannot be blank.");
783 active_filter
= false;
785 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=editSave&id=" +
786 filter
+ "&r=" + param_escape(regexp
) + "&d=" + param_escape(descr
) +
787 "&m=" + param_escape(v_match
), true);
789 xmlhttp
.onreadystatechange
=filterlist_callback
;
794 function editSelectedLabel() {
795 var rows
= getSelectedLabels();
797 if (rows
.length
== 0) {
798 notify("No labels are selected.");
802 if (rows
.length
> 1) {
803 notify("Please select one label.");
811 function editSelectedUser() {
812 var rows
= getSelectedUsers();
814 if (rows
.length
== 0) {
815 notify("No users are selected.");
819 if (rows
.length
> 1) {
820 notify("Please select one user.");
827 function resetSelectedUserPass() {
828 var rows
= getSelectedUsers();
830 if (rows
.length
== 0) {
831 notify("No users are selected.");
835 if (rows
.length
> 1) {
836 notify("Please select one user.");
840 notify("Resetting password for selected user...");
844 xmlhttp
.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
845 param_escape(id
), true);
846 xmlhttp
.onreadystatechange
=userlist_callback
;
853 function editSelectedFilter() {
854 var rows
= getSelectedFilters();
856 if (rows
.length
== 0) {
857 notify("No filters are selected.");
861 if (rows
.length
> 1) {
862 notify("Please select one filter.");
871 function editSelectedFeed() {
872 var rows
= getSelectedFeeds();
874 if (rows
.length
== 0) {
875 notify("No feeds are selected.");
879 if (rows
.length
> 1) {
880 notify("Please select one feed.");
888 function localPiggieFunction(enable
) {
890 piggie
.style
.display
= "block";
892 notify("I loveded it!!!");
894 piggie
.style
.display
= "none";
899 function validateOpmlImport() {
901 var opml_file
= document
.getElementById("opml_file");
903 if (opml_file
.value
.length
== 0) {
904 notify("Please select OPML file to upload.");
911 function updateFilterList() {
913 if (!xmlhttp_ready(xmlhttp
)) {
918 // document.getElementById("prefContent").innerHTML = "Loading filters, please wait...";
920 p_notify("Loading, please wait...");
922 xmlhttp
.open("GET", "backend.php?op=pref-filters", true);
923 xmlhttp
.onreadystatechange
=filterlist_callback
;
928 function updateLabelList() {
930 if (!xmlhttp_ready(xmlhttp
)) {
935 p_notify("Loading, please wait...");
937 // document.getElementById("prefContent").innerHTML = "Loading labels, please wait...";
939 xmlhttp
.open("GET", "backend.php?op=pref-labels", true);
940 xmlhttp
.onreadystatechange
=labellist_callback
;
944 function updatePrefsList() {
946 if (!xmlhttp_ready(xmlhttp
)) {
951 p_notify("Loading, please wait...");
953 xmlhttp
.open("GET", "backend.php?op=pref-prefs", true);
954 xmlhttp
.onreadystatechange
=prefslist_callback
;
959 function selectTab(id
) {
961 if (id
== "feedConfig") {
963 } else if (id
== "filterConfig") {
965 } else if (id
== "labelConfig") {
967 } else if (id
== "genConfig") {
969 } else if (id
== "userConfig") {
973 var tab
= document
.getElementById(active_tab
+ "Tab");
976 if (tab
.className
.match("Selected")) {
977 tab
.className
= "prefsTab";
981 tab
= document
.getElementById(id
+ "Tab");
984 if (!tab
.className
.match("Selected")) {
985 tab
.className
= tab
.className
+ "Selected";
998 document
.getElementById("prefContent").innerHTML
=
999 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1000 "to function properly. Your browser doesn't seem to support it.";
1004 selectTab("genConfig");
1006 document
.onkeydown
= hotkey_handler
;
1012 var help_topic_id = false;
1014 function do_dispOptionHelp() {
1016 if (!xmlhttp_ready(xmlhttp))
1019 xmlhttp.open("GET", "backend.php?op=pref-prefs&subop=getHelp&pn=" +
1020 param_escape(help_topic_id), true);
1021 xmlhttp.onreadystatechange=gethelp_callback;
1026 function dispOptionHelp(event, sender) {
1028 help_topic_id = sender.id;
1030 // document.setTimeout("do_dispOptionHelp()", 100);