]> git.wh0rd.org - tt-rss.git/blame - tt-rss.js
updateFeedList() now displays saner notify() message
[tt-rss.git] / tt-rss.js
CommitLineData
1cd17194
AD
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
6var xmlhttp = false;
525116d4 7var xmlhttp_rpc = false;
1cd17194 8
76798ff3 9var total_unread = 0;
525116d4 10var first_run = true;
76798ff3 11
1cd17194
AD
12/*@cc_on @*/
13/*@if (@_jscript_version >= 5)
14// JScript gives us Conditional compilation, we can cope with old IE versions.
15// and security blocked creation of the objects.
16try {
17 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
18} catch (e) {
19 try {
20 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
21 } catch (E) {
22 xmlhttp = false;
23 }
24}
25@end @*/
26
27if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
28 xmlhttp = new XMLHttpRequest();
525116d4
AD
29 xmlhttp_rpc = new XMLHttpRequest();
30
1cd17194
AD
31}
32
a234aee5
AD
33function printLockingError() {
34 notify("Please wait until operation finishes");
35}
36
175847de
AD
37function notify_callback() {
38 var container = document.getElementById('notify');
39 if (xmlhttp.readyState == 4) {
40 container.innerHTML=xmlhttp.responseText;
41 }
42}
43
1cd17194 44function feedlist_callback() {
d76a3b03 45 var container = document.getElementById('feeds');
1cd17194 46 if (xmlhttp.readyState == 4) {
d76a3b03 47 container.innerHTML=xmlhttp.responseText;
76798ff3
AD
48
49 var feedtu = document.getElementById("FEEDTU");
50
51 if (feedtu) {
52 total_unread = feedtu.innerHTML;
53 update_title();
54 }
476cac42 55
525116d4
AD
56 if (first_run) {
57 scheduleFeedUpdate();
58 first_run = false;
59 } else {
60 notify("");
61 }
1cd17194
AD
62 }
63}
64
65function viewfeed_callback() {
d76a3b03 66 var container = document.getElementById('headlines');
1cd17194 67 if (xmlhttp.readyState == 4) {
d76a3b03 68 container.innerHTML = xmlhttp.responseText;
a1a8a2be
AD
69
70 var factive = document.getElementById("FACTIVE");
71 var funread = document.getElementById("FUNREAD");
72 var ftotal = document.getElementById("FTOTAL");
73
74 if (ftotal && factive && funread) {
75 var feed_id = factive.innerHTML;
76
77 var feedr = document.getElementById("FEEDR-" + feed_id);
78 var feedt = document.getElementById("FEEDT-" + feed_id);
79 var feedu = document.getElementById("FEEDU-" + feed_id);
80
81 feedt.innerHTML = ftotal.innerHTML;
82 feedu.innerHTML = funread.innerHTML;
83
84 if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) {
85 feedr.className = feedr.className + "Unread";
86 } else if (feedu.innerHTML <= 0) {
87 feedr.className = feedr.className.replace("Unread", "");
88 }
89
90 }
1c37c607
AD
91
92 notify("");
93
94 }
1cd17194
AD
95}
96
97function view_callback() {
d76a3b03 98 var container = document.getElementById('content');
1cd17194 99 if (xmlhttp.readyState == 4) {
d76a3b03 100 container.innerHTML=xmlhttp.responseText;
1cd17194
AD
101 }
102}
103
525116d4
AD
104function refetch_callback() {
105 if (xmlhttp_rpc.readyState == 4) {
106 // feeds are updated in background
107 updateFeedList(false, false);
108// notify("All feeds updated");
109 }
110}
111
112function scheduleFeedUpdate() {
113
114 notify("Updating feeds in background...");
115
116 var query_str = "backend.php?op=rpc&subop=forceUpdateAllFeeds";
117
118 if (xmlhttp_rpc.readyState == 4 || xmlhttp_rpc.readyState == 0) {
119 xmlhttp_rpc.open("GET", query_str, true);
120 xmlhttp_rpc.onreadystatechange=refetch_callback;
121 xmlhttp_rpc.send(null);
122 } else {
123 printLockingError();
124 }
125}
1cd17194 126
525116d4 127function updateFeedList(silent, fetch) {
076682aa 128
525116d4 129 if (silent != true) {
11c2f3fa 130 notify("Loading feed list...");
40d13c28 131 }
82baad4a 132
331900c6
AD
133 var query_str = "backend.php?op=feeds";
134
135 if (fetch) query_str = query_str + "&fetch=yes";
136
076682aa
AD
137 if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
138 xmlhttp.open("GET", query_str, true);
139 xmlhttp.onreadystatechange=feedlist_callback;
140 xmlhttp.send(null);
141 } else {
a234aee5 142 printLockingError();
076682aa 143 }
1cd17194
AD
144}
145
175847de
AD
146function catchupPage(feed) {
147
076682aa 148 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
a234aee5 149 printLockingError();
076682aa
AD
150 return
151 }
152
175847de
AD
153 var content = document.getElementById("headlinesList");
154
155 var rows = new Array();
156
157 for (i = 0; i < content.rows.length; i++) {
158 var row_id = content.rows[i].id.replace("RROW-", "");
159 if (row_id.length > 0) {
160 rows.push(row_id);
161 content.rows[i].className = content.rows[i].className.replace("Unread", "");
162 }
163 }
164
165 var feedr = document.getElementById("FEEDR-" + feed);
166 var feedu = document.getElementById("FEEDU-" + feed);
167
168 feedu.innerHTML = feedu.innerHTML - rows.length;
169
170 if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) {
171 feedr.className = feedr.className + "Unread";
172 } else if (feedu.innerHTML <= 0) {
173 feedr.className = feedr.className.replace("Unread", "");
174 }
175
176 var query_str = "backend.php?op=rpc&subop=catchupPage&ids=" +
177 param_escape(rows.toString());
178
179 notify("Marking this page as read...");
180
181 xmlhttp.open("GET", query_str, true);
182 xmlhttp.onreadystatechange=notify_callback;
183 xmlhttp.send(null);
184
185}
186
476cac42 187function catchupAllFeeds() {
076682aa
AD
188
189 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
a234aee5 190 printLockingError();
076682aa
AD
191 return
192 }
476cac42
AD
193 var query_str = "backend.php?op=feeds&subop=catchupAll";
194
195 notify("Marking all feeds as read...");
196
197 xmlhttp.open("GET", query_str, true);
198 xmlhttp.onreadystatechange=feedlist_callback;
199 xmlhttp.send(null);
200
201}
1cd17194 202
476cac42 203function viewfeed(feed, skip, subop) {
1cd17194 204
1c37c607
AD
205// document.getElementById('headlines').innerHTML='Loading headlines, please wait...';
206// document.getElementById('content').innerHTML='&nbsp;';
d76a3b03 207
076682aa 208 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
a234aee5 209 printLockingError();
076682aa
AD
210 return
211 }
212
d76a3b03 213 xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) +
476cac42 214 "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) , true);
1cd17194
AD
215 xmlhttp.onreadystatechange=viewfeed_callback;
216 xmlhttp.send(null);
217
1c37c607
AD
218 notify("Loading headlines...");
219
1cd17194
AD
220}
221
a1a8a2be 222function view(id,feed_id) {
d76a3b03 223
076682aa 224 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
a234aee5 225 printLockingError();
076682aa
AD
226 return
227 }
228
d76a3b03
AD
229 var crow = document.getElementById("RROW-" + id);
230
a1a8a2be
AD
231 if (crow.className.match("Unread")) {
232 var umark = document.getElementById("FEEDU-" + feed_id);
233 umark.innerHTML = umark.innerHTML - 1;
d76a3b03 234 crow.className = crow.className.replace("Unread", "");
d76a3b03 235
a1a8a2be
AD
236 if (umark.innerHTML == "0") {
237 var feedr = document.getElementById("FEEDR-" + feed_id);
238 feedr.className = feedr.className.replace("Unread", "");
239 }
b197f117 240
76798ff3
AD
241 total_unread--;
242
b197f117 243 update_title();
76798ff3 244 }
1cd17194 245
b197f117
AD
246 var upd_img_pic = document.getElementById("FUPDPIC-" + id);
247
248 if (upd_img_pic) {
249 upd_img_pic.innerHTML = "";
250 }
251
d76a3b03 252 document.getElementById('content').innerHTML='Loading, please wait...';
1cd17194 253
d76a3b03 254 xmlhttp.open("GET", "backend.php?op=view&id=" + param_escape(id), true);
1cd17194
AD
255 xmlhttp.onreadystatechange=view_callback;
256 xmlhttp.send(null);
257
258}
259
40d13c28
AD
260function timeout() {
261
01947781 262 scheduleFeedUpdate();
40d13c28 263
ac53063a
AD
264 setTimeout("timeout()", 1800*1000);
265
266}
267
268function search(feed, sender) {
269
076682aa 270 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
a234aee5 271 printLockingError();
076682aa
AD
272 return
273 }
274
ac53063a
AD
275 notify("Search: " + feed + ", " + sender.value)
276
277 document.getElementById('headlines').innerHTML='Loading headlines, please wait...';
278 document.getElementById('content').innerHTML='&nbsp;';
279
280 xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) +
281 "&search=" + param_escape(sender.value) + "&ext=SEARCH", true);
282 xmlhttp.onreadystatechange=viewfeed_callback;
283 xmlhttp.send(null);
40d13c28
AD
284
285}
286
76798ff3
AD
287function update_title() {
288 //document.title = "Tiny Tiny RSS (" + total_unread + " unread)";
289}
1cd17194 290
76798ff3 291function init() {
476cac42 292 updateFeedList(false, false);
ac53063a 293 setTimeout("timeout()", 1800*1000);
1cd17194 294}