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