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