]> git.wh0rd.org Git - tt-rss.git/blob - prefs.js
mark headlines page as read now works (via rpc)
[tt-rss.git] / prefs.js
1 /*
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.
4 */
5
6 var xmlhttp = false;
7
8 /*@cc_on @*/
9 /*@if (@_jscript_version >= 5)
10 // JScript gives us Conditional compilation, we can cope with old IE versions.
11 // and security blocked creation of the objects.
12 try {
13         xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
14 } catch (e) {
15         try {
16                 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
17         } catch (E) {
18                 xmlhttp = false;
19         }
20 }
21 @end @*/
22
23 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
24         xmlhttp = new XMLHttpRequest();
25 }
26
27
28 function feedlist_callback() {
29         var container = document.getElementById('feeds');
30         if (xmlhttp.readyState == 4) {
31                 container.innerHTML=xmlhttp.responseText;
32         }
33 }
34
35 function notify_callback() {
36         var container = document.getElementById('notify');
37         if (xmlhttp.readyState == 4) {
38                 container.innerHTML=xmlhttp.responseText;
39         }
40 }
41
42
43 function updateFeedList() {
44
45         document.getElementById("feeds").innerHTML = "Loading feeds, please wait...";
46
47         xmlhttp.open("GET", "backend.php?op=pref-feeds", true);
48         xmlhttp.onreadystatechange=feedlist_callback;
49         xmlhttp.send(null);
50
51 }
52
53 function toggleSelectRow(sender) {
54         var parent_row = sender.parentNode.parentNode;
55
56         if (sender.checked) {
57                 if (!parent_row.className.match("Selected")) {
58                         parent_row.className = parent_row.className + "Selected";
59                 }
60         } else {
61                 if (parent_row.className.match("Selected")) {
62                         parent_row.className = parent_row.className.replace("Selected", "");
63                 }
64         }
65 }
66
67 function addFeed() {
68
69         var link = document.getElementById("fadd_link");
70
71         if (link.value.length == 0) {
72                 notify("Error: Missing feed URL.");
73         } else {
74                 notify("Adding feed...");
75
76                 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
77                         param_escape(link.value), true);
78                 xmlhttp.onreadystatechange=feedlist_callback;
79                 xmlhttp.send(null);
80
81                 link.value = "";
82
83         }
84
85 }
86
87 function editFeed(feed) {
88
89         notify("Editing feed...");
90
91         xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=edit&id=" +
92                 param_escape(feed), true);
93         xmlhttp.onreadystatechange=feedlist_callback;
94         xmlhttp.send(null);
95
96 }
97
98 function getSelectedFeeds() {
99
100         var content = document.getElementById("prefFeedList");
101
102         var sel_rows = new Array();
103
104         for (i = 0; i < content.rows.length; i++) {
105                 if (content.rows[i].className.match("Selected")) {
106                         var row_id = content.rows[i].id.replace("FEEDR-", "");
107                         sel_rows.push(row_id);  
108                 }
109         }
110
111         return sel_rows;
112 }
113
114 function readSelectedFeeds() {
115
116         var sel_rows = getSelectedFeeds();
117
118         if (sel_rows.length > 0) {
119
120                 notify("Marking selected feeds as read...");
121
122                 xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
123                         param_escape(sel_rows.toString()), true);
124                 xmlhttp.onreadystatechange=notify_callback;
125                 xmlhttp.send(null);
126
127         } else {
128
129                 notify("Error: Please select some feeds first.");
130
131         }
132 }
133
134 function unreadSelectedFeeds() {
135
136         var sel_rows = getSelectedFeeds();
137
138         if (sel_rows.length > 0) {
139
140                 notify("Marking selected feeds as unread...");
141
142                 xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
143                         param_escape(sel_rows.toString()), true);
144                 xmlhttp.onreadystatechange=notify_callback;
145                 xmlhttp.send(null);
146
147         } else {
148
149                 notify("Error: Please select some feeds first.");
150
151         }
152 }
153
154 function removeSelectedFeeds() {
155
156         var sel_rows = getSelectedFeeds();
157
158         if (sel_rows.length > 0) {
159
160                 notify("Removing selected feeds...");
161
162                 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
163                         param_escape(sel_rows.toString()), true);
164                 xmlhttp.onreadystatechange=feedlist_callback;
165                 xmlhttp.send(null);
166
167         } else {
168
169                 notify("Error: Please select some feeds first.");
170
171         }
172
173 }
174
175 function init() {
176         
177         updateFeedList();
178
179         notify("");
180
181 }