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