]> git.wh0rd.org - tt-rss.git/blob - viewfeed.js
tweak category counter display, new styles: .catCtrNoUnread, .catCtrHasUnread
[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, 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
107 function 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
161 function 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 (active_post_id == false) {
173 next_id = getFirstVisibleHeadlineId();
174 prev_id = getLastVisibleHeadlineId();
175 } else {
176 for (var i = 0; i < rows.length; i++) {
177 if (rows[i] == active_post_id) {
178 prev_id = rows[i-1];
179 next_id = rows[i+1];
180 }
181 }
182 }
183
184 if (mode == "next") {
185 if (next_id != undefined) {
186 view(next_id, getActiveFeedId());
187 }
188 }
189
190 if (mode == "prev") {
191 if ( prev_id != undefined) {
192 view(prev_id, getActiveFeedId());
193 }
194 }
195 }
196
197 function toggleUnread(id, cmode) {
198 try {
199 if (!xmlhttp_ready(xmlhttp_rpc)) {
200 printLockingError();
201 return;
202 }
203
204 var row = document.getElementById("RROW-" + id);
205 if (row) {
206 var nc = row.className;
207 nc = nc.replace("Unread", "");
208 nc = nc.replace("Selected", "");
209
210 if (row.className.match("Unread")) {
211 row.className = nc;
212 } else {
213 row.className = nc + "Unread";
214 }
215
216 if (!cmode) cmode = 2;
217
218 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
219 param_escape(id) + "&cmode=" + param_escape(cmode);
220
221 xmlhttp_rpc.open("GET", query, true);
222 xmlhttp_rpc.onreadystatechange=all_counters_callback;
223 xmlhttp_rpc.send(null);
224
225 }
226
227
228 } catch (e) {
229 exception_error("toggleUnread", e);
230 }
231 }
232
233 function selectionToggleUnread(cdm_mode, set_state, callback_func) {
234 try {
235 if (!xmlhttp_ready(xmlhttp_rpc)) {
236 printLockingError();
237 return;
238 }
239
240 var rows;
241
242 if (cdm_mode) {
243 rows = cdmGetSelectedArticles();
244 } else {
245 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
246 }
247
248 for (i = 0; i < rows.length; i++) {
249 var row = document.getElementById("RROW-" + rows[i]);
250 if (row) {
251 var nc = row.className;
252 nc = nc.replace("Unread", "");
253 nc = nc.replace("Selected", "");
254
255 if (row.className.match("Unread")) {
256 row.className = nc + "Selected";
257 } else {
258 row.className = nc + "UnreadSelected";
259 }
260 }
261 }
262
263 if (rows.length > 0) {
264
265 var cmode = "";
266
267 if (set_state == undefined) {
268 cmode = "2";
269 } else if (set_state == true) {
270 cmode = "1";
271 } else if (set_state == false) {
272 cmode = "0";
273 }
274
275 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
276 param_escape(rows.toString()) + "&cmode=" + cmode;
277
278 _catchup_callback_func = callback_func;
279
280 xmlhttp_rpc.open("GET", query, true);
281 xmlhttp_rpc.onreadystatechange=catchup_callback;
282 xmlhttp_rpc.send(null);
283
284 }
285
286 } catch (e) {
287 exception_error("selectionToggleUnread", e);
288 }
289 }
290
291 function selectionToggleMarked(cdm_mode) {
292 try {
293 if (!xmlhttp_ready(xmlhttp_rpc)) {
294 printLockingError();
295 return;
296 }
297
298 var rows;
299
300 if (cdm_mode) {
301 rows = cdmGetSelectedArticles();
302 } else {
303 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
304 }
305
306 for (i = 0; i < rows.length; i++) {
307 var row = document.getElementById("RROW-" + rows[i]);
308 var mark_img = document.getElementById("FMARKPIC-" + rows[i]);
309
310 if (row && mark_img) {
311
312 if (mark_img.alt == "Set mark") {
313 mark_img.src = "images/mark_set.png";
314 mark_img.alt = "Reset mark";
315 mark_img.setAttribute('onclick',
316 'javascript:toggleMark('+rows[i]+', false)');
317
318 } else {
319 mark_img.src = "images/mark_unset.png";
320 mark_img.alt = "Set mark";
321 mark_img.setAttribute('onclick',
322 'javascript:toggleMark('+rows[i]+', true)');
323 }
324 }
325 }
326
327 if (rows.length > 0) {
328
329 var query = "backend.php?op=rpc&subop=markSelected&ids=" +
330 param_escape(rows.toString()) + "&cmode=2";
331
332 xmlhttp_rpc.open("GET", query, true);
333 xmlhttp_rpc.onreadystatechange=all_counters_callback;
334 xmlhttp_rpc.send(null);
335
336 }
337
338 } catch (e) {
339 exception_error("selectionToggleMarked", e);
340 }
341 }
342
343 function cdmGetSelectedArticles() {
344 var sel_articles = new Array();
345 var container = document.getElementById("headlinesInnerContainer");
346
347 for (i = 0; i < container.childNodes.length; i++) {
348 var child = container.childNodes[i];
349
350 if (child.id.match("RROW-") && child.className.match("Selected")) {
351 var c_id = child.id.replace("RROW-", "");
352 sel_articles.push(c_id);
353 }
354 }
355
356 return sel_articles;
357 }
358
359 // mode = all,none,unread
360 function cdmSelectArticles(mode) {
361 var container = document.getElementById("headlinesInnerContainer");
362
363 for (i = 0; i < container.childNodes.length; i++) {
364 var child = container.childNodes[i];
365
366 if (child.id.match("RROW-")) {
367 var aid = child.id.replace("RROW-", "");
368
369 var cb = document.getElementById("RCHK-" + aid);
370
371 if (mode == "all") {
372 if (!child.className.match("Selected")) {
373 child.className = child.className + "Selected";
374 cb.checked = true;
375 }
376 } else if (mode == "unread") {
377 if (child.className.match("Unread") && !child.className.match("Selected")) {
378 child.className = child.className + "Selected";
379 cb.checked = true;
380 }
381 } else {
382 child.className = child.className.replace("Selected", "");
383 cb.checked = false;
384 }
385 }
386 }
387 }
388
389 function catchupPage() {
390
391 if (document.getElementById("headlinesList")) {
392 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
393 selectionToggleUnread(false, false, 'viewCurrentFeed()');
394 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
395 } else {
396 cdmSelectArticles('all');
397 selectionToggleUnread(true, false, 'viewCurrentFeed()')
398 cdmSelectArticles('none');
399 }
400 }
401
402 function labelFromSearch(search, search_mode, match_on, feed_id, is_cat) {
403
404 if (!xmlhttp_ready(xmlhttp_rpc)) {
405 printLockingError();
406 }
407
408 var title = prompt("Please enter label title:", "");
409
410 if (title) {
411
412 var query = "backend.php?op=labelFromSearch&search=" + param_escape(search) +
413 "&smode=" + param_escape(search_mode) + "&match=" + param_escape(match_on) +
414 "&feed=" + param_escape(feed_id) + "&is_cat=" + param_escape(is_cat) +
415 "&title=" + param_escape(title);
416
417 debug("LFS: " + query);
418
419 xmlhttp_rpc.open("GET", query, true);
420 xmlhttp_rpc.onreadystatechange=dlg_frefresh_callback;
421 xmlhttp_rpc.send(null);
422 }
423
424 }
425
426