]>
Commit | Line | Data |
---|---|---|
bb7cface | 1 | var active_post_id = false; |
4b6206fa | 2 | var last_article_view = false; |
0b126ac2 AD |
3 | var active_real_feed_id = false; |
4 | ||
13f08f75 | 5 | // FIXME: kludges, needs proper implementation |
0b126ac2 | 6 | var _reload_feedlist_after_view = false; |
e08443c1 | 7 | |
ba0978c8 AD |
8 | var _cdm_wd_timeout = false; |
9 | var _cdm_wd_vishist = new Array(); | |
10 | ||
e097e8be AD |
11 | var article_cache = new Array(); |
12 | ||
081e527d | 13 | var vgroup_last_feed = false; |
314fcd2b | 14 | var post_under_pointer = false; |
081e527d | 15 | |
022d9e9e AD |
16 | var last_requested_article = false; |
17 | ||
b39b57ac AD |
18 | var preload_id_batch = []; |
19 | var preload_timeout_id = false; | |
20 | ||
21 | var cache_added = []; | |
22 | ||
1341ea0d AD |
23 | function catchup_callback2(transport, callback) { |
24 | try { | |
84c7b824 | 25 | console.log("catchup_callback2 " + transport + ", " + callback); |
1341ea0d | 26 | notify(""); |
f8fb4498 | 27 | handle_rpc_reply(transport); |
1341ea0d AD |
28 | if (callback) { |
29 | setTimeout(callback, 10); | |
30 | } | |
31 | } catch (e) { | |
273d1e29 | 32 | exception_error("catchup_callback2", e, transport); |
1341ea0d AD |
33 | } |
34 | } | |
35 | ||
e19c1824 | 36 | function clean_feed_selections() { |
a49f5e05 | 37 | try { |
acac8448 | 38 | var feeds = $("feedList").getElementsByTagName("LI"); |
a49f5e05 | 39 | |
6c3b0198 AD |
40 | for (var i = 0; i < feeds.length; i++) { |
41 | if (feeds[i].id && feeds[i].id.match("FEEDR-")) { | |
42 | feeds[i].className = feeds[i].className.replace("Selected", ""); | |
43 | } | |
5ee9816c AD |
44 | if (feeds[i].id && feeds[i].id.match("FCAT-")) { |
45 | feeds[i].className = feeds[i].className.replace("Selected", ""); | |
46 | } | |
6c3b0198 | 47 | } |
e19c1824 AD |
48 | } catch (e) { |
49 | exception_error("clean_feed_selections", e); | |
50 | } | |
51 | } | |
52 | ||
3d72bbdb | 53 | function headlines_callback2(transport, feed_cur_page) { |
e19c1824 AD |
54 | try { |
55 | ||
f8fb4498 | 56 | if (!handle_rpc_reply(transport)) return; |
9ca945a6 | 57 | |
730dbf19 AD |
58 | loading_set_progress(100); |
59 | ||
84c7b824 | 60 | console.log("headlines_callback2 [page=" + feed_cur_page + "]"); |
e19c1824 | 61 | |
2184738a AD |
62 | if (!transport_error_check(transport)) return; |
63 | ||
e19c1824 | 64 | clean_feed_selections(); |
3d72bbdb AD |
65 | |
66 | var is_cat = false; | |
67 | var feed_id = false; | |
ac541432 | 68 | |
3d72bbdb AD |
69 | if (transport.responseXML) { |
70 | var headlines = transport.responseXML.getElementsByTagName("headlines")[0]; | |
71 | if (headlines) { | |
72 | is_cat = headlines.getAttribute("is_cat"); | |
73 | feed_id = headlines.getAttribute("id"); | |
74 | setActiveFeedId(feed_id, is_cat); | |
75 | } | |
6c3b0198 | 76 | } |
f46192bb | 77 | |
6e35a862 AD |
78 | var ll = $('FLL-' + feed_id); |
79 | ||
6c3b0198 | 80 | if (!is_cat) { |
acac8448 | 81 | var feedr = $("FEEDR-" + feed_id); |
6c3b0198 AD |
82 | if (feedr && !feedr.className.match("Selected")) { |
83 | feedr.className = feedr.className + "Selected"; | |
84 | } | |
6e35a862 | 85 | if (feedr && ll) feedr.removeChild(ll); |
5ee9816c | 86 | } else { |
acac8448 | 87 | var feedr = $("FCAT-" + feed_id); |
5ee9816c AD |
88 | if (feedr && !feedr.className.match("Selected")) { |
89 | feedr.className = feedr.className + "Selected"; | |
90 | } | |
b7665618 AD |
91 | |
92 | var fcap = $("FCAP-" + feed_id); | |
93 | if (fcap && ll) fcap.removeChild(ll); | |
6e35a862 | 94 | |
6c3b0198 | 95 | } |
6e35a862 | 96 | |
105b61b7 AD |
97 | var img = $('FIMG-' + feed_id); |
98 | ||
99 | if (img && !is_cat) { | |
100 | img.src = img.alt; | |
105b61b7 AD |
101 | } |
102 | ||
acac8448 | 103 | var f = $("headlines-frame"); |
6c3b0198 AD |
104 | try { |
105 | if (feed_cur_page == 0) { | |
f8fb4498 | 106 | //console.log("resetting headlines scrollTop"); |
6c3b0198 | 107 | f.scrollTop = 0; |
a49f5e05 | 108 | } |
6c3b0198 AD |
109 | } catch (e) { }; |
110 | ||
111 | if (transport.responseXML) { | |
ffbe082d | 112 | var response = transport.responseXML; |
e19c1824 | 113 | |
ffbe082d AD |
114 | var headlines = response.getElementsByTagName("headlines")[0]; |
115 | var headlines_info = response.getElementsByTagName("headlines-info")[0]; | |
081e527d | 116 | |
ffbe082d AD |
117 | if (headlines_info) |
118 | headlines_info = JSON.parse(headlines_info.firstChild.nodeValue); | |
f8fb4498 AD |
119 | else { |
120 | console.error("didn't find headlines-info object in response"); | |
121 | return; | |
122 | } | |
e19c1824 | 123 | |
ffbe082d AD |
124 | var headlines_count = headlines_info.count; |
125 | var headlines_unread = headlines_info.unread; | |
126 | var disable_cache = headlines_info.disable_cache; | |
127 | ||
128 | vgroup_last_feed = headlines_info.vgroup_last_feed; | |
081e527d | 129 | |
587bef10 AD |
130 | if (headlines_count == 0) { |
131 | _infscroll_disable = 1; | |
132 | } else { | |
133 | _infscroll_disable = 0; | |
134 | } | |
135 | ||
ffbe082d AD |
136 | var counters = response.getElementsByTagName("counters")[0]; |
137 | var articles = response.getElementsByTagName("article"); | |
138 | var runtime_info = response.getElementsByTagName("runtime-info"); | |
6c3b0198 AD |
139 | |
140 | if (feed_cur_page == 0) { | |
141 | if (headlines) { | |
142 | f.innerHTML = headlines.firstChild.nodeValue; | |
e19c1824 | 143 | |
dd5865d4 AD |
144 | var cache_prefix = ""; |
145 | ||
146 | if (is_cat) { | |
147 | cache_prefix = "C:"; | |
148 | } else { | |
149 | cache_prefix = "F:"; | |
150 | } | |
151 | ||
3d72bbdb | 152 | cache_invalidate(cache_prefix + feed_id); |
7e8832b3 | 153 | |
52d7e7da | 154 | if (!disable_cache) { |
3d72bbdb | 155 | cache_inject(cache_prefix + feed_id, |
52d7e7da AD |
156 | headlines.firstChild.nodeValue, headlines_unread); |
157 | } | |
e19c1824 | 158 | |
6c3b0198 | 159 | } else { |
f8fb4498 | 160 | console.warn("headlines_callback: returned no data"); |
6c3b0198 AD |
161 | f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>"; |
162 | ||
163 | } | |
164 | } else { | |
165 | if (headlines) { | |
166 | if (headlines_count > 0) { | |
f8fb4498 | 167 | console.warn("adding some more headlines..."); |
6c3b0198 | 168 | |
acac8448 | 169 | var c = $("headlinesList"); |
6c3b0198 AD |
170 | |
171 | if (!c) { | |
acac8448 | 172 | c = $("headlinesInnerContainer"); |
6c3b0198 | 173 | } |
c32cd48a AD |
174 | |
175 | var ids = getSelectedArticleIds2(); | |
6c3b0198 AD |
176 | |
177 | c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue; | |
c32cd48a | 178 | |
84c7b824 | 179 | console.log("restore selected ids: " + ids); |
c32cd48a AD |
180 | |
181 | for (var i = 0; i < ids.length; i++) { | |
182 | markHeadline(ids[i]); | |
183 | } | |
184 | ||
6c3b0198 | 185 | } else { |
84c7b824 | 186 | console.log("no new headlines received"); |
29dfb258 | 187 | } |
29dfb258 | 188 | } else { |
f8fb4498 | 189 | console.warn("headlines_callback: returned no data"); |
6c3b0198 AD |
190 | notify_error("Error while trying to load more headlines"); |
191 | } | |
730dbf19 | 192 | |
6c3b0198 AD |
193 | } |
194 | ||
195 | if (articles) { | |
196 | for (var i = 0; i < articles.length; i++) { | |
197 | var a_id = articles[i].getAttribute("id"); | |
f8fb4498 | 198 | //console.log("found id: " + a_id); |
6c3b0198 | 199 | cache_inject(a_id, articles[i].firstChild.nodeValue); |
ac541432 | 200 | } |
007a38d4 | 201 | } else { |
84c7b824 | 202 | console.log("no cached articles received"); |
961f4c73 | 203 | } |
d36f5607 AD |
204 | |
205 | if (counters) | |
206 | parse_counters(counters); | |
207 | else | |
208 | request_counters(); | |
f8fb4498 | 209 | |
6c3b0198 | 210 | if (runtime_info) { |
6c3b0198 | 211 | parse_runtime_info(runtime_info[0]); |
f8fb4498 | 212 | } |
6c3b0198 | 213 | |
3de0261a | 214 | } else { |
f8fb4498 | 215 | console.warn("headlines_callback: returned no XML object"); |
6c3b0198 | 216 | f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>"; |
3de0261a | 217 | } |
6c3b0198 | 218 | |
5225d420 | 219 | |
6c3b0198 AD |
220 | if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout); |
221 | ||
acac8448 | 222 | if (!$("headlinesList") && |
a969b30b | 223 | getActiveFeedId() != -3 && |
6c3b0198 | 224 | getInitParam("cdm_auto_catchup") == 1) { |
84c7b824 | 225 | console.log("starting CDM watchdog"); |
6c3b0198 AD |
226 | _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000); |
227 | _cdm_wd_vishist = new Array(); | |
ac7bcd71 | 228 | } else { |
84c7b824 | 229 | console.log("not in CDM mode or watchdog disabled"); |
ba0978c8 | 230 | } |
6c3b0198 | 231 | |
6c3b0198 | 232 | _feed_cur_page = feed_cur_page; |
82764a41 AD |
233 | _infscroll_request_sent = 0; |
234 | ||
6c3b0198 | 235 | notify(""); |
730dbf19 AD |
236 | |
237 | remove_splash(); | |
238 | ||
6c3b0198 | 239 | } catch (e) { |
273d1e29 | 240 | exception_error("headlines_callback2", e, transport); |
6b4163cb AD |
241 | } |
242 | } | |
243 | ||
e097e8be AD |
244 | function render_article(article) { |
245 | try { | |
acac8448 | 246 | var f = $("content-frame"); |
44cc6f20 AD |
247 | try { |
248 | f.scrollTop = 0; | |
249 | } catch (e) { }; | |
e097e8be | 250 | |
acac8448 | 251 | var fi = $("content-insert"); |
17042fc0 | 252 | |
e5ebee09 AD |
253 | try { |
254 | fi.scrollTop = 0; | |
255 | } catch (e) { }; | |
95f67d2e | 256 | |
17042fc0 | 257 | fi.innerHTML = article; |
95f67d2e | 258 | |
51682b23 | 259 | // article.evalScripts(); |
e097e8be AD |
260 | |
261 | } catch (e) { | |
262 | exception_error("render_article", e); | |
263 | } | |
264 | } | |
265 | ||
71d277de | 266 | function showArticleInHeadlines(id) { |
e097e8be | 267 | |
868d0ed2 | 268 | try { |
e097e8be | 269 | |
868d0ed2 | 270 | cleanSelected("headlinesList"); |
71d277de | 271 | |
acac8448 | 272 | var crow = $("RROW-" + id); |
76283a4c AD |
273 | |
274 | if (!crow) return; | |
275 | ||
868d0ed2 AD |
276 | var article_is_unread = crow.className.match("Unread"); |
277 | ||
278 | crow.className = crow.className.replace("Unread", ""); | |
fdcdf2de AD |
279 | |
280 | selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false); | |
fdcdf2de | 281 | |
acac8448 | 282 | var upd_img_pic = $("FUPDPIC-" + id); |
ebda016b | 283 | |
fdcdf2de | 284 | var cache_prefix = ""; |
ebda016b | 285 | |
fdcdf2de AD |
286 | if (activeFeedIsCat()) { |
287 | cache_prefix = "C:"; | |
288 | } else { | |
289 | cache_prefix = "F:"; | |
290 | } | |
11063ec6 AD |
291 | |
292 | var view_mode = false; | |
293 | ||
294 | try { | |
295 | view_mode = document.forms['main_toolbar_form'].view_mode; | |
296 | view_mode = view_mode[view_mode.selectedIndex].value; | |
297 | } catch (e) { | |
273d1e29 | 298 | // |
11063ec6 AD |
299 | } |
300 | ||
784ac51f AD |
301 | if (upd_img_pic && (upd_img_pic.src.match("updated.png") || |
302 | upd_img_pic.src.match("fresh_sign.png"))) { | |
303 | ||
fdcdf2de | 304 | upd_img_pic.src = "images/blank_icon.gif"; |
ebda016b AD |
305 | |
306 | cache_invalidate(cache_prefix + getActiveFeedId()); | |
ce411c4b AD |
307 | |
308 | cache_inject(cache_prefix + getActiveFeedId(), | |
acac8448 | 309 | $("headlines-frame").innerHTML, |
ce411c4b | 310 | get_feed_unread(getActiveFeedId())); |
fdcdf2de | 311 | |
11063ec6 | 312 | } else if (article_is_unread && view_mode == "all_articles") { |
fdcdf2de AD |
313 | |
314 | cache_invalidate(cache_prefix + getActiveFeedId()); | |
315 | ||
316 | cache_inject(cache_prefix + getActiveFeedId(), | |
acac8448 | 317 | $("headlines-frame").innerHTML, |
fdcdf2de AD |
318 | get_feed_unread(getActiveFeedId())-1); |
319 | ||
3de99e6b AD |
320 | } else if (article_is_unread) { |
321 | cache_invalidate(cache_prefix + getActiveFeedId()); | |
868d0ed2 | 322 | } |
e097e8be | 323 | |
4c009c78 AD |
324 | markHeadline(id); |
325 | ||
868d0ed2 AD |
326 | } catch (e) { |
327 | exception_error("showArticleInHeadlines", e); | |
328 | } | |
71d277de | 329 | } |
e097e8be | 330 | |
a491a7f1 | 331 | function article_callback2(transport, id) { |
71d277de | 332 | try { |
84c7b824 | 333 | console.log("article_callback2 " + id); |
e097e8be | 334 | |
f8fb4498 | 335 | if (!handle_rpc_reply(transport)) return; |
9ca945a6 | 336 | |
71d277de | 337 | if (transport.responseXML) { |
e097e8be | 338 | |
2184738a AD |
339 | if (!transport_error_check(transport)) return; |
340 | ||
b1039124 | 341 | /* var ll = $('LL-' + id); |
6e35a862 AD |
342 | var content = $('HLC-' + id); |
343 | ||
b1039124 | 344 | if (ll && content) content.removeChild(ll); */ |
6e35a862 | 345 | |
b1039124 AD |
346 | var upic = $('FUPDPIC-' + id); |
347 | ||
348 | if (upic) { | |
349 | upic.src = 'images/blank_icon.gif'; | |
350 | } | |
351 | ||
6e35a862 | 352 | if (id != last_requested_article) { |
84c7b824 | 353 | console.log("requested article id is out of sequence, aborting"); |
6e35a862 AD |
354 | return; |
355 | } | |
356 | ||
6e35a862 AD |
357 | active_post_id = id; |
358 | ||
f8fb4498 | 359 | //console.log("looking for articles to cache..."); |
71d277de AD |
360 | |
361 | var articles = transport.responseXML.getElementsByTagName("article"); | |
362 | ||
363 | for (var i = 0; i < articles.length; i++) { | |
364 | var a_id = articles[i].getAttribute("id"); | |
365 | ||
f8fb4498 | 366 | //console.log("found id: " + a_id); |
71d277de AD |
367 | |
368 | if (a_id == active_post_id) { | |
f8fb4498 | 369 | //console.log("active article, rendering..."); |
71d277de | 370 | render_article(articles[i].firstChild.nodeValue); |
e097e8be | 371 | } |
71d277de AD |
372 | |
373 | cache_inject(a_id, articles[i].firstChild.nodeValue); | |
e097e8be | 374 | } |
fbcabe1e | 375 | |
fbcabe1e AD |
376 | |
377 | showArticleInHeadlines(id); | |
378 | ||
2f71f07b AD |
379 | if (db) { |
380 | db.execute("UPDATE articles SET unread = 0 WHERE id = ?", [id]); | |
381 | } | |
382 | ||
fbcabe1e | 383 | var reply = transport.responseXML.firstChild.firstChild; |
71d277de AD |
384 | |
385 | } else { | |
f8fb4498 | 386 | console.warn("article_callback: returned no XML object"); |
acac8448 | 387 | //var f = $("content-frame"); |
17042fc0 | 388 | //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>"; |
e097e8be | 389 | } |
4b6206fa AD |
390 | |
391 | var date = new Date(); | |
392 | last_article_view = date.getTime() / 1000; | |
393 | ||
0b126ac2 AD |
394 | if (_reload_feedlist_after_view) { |
395 | setTimeout('updateFeedList(false, false)', 50); | |
396 | _reload_feedlist_after_view = false; | |
397 | } else { | |
f8fb4498 | 398 | request_counters(); |
0b126ac2 | 399 | } |
9ec58704 AD |
400 | |
401 | notify(""); | |
71d277de | 402 | } catch (e) { |
273d1e29 | 403 | exception_error("article_callback2", e, transport); |
6b4163cb AD |
404 | } |
405 | } | |
406 | ||
a491a7f1 | 407 | function view(id) { |
ee1f45f4 | 408 | try { |
84c7b824 | 409 | console.log("loading article: " + id); |
12e55b90 | 410 | |
a491a7f1 | 411 | if (offline_mode) return view_offline(id); |
45a6446d | 412 | |
e097e8be AD |
413 | var cached_article = cache_find(id); |
414 | ||
84c7b824 | 415 | console.log("cache check result: " + (cached_article != false)); |
ee1f45f4 | 416 | |
ee1f45f4 | 417 | enableHotkeys(); |
664306d3 AD |
418 | hideAuxDlg(); |
419 | ||
a491a7f1 | 420 | var query = "?op=view&id=" + param_escape(id); |
6b4163cb | 421 | |
71d277de | 422 | var neighbor_ids = getRelativePostIds(active_post_id); |
e097e8be | 423 | |
71d277de | 424 | /* only request uncached articles */ |
e097e8be | 425 | |
71d277de | 426 | var cids_to_request = Array(); |
5a94a953 | 427 | |
71d277de AD |
428 | for (var i = 0; i < neighbor_ids.length; i++) { |
429 | if (!cache_check(neighbor_ids[i])) { | |
430 | cids_to_request.push(neighbor_ids[i]); | |
5a94a953 | 431 | } |
71d277de | 432 | } |
5a94a953 | 433 | |
84c7b824 | 434 | console.log("additional ids: " + cids_to_request.toString()); |
b39b57ac | 435 | |
71d277de | 436 | /* additional info for piggyback counters */ |
e097e8be | 437 | |
71d277de AD |
438 | if (tagsAreDisplayed()) { |
439 | query = query + "&omode=lt"; | |
440 | } else { | |
441 | query = query + "&omode=flc"; | |
442 | } | |
e097e8be | 443 | |
71d277de | 444 | query = query + "&cids=" + cids_to_request.toString(); |
e097e8be | 445 | |
acac8448 | 446 | var crow = $("RROW-" + id); |
71d277de | 447 | var article_is_unread = crow.className.match("Unread"); |
e097e8be | 448 | |
3f70f90f AD |
449 | showArticleInHeadlines(id); |
450 | ||
71d277de | 451 | if (!cached_article) { |
e097e8be | 452 | |
b1039124 AD |
453 | var upic = $('FUPDPIC-' + id); |
454 | ||
455 | if (upic) { | |
883fee8d | 456 | upic.src = getInitParam("sign_progress"); |
6e35a862 | 457 | } |
e097e8be | 458 | |
71d277de | 459 | } else if (cached_article && article_is_unread) { |
addb5836 | 460 | |
71d277de | 461 | query = query + "&mode=prefetch"; |
addb5836 | 462 | |
71d277de | 463 | render_article(cached_article); |
addb5836 | 464 | |
71d277de | 465 | } else if (cached_article) { |
e097e8be | 466 | |
71d277de AD |
467 | query = query + "&mode=prefetch_old"; |
468 | render_article(cached_article); | |
997d9d7c | 469 | |
71d277de | 470 | } |
e097e8be | 471 | |
71d277de | 472 | cache_expire(); |
86173d9a | 473 | |
022d9e9e AD |
474 | last_requested_article = id; |
475 | ||
b4e75b2a AD |
476 | new Ajax.Request("backend.php", { |
477 | parameters: query, | |
71d277de | 478 | onComplete: function(transport) { |
a491a7f1 | 479 | article_callback2(transport, id); |
71d277de | 480 | } }); |
6b4163cb | 481 | |
a7764e51 AD |
482 | return false; |
483 | ||
ee1f45f4 AD |
484 | } catch (e) { |
485 | exception_error("view", e); | |
486 | } | |
f0601b87 AD |
487 | } |
488 | ||
67343d9f AD |
489 | function tMark(id) { |
490 | return toggleMark(id); | |
491 | } | |
492 | ||
e4f4b46f AD |
493 | function tPub(id) { |
494 | return togglePub(id); | |
495 | } | |
496 | ||
6b0f49f9 AD |
497 | function tMark_afh_off(effect) { |
498 | try { | |
499 | var elem = effect.effects[0].element; | |
500 | ||
f8fb4498 | 501 | //console.log("tMark_afh_off : " + elem.id); |
6b0f49f9 AD |
502 | |
503 | if (elem) { | |
f5e0338d AD |
504 | elem.src = elem.src.replace("mark_set", "mark_unset"); |
505 | elem.alt = __("Star article"); | |
6b0f49f9 AD |
506 | Element.show(elem); |
507 | } | |
508 | ||
509 | } catch (e) { | |
510 | exception_error("tMark_afh_off", e); | |
511 | } | |
512 | } | |
513 | ||
514 | function tPub_afh_off(effect) { | |
515 | try { | |
516 | var elem = effect.effects[0].element; | |
517 | ||
f8fb4498 | 518 | //console.log("tPub_afh_off : " + elem.id); |
6b0f49f9 AD |
519 | |
520 | if (elem) { | |
f5e0338d AD |
521 | elem.src = elem.src.replace("pub_set", "pub_unset"); |
522 | elem.alt = __("Publish article"); | |
6b0f49f9 AD |
523 | Element.show(elem); |
524 | } | |
525 | ||
526 | } catch (e) { | |
527 | exception_error("tPub_afh_off", e); | |
528 | } | |
529 | } | |
e4f4b46f | 530 | |
f5e0338d | 531 | function toggleMark(id, client_only, no_effects) { |
f0601b87 | 532 | |
b685ba25 | 533 | try { |
254e0e4b | 534 | |
b4e75b2a | 535 | var query = "?op=rpc&id=" + id + "&subop=mark"; |
b685ba25 AD |
536 | |
537 | query = query + "&afid=" + getActiveFeedId(); | |
538 | ||
539 | if (tagsAreDisplayed()) { | |
540 | query = query + "&omode=tl"; | |
541 | } else { | |
542 | query = query + "&omode=flc"; | |
7ba176d2 | 543 | } |
b685ba25 | 544 | |
acac8448 | 545 | var mark_img = $("FMPIC-" + id); |
56ff7564 AD |
546 | |
547 | if (!mark_img) return; | |
548 | ||
acac8448 AD |
549 | var vfeedu = $("FEEDU--1"); |
550 | var crow = $("RROW-" + id); | |
b685ba25 | 551 | |
f5e0338d AD |
552 | if (mark_img.src.match("mark_unset")) { |
553 | mark_img.src = mark_img.src.replace("mark_unset", "mark_set"); | |
554 | mark_img.alt = __("Unstar article"); | |
b685ba25 | 555 | query = query + "&mark=1"; |
ee8768db | 556 | |
2f71f07b AD |
557 | if (db) { |
558 | db.execute("UPDATE articles SET marked = 1 WHERE id = ?", [id]); | |
559 | } | |
560 | ||
b685ba25 | 561 | } else { |
f5e0338d | 562 | mark_img.alt = __("Please wait..."); |
b685ba25 AD |
563 | query = query + "&mark=0"; |
564 | ||
acac8448 | 565 | if ($("headlinesList") && !no_effects) { |
b685ba25 AD |
566 | Effect.Puff(mark_img, {duration : 0.25, afterFinish: tMark_afh_off}); |
567 | } else { | |
f5e0338d AD |
568 | mark_img.src = mark_img.src.replace("mark_set", "mark_unset"); |
569 | mark_img.alt = __("Star article"); | |
b685ba25 | 570 | } |
2f71f07b AD |
571 | |
572 | if (db) { | |
573 | db.execute("UPDATE articles SET marked = 0 WHERE id = ?", [id]); | |
574 | } | |
575 | ||
ace1a6da | 576 | } |
772bc83b | 577 | |
46b84d29 | 578 | if (!no_effects) update_local_feedlist_counters(); |
c8a9fe5b | 579 | |
f5e0338d | 580 | if (!client_only) { |
f8fb4498 | 581 | //console.log(query); |
36e05046 | 582 | |
b4e75b2a AD |
583 | new Ajax.Request("backend.php", { |
584 | parameters: query, | |
1341ea0d | 585 | onComplete: function(transport) { |
f8fb4498 | 586 | handle_rpc_reply(transport); |
1341ea0d AD |
587 | } }); |
588 | ||
f5e0338d | 589 | } |
f0601b87 | 590 | |
b685ba25 AD |
591 | } catch (e) { |
592 | exception_error("toggleMark", e); | |
593 | } | |
f0601b87 AD |
594 | } |
595 | ||
c7e51de1 | 596 | function togglePub(id, client_only, no_effects, note) { |
e4f4b46f | 597 | |
2bc2147f | 598 | try { |
e4f4b46f | 599 | |
b4e75b2a | 600 | var query = "?op=rpc&id=" + id + "&subop=publ"; |
2bc2147f AD |
601 | |
602 | query = query + "&afid=" + getActiveFeedId(); | |
c7e51de1 AD |
603 | |
604 | if (note != undefined) { | |
605 | query = query + "¬e=" + param_escape(note); | |
606 | } else { | |
607 | query = query + "¬e=undefined"; | |
608 | } | |
2bc2147f AD |
609 | |
610 | if (tagsAreDisplayed()) { | |
611 | query = query + "&omode=tl"; | |
612 | } else { | |
613 | query = query + "&omode=flc"; | |
e4f4b46f | 614 | } |
2bc2147f | 615 | |
acac8448 | 616 | var mark_img = $("FPPIC-" + id); |
56ff7564 AD |
617 | |
618 | if (!mark_img) return; | |
619 | ||
acac8448 AD |
620 | var vfeedu = $("FEEDU--2"); |
621 | var crow = $("RROW-" + id); | |
2bc2147f | 622 | |
c7e51de1 | 623 | if (mark_img.src.match("pub_unset") || note != undefined) { |
f5e0338d AD |
624 | mark_img.src = mark_img.src.replace("pub_unset", "pub_set"); |
625 | mark_img.alt = __("Unpublish article"); | |
2bc2147f | 626 | query = query + "&pub=1"; |
ee8768db | 627 | |
e4f4b46f | 628 | } else { |
f5e0338d | 629 | mark_img.alt = __("Please wait..."); |
2bc2147f AD |
630 | query = query + "&pub=0"; |
631 | ||
acac8448 | 632 | if ($("headlinesList") && !no_effects) { |
ace1a6da AD |
633 | Effect.Puff(mark_img, {duration : 0.25, afterFinish: tPub_afh_off}); |
634 | } else { | |
f5e0338d AD |
635 | mark_img.src = mark_img.src.replace("pub_set", "pub_unset"); |
636 | mark_img.alt = __("Publish article"); | |
ace1a6da | 637 | } |
e4f4b46f | 638 | } |
b685ba25 | 639 | |
f5e0338d | 640 | if (!client_only) { |
b4e75b2a AD |
641 | new Ajax.Request("backend.php", { |
642 | parameters: query, | |
1341ea0d | 643 | onComplete: function(transport) { |
f8fb4498 | 644 | handle_rpc_reply(transport); |
a5819bb3 AD |
645 | |
646 | var note = transport.responseXML.getElementsByTagName("note")[0]; | |
647 | ||
648 | if (note) { | |
649 | var note_id = note.getAttribute("id"); | |
650 | var note_size = note.getAttribute("size"); | |
651 | var note_content = note.firstChild.nodeValue; | |
652 | ||
653 | var container = $('POSTNOTE-' + note_id); | |
654 | ||
655 | cache_invalidate(note_id); | |
656 | ||
657 | if (container) { | |
658 | if (note_size == "0") { | |
659 | Element.hide(container); | |
660 | } else { | |
661 | container.innerHTML = note_content; | |
662 | Element.show(container); | |
663 | } | |
664 | } | |
665 | } | |
666 | ||
1341ea0d | 667 | } }); |
f5e0338d | 668 | } |
b685ba25 | 669 | |
2bc2147f | 670 | } catch (e) { |
2bc2147f AD |
671 | exception_error("togglePub", e); |
672 | } | |
e4f4b46f AD |
673 | } |
674 | ||
ac162cbe AD |
675 | function correctHeadlinesOffset(id) { |
676 | ||
677 | try { | |
678 | ||
acac8448 AD |
679 | var hlist = $("headlinesList"); |
680 | var container = $("headlinesInnerContainer"); | |
681 | var row = $("RROW-" + id); | |
ac162cbe AD |
682 | |
683 | var viewport = container.offsetHeight; | |
684 | ||
685 | var rel_offset_top = row.offsetTop - container.scrollTop; | |
686 | var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop; | |
687 | ||
84c7b824 AD |
688 | console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom); |
689 | console.log("Vport: " + viewport); | |
a5e46e0f | 690 | |
ac162cbe AD |
691 | if (rel_offset_top <= 0 || rel_offset_top > viewport) { |
692 | container.scrollTop = row.offsetTop; | |
693 | } else if (rel_offset_bottom > viewport) { | |
a5e46e0f AD |
694 | |
695 | /* doesn't properly work with Opera in some cases because | |
696 | Opera fucks up element scrolling */ | |
697 | ||
ac162cbe AD |
698 | container.scrollTop = row.offsetTop + row.offsetHeight - viewport; |
699 | } | |
700 | ||
701 | } catch (e) { | |
702 | exception_error("correctHeadlinesOffset", e); | |
703 | } | |
704 | ||
705 | } | |
706 | ||
bb7cface | 707 | function moveToPost(mode) { |
f0601b87 | 708 | |
b8e6acea AD |
709 | try { |
710 | ||
5ad9d132 AD |
711 | var rows; |
712 | ||
713 | if (isCdmMode()) { | |
714 | rows = cdmGetVisibleArticles(); | |
715 | } else { | |
716 | rows = getVisibleHeadlineIds(); | |
717 | } | |
b8e6acea | 718 | |
5ad9d132 AD |
719 | var prev_id = false; |
720 | var next_id = false; | |
b8e6acea | 721 | |
acac8448 | 722 | if (!$('RROW-' + active_post_id)) { |
5ad9d132 AD |
723 | active_post_id = false; |
724 | } | |
b8e6acea | 725 | |
5ad9d132 AD |
726 | if (active_post_id == false) { |
727 | next_id = getFirstVisibleHeadlineId(); | |
728 | prev_id = getLastVisibleHeadlineId(); | |
729 | } else { | |
730 | for (var i = 0; i < rows.length; i++) { | |
731 | if (rows[i] == active_post_id) { | |
732 | prev_id = rows[i-1]; | |
733 | next_id = rows[i+1]; | |
b8e6acea AD |
734 | } |
735 | } | |
5ad9d132 | 736 | } |
b8e6acea | 737 | |
5ad9d132 AD |
738 | if (mode == "next") { |
739 | if (next_id) { | |
740 | if (isCdmMode()) { | |
741 | ||
dad14b51 AD |
742 | cdmExpandArticle(next_id); |
743 | cdmScrollToArticleId(next_id); | |
5ad9d132 AD |
744 | |
745 | } else { | |
b8e6acea AD |
746 | correctHeadlinesOffset(next_id); |
747 | view(next_id, getActiveFeedId()); | |
748 | } | |
749 | } | |
5ad9d132 | 750 | } |
b8e6acea | 751 | |
5ad9d132 AD |
752 | if (mode == "prev") { |
753 | if (prev_id) { | |
754 | if (isCdmMode()) { | |
dad14b51 | 755 | cdmExpandArticle(prev_id); |
5ad9d132 | 756 | cdmScrollToArticleId(prev_id); |
5ad9d132 | 757 | } else { |
b8e6acea AD |
758 | correctHeadlinesOffset(prev_id); |
759 | view(prev_id, getActiveFeedId()); | |
760 | } | |
5ad9d132 AD |
761 | } |
762 | } | |
763 | ||
b8e6acea | 764 | } catch (e) { |
438f2ce9 | 765 | exception_error("moveToPost", e); |
bb7cface | 766 | } |
b8e6acea AD |
767 | } |
768 | ||
769 | function toggleSelected(id) { | |
770 | try { | |
771 | ||
acac8448 | 772 | var cb = $("RCHK-" + id); |
5ad9d132 | 773 | |
acac8448 | 774 | var row = $("RROW-" + id); |
b8e6acea AD |
775 | if (row) { |
776 | var nc = row.className; | |
777 | ||
778 | if (!nc.match("Selected")) { | |
779 | nc = nc + "Selected"; | |
5ad9d132 AD |
780 | if (cb) { |
781 | cb.checked = true; | |
782 | } | |
783 | ||
784 | // In CDM basically last selected article == active article | |
785 | if (isCdmMode()) active_post_id = id; | |
b8e6acea AD |
786 | } else { |
787 | nc = nc.replace("Selected", ""); | |
5ad9d132 AD |
788 | if (cb) { |
789 | cb.checked = false; | |
790 | } | |
791 | ||
b8e6acea | 792 | } |
bb7cface | 793 | |
b8e6acea | 794 | row.className = nc; |
bb7cface | 795 | } |
b8e6acea | 796 | } catch (e) { |
438f2ce9 | 797 | exception_error("toggleSelected", e); |
b8e6acea | 798 | } |
bb7cface AD |
799 | } |
800 | ||
0df009c3 | 801 | function toggleUnread_afh(effect) { |
b8e6acea AD |
802 | try { |
803 | ||
804 | var elem = effect.element; | |
0df009c3 | 805 | elem.style.backgroundColor = ""; |
b8e6acea | 806 | |
b8e6acea | 807 | } catch (e) { |
438f2ce9 | 808 | exception_error("toggleUnread_afh", e); |
b8e6acea | 809 | } |
0df009c3 | 810 | } |
b8e6acea AD |
811 | |
812 | function toggleUnread(id, cmode, effect) { | |
5f51022a | 813 | try { |
5f51022a | 814 | |
acac8448 | 815 | var row = $("RROW-" + id); |
5f51022a AD |
816 | if (row) { |
817 | var nc = row.className; | |
93f66472 | 818 | var is_selected = row.className.match("Selected"); |
5f51022a AD |
819 | nc = nc.replace("Unread", ""); |
820 | nc = nc.replace("Selected", ""); | |
821 | ||
b8e6acea AD |
822 | // since we are removing selection from the object, uncheck |
823 | // corresponding checkbox | |
824 | ||
acac8448 | 825 | var cb = $("RCHK-" + id); |
b8e6acea AD |
826 | if (cb) { |
827 | cb.checked = false; | |
828 | } | |
829 | ||
830 | // NOTE: I'm not sure that resetting selection here is a feature -fox | |
831 | ||
a70ab740 AD |
832 | if (cmode == undefined || cmode == 2) { |
833 | if (row.className.match("Unread")) { | |
834 | row.className = nc; | |
b8e6acea | 835 | |
0df009c3 | 836 | if (effect) { |
b8e6acea AD |
837 | new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5", |
838 | afterFinish: toggleUnread_afh, | |
839 | queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } ); | |
0df009c3 | 840 | } |
b8e6acea | 841 | |
a70ab740 AD |
842 | } else { |
843 | row.className = nc + "Unread"; | |
844 | } | |
1a003258 AD |
845 | |
846 | if (db) { | |
847 | db.execute("UPDATE articles SET unread = not unread "+ | |
848 | "WHERE id = ?", [id]); | |
849 | } | |
850 | ||
a70ab740 | 851 | } else if (cmode == 0) { |
5f51022a | 852 | row.className = nc; |
b8e6acea | 853 | |
54eb7d20 | 854 | if (effect) { |
b8e6acea | 855 | new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5", |
54eb7d20 | 856 | afterFinish: toggleUnread_afh, |
b8e6acea | 857 | queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } ); |
54eb7d20 | 858 | } |
1a003258 AD |
859 | |
860 | if (db) { | |
861 | db.execute("UPDATE articles SET unread = 0 "+ | |
862 | "WHERE id = ?", [id]); | |
863 | } | |
864 | ||
a70ab740 | 865 | } else if (cmode == 1) { |
5f51022a | 866 | row.className = nc + "Unread"; |
1a003258 AD |
867 | |
868 | if (db) { | |
869 | db.execute("UPDATE articles SET unread = 1 "+ | |
870 | "WHERE id = ?", [id]); | |
871 | } | |
872 | ||
5f51022a AD |
873 | } |
874 | ||
1a003258 AD |
875 | update_local_feedlist_counters(); |
876 | ||
93f66472 AD |
877 | // Disable unmarking as selected for the time being (16.05.08) -fox |
878 | if (is_selected) row.className = row.className + "Selected"; | |
879 | ||
a70ab740 | 880 | if (cmode == undefined) cmode = 2; |
5f51022a | 881 | |
b4e75b2a AD |
882 | var query = "?op=rpc&subop=catchupSelected" + |
883 | "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id); | |
5f51022a | 884 | |
1341ea0d | 885 | // notify_progress("Loading, please wait..."); |
9ec58704 | 886 | |
b4e75b2a AD |
887 | new Ajax.Request("backend.php", { |
888 | parameters: query, | |
1341ea0d | 889 | onComplete: function(transport) { |
f8fb4498 | 890 | handle_rpc_reply(transport); |
1341ea0d | 891 | } }); |
5f51022a AD |
892 | |
893 | } | |
894 | ||
5f51022a AD |
895 | } catch (e) { |
896 | exception_error("toggleUnread", e); | |
897 | } | |
898 | } | |
899 | ||
933ba4ee AD |
900 | function selectionRemoveLabel(id) { |
901 | try { | |
902 | ||
903 | var ids = getSelectedArticleIds2(); | |
904 | ||
905 | if (ids.length == 0) { | |
906 | alert(__("No articles are selected.")); | |
907 | return; | |
908 | } | |
909 | ||
37843d70 | 910 | // var ok = confirm(__("Remove selected articles from label?")); |
933ba4ee | 911 | |
37843d70 | 912 | // if (ok) { |
933ba4ee | 913 | |
b4e75b2a | 914 | var query = "?op=rpc&subop=removeFromLabel&ids=" + |
933ba4ee AD |
915 | param_escape(ids.toString()) + "&lid=" + param_escape(id); |
916 | ||
905ff52a AD |
917 | console.log(query); |
918 | ||
933ba4ee AD |
919 | // notify_progress("Loading, please wait..."); |
920 | ||
898e8562 AD |
921 | cache_invalidate("F:" + (-11 - id)); |
922 | ||
b4e75b2a AD |
923 | new Ajax.Request("backend.php", { |
924 | parameters: query, | |
933ba4ee | 925 | onComplete: function(transport) { |
1c9c6025 | 926 | show_labels_in_headlines(transport); |
f8fb4498 | 927 | handle_rpc_reply(transport); |
933ba4ee AD |
928 | } }); |
929 | ||
37843d70 | 930 | // } |
933ba4ee AD |
931 | |
932 | } catch (e) { | |
933 | exception_error("selectionAssignLabel", e); | |
934 | ||
935 | } | |
936 | } | |
937 | ||
b8a637f3 AD |
938 | function selectionAssignLabel(id) { |
939 | try { | |
940 | ||
941 | var ids = getSelectedArticleIds2(); | |
942 | ||
943 | if (ids.length == 0) { | |
944 | alert(__("No articles are selected.")); | |
945 | return; | |
946 | } | |
947 | ||
37843d70 | 948 | // var ok = confirm(__("Assign selected articles to label?")); |
b8a637f3 | 949 | |
37843d70 | 950 | // if (ok) { |
b8a637f3 | 951 | |
898e8562 AD |
952 | cache_invalidate("F:" + (-11 - id)); |
953 | ||
b4e75b2a | 954 | var query = "?op=rpc&subop=assignToLabel&ids=" + |
b8a637f3 AD |
955 | param_escape(ids.toString()) + "&lid=" + param_escape(id); |
956 | ||
905ff52a AD |
957 | console.log(query); |
958 | ||
b8a637f3 AD |
959 | // notify_progress("Loading, please wait..."); |
960 | ||
b4e75b2a AD |
961 | new Ajax.Request("backend.php", { |
962 | parameters: query, | |
b8a637f3 | 963 | onComplete: function(transport) { |
f9247195 | 964 | show_labels_in_headlines(transport); |
f8fb4498 | 965 | handle_rpc_reply(transport); |
b8a637f3 AD |
966 | } }); |
967 | ||
37843d70 | 968 | // } |
b8a637f3 AD |
969 | |
970 | } catch (e) { | |
971 | exception_error("selectionAssignLabel", e); | |
972 | ||
973 | } | |
974 | } | |
975 | ||
50eefedb | 976 | function selectionToggleUnread(set_state, callback_func, no_error) { |
1572afe5 | 977 | try { |
b83d72b1 | 978 | var rows = getSelectedArticleIds2(); |
1572afe5 | 979 | |
2228d0e4 | 980 | if (rows.length == 0 && !no_error) { |
9cc600d1 AD |
981 | alert(__("No articles are selected.")); |
982 | return; | |
983 | } | |
984 | ||
1572afe5 | 985 | for (i = 0; i < rows.length; i++) { |
acac8448 | 986 | var row = $("RROW-" + rows[i]); |
f1f2db64 AD |
987 | if (row) { |
988 | var nc = row.className; | |
989 | nc = nc.replace("Unread", ""); | |
990 | nc = nc.replace("Selected", ""); | |
991 | ||
a5ae125a AD |
992 | if (set_state == undefined) { |
993 | if (row.className.match("Unread")) { | |
994 | row.className = nc + "Selected"; | |
995 | } else { | |
996 | row.className = nc + "UnreadSelected"; | |
997 | } | |
46b84d29 AD |
998 | if (db) { |
999 | db.execute("UPDATE articles SET unread = NOT unread WHERE id = ?", | |
1000 | [rows[i]]); | |
1001 | } | |
a5ae125a AD |
1002 | } |
1003 | ||
1004 | if (set_state == false) { | |
f1f2db64 | 1005 | row.className = nc + "Selected"; |
46b84d29 AD |
1006 | if (db) { |
1007 | db.execute("UPDATE articles SET unread = 0 WHERE id = ?", | |
1008 | [rows[i]]); | |
1009 | } | |
a5ae125a AD |
1010 | } |
1011 | ||
1012 | if (set_state == true) { | |
f1f2db64 | 1013 | row.className = nc + "UnreadSelected"; |
46b84d29 AD |
1014 | if (db) { |
1015 | db.execute("UPDATE articles SET unread = 1 WHERE id = ?", | |
1016 | [rows[i]]); | |
1017 | } | |
f1f2db64 AD |
1018 | } |
1019 | } | |
1572afe5 AD |
1020 | } |
1021 | ||
1022 | if (rows.length > 0) { | |
1023 | ||
46b84d29 AD |
1024 | update_local_feedlist_counters(); |
1025 | ||
b47b5af7 AD |
1026 | var cmode = ""; |
1027 | ||
1028 | if (set_state == undefined) { | |
1029 | cmode = "2"; | |
1030 | } else if (set_state == true) { | |
1031 | cmode = "1"; | |
1032 | } else if (set_state == false) { | |
1033 | cmode = "0"; | |
1034 | } | |
1035 | ||
b4e75b2a AD |
1036 | var query = "?op=rpc&subop=catchupSelected" + |
1037 | "&cmode=" + cmode + "&ids=" + param_escape(rows.toString()); | |
1572afe5 | 1038 | |
9ec58704 AD |
1039 | notify_progress("Loading, please wait..."); |
1040 | ||
b4e75b2a AD |
1041 | new Ajax.Request("backend.php", { |
1042 | parameters: query, | |
1341ea0d AD |
1043 | onComplete: function(transport) { |
1044 | catchup_callback2(transport, callback_func); | |
1045 | } }); | |
1572afe5 AD |
1046 | |
1047 | } | |
1048 | ||
1049 | } catch (e) { | |
83f043bb | 1050 | exception_error("selectionToggleUnread", e); |
1572afe5 AD |
1051 | } |
1052 | } | |
1053 | ||
50eefedb | 1054 | function selectionToggleMarked() { |
1572afe5 | 1055 | try { |
1572afe5 | 1056 | |
b83d72b1 | 1057 | var rows = getSelectedArticleIds2(); |
386cbf27 | 1058 | |
9cc600d1 AD |
1059 | if (rows.length == 0) { |
1060 | alert(__("No articles are selected.")); | |
1061 | return; | |
1062 | } | |
1063 | ||
1572afe5 | 1064 | for (i = 0; i < rows.length; i++) { |
f5e0338d | 1065 | toggleMark(rows[i], true, true); |
1572afe5 AD |
1066 | } |
1067 | ||
46b84d29 AD |
1068 | update_local_feedlist_counters(); |
1069 | ||
1572afe5 AD |
1070 | if (rows.length > 0) { |
1071 | ||
b4e75b2a | 1072 | var query = "?op=rpc&subop=markSelected&ids=" + |
1572afe5 AD |
1073 | param_escape(rows.toString()) + "&cmode=2"; |
1074 | ||
2bc2147f AD |
1075 | query = query + "&afid=" + getActiveFeedId(); |
1076 | ||
1341ea0d | 1077 | query = query + "&omode=lc"; |
2bc2147f | 1078 | |
b4e75b2a AD |
1079 | new Ajax.Request("backend.php", { |
1080 | parameters: query, | |
1341ea0d | 1081 | onComplete: function(transport) { |
f8fb4498 | 1082 | handle_rpc_reply(transport); |
1341ea0d | 1083 | } }); |
1572afe5 AD |
1084 | |
1085 | } | |
1086 | ||
1087 | } catch (e) { | |
83f043bb | 1088 | exception_error("selectionToggleMarked", e); |
1572afe5 AD |
1089 | } |
1090 | } | |
1091 | ||
50eefedb | 1092 | function selectionTogglePublished() { |
e4f4b46f | 1093 | try { |
e4f4b46f | 1094 | |
b83d72b1 | 1095 | var rows = getSelectedArticleIds2(); |
e4f4b46f AD |
1096 | |
1097 | if (rows.length == 0) { | |
1098 | alert(__("No articles are selected.")); | |
1099 | return; | |
1100 | } | |
1101 | ||
1102 | for (i = 0; i < rows.length; i++) { | |
f5e0338d | 1103 | togglePub(rows[i], true, true); |
e4f4b46f AD |
1104 | } |
1105 | ||
1106 | if (rows.length > 0) { | |
1107 | ||
b4e75b2a | 1108 | var query = "?op=rpc&subop=publishSelected&ids=" + |
e4f4b46f AD |
1109 | param_escape(rows.toString()) + "&cmode=2"; |
1110 | ||
2bc2147f AD |
1111 | query = query + "&afid=" + getActiveFeedId(); |
1112 | ||
1341ea0d | 1113 | query = query + "&omode=lc"; |
2bc2147f | 1114 | |
b4e75b2a AD |
1115 | new Ajax.Request("backend.php", { |
1116 | parameters: query, | |
1341ea0d | 1117 | onComplete: function(transport) { |
f8fb4498 | 1118 | handle_rpc_reply(transport); |
1341ea0d | 1119 | } }); |
e4f4b46f AD |
1120 | |
1121 | } | |
1122 | ||
1123 | } catch (e) { | |
1124 | exception_error("selectionToggleMarked", e); | |
1125 | } | |
1126 | } | |
1127 | ||
386cbf27 AD |
1128 | function cdmGetSelectedArticles() { |
1129 | var sel_articles = new Array(); | |
acac8448 | 1130 | var container = $("headlinesInnerContainer"); |
386cbf27 AD |
1131 | |
1132 | for (i = 0; i < container.childNodes.length; i++) { | |
1133 | var child = container.childNodes[i]; | |
1134 | ||
02895941 | 1135 | if (child.id && child.id.match("RROW-") && child.className.match("Selected")) { |
386cbf27 AD |
1136 | var c_id = child.id.replace("RROW-", ""); |
1137 | sel_articles.push(c_id); | |
1138 | } | |
1139 | } | |
1140 | ||
1141 | return sel_articles; | |
1142 | } | |
1143 | ||
8be83f42 AD |
1144 | function cdmGetVisibleArticles() { |
1145 | var sel_articles = new Array(); | |
acac8448 | 1146 | var container = $("headlinesInnerContainer"); |
8be83f42 | 1147 | |
3a40e8a2 AD |
1148 | if (!container) return sel_articles; |
1149 | ||
8be83f42 AD |
1150 | for (i = 0; i < container.childNodes.length; i++) { |
1151 | var child = container.childNodes[i]; | |
1152 | ||
02895941 | 1153 | if (child.id && child.id.match("RROW-")) { |
8be83f42 AD |
1154 | var c_id = child.id.replace("RROW-", ""); |
1155 | sel_articles.push(c_id); | |
1156 | } | |
1157 | } | |
1158 | ||
1159 | return sel_articles; | |
1160 | } | |
1161 | ||
1162 | function cdmGetUnreadArticles() { | |
1163 | var sel_articles = new Array(); | |
acac8448 | 1164 | var container = $("headlinesInnerContainer"); |
8be83f42 AD |
1165 | |
1166 | for (i = 0; i < container.childNodes.length; i++) { | |
1167 | var child = container.childNodes[i]; | |
1168 | ||
02895941 | 1169 | if (child.id && child.id.match("RROW-") && child.className.match("Unread")) { |
8be83f42 AD |
1170 | var c_id = child.id.replace("RROW-", ""); |
1171 | sel_articles.push(c_id); | |
1172 | } | |
1173 | } | |
1174 | ||
1175 | return sel_articles; | |
1176 | } | |
1177 | ||
1178 | ||
386cbf27 AD |
1179 | // mode = all,none,unread |
1180 | function cdmSelectArticles(mode) { | |
acac8448 | 1181 | var container = $("headlinesInnerContainer"); |
386cbf27 AD |
1182 | |
1183 | for (i = 0; i < container.childNodes.length; i++) { | |
1184 | var child = container.childNodes[i]; | |
1185 | ||
02895941 | 1186 | if (child.id && child.id.match("RROW-")) { |
06d1a1c1 AD |
1187 | var aid = child.id.replace("RROW-", ""); |
1188 | ||
acac8448 | 1189 | var cb = $("RCHK-" + aid); |
06d1a1c1 | 1190 | |
386cbf27 AD |
1191 | if (mode == "all") { |
1192 | if (!child.className.match("Selected")) { | |
1193 | child.className = child.className + "Selected"; | |
06d1a1c1 | 1194 | cb.checked = true; |
386cbf27 AD |
1195 | } |
1196 | } else if (mode == "unread") { | |
1197 | if (child.className.match("Unread") && !child.className.match("Selected")) { | |
1198 | child.className = child.className + "Selected"; | |
06d1a1c1 | 1199 | cb.checked = true; |
386cbf27 AD |
1200 | } |
1201 | } else { | |
1202 | child.className = child.className.replace("Selected", ""); | |
06d1a1c1 | 1203 | cb.checked = false; |
386cbf27 AD |
1204 | } |
1205 | } | |
1206 | } | |
1207 | } | |
1208 | ||
98bea1b1 | 1209 | function catchupPage() { |
b47b5af7 | 1210 | |
3d72bbdb | 1211 | var fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); |
8a5b4579 | 1212 | |
a5ae125a AD |
1213 | var str = __("Mark all visible articles in %s as read?"); |
1214 | ||
1215 | str = str.replace("%s", fn); | |
8a5b4579 AD |
1216 | |
1217 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
1218 | return; | |
1219 | } | |
1220 | ||
acac8448 | 1221 | if ($("headlinesList")) { |
b47b5af7 | 1222 | selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true); |
50eefedb | 1223 | selectionToggleUnread(false, 'viewCurrentFeed()', true); |
b47b5af7 AD |
1224 | selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false); |
1225 | } else { | |
1226 | cdmSelectArticles('all'); | |
50eefedb | 1227 | selectionToggleUnread(false, 'viewCurrentFeed()', true) |
b47b5af7 AD |
1228 | cdmSelectArticles('none'); |
1229 | } | |
98bea1b1 AD |
1230 | } |
1231 | ||
e04c18a2 AD |
1232 | function deleteSelection() { |
1233 | ||
1234 | try { | |
e04c18a2 | 1235 | |
b83d72b1 AD |
1236 | var rows = getSelectedArticleIds2(); |
1237 | ||
e04c18a2 AD |
1238 | if (rows.length == 0) { |
1239 | alert(__("No articles are selected.")); | |
1240 | return; | |
1241 | } | |
1242 | ||
e04c18a2 AD |
1243 | var fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); |
1244 | var str; | |
1245 | var op; | |
1246 | ||
1247 | if (getActiveFeedId() != 0) { | |
1248 | str = __("Delete %d selected articles in %s?"); | |
1249 | } else { | |
1250 | str = __("Delete %d selected articles?"); | |
1251 | } | |
1252 | ||
1253 | str = str.replace("%d", rows.length); | |
1254 | str = str.replace("%s", fn); | |
1255 | ||
1256 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
1257 | return; | |
1258 | } | |
1259 | ||
b4e75b2a | 1260 | query = "?op=rpc&subop=delete&ids=" + param_escape(rows); |
e04c18a2 | 1261 | |
84c7b824 | 1262 | console.log(query); |
e04c18a2 | 1263 | |
b4e75b2a AD |
1264 | new Ajax.Request("backend.php", { |
1265 | parameters: query, | |
e04c18a2 AD |
1266 | onComplete: function(transport) { |
1267 | viewCurrentFeed(); | |
1268 | } }); | |
1269 | ||
1270 | } catch (e) { | |
a12eb9c3 | 1271 | exception_error("deleteSelection", e); |
e04c18a2 AD |
1272 | } |
1273 | } | |
1274 | ||
1275 | function archiveSelection() { | |
1276 | ||
1277 | try { | |
1278 | ||
b83d72b1 AD |
1279 | var rows = getSelectedArticleIds2(); |
1280 | ||
e04c18a2 AD |
1281 | if (rows.length == 0) { |
1282 | alert(__("No articles are selected.")); | |
1283 | return; | |
1284 | } | |
1285 | ||
e04c18a2 AD |
1286 | var fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); |
1287 | var str; | |
1288 | var op; | |
1289 | ||
1290 | if (getActiveFeedId() != 0) { | |
1291 | str = __("Archive %d selected articles in %s?"); | |
1292 | op = "archive"; | |
1293 | } else { | |
1294 | str = __("Move %d archived articles back?"); | |
1295 | op = "unarchive"; | |
1296 | } | |
1297 | ||
1298 | str = str.replace("%d", rows.length); | |
1299 | str = str.replace("%s", fn); | |
1300 | ||
1301 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
1302 | return; | |
1303 | } | |
1304 | ||
b4e75b2a | 1305 | query = "?op=rpc&subop="+op+"&ids=" + param_escape(rows); |
e04c18a2 | 1306 | |
84c7b824 | 1307 | console.log(query); |
e04c18a2 | 1308 | |
a12eb9c3 AD |
1309 | for (var i = 0; i < rows.length; i++) { |
1310 | cache_invalidate(rows[i]); | |
1311 | } | |
1312 | ||
b4e75b2a AD |
1313 | new Ajax.Request("backend.php", { |
1314 | parameters: query, | |
e04c18a2 AD |
1315 | onComplete: function(transport) { |
1316 | viewCurrentFeed(); | |
1317 | } }); | |
1318 | ||
1319 | } catch (e) { | |
1320 | exception_error("archiveSelection", e); | |
1321 | } | |
1322 | } | |
1323 | ||
a5ae125a AD |
1324 | function catchupSelection() { |
1325 | ||
1326 | try { | |
1327 | ||
b83d72b1 AD |
1328 | var rows = getSelectedArticleIds2(); |
1329 | ||
a5ae125a AD |
1330 | if (rows.length == 0) { |
1331 | alert(__("No articles are selected.")); | |
1332 | return; | |
1333 | } | |
1334 | ||
3d72bbdb | 1335 | var fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); |
a5ae125a | 1336 | |
ba5fac1b | 1337 | var str = __("Mark %d selected articles in %s as read?"); |
a5ae125a | 1338 | |
ba5fac1b | 1339 | str = str.replace("%d", rows.length); |
a5ae125a AD |
1340 | str = str.replace("%s", fn); |
1341 | ||
1342 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
1343 | return; | |
1344 | } | |
1345 | ||
acac8448 | 1346 | if ($("headlinesList")) { |
50eefedb | 1347 | selectionToggleUnread(false, 'viewCurrentFeed()', true); |
a5ae125a | 1348 | } else { |
50eefedb | 1349 | selectionToggleUnread(false, 'viewCurrentFeed()', true) |
a5ae125a AD |
1350 | } |
1351 | ||
1352 | } catch (e) { | |
1353 | exception_error("catchupSelection", e); | |
1354 | } | |
1355 | } | |
1356 | ||
13f08f75 | 1357 | function editArticleTags(id, feed_id, cdm_enabled) { |
542aebac AL |
1358 | displayDlg('editArticleTags', id, |
1359 | function () { | |
126cd3c8 AD |
1360 | $("tags_str").focus(); |
1361 | ||
1362 | new Ajax.Autocompleter('tags_str', 'tags_choices', | |
542aebac AL |
1363 | "backend.php?op=rpc&subop=completeTags", |
1364 | { tokens: ',', paramName: "search" }); | |
1365 | }); | |
0b126ac2 AD |
1366 | } |
1367 | ||
0b126ac2 AD |
1368 | function editTagsSave() { |
1369 | ||
42c32916 | 1370 | notify_progress("Saving article tags..."); |
88040f57 | 1371 | |
0b126ac2 AD |
1372 | var form = document.forms["tag_edit_form"]; |
1373 | ||
1374 | var query = Form.serialize("tag_edit_form"); | |
1375 | ||
b4e75b2a | 1376 | query = "?op=rpc&subop=setArticleTags&" + query; |
14b6c54b | 1377 | |
f8fb4498 | 1378 | //console.log(query); |
14b6c54b | 1379 | |
b4e75b2a AD |
1380 | new Ajax.Request("backend.php", { |
1381 | parameters: query, | |
2ef1af84 | 1382 | onComplete: function(transport) { |
a5819bb3 | 1383 | try { |
f8fb4498 | 1384 | //console.log("tags saved..."); |
a5819bb3 AD |
1385 | |
1386 | closeInfoBox(); | |
1387 | notify(""); | |
1388 | ||
1389 | if (tagsAreDisplayed()) { | |
1390 | _reload_feedlist_after_view = true; | |
1391 | } | |
1392 | ||
1393 | if (transport.responseXML) { | |
1394 | var tags_str = transport.responseXML.getElementsByTagName("tags-str")[0]; | |
1395 | ||
1396 | if (tags_str) { | |
1397 | var id = tags_str.getAttribute("id"); | |
1398 | ||
1399 | if (id) { | |
1400 | var tags = $("ATSTR-" + id); | |
1401 | if (tags) { | |
1402 | tags.innerHTML = tags_str.firstChild.nodeValue; | |
1403 | } | |
bd3f2ade AD |
1404 | |
1405 | cache_invalidate(id); | |
a5819bb3 AD |
1406 | } |
1407 | } | |
1408 | } | |
1409 | ||
1410 | } catch (e) { | |
1411 | exception_error("editTagsSave", e); | |
1412 | } | |
2ef1af84 | 1413 | } }); |
0b126ac2 | 1414 | } |
d62a3b63 AD |
1415 | |
1416 | function editTagsInsert() { | |
1417 | try { | |
1418 | ||
1419 | var form = document.forms["tag_edit_form"]; | |
1420 | ||
1421 | var found_tags = form.found_tags; | |
1422 | var tags_str = form.tags_str; | |
1423 | ||
1424 | var tag = found_tags[found_tags.selectedIndex].value; | |
1425 | ||
1426 | if (tags_str.value.length > 0 && | |
1427 | tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) { | |
1428 | ||
1429 | tags_str.value = tags_str.value + ", "; | |
1430 | } | |
1431 | ||
1432 | tags_str.value = tags_str.value + tag + ", "; | |
1433 | ||
1434 | found_tags.selectedIndex = 0; | |
1435 | ||
1436 | } catch (e) { | |
438f2ce9 | 1437 | exception_error("editTagsInsert", e); |
d62a3b63 AD |
1438 | } |
1439 | } | |
ba0978c8 | 1440 | |
587bef10 | 1441 | function cdmScrollViewport(where) { |
84c7b824 | 1442 | console.log("cdmScrollViewport: " + where); |
587bef10 | 1443 | |
acac8448 | 1444 | var ctr = $("headlinesInnerContainer"); |
587bef10 AD |
1445 | |
1446 | if (!ctr) return; | |
1447 | ||
1448 | if (where == "bottom") { | |
1449 | ctr.scrollTop = ctr.scrollHeight; | |
1450 | } else { | |
1451 | ctr.scrollTop = where; | |
1452 | } | |
1453 | } | |
1454 | ||
b8e6acea AD |
1455 | function cdmArticleIsBelowViewport(id) { |
1456 | try { | |
acac8448 AD |
1457 | var ctr = $("headlinesInnerContainer"); |
1458 | var e = $("RROW-" + id); | |
b8e6acea AD |
1459 | |
1460 | if (!e || !ctr) return; | |
1461 | ||
1462 | // article starts below viewport | |
1463 | ||
1464 | if (ctr.scrollTop < e.offsetTop) { | |
1465 | return true; | |
1466 | } else { | |
1467 | return false; | |
1468 | } | |
1469 | ||
1470 | } catch (e) { | |
438f2ce9 | 1471 | exception_error("cdmArticleIsVisible", e); |
b8e6acea AD |
1472 | } |
1473 | } | |
1474 | ||
1475 | function cdmArticleIsAboveViewport(id) { | |
1476 | try { | |
acac8448 AD |
1477 | var ctr = $("headlinesInnerContainer"); |
1478 | var e = $("RROW-" + id); | |
b8e6acea AD |
1479 | |
1480 | if (!e || !ctr) return; | |
1481 | ||
1482 | // article starts above viewport | |
1483 | ||
1484 | if (ctr.scrollTop > e.offsetTop + e.offsetHeight) { | |
1485 | return true; | |
1486 | } else { | |
1487 | return false; | |
1488 | } | |
1489 | ||
1490 | } catch (e) { | |
438f2ce9 | 1491 | exception_error("cdmArticleIsVisible", e); |
b8e6acea AD |
1492 | } |
1493 | } | |
1494 | ||
1495 | function cdmScrollToArticleId(id) { | |
1496 | try { | |
acac8448 AD |
1497 | var ctr = $("headlinesInnerContainer"); |
1498 | var e = $("RROW-" + id); | |
b8e6acea AD |
1499 | |
1500 | if (!e || !ctr) return; | |
1501 | ||
1502 | ctr.scrollTop = e.offsetTop; | |
1503 | ||
1504 | } catch (e) { | |
438f2ce9 | 1505 | exception_error("cdmScrollToArticleId", e); |
b8e6acea AD |
1506 | } |
1507 | } | |
1508 | ||
1509 | function cdmArticleIsActuallyVisible(id) { | |
1510 | try { | |
acac8448 AD |
1511 | var ctr = $("headlinesInnerContainer"); |
1512 | var e = $("RROW-" + id); | |
b8e6acea AD |
1513 | |
1514 | if (!e || !ctr) return; | |
1515 | ||
1516 | // article fits in viewport OR article is longer than viewport and | |
1517 | // its bottom is visible | |
1518 | ||
1519 | if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <= | |
1520 | ctr.scrollTop + ctr.offsetHeight) { | |
1521 | ||
1522 | return true; | |
1523 | ||
1524 | } else if (e.offsetHeight > ctr.offsetHeight && | |
1525 | e.offsetTop + e.offsetHeight >= ctr.scrollTop && | |
1526 | e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) { | |
1527 | ||
1528 | return true; | |
1529 | ||
1530 | } | |
1531 | ||
1532 | return false; | |
1533 | ||
1534 | } catch (e) { | |
438f2ce9 | 1535 | exception_error("cdmArticleIsVisible", e); |
b8e6acea AD |
1536 | } |
1537 | } | |
1538 | ||
ba0978c8 AD |
1539 | function cdmWatchdog() { |
1540 | ||
1541 | try { | |
1542 | ||
acac8448 | 1543 | var ctr = $("headlinesInnerContainer"); |
ba0978c8 | 1544 | |
9acd22e8 AD |
1545 | if (!ctr) return; |
1546 | ||
ba0978c8 AD |
1547 | var ids = new Array(); |
1548 | ||
1549 | var e = ctr.firstChild; | |
1550 | ||
1551 | while (e) { | |
1552 | if (e.className && e.className == "cdmArticleUnread" && e.id && | |
1553 | e.id.match("RROW-")) { | |
1554 | ||
1555 | // article fits in viewport OR article is longer than viewport and | |
1556 | // its bottom is visible | |
1557 | ||
1558 | if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <= | |
1559 | ctr.scrollTop + ctr.offsetHeight) { | |
1560 | ||
84c7b824 | 1561 | // console.log(e.id + " is visible " + e.offsetTop + "." + |
ba0978c8 AD |
1562 | // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." + |
1563 | // (ctr.scrollTop + ctr.offsetHeight)); | |
1564 | ||
1565 | ids.push(e.id.replace("RROW-", "")); | |
1566 | ||
1567 | } else if (e.offsetHeight > ctr.offsetHeight && | |
1568 | e.offsetTop + e.offsetHeight >= ctr.scrollTop && | |
1569 | e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) { | |
1570 | ||
1571 | ids.push(e.id.replace("RROW-", "")); | |
1572 | ||
1573 | } | |
1574 | ||
c50e2b30 AD |
1575 | // method 2: article bottom is visible and is in upper 1/2 of the viewport |
1576 | ||
1577 | /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop && | |
1578 | e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) { | |
1579 | ||
1580 | ids.push(e.id.replace("RROW-", "")); | |
1581 | ||
1582 | } */ | |
1583 | ||
ba0978c8 AD |
1584 | } |
1585 | ||
1586 | e = e.nextSibling; | |
1587 | } | |
1588 | ||
84c7b824 | 1589 | console.log("cdmWatchdog, ids= " + ids.toString()); |
ba0978c8 | 1590 | |
1341ea0d | 1591 | if (ids.length > 0) { |
ba0978c8 AD |
1592 | |
1593 | for (var i = 0; i < ids.length; i++) { | |
acac8448 | 1594 | var e = $("RROW-" + ids[i]); |
ba0978c8 AD |
1595 | if (e) { |
1596 | e.className = e.className.replace("Unread", ""); | |
1597 | } | |
1598 | } | |
1599 | ||
b4e75b2a AD |
1600 | var query = "?op=rpc&subop=catchupSelected" + |
1601 | "&cmode=0" + "&ids=" + param_escape(ids.toString()); | |
ba0978c8 | 1602 | |
b4e75b2a AD |
1603 | new Ajax.Request("backend.php", { |
1604 | parameters: query, | |
1341ea0d | 1605 | onComplete: function(transport) { |
f8fb4498 | 1606 | handle_rpc_reply(transport); |
1341ea0d | 1607 | } }); |
ba0978c8 AD |
1608 | |
1609 | } | |
1610 | ||
c50e2b30 | 1611 | _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000); |
ba0978c8 AD |
1612 | |
1613 | } catch (e) { | |
438f2ce9 | 1614 | exception_error("cdmWatchdog", e); |
ba0978c8 AD |
1615 | } |
1616 | ||
1617 | } | |
e097e8be AD |
1618 | |
1619 | ||
e19c1824 | 1620 | function cache_inject(id, article, param) { |
b39b57ac | 1621 | |
fb456d28 AD |
1622 | try { |
1623 | if (!cache_check_param(id, param)) { | |
f8fb4498 | 1624 | //console.log("cache_article: miss: " + id + " [p=" + param + "]"); |
e097e8be | 1625 | |
b39b57ac AD |
1626 | var date = new Date(); |
1627 | var ts = Math.round(date.getTime() / 1000); | |
1628 | ||
1629 | if (db) { | |
e097e8be | 1630 | |
fb456d28 AD |
1631 | db.execute("INSERT INTO cache (id, article, param, added) VALUES (?, ?, ?, ?)", |
1632 | [id, article, param, ts]); | |
1633 | } else { | |
1634 | ||
ff0010c1 | 1635 | var cache_obj = {}; |
fb456d28 AD |
1636 | |
1637 | cache_obj["id"] = id; | |
1638 | cache_obj["data"] = article; | |
1639 | cache_obj["param"] = param; | |
ff0010c1 AD |
1640 | |
1641 | if (param) id = id + ":" + param; | |
1642 | ||
b39b57ac AD |
1643 | cache_added["TS:" + id] = ts; |
1644 | ||
ff0010c1 AD |
1645 | if (has_local_storage()) |
1646 | localStorage.setItem(id, JSON.stringify(cache_obj)); | |
1647 | else | |
1648 | article_cache.push(cache_obj); | |
fb456d28 AD |
1649 | } |
1650 | ||
1651 | } else { | |
f8fb4498 | 1652 | //console.log("cache_article: hit: " + id + " [p=" + param + "]"); |
fb456d28 AD |
1653 | } |
1654 | } catch (e) { | |
1655 | exception_error("cache_inject", e); | |
e097e8be AD |
1656 | } |
1657 | } | |
1658 | ||
1659 | function cache_find(id) { | |
fb456d28 AD |
1660 | |
1661 | if (db) { | |
31234407 | 1662 | var rs = db.execute("SELECT article FROM cache WHERE id = ?", [id]); |
03c96380 | 1663 | var a = false; |
31234407 AD |
1664 | |
1665 | if (rs.isValidRow()) { | |
03c96380 | 1666 | var a = rs.field(0); |
31234407 | 1667 | } |
fb456d28 | 1668 | |
03c96380 AD |
1669 | rs.close(); |
1670 | ||
1671 | return a; | |
1672 | ||
fb456d28 | 1673 | } else { |
ff0010c1 AD |
1674 | |
1675 | if (has_local_storage()) { | |
1676 | var cache_obj = localStorage.getItem(id); | |
1677 | ||
1678 | if (cache_obj) { | |
1679 | cache_obj = JSON.parse(cache_obj); | |
1680 | ||
1681 | if (cache_obj) | |
1682 | return cache_obj['data']; | |
1683 | } | |
1684 | ||
1685 | } else { | |
1686 | for (var i = 0; i < article_cache.length; i++) { | |
1687 | if (article_cache[i]["id"] == id) { | |
1688 | return article_cache[i]["data"]; | |
1689 | } | |
fb456d28 | 1690 | } |
fed4387d | 1691 | } |
e097e8be | 1692 | } |
fed4387d | 1693 | return false; |
e097e8be AD |
1694 | } |
1695 | ||
5d17ead9 | 1696 | function cache_find_param(id, param) { |
fb456d28 AD |
1697 | |
1698 | if (db) { | |
1699 | var rs = db.execute("SELECT article FROM cache WHERE id = ? AND param = ?", | |
1700 | [id, param]); | |
03c96380 | 1701 | var a = false; |
fb456d28 AD |
1702 | |
1703 | if (rs.isValidRow()) { | |
03c96380 | 1704 | a = rs.field(0); |
fb456d28 AD |
1705 | } |
1706 | ||
03c96380 AD |
1707 | rs.close(); |
1708 | ||
1709 | return a; | |
1710 | ||
fb456d28 | 1711 | } else { |
ff0010c1 AD |
1712 | |
1713 | if (has_local_storage()) { | |
b39b57ac AD |
1714 | |
1715 | if (param) id = id + ":" + param; | |
1716 | ||
1717 | var cache_obj = localStorage.getItem(id); | |
ff0010c1 AD |
1718 | |
1719 | if (cache_obj) { | |
1720 | cache_obj = JSON.parse(cache_obj); | |
1721 | ||
1722 | if (cache_obj) | |
1723 | return cache_obj['data']; | |
1724 | } | |
1725 | ||
1726 | } else { | |
1727 | for (var i = 0; i < article_cache.length; i++) { | |
1728 | if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) { | |
1729 | return article_cache[i]["data"]; | |
1730 | } | |
fb456d28 | 1731 | } |
e19c1824 AD |
1732 | } |
1733 | } | |
1734 | return false; | |
1735 | } | |
1736 | ||
e097e8be | 1737 | function cache_check(id) { |
fb456d28 AD |
1738 | |
1739 | if (db) { | |
1740 | var rs = db.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ?", | |
1741 | [id]); | |
03c96380 | 1742 | var a = false; |
fb456d28 AD |
1743 | |
1744 | if (rs.isValidRow()) { | |
03c96380 | 1745 | a = rs.field(0) != "0"; |
fb456d28 AD |
1746 | } |
1747 | ||
03c96380 AD |
1748 | rs.close(); |
1749 | ||
1750 | return a; | |
1751 | ||
fb456d28 | 1752 | } else { |
b39b57ac | 1753 | if (has_local_storage()) { |
ff0010c1 | 1754 | if (localStorage.getItem(id)) |
b39b57ac | 1755 | return true; |
ff0010c1 AD |
1756 | } else { |
1757 | for (var i = 0; i < article_cache.length; i++) { | |
1758 | if (article_cache[i]["id"] == id) { | |
1759 | return true; | |
1760 | } | |
fb456d28 | 1761 | } |
fed4387d AD |
1762 | } |
1763 | } | |
1764 | return false; | |
e097e8be AD |
1765 | } |
1766 | ||
e19c1824 | 1767 | function cache_check_param(id, param) { |
5d17ead9 | 1768 | |
fb456d28 AD |
1769 | if (db) { |
1770 | var rs = db.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ? AND param = ?", | |
1771 | [id, param]); | |
03c96380 | 1772 | var a = false; |
5d17ead9 | 1773 | |
fb456d28 | 1774 | if (rs.isValidRow()) { |
03c96380 | 1775 | a = rs.field(0) != "0"; |
fb456d28 AD |
1776 | } |
1777 | ||
03c96380 AD |
1778 | rs.close(); |
1779 | ||
1780 | return a; | |
1781 | ||
fb456d28 | 1782 | } else { |
ff0010c1 | 1783 | |
b39b57ac AD |
1784 | if (has_local_storage()) { |
1785 | ||
1786 | if (param) id = id + ":" + param; | |
1787 | ||
1788 | if (localStorage.getItem(id)) | |
1789 | return true; | |
1790 | ||
ff0010c1 AD |
1791 | } else { |
1792 | for (var i = 0; i < article_cache.length; i++) { | |
1793 | if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) { | |
1794 | return true; | |
1795 | } | |
fb456d28 | 1796 | } |
e19c1824 AD |
1797 | } |
1798 | } | |
1799 | return false; | |
1800 | } | |
1801 | ||
e097e8be | 1802 | function cache_expire() { |
31234407 AD |
1803 | if (db) { |
1804 | var date = new Date(); | |
1805 | var ts = Math.round(date.getTime() / 1000); | |
1806 | ||
e0999d95 AD |
1807 | db.execute("DELETE FROM cache WHERE added < ? - 1800 AND id LIKE 'FEEDLIST'", [ts]); |
1808 | db.execute("DELETE FROM cache WHERE added < ? - 600 AND (id LIKE 'F:%' OR id LIKE 'C:%')", [ts]); | |
1809 | db.execute("DELETE FROM cache WHERE added < ? - 86400", [ts]); | |
1810 | ||
31234407 AD |
1811 | |
1812 | } else { | |
ff0010c1 | 1813 | if (has_local_storage()) { |
b39b57ac AD |
1814 | |
1815 | var date = new Date(); | |
1816 | var timestamp = Math.round(date.getTime() / 1000); | |
1817 | ||
905ff52a | 1818 | for (var i = 0; i < localStorage.length; i++) { |
23d064cc | 1819 | |
905ff52a | 1820 | var id = localStorage.key(i); |
23d064cc | 1821 | |
905ff52a AD |
1822 | if (timestamp - cache_added["TS:" + id] > 180) { |
1823 | localStorage.removeItem(id); | |
b39b57ac | 1824 | } |
ff0010c1 | 1825 | } |
b39b57ac | 1826 | |
ff0010c1 AD |
1827 | } else { |
1828 | while (article_cache.length > 25) { | |
1829 | article_cache.shift(); | |
1830 | } | |
fb456d28 | 1831 | } |
fed4387d | 1832 | } |
e097e8be | 1833 | } |
b07b61da | 1834 | |
641444d3 | 1835 | function cache_flush() { |
5225d420 AD |
1836 | if (db) { |
1837 | db.execute("DELETE FROM cache"); | |
1838 | } else if (has_local_storage()) { | |
1839 | localStorage.clear(); | |
1840 | } else { | |
1841 | article_cache = new Array(); | |
1842 | } | |
3c2d7945 AD |
1843 | } |
1844 | ||
b07b61da | 1845 | function cache_invalidate(id) { |
c1b18749 AD |
1846 | try { |
1847 | ||
fb456d28 AD |
1848 | if (db) { |
1849 | rs = db.execute("DELETE FROM cache WHERE id = ?", [id]); | |
1850 | return rs.rowsAffected != 0; | |
1851 | } else { | |
1852 | ||
ff0010c1 | 1853 | if (has_local_storage()) { |
fb456d28 | 1854 | |
b39b57ac AD |
1855 | var found = false; |
1856 | ||
905ff52a AD |
1857 | for (var i = 0; i < localStorage.length; i++) { |
1858 | var key = localStorage.key(i); | |
b39b57ac AD |
1859 | |
1860 | // console.warn("cache_invalidate: " + key_id + " cmp " + id); | |
ff0010c1 | 1861 | |
905ff52a AD |
1862 | if (key == id || key.indexOf(id + ":") == 0) { |
1863 | localStorage.removeItem(key); | |
b39b57ac AD |
1864 | found = true; |
1865 | break; | |
b39b57ac | 1866 | } |
ff0010c1 | 1867 | } |
b39b57ac | 1868 | |
b39b57ac AD |
1869 | return found; |
1870 | ||
ff0010c1 AD |
1871 | } else { |
1872 | var i = 0 | |
1873 | ||
1874 | while (i < article_cache.length) { | |
1875 | if (article_cache[i]["id"] == id) { | |
f8fb4498 | 1876 | //console.log("cache_invalidate: removed id " + id); |
ff0010c1 AD |
1877 | article_cache.splice(i, 1); |
1878 | return true; | |
1879 | } | |
1880 | i++; | |
fb456d28 | 1881 | } |
c1b18749 | 1882 | } |
b07b61da | 1883 | } |
fb456d28 | 1884 | |
f8fb4498 | 1885 | //console.log("cache_invalidate: id not found: " + id); |
c1b18749 AD |
1886 | return false; |
1887 | } catch (e) { | |
1888 | exception_error("cache_invalidate", e); | |
b07b61da | 1889 | } |
b07b61da | 1890 | } |
298f3f78 AD |
1891 | |
1892 | function getActiveArticleId() { | |
1893 | return active_post_id; | |
1894 | } | |
e4914b62 | 1895 | |
b39b57ac AD |
1896 | function preloadBatchedArticles() { |
1897 | try { | |
1898 | ||
1899 | var query = "?op=rpc&subop=getArticles&ids=" + | |
1900 | preload_id_batch.toString(); | |
1901 | ||
1902 | new Ajax.Request("backend.php", { | |
1903 | parameters: query, | |
1904 | onComplete: function(transport) { | |
1905 | ||
1906 | preload_id_batch = []; | |
1907 | ||
1908 | var articles = transport.responseXML.getElementsByTagName("article"); | |
1909 | ||
1910 | for (var i = 0; i < articles.length; i++) { | |
1911 | var id = articles[i].getAttribute("id"); | |
1912 | if (!cache_check(id)) { | |
1913 | cache_inject(id, articles[i].firstChild.nodeValue); | |
1914 | console.log("preloaded article: " + id); | |
1915 | } | |
1916 | } | |
1917 | } }); | |
1918 | ||
1919 | } catch (e) { | |
1920 | exception_error("preloadBatchedArticles", e); | |
1921 | } | |
1922 | } | |
1923 | ||
aa0fa9df AD |
1924 | function preloadArticleUnderPointer(id) { |
1925 | try { | |
a598370d AD |
1926 | if (getInitParam("bw_limit") == "1") return; |
1927 | ||
b2bb787c | 1928 | if (post_under_pointer == id && !cache_check(id)) { |
aa0fa9df | 1929 | |
84c7b824 | 1930 | console.log("trying to preload article " + id); |
aa0fa9df AD |
1931 | |
1932 | var neighbor_ids = getRelativePostIds(id, 1); | |
1933 | ||
1934 | /* only request uncached articles */ | |
1935 | ||
b39b57ac AD |
1936 | if (preload_id_batch.indexOf(id) == -1) { |
1937 | for (var i = 0; i < neighbor_ids.length; i++) { | |
1938 | if (!cache_check(neighbor_ids[i])) { | |
1939 | preload_id_batch.push(neighbor_ids[i]); | |
1940 | } | |
aa0fa9df AD |
1941 | } |
1942 | } | |
aa0fa9df | 1943 | |
b39b57ac AD |
1944 | if (preload_id_batch.indexOf(id) == -1) |
1945 | preload_id_batch.push(id); | |
aa0fa9df | 1946 | |
f8fb4498 | 1947 | //console.log("preload ids batch: " + preload_id_batch.toString()); |
b4e75b2a | 1948 | |
b39b57ac AD |
1949 | window.clearTimeout(preload_timeout_id); |
1950 | preload_batch_timeout_id = window.setTimeout('preloadBatchedArticles()', 1000); | |
a5819bb3 | 1951 | |
aa0fa9df AD |
1952 | } |
1953 | } catch (e) { | |
1954 | exception_error("preloadArticleUnderPointer", e); | |
1955 | } | |
1956 | } | |
1957 | ||
314fcd2b AD |
1958 | function postMouseIn(id) { |
1959 | try { | |
aa0fa9df AD |
1960 | if (post_under_pointer != id) { |
1961 | post_under_pointer = id; | |
1962 | if (!isCdmMode()) { | |
1963 | window.setTimeout("preloadArticleUnderPointer(" + id + ")", 250); | |
1964 | } | |
1965 | } | |
1966 | ||
314fcd2b AD |
1967 | } catch (e) { |
1968 | exception_error("postMouseIn", e); | |
1969 | } | |
1970 | } | |
1971 | ||
1972 | function postMouseOut(id) { | |
1973 | try { | |
1974 | post_under_pointer = false; | |
1975 | } catch (e) { | |
1976 | exception_error("postMouseOut", e); | |
1977 | } | |
1978 | } | |
1979 | ||
ac541432 AD |
1980 | function headlines_scroll_handler() { |
1981 | try { | |
1982 | ||
acac8448 | 1983 | var e = $("headlinesInnerContainer"); |
ac541432 | 1984 | |
4764c27e AD |
1985 | var toolbar_form = document.forms["main_toolbar_form"]; |
1986 | ||
dad14b51 AD |
1987 | // console.log((e.scrollTop + e.offsetHeight) + " vs " + e.scrollHeight + " dis? " + |
1988 | // _infscroll_disable); | |
587bef10 | 1989 | |
6f068202 AD |
1990 | if (e.scrollTop + e.offsetHeight > e.scrollHeight - 100) { |
1991 | if (!_infscroll_disable) { | |
6f068202 | 1992 | viewNextFeedPage(); |
29dfb258 | 1993 | } |
ac541432 AD |
1994 | } |
1995 | ||
1996 | } catch (e) { | |
1997 | exception_error("headlines_scroll_handler", e); | |
1998 | } | |
1999 | } | |
8be83f42 AD |
2000 | |
2001 | function catchupRelativeToArticle(below) { | |
2002 | ||
2003 | try { | |
2004 | ||
49fd1e94 | 2005 | |
8be83f42 AD |
2006 | if (!getActiveArticleId()) { |
2007 | alert(__("No article is selected.")); | |
2008 | return; | |
2009 | } | |
2010 | ||
2011 | var visible_ids; | |
2012 | ||
acac8448 | 2013 | if ($("headlinesList")) { |
8be83f42 AD |
2014 | visible_ids = getVisibleHeadlineIds(); |
2015 | } else { | |
2016 | visible_ids = cdmGetVisibleArticles(); | |
2017 | } | |
2018 | ||
2019 | var ids_to_mark = new Array(); | |
2020 | ||
2021 | if (!below) { | |
2022 | for (var i = 0; i < visible_ids.length; i++) { | |
2023 | if (visible_ids[i] != getActiveArticleId()) { | |
acac8448 | 2024 | var e = $("RROW-" + visible_ids[i]); |
8be83f42 AD |
2025 | |
2026 | if (e && e.className.match("Unread")) { | |
2027 | ids_to_mark.push(visible_ids[i]); | |
2028 | } | |
2029 | } else { | |
2030 | break; | |
2031 | } | |
2032 | } | |
2033 | } else { | |
2034 | for (var i = visible_ids.length-1; i >= 0; i--) { | |
2035 | if (visible_ids[i] != getActiveArticleId()) { | |
acac8448 | 2036 | var e = $("RROW-" + visible_ids[i]); |
8be83f42 AD |
2037 | |
2038 | if (e && e.className.match("Unread")) { | |
2039 | ids_to_mark.push(visible_ids[i]); | |
2040 | } | |
2041 | } else { | |
2042 | break; | |
2043 | } | |
2044 | } | |
2045 | } | |
2046 | ||
2047 | if (ids_to_mark.length == 0) { | |
2048 | alert(__("No articles found to mark")); | |
2049 | } else { | |
2050 | var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length); | |
2051 | ||
fb45339a | 2052 | if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) { |
8be83f42 AD |
2053 | |
2054 | for (var i = 0; i < ids_to_mark.length; i++) { | |
acac8448 | 2055 | var e = $("RROW-" + ids_to_mark[i]); |
8be83f42 AD |
2056 | e.className = e.className.replace("Unread", ""); |
2057 | } | |
2058 | ||
b4e75b2a AD |
2059 | var query = "?op=rpc&subop=catchupSelected" + |
2060 | "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString()); | |
8be83f42 | 2061 | |
b4e75b2a AD |
2062 | new Ajax.Request("backend.php", { |
2063 | parameters: query, | |
5fe7767c AD |
2064 | onComplete: function(transport) { |
2065 | catchup_callback2(transport); | |
2066 | } }); | |
2067 | ||
8be83f42 AD |
2068 | } |
2069 | } | |
2070 | ||
2071 | } catch (e) { | |
2072 | exception_error("catchupRelativeToArticle", e); | |
2073 | } | |
2074 | } | |
a04c8e8d | 2075 | |
dad14b51 | 2076 | function cdmExpandArticle(id) { |
a04c8e8d | 2077 | try { |
a04c8e8d | 2078 | |
dad14b51 | 2079 | var elem = $("CICD-" + active_post_id); |
3cd4239a | 2080 | |
dad14b51 AD |
2081 | if (id == active_post_id && Element.visible(elem)) |
2082 | return true; | |
2083 | ||
2084 | cdmSelectArticles("none"); | |
2085 | ||
2086 | var old_offset = $("RROW-" + id).offsetTop; | |
2087 | ||
2088 | if (active_post_id && elem) { | |
2089 | Element.hide(elem); | |
2090 | Element.show("CEXC-" + active_post_id); | |
2091 | } | |
a04c8e8d | 2092 | |
dad14b51 | 2093 | active_post_id = id; |
a04c8e8d | 2094 | |
dad14b51 AD |
2095 | elem = $("CICD-" + id); |
2096 | ||
2097 | if (!Element.visible(elem)) { | |
2098 | Element.show(elem); | |
2099 | Element.hide("CEXC-" + id); | |
2100 | } | |
2101 | ||
2102 | var new_offset = $("RROW-" + id).offsetTop; | |
2103 | ||
2104 | $("headlinesInnerContainer").scrollTop += (new_offset-old_offset); | |
2105 | ||
2106 | if ($("RROW-" + id).offsetTop != old_offset) | |
2107 | $("headlinesInnerContainer").scrollTop = new_offset; | |
2108 | ||
2109 | toggleUnread(id, 0, true); | |
2110 | toggleSelected(id); | |
a04c8e8d AD |
2111 | |
2112 | } catch (e) { | |
d5ed5446 | 2113 | exception_error("cdmExpandArticle", e); |
a04c8e8d AD |
2114 | } |
2115 | ||
dad14b51 | 2116 | return false; |
a04c8e8d AD |
2117 | } |
2118 | ||
3818a89b AD |
2119 | function fixHeadlinesOrder(ids) { |
2120 | try { | |
2121 | for (var i = 0; i < ids.length; i++) { | |
acac8448 | 2122 | var e = $("RROW-" + ids[i]); |
3818a89b AD |
2123 | |
2124 | if (e) { | |
2125 | if (i % 2 == 0) { | |
2126 | e.className = e.className.replace("even", "odd"); | |
2127 | } else { | |
2128 | e.className = e.className.replace("odd", "even"); | |
2129 | } | |
2130 | } | |
2131 | } | |
2132 | } catch (e) { | |
2133 | exception_error("fixHeadlinesOrder", e); | |
2134 | } | |
2135 | } | |
2136 | ||
df485d4f AD |
2137 | function hideReadHeadlines() { |
2138 | try { | |
2139 | ||
2140 | var ids = false; | |
2141 | var vis_ids = new Array(); | |
2142 | ||
acac8448 | 2143 | if ($("headlinesList")) { |
df485d4f AD |
2144 | ids = getVisibleHeadlineIds(); |
2145 | } else { | |
2146 | ids = cdmGetVisibleArticles(); | |
2147 | } | |
2148 | ||
004523dd AD |
2149 | var read_headlines_visible = true; |
2150 | ||
df485d4f | 2151 | for (var i = 0; i < ids.length; i++) { |
acac8448 | 2152 | var row = $("RROW-" + ids[i]); |
df485d4f AD |
2153 | |
2154 | if (row && row.className) { | |
2155 | if (read_headlines_visible) { | |
2156 | if (row.className.match("Unread") || row.className.match("Selected")) { | |
2157 | Element.show(row); | |
2158 | vis_ids.push(ids[i]); | |
2159 | } else { | |
2160 | //Effect.Fade(row, {duration : 0.3}); | |
2161 | Element.hide(row); | |
2162 | } | |
2163 | } else { | |
2164 | Element.show(row); | |
2165 | vis_ids.push(ids[i]); | |
2166 | } | |
2167 | } | |
2168 | } | |
2169 | ||
2170 | fixHeadlinesOrder(vis_ids); | |
2171 | ||
2172 | read_headlines_visible = !read_headlines_visible; | |
2173 | ||
2174 | } catch (e) { | |
2175 | exception_error("hideReadHeadlines", e); | |
2176 | } | |
2177 | } | |
2178 | ||
e75d70b5 AD |
2179 | function invertHeadlineSelection() { |
2180 | try { | |
2181 | var rows = new Array(); | |
2182 | var r = false; | |
2183 | ||
2184 | if (!isCdmMode()) { | |
2185 | r = document.getElementsByTagName("TR"); | |
2186 | } else { | |
2187 | r = document.getElementsByTagName("DIV"); | |
2188 | } | |
2189 | ||
2190 | for (var i = 0; i < r.length; i++) { | |
2191 | if (r[i].id && r[i].id.match("RROW-")) { | |
2192 | rows.push(r[i]); | |
2193 | } | |
2194 | } | |
2195 | ||
2196 | for (var i = 0; i < rows.length; i++) { | |
2197 | var nc = rows[i].className; | |
2198 | var id = rows[i].id.replace("RROW-", ""); | |
acac8448 | 2199 | var cb = $("RCHK-" + id); |
e75d70b5 AD |
2200 | |
2201 | if (!rows[i].className.match("Selected")) { | |
2202 | nc = nc + "Selected"; | |
2203 | cb.checked = true; | |
2204 | } else { | |
2205 | nc = nc.replace("Selected", ""); | |
2206 | cb.checked = false; | |
2207 | } | |
2208 | ||
2209 | rows[i].className = nc; | |
2210 | ||
2211 | } | |
2212 | ||
2213 | } catch (e) { | |
2214 | exception_error("invertHeadlineSelection", e); | |
2215 | } | |
2216 | } | |
2217 | ||
314fcd2b AD |
2218 | function getArticleUnderPointer() { |
2219 | return post_under_pointer; | |
7a822893 | 2220 | } |
eedfb635 AD |
2221 | |
2222 | function zoomToArticle(id) { | |
2223 | try { | |
2224 | var w = window.open("backend.php?op=view&mode=zoom&id=" + param_escape(id), | |
2225 | "ttrss_zoom_" + id, | |
2226 | "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0"); | |
2227 | ||
2228 | } catch (e) { | |
2229 | exception_error("zoomToArticle", e); | |
2230 | } | |
2231 | } | |
a411875b AD |
2232 | |
2233 | function scrollArticle(offset) { | |
2234 | try { | |
2235 | if (!isCdmMode()) { | |
acac8448 | 2236 | var ci = $("content-insert"); |
a411875b AD |
2237 | if (ci) { |
2238 | ci.scrollTop += offset; | |
2239 | } | |
2240 | } else { | |
acac8448 | 2241 | var hi = $("headlinesInnerContainer"); |
a411875b AD |
2242 | if (hi) { |
2243 | hi.scrollTop += offset; | |
2244 | } | |
2245 | ||
2246 | } | |
2247 | } catch (e) { | |
2248 | exception_error("scrollArticle", e); | |
2249 | } | |
2250 | } | |
f9247195 AD |
2251 | |
2252 | function show_labels_in_headlines(transport) { | |
2253 | try { | |
2254 | if (transport.responseXML) { | |
2255 | var info = transport.responseXML.getElementsByTagName("info-for-headlines")[0]; | |
2256 | ||
2257 | var elems = info.getElementsByTagName("entry"); | |
2258 | ||
2259 | for (var l = 0; l < elems.length; l++) { | |
2260 | var e_id = elems[l].getAttribute("id"); | |
2261 | ||
2262 | if (e_id) { | |
2263 | ||
acac8448 | 2264 | var ctr = $("HLLCTR-" + e_id); |
f9247195 AD |
2265 | |
2266 | if (ctr) { | |
2267 | ctr.innerHTML = elems[l].firstChild.nodeValue; | |
2268 | } | |
2269 | } | |
2270 | ||
2271 | } | |
2272 | ||
2273 | } | |
2274 | } catch (e) { | |
2275 | exception_error("show_labels_in_headlines", e); | |
2276 | ||
2277 | } | |
2278 | } | |
bf3c9838 AD |
2279 | |
2280 | function toggleHeadlineActions() { | |
2281 | try { | |
acac8448 AD |
2282 | var e = $("headlineActionsBody"); |
2283 | var p = $("headlineActionsDrop"); | |
bf3c9838 AD |
2284 | |
2285 | if (!Element.visible(e)) { | |
2286 | Element.show(e); | |
2287 | } else { | |
2288 | Element.hide(e); | |
2289 | } | |
2290 | ||
b62f6ff4 | 2291 | e.scrollTop = 0; |
bf3c9838 | 2292 | e.style.left = (p.offsetLeft + 1) + "px"; |
b4dc02e2 | 2293 | e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px"; |
bf3c9838 AD |
2294 | |
2295 | } catch (e) { | |
2296 | exception_error("toggleHeadlineActions", e); | |
2297 | } | |
2298 | } | |
c7e51de1 AD |
2299 | |
2300 | function publishWithNote(id, def_note) { | |
2301 | try { | |
2302 | if (!def_note) def_note = ''; | |
2303 | ||
2304 | var note = prompt(__("Please enter a note for this article:"), def_note); | |
2305 | ||
2306 | if (note != undefined) { | |
2307 | togglePub(id, false, false, note); | |
2308 | } | |
2309 | ||
2310 | } catch (e) { | |
2311 | exception_error("publishWithNote", e); | |
2312 | } | |
2313 | } | |
31a53903 AD |
2314 | |
2315 | function emailArticle(id) { | |
2316 | try { | |
f72a7b66 AD |
2317 | if (!id) { |
2318 | var ids = getSelectedArticleIds2(); | |
2319 | ||
2320 | if (ids.length == 0) { | |
2321 | alert(__("No articles are selected.")); | |
2322 | return; | |
2323 | } | |
2324 | ||
2325 | id = ids.toString(); | |
2326 | } | |
2327 | ||
31a53903 AD |
2328 | displayDlg('emailArticle', id, |
2329 | function () { | |
2330 | document.forms['article_email_form'].destination.focus(); | |
2331 | ||
2332 | new Ajax.Autocompleter('destination', 'destination_choices', | |
2333 | "backend.php?op=rpc&subop=completeEmails", | |
2334 | { tokens: '', paramName: "search" }); | |
2335 | ||
2336 | }); | |
2337 | ||
2338 | } catch (e) { | |
2339 | exception_error("emailArticle", e); | |
2340 | } | |
2341 | } | |
2342 | ||
f72a7b66 | 2343 | function emailArticleDo() { |
31a53903 AD |
2344 | try { |
2345 | var f = document.forms['article_email_form']; | |
2346 | ||
2347 | if (f.destination.value == "") { | |
2348 | alert("Please fill in the destination email."); | |
2349 | return; | |
2350 | } | |
2351 | ||
2352 | if (f.subject.value == "") { | |
2353 | alert("Please fill in the subject."); | |
2354 | return; | |
2355 | } | |
2356 | ||
2357 | var query = Form.serialize("article_email_form"); | |
2358 | ||
2359 | // console.log(query); | |
2360 | ||
2361 | new Ajax.Request("backend.php", { | |
2362 | parameters: query, | |
2363 | onComplete: function(transport) { | |
2364 | try { | |
2365 | ||
2366 | var error = transport.responseXML.getElementsByTagName('error')[0]; | |
2367 | ||
2368 | if (error) { | |
2369 | alert(__('Error sending email:') + ' ' + error.firstChild.nodeValue); | |
2370 | } else { | |
2371 | notify_info('Your message has been sent.'); | |
2372 | closeInfoBox(); | |
2373 | } | |
2374 | ||
2375 | } catch (e) { | |
2376 | exception_error("sendEmailDo", e); | |
2377 | } | |
2378 | ||
2379 | } }); | |
2380 | ||
2381 | } catch (e) { | |
2382 | exception_error("emailArticleDo", e); | |
2383 | } | |
2384 | } | |
dad14b51 AD |
2385 | |
2386 | function cdmDismissArticle(id) { | |
2387 | try { | |
2388 | var elem = $("RROW-" + id); | |
2389 | ||
2390 | toggleUnread(id, 0, true); | |
2391 | ||
2392 | new Effect.Fade(elem, {duration : 0.5}); | |
2393 | ||
2394 | } catch (e) { | |
2395 | exception_error("cdmDismissArticle", e); | |
2396 | } | |
2397 | } | |
bfa0e792 AD |
2398 | |
2399 | function cdmDismissSelectedArticles() { | |
2400 | try { | |
2401 | ||
2402 | var ids = getSelectedArticleIds2(); | |
2403 | ||
2404 | for (var i = 0; i < ids.length; i++) { | |
2405 | var elem = $("RROW-" + ids[i]); | |
2406 | new Effect.Fade(elem, {duration : 0.5}); | |
2407 | } | |
2408 | ||
2409 | if (ids.length > 0) | |
2410 | selectionToggleUnread(false); | |
2411 | ||
2412 | } catch (e) { | |
2413 | exception_error("cdmDismissArticle", e); | |
2414 | } | |
2415 | } |