]> git.wh0rd.org - tt-rss.git/blame_incremental - feedlist.js
rework editSelectedFeeds to use http POST
[tt-rss.git] / feedlist.js
... / ...
CommitLineData
1var _infscroll_disable = 0;
2var _infscroll_request_sent = 0;
3var _search_query = false;
4
5var counter_timeout_id = false;
6
7var counters_last_request = 0;
8
9function viewCategory(cat) {
10 viewfeed(cat, '', true);
11 return false;
12}
13
14function loadMoreHeadlines() {
15 try {
16 console.log("loadMoreHeadlines");
17
18 var offset = 0;
19
20 var view_mode = document.forms["main_toolbar_form"].view_mode.value;
21 var num_unread = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length;
22 var num_all = $$("#headlines-frame > div[id*=RROW]").length;
23
24 // TODO implement marked & published
25
26 if (view_mode == "marked") {
27 console.warn("loadMoreHeadlines: marked is not implemented, falling back.");
28 offset = num_all;
29 } else if (view_mode == "published") {
30 console.warn("loadMoreHeadlines: published is not implemented, falling back.");
31 offset = num_all;
32 } else if (view_mode == "unread") {
33 offset = num_unread;
34 } else if (view_mode == "adaptive") {
35 if (num_unread > 0)
36 offset = num_unread;
37 else
38 offset = num_all;
39 } else {
40 offset = num_all;
41 }
42
43 viewfeed(getActiveFeedId(), '', activeFeedIsCat(), offset, false, true);
44
45 } catch (e) {
46 exception_error("viewNextFeedPage", e);
47 }
48}
49
50
51function viewfeed(feed, subop, is_cat, offset, background, infscrol_req) {
52 try {
53 if (is_cat == undefined)
54 is_cat = false;
55 else
56 is_cat = !!is_cat;
57
58 if (subop == undefined) subop = '';
59 if (offset == undefined) offset = 0;
60 if (background == undefined) background = false;
61 if (infscrol_req == undefined) infscrol_req = false;
62
63 last_requested_article = 0;
64
65 var cached_headlines = false;
66
67 if (feed == getActiveFeedId())
68 cache_delete("feed:" + feed + ":" + is_cat);
69 else
70 cached_headlines = cache_get("feed:" + feed + ":" + is_cat);
71
72 if (offset == 0)
73 dijit.byId("content-tabs").selectChild(
74 dijit.byId("content-tabs").getChildren()[0]);
75
76 var force_nocache = false;
77
78 if (!background) {
79 if (getActiveFeedId() != feed || offset == 0) {
80 active_post_id = 0;
81 _infscroll_disable = 0;
82 }
83
84 if (!offset && !subop && cached_headlines && !background) {
85 try {
86 render_local_headlines(feed, is_cat, JSON.parse(cached_headlines));
87 return;
88 } catch (e) {
89 console.warn("render_local_headlines failed: " + e);
90 }
91 }
92
93 if (offset != 0 && !subop) {
94 var date = new Date();
95 var timestamp = Math.round(date.getTime() / 1000);
96
97 if (_infscroll_request_sent && _infscroll_request_sent + 30 > timestamp) {
98 //console.log("infscroll request in progress, aborting");
99 return;
100 }
101
102 _infscroll_request_sent = timestamp;
103 }
104
105 hideAuxDlg();
106 }
107
108 Form.enable("main_toolbar_form");
109
110 var toolbar_query = Form.serialize("main_toolbar_form");
111
112 var query = "?op=viewfeed&feed=" + feed + "&" +
113 toolbar_query + "&subop=" + param_escape(subop);
114
115 if (!background) {
116 if (_search_query) {
117 force_nocache = true;
118 query = query + "&" + _search_query;
119 _search_query = false;
120 }
121
122 if (subop == "MarkAllRead") {
123
124 var show_next_feed = getInitParam("on_catchup_show_next_feed") == "1";
125
126 if (show_next_feed) {
127 var nuf = getNextUnreadFeed(feed, is_cat);
128
129 if (nuf) {
130 var cached_nuf = cache_get("feed:" + nuf + ":false");
131
132 if (cached_nuf) {
133
134 render_local_headlines(nuf, false, JSON.parse(cached_nuf));
135
136 var catchup_query = "?op=rpc&subop=catchupFeed&feed_id=" +
137 feed + "&is_cat=" + is_cat;
138
139 console.log(catchup_query);
140
141 new Ajax.Request("backend.php", {
142 parameters: catchup_query,
143 onComplete: function(transport) {
144 handle_rpc_json(transport);
145 } });
146
147 return;
148 } else {
149 query += "&nuf=" + param_escape(nuf);
150 }
151 }
152 }
153 }
154
155 if (offset != 0) {
156 query = query + "&skip=" + offset;
157
158 // to prevent duplicate feed titles when showing grouped vfeeds
159 if (vgroup_last_feed) {
160 query = query + "&vgrlf=" + param_escape(vgroup_last_feed);
161 }
162 }
163
164 Form.enable("main_toolbar_form");
165
166 if (!offset)
167 if (!is_cat) {
168 if (!setFeedExpandoIcon(feed, is_cat, 'images/indicator_white.gif'))
169 notify_progress("Loading, please wait...", true);
170 } else {
171 notify_progress("Loading, please wait...", true);
172 }
173 }
174
175 query += "&cat=" + is_cat;
176
177 console.log(query);
178
179 new Ajax.Request("backend.php", {
180 parameters: query,
181 onComplete: function(transport) {
182 setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif');
183 headlines_callback2(transport, offset, background, infscrol_req);
184 } });
185
186 } catch (e) {
187 exception_error("viewfeed", e);
188 }
189}
190
191function feedlist_init() {
192 try {
193 console.log("in feedlist init");
194
195 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
196 document.onkeydown = hotkey_handler;
197 setTimeout("hotkey_prefix_timeout()", 5*1000);
198
199 if (!getActiveFeedId()) {
200 setTimeout("viewfeed(-3)", 100);
201 }
202
203 console.log("T:" +
204 getInitParam("cdm_auto_catchup") + " " + getFeedUnread(-3));
205
206 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
207
208 setTimeout("timeout()", 5000);
209 setTimeout("precache_headlines_idle()", 3000);
210
211 } catch (e) {
212 exception_error("feedlist/init", e);
213 }
214}
215
216function request_counters_real() {
217 try {
218 console.log("requesting counters...");
219
220 var query = "?op=rpc&subop=getAllCounters&seq=" + next_seq();
221
222 query = query + "&omode=flc";
223
224 new Ajax.Request("backend.php", {
225 parameters: query,
226 onComplete: function(transport) {
227 try {
228 handle_rpc_json(transport);
229 } catch (e) {
230 exception_error("viewfeed/getcounters", e);
231 }
232 } });
233
234 } catch (e) {
235 exception_error("request_counters_real", e);
236 }
237}
238
239
240function request_counters() {
241
242 try {
243
244 if (getInitParam("bw_limit") == "1") return;
245
246 var date = new Date();
247 var timestamp = Math.round(date.getTime() / 1000);
248
249 if (timestamp - counters_last_request > 5) {
250 console.log("scheduling request of counters...");
251
252 window.clearTimeout(counter_timeout_id);
253 counter_timeout_id = window.setTimeout("request_counters_real()", 1000);
254
255 counters_last_request = timestamp;
256 } else {
257 console.log("request_counters: rate limit reached: " + (timestamp - counters_last_request));
258 }
259
260 } catch (e) {
261 exception_error("request_counters", e);
262 }
263}
264
265function displayNewContentPrompt(id) {
266 try {
267
268 var msg = "<a href='#' onclick='viewCurrentFeed()'>" +
269 __("New articles available in this feed (click to show)") + "</a>";
270
271 msg = msg.replace("%s", getFeedName(id));
272
273 $('auxDlg').innerHTML = msg;
274
275 new Effect.Appear('auxDlg', {duration : 0.5});
276
277 } catch (e) {
278 exception_error("displayNewContentPrompt", e);
279 }
280}
281
282function parse_counters(elems, scheduled_call) {
283 try {
284
285 var feeds_found = 0;
286
287 for (var l = 0; l < elems.length; l++) {
288
289 var id = elems[l].id
290 var kind = elems[l].kind;
291 var ctr = parseInt(elems[l].counter)
292 var error = elems[l].error;
293 var has_img = elems[l].has_img;
294 var updated = elems[l].updated;
295 var title = elems[l].title;
296
297 if (id == "global-unread") {
298 global_unread = ctr;
299 updateTitle();
300 continue;
301 }
302
303 if (id == "subscribed-feeds") {
304 feeds_found = ctr;
305 continue;
306 }
307
308 var treeItem;
309
310 // TODO: enable new content notification for categories
311
312 if (!activeFeedIsCat() && id == getActiveFeedId()
313 && ctr > getFeedUnread(id) && scheduled_call) {
314 displayNewContentPrompt(id);
315 }
316
317 if (getFeedUnread(id, (kind == "cat")) != ctr)
318 cache_delete("feed:" + id + ":" + (kind == "cat"));
319
320 setFeedUnread(id, (kind == "cat"), ctr);
321
322 if (kind != "cat") {
323 setFeedValue(id, false, 'error', error);
324 setFeedValue(id, false, 'updated', updated);
325
326 if (id > 0) {
327 if (has_img) {
328 setFeedIcon(id, false,
329 getInitParam("icons_url") + "/" + id + ".ico");
330 } else {
331 setFeedIcon(id, false, 'images/blank_icon.gif');
332 }
333 }
334 }
335 }
336
337 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
338
339 } catch (e) {
340 exception_error("parse_counters", e);
341 }
342}
343
344function getFeedUnread(feed, is_cat) {
345 try {
346 var tree = dijit.byId("feedTree");
347
348 if (tree && tree.model)
349 return tree.model.getFeedUnread(feed, is_cat);
350
351 } catch (e) {
352 //
353 }
354
355 return -1;
356}
357
358function resort_feedlist() {
359 console.warn("resort_feedlist: function not implemented");
360}
361
362function hideOrShowFeeds(hide) {
363 var tree = dijit.byId("feedTree");
364
365 if (tree)
366 return tree.hideRead(hide, getInitParam("hide_read_shows_special"));
367}
368
369function getFeedName(feed, is_cat) {
370 var tree = dijit.byId("feedTree");
371
372 if (tree && tree.model)
373 return tree.model.getFeedValue(feed, is_cat, 'name');
374}
375
376function getFeedValue(feed, is_cat, key) {
377 try {
378 var tree = dijit.byId("feedTree");
379
380 if (tree && tree.model)
381 return tree.model.getFeedValue(feed, is_cat, key);
382
383 } catch (e) {
384 //
385 }
386 return '';
387}
388
389function setFeedUnread(feed, is_cat, unread) {
390 try {
391 var tree = dijit.byId("feedTree");
392
393 if (tree && tree.model)
394 return tree.model.setFeedUnread(feed, is_cat, unread);
395
396 } catch (e) {
397 exception_error("setFeedUnread", e);
398 }
399}
400
401function setFeedValue(feed, is_cat, key, value) {
402 try {
403 var tree = dijit.byId("feedTree");
404
405 if (tree && tree.model)
406 return tree.model.setFeedValue(feed, is_cat, key, value);
407
408 } catch (e) {
409 //
410 }
411}
412
413function selectFeed(feed, is_cat) {
414 try {
415 var tree = dijit.byId("feedTree");
416
417 if (tree) return tree.selectFeed(feed, is_cat);
418
419 } catch (e) {
420 exception_error("selectFeed", e);
421 }
422}
423
424function setFeedIcon(feed, is_cat, src) {
425 try {
426 var tree = dijit.byId("feedTree");
427
428 if (tree) return tree.setFeedIcon(feed, is_cat, src);
429
430 } catch (e) {
431 exception_error("setFeedIcon", e);
432 }
433}
434
435function setFeedExpandoIcon(feed, is_cat, src) {
436 try {
437 var tree = dijit.byId("feedTree");
438
439 if (tree) return tree.setFeedExpandoIcon(feed, is_cat, src);
440
441 } catch (e) {
442 exception_error("setFeedIcon", e);
443 }
444 return false;
445}
446
447function getNextUnreadFeed(feed, is_cat) {
448 try {
449 var tree = dijit.byId("feedTree");
450 var nuf = tree.model.getNextUnreadFeed(feed, is_cat);
451
452 if (nuf)
453 return tree.model.store.getValue(nuf, 'bare_id');
454
455 } catch (e) {
456 exception_error("getNextUnreadFeed", e);
457 }
458}
459