]> git.wh0rd.org - tt-rss.git/blob - viewfeed.js
detect xmlhttp deadlocks in view()
[tt-rss.git] / viewfeed.js
1 var active_post_id = false;
2 var _catchup_callback_func = false;
3 var last_article_view = false;
4
5 function catchup_callback() {
6 if (xmlhttp_rpc.readyState == 4) {
7 try {
8 debug("catchup_callback");
9 if (_catchup_callback_func) {
10 setTimeout(_catchup_callback_func, 100);
11 }
12 all_counters_callback();
13 } catch (e) {
14 exception_error("catchup_callback", e);
15 }
16 }
17 }
18
19 function headlines_callback() {
20 if (xmlhttp.readyState == 4) {
21 debug("headlines_callback");
22 var f = document.getElementById("headlines-frame");
23 try {
24 f.scrollTop = 0;
25 } catch (e) { };
26 f.innerHTML = xmlhttp.responseText;
27 update_all_counters();
28 if (typeof correctPNG != 'undefined') {
29 correctPNG();
30 }
31 notify("");
32 }
33 }
34
35 function article_callback() {
36 if (xmlhttp.readyState == 4) {
37 debug("article_callback");
38 var f = document.getElementById("content-frame");
39 try {
40 f.scrollTop = 0;
41 } catch (e) { };
42 f.innerHTML = xmlhttp.responseText;
43
44 var date = new Date();
45 last_article_view = date.getTime() / 1000;
46
47 if (typeof correctPNG != 'undefined') {
48 correctPNG();
49 }
50 update_all_counters();
51 }
52 }
53
54 function view(id, feed_id) {
55
56 try {
57 debug("loading article: " + id + "/" + feed_id);
58
59 enableHotkeys();
60
61 active_post_id = id;
62 //setActiveFeedId(feed_id);
63
64 var query = "backend.php?op=view&id=" + param_escape(id) +
65 "&feed=" + param_escape(feed_id);
66
67 var date = new Date();
68
69 if (!xmlhttp_ready(xmlhttp) && last_article_view < date.getTime() / 1000 - 15) {
70 debug("<b>xmlhttp seems to be stuck at view, aborting</b>");
71 xmlhttp.abort();
72 }
73
74 if (xmlhttp_ready(xmlhttp)) {
75
76 cleanSelected("headlinesList");
77
78 var crow = document.getElementById("RROW-" + active_post_id);
79 crow.className = crow.className.replace("Unread", "");
80
81 var upd_img_pic = document.getElementById("FUPDPIC-" + active_post_id);
82
83 if (upd_img_pic) {
84 upd_img_pic.src = "images/blank_icon.gif";
85 }
86
87 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
88 markHeadline(active_post_id);
89
90 xmlhttp.open("GET", query, true);
91 xmlhttp.onreadystatechange=article_callback;
92 xmlhttp.send(null);
93 } else {
94 debug("xmlhttp busy (@view)");
95 printLockingError();
96 }
97
98 } catch (e) {
99 exception_error("view", e);
100 }
101 }
102
103 function toggleMark(id) {
104
105 if (!xmlhttp_ready(xmlhttp_rpc)) {
106 printLockingError();
107 return;
108 }
109
110 var query = "backend.php?op=rpc&id=" + id + "&subop=mark";
111
112 var mark_img = document.getElementById("FMARKPIC-" + id);
113 var vfeedu = document.getElementById("FEEDU--1");
114 var crow = document.getElementById("RROW-" + id);
115
116 if (mark_img.alt != "Reset mark") {
117 mark_img.src = "images/mark_set.png";
118 mark_img.alt = "Reset mark";
119 query = query + "&mark=1";
120
121 if (vfeedu && crow.className.match("Unread")) {
122 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
123 }
124
125 } else {
126 mark_img.src = "images/mark_unset.png";
127 mark_img.alt = "Set mark";
128 query = query + "&mark=0";
129
130 if (vfeedu && crow.className.match("Unread")) {
131 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
132 }
133
134 }
135
136 var vfeedctr = document.getElementById("FEEDCTR--1");
137 var vfeedr = document.getElementById("FEEDR--1");
138
139 if (vfeedu && vfeedctr) {
140 if ((+vfeedu.innerHTML) > 0) {
141 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
142 vfeedr.className = vfeedr.className + "Unread";
143 vfeedctr.className = "odd";
144 }
145 } else {
146 vfeedctr.className = "invisible";
147 vfeedr.className = vfeedr.className.replace("Unread", "");
148 }
149 }
150
151 debug("toggle starred for aid " + id);
152
153 new Ajax.Request(query);
154
155 }
156
157 function moveToPost(mode) {
158
159 // check for combined mode
160 if (!document.getElementById("headlinesList"))
161 return;
162
163 var rows = getVisibleHeadlineIds();
164
165 var prev_id;
166 var next_id;
167
168 if (active_post_id == false) {
169 next_id = getFirstVisibleHeadlineId();
170 prev_id = getLastVisibleHeadlineId();
171 } else {
172 for (var i = 0; i < rows.length; i++) {
173 if (rows[i] == active_post_id) {
174 prev_id = rows[i-1];
175 next_id = rows[i+1];
176 }
177 }
178 }
179
180 if (mode == "next") {
181 if (next_id != undefined) {
182 view(next_id, getActiveFeedId());
183 }
184 }
185
186 if (mode == "prev") {
187 if ( prev_id != undefined) {
188 view(prev_id, getActiveFeedId());
189 }
190 }
191 }
192
193 function toggleUnread(id, cmode) {
194 try {
195 if (!xmlhttp_ready(xmlhttp_rpc)) {
196 printLockingError();
197 return;
198 }
199
200 var row = document.getElementById("RROW-" + id);
201 if (row) {
202 var nc = row.className;
203 nc = nc.replace("Unread", "");
204 nc = nc.replace("Selected", "");
205
206 if (row.className.match("Unread")) {
207 row.className = nc;
208 } else {
209 row.className = nc + "Unread";
210 }
211
212 if (!cmode) cmode = 2;
213
214 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
215 param_escape(id) + "&cmode=" + param_escape(cmode);
216
217 xmlhttp_rpc.open("GET", query, true);
218 xmlhttp_rpc.onreadystatechange=all_counters_callback;
219 xmlhttp_rpc.send(null);
220
221 }
222
223
224 } catch (e) {
225 exception_error("toggleUnread", e);
226 }
227 }
228
229 function selectionToggleUnread(cdm_mode, set_state, callback_func) {
230 try {
231 if (!xmlhttp_ready(xmlhttp_rpc)) {
232 printLockingError();
233 return;
234 }
235
236 var rows;
237
238 if (cdm_mode) {
239 rows = cdmGetSelectedArticles();
240 } else {
241 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
242 }
243
244 for (i = 0; i < rows.length; i++) {
245 var row = document.getElementById("RROW-" + rows[i]);
246 if (row) {
247 var nc = row.className;
248 nc = nc.replace("Unread", "");
249 nc = nc.replace("Selected", "");
250
251 if (row.className.match("Unread")) {
252 row.className = nc + "Selected";
253 } else {
254 row.className = nc + "UnreadSelected";
255 }
256 }
257 }
258
259 if (rows.length > 0) {
260
261 var cmode = "";
262
263 if (set_state == undefined) {
264 cmode = "2";
265 } else if (set_state == true) {
266 cmode = "1";
267 } else if (set_state == false) {
268 cmode = "0";
269 }
270
271 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
272 param_escape(rows.toString()) + "&cmode=" + cmode;
273
274 _catchup_callback_func = callback_func;
275
276 xmlhttp_rpc.open("GET", query, true);
277 xmlhttp_rpc.onreadystatechange=catchup_callback;
278 xmlhttp_rpc.send(null);
279
280 }
281
282 } catch (e) {
283 exception_error("selectionToggleUnread", e);
284 }
285 }
286
287 function selectionToggleMarked(cdm_mode) {
288 try {
289 if (!xmlhttp_ready(xmlhttp_rpc)) {
290 printLockingError();
291 return;
292 }
293
294 var rows;
295
296 if (cdm_mode) {
297 rows = cdmGetSelectedArticles();
298 } else {
299 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
300 }
301
302 for (i = 0; i < rows.length; i++) {
303 var row = document.getElementById("RROW-" + rows[i]);
304 var mark_img = document.getElementById("FMARKPIC-" + rows[i]);
305
306 if (row && mark_img) {
307
308 if (mark_img.alt == "Set mark") {
309 mark_img.src = "images/mark_set.png";
310 mark_img.alt = "Reset mark";
311 mark_img.setAttribute('onclick',
312 'javascript:toggleMark('+rows[i]+', false)');
313
314 } else {
315 mark_img.src = "images/mark_unset.png";
316 mark_img.alt = "Set mark";
317 mark_img.setAttribute('onclick',
318 'javascript:toggleMark('+rows[i]+', true)');
319 }
320 }
321 }
322
323 if (rows.length > 0) {
324
325 var query = "backend.php?op=rpc&subop=markSelected&ids=" +
326 param_escape(rows.toString()) + "&cmode=2";
327
328 xmlhttp_rpc.open("GET", query, true);
329 xmlhttp_rpc.onreadystatechange=all_counters_callback;
330 xmlhttp_rpc.send(null);
331
332 }
333
334 } catch (e) {
335 exception_error("selectionToggleMarked", e);
336 }
337 }
338
339 function cdmGetSelectedArticles() {
340 var sel_articles = new Array();
341 var container = document.getElementById("headlinesInnerContainer");
342
343 for (i = 0; i < container.childNodes.length; i++) {
344 var child = container.childNodes[i];
345
346 if (child.id.match("RROW-") && child.className.match("Selected")) {
347 var c_id = child.id.replace("RROW-", "");
348 sel_articles.push(c_id);
349 }
350 }
351
352 return sel_articles;
353 }
354
355 // mode = all,none,unread
356 function cdmSelectArticles(mode) {
357 var container = document.getElementById("headlinesInnerContainer");
358
359 for (i = 0; i < container.childNodes.length; i++) {
360 var child = container.childNodes[i];
361
362 if (child.id.match("RROW-")) {
363 var aid = child.id.replace("RROW-", "");
364
365 var cb = document.getElementById("RCHK-" + aid);
366
367 if (mode == "all") {
368 if (!child.className.match("Selected")) {
369 child.className = child.className + "Selected";
370 cb.checked = true;
371 }
372 } else if (mode == "unread") {
373 if (child.className.match("Unread") && !child.className.match("Selected")) {
374 child.className = child.className + "Selected";
375 cb.checked = true;
376 }
377 } else {
378 child.className = child.className.replace("Selected", "");
379 cb.checked = false;
380 }
381 }
382 }
383 }
384
385 function catchupPage() {
386
387 if (document.getElementById("headlinesList")) {
388 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
389 selectionToggleUnread(false, false, 'viewCurrentFeed()');
390 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
391 } else {
392 cdmSelectArticles('all');
393 selectionToggleUnread(true, false, 'viewCurrentFeed()')
394 cdmSelectArticles('none');
395 }
396 }
397
398 function labelFromSearch(search, search_mode, match_on, feed_id, is_cat) {
399
400 if (!xmlhttp_ready(xmlhttp_rpc)) {
401 printLockingError();
402 }
403
404 var title = prompt("Please enter label title:", "");
405
406 if (title) {
407
408 var query = "backend.php?op=labelFromSearch&search=" + param_escape(search) +
409 "&smode=" + param_escape(search_mode) + "&match=" + param_escape(match_on) +
410 "&feed=" + param_escape(feed_id) + "&is_cat=" + param_escape(is_cat) +
411 "&title=" + param_escape(title);
412
413 debug("LFS: " + query);
414
415 xmlhttp_rpc.open("GET", query, true);
416 xmlhttp_rpc.onreadystatechange=dlg_frefresh_callback;
417 xmlhttp_rpc.send(null);
418 }
419
420 }
421
422