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