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