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