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