]> git.wh0rd.org - tt-rss.git/blob - tt-rss.js
add purge_interval in ttrss_feeds (schema updated)
[tt-rss.git] / tt-rss.js
1 /*
2 This program is Copyright (c) 2003-2005 Andrew Dolgov <cthulhoo@gmail.com>
3 Licensed under GPL v.2 or (at your preference) any later version.
4 */
5
6 var xmlhttp = false;
7
8 var total_unread = 0;
9 var first_run = true;
10
11 var search_query = "";
12 var search_mode = "";
13
14 var display_tags = false;
15 //var display_read_feeds = true;
16
17 var global_unread = 0;
18
19 /*@cc_on @*/
20 /*@if (@_jscript_version >= 5)
21 // JScript gives us Conditional compilation, we can cope with old IE versions.
22 // and security blocked creation of the objects.
23 try {
24 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
25 } catch (e) {
26 try {
27 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
28 } catch (E) {
29 xmlhttp = false;
30 }
31 }
32 @end @*/
33
34 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
35 xmlhttp = new XMLHttpRequest();
36 }
37
38 function toggleTags() {
39 display_tags = !display_tags;
40
41 var p = document.getElementById("dispSwitchPrompt");
42
43 if (display_tags) {
44 p.innerHTML = "display feeds";
45 } else {
46 p.innerHTML = "display tags";
47 }
48
49 updateFeedList();
50 }
51
52 function dlg_frefresh_callback() {
53 if (xmlhttp.readyState == 4) {
54 updateFeedList(false, false);
55 closeDlg();
56 }
57 }
58
59 function dialog_refresh_callback() {
60 if (xmlhttp.readyState == 4) {
61 var dlg = document.getElementById("userDlg");
62
63 dlg.innerHTML = xmlhttp.responseText;
64 dlg.style.display = "block";
65 }
66 }
67
68 function refetch_callback() {
69 if (xmlhttp.readyState == 4) {
70
71 // document.title = "Tiny Tiny RSS";
72
73 if (!xmlhttp.responseXML) {
74 notify("refetch_callback: backend did not return valid XML");
75 return;
76 }
77
78 var reply = xmlhttp.responseXML.firstChild;
79
80 if (!reply) {
81 notify("refetch_callback: backend did not return expected XML object");
82 return;
83 }
84
85 var f_document = window.frames["feeds-frame"].document;
86
87 for (var l = 0; l < reply.childNodes.length; l++) {
88 var id = reply.childNodes[l].getAttribute("id");
89 var ctr = reply.childNodes[l].getAttribute("counter");
90
91 var feedctr = f_document.getElementById("FEEDCTR-" + id);
92 var feedu = f_document.getElementById("FEEDU-" + id);
93 var feedr = f_document.getElementById("FEEDR-" + id);
94
95 /* TODO figure out how to update this from viewfeed.js->view()
96 disabled for now...
97
98 if (id == "global-unread") {
99 global_unread = ctr;
100 } */
101
102 if (feedctr && feedu && feedr) {
103
104 feedu.innerHTML = ctr;
105
106 if (ctr > 0) {
107 feedctr.className = "odd";
108 if (!feedr.className.match("Unread")) {
109 feedr.className = feedr.className + "Unread";
110 }
111 } else {
112 feedctr.className = "invisible";
113 feedr.className = feedr.className.replace("Unread", "");
114 }
115 }
116 }
117
118 updateTitle("");
119 notify("All feeds updated.");
120
121 }
122 }
123
124 function updateFeed(feed_id) {
125
126 var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
127
128 if (xmlhttp_ready(xmlhttp)) {
129 xmlhttp.open("GET", query_str, true);
130 xmlhttp.onreadystatechange=feed_update_callback;
131 xmlhttp.send(null);
132 } else {
133 printLockingError();
134 }
135
136 }
137
138 function scheduleFeedUpdate(force) {
139
140 notify("Updating feeds in background...");
141
142 // document.title = "Tiny Tiny RSS - Updating...";
143
144 updateTitle("Updating...");
145
146 var query_str = "backend.php?op=rpc&subop=";
147
148 if (force) {
149 query_str = query_str + "forceUpdateAllFeeds";
150 } else {
151 query_str = query_str + "updateAllFeeds";
152 }
153
154 var omode;
155
156 if (display_tags) {
157 omode = "t";
158 } else {
159 omode = "fl";
160 }
161
162 query_str = query_str + "&omode=" + omode;
163
164 if (xmlhttp_ready(xmlhttp)) {
165 xmlhttp.open("GET", query_str, true);
166 xmlhttp.onreadystatechange=refetch_callback;
167 xmlhttp.send(null);
168 } else {
169 printLockingError();
170 }
171 }
172
173 function updateFeedList(silent, fetch) {
174
175 // if (silent != true) {
176 // notify("Loading feed list...");
177 // }
178
179 var query_str = "backend.php?op=feeds";
180
181 if (display_tags) {
182 query_str = query_str + "&tags=1";
183 }
184
185 if (getActiveFeedId()) {
186 query_str = query_str + "&actid=" + getActiveFeedId();
187 }
188
189 if (fetch) query_str = query_str + "&fetch=yes";
190
191 var feeds_frame = document.getElementById("feeds-frame");
192
193 feeds_frame.src = query_str;
194 }
195
196 function catchupAllFeeds() {
197
198 var query_str = "backend.php?op=feeds&subop=catchupAll";
199
200 notify("Marking all feeds as read...");
201
202 var feeds_frame = document.getElementById("feeds-frame");
203
204 feeds_frame.src = query_str;
205
206 global_unread = 0;
207 updateTitle();
208
209 }
210
211 function viewCurrentFeed(skip, subop) {
212
213 if (getActiveFeedId()) {
214 viewfeed(getActiveFeedId(), skip, subop);
215 } else {
216 disableContainerChildren("headlinesToolbar", false, document);
217 viewfeed(-1, skip, subop); // FIXME
218 }
219 }
220
221 function viewfeed(feed, skip, subop) {
222 var f = window.frames["feeds-frame"];
223 f.viewfeed(feed, skip, subop);
224 }
225
226 function timeout() {
227 scheduleFeedUpdate(true);
228 setTimeout("timeout()", 1800*1000);
229 }
230
231 function resetSearch() {
232 var searchbox = document.getElementById("searchbox")
233
234 if (searchbox.value != "" && getActiveFeedId()) {
235 searchbox.value = "";
236 viewfeed(getActiveFeedId(), 0, "");
237 }
238 }
239
240 function search() {
241 viewCurrentFeed(0, "");
242 }
243
244 function localPiggieFunction(enable) {
245 if (enable) {
246 var query_str = "backend.php?op=feeds&subop=piggie";
247
248 if (xmlhttp_ready(xmlhttp)) {
249
250 xmlhttp.open("GET", query_str, true);
251 xmlhttp.onreadystatechange=feedlist_callback;
252 xmlhttp.send(null);
253 }
254 }
255 }
256
257 function localHotkeyHandler(keycode) {
258
259 /* if (keycode == 78) {
260 return moveToPost('next');
261 }
262
263 if (keycode == 80) {
264 return moveToPost('prev');
265 } */
266
267 if (keycode == 82) { // r
268 return scheduleFeedUpdate(true);
269 }
270
271 if (keycode == 85) { // u
272 if (getActiveFeedId()) {
273 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
274 }
275 }
276
277 if (keycode == 65) { // a
278 return toggleDispRead();
279 }
280
281 // notify("KC: " + keycode);
282
283 }
284
285 function updateTitle(s) {
286 var tmp = "Tiny Tiny RSS";
287
288 if (global_unread > 0) {
289 tmp = tmp + " (" + global_unread + ")";
290 }
291
292 if (s) {
293 tmp = tmp + " - " + s;
294 }
295 document.title = tmp;
296 }
297
298 function genericSanityCheck() {
299
300 if (!xmlhttp) {
301 document.getElementById("headlines").innerHTML =
302 "<b>Fatal error:</b> This program requires XmlHttpRequest " +
303 "to function properly. Your browser doesn't seem to support it.";
304 return false;
305 }
306
307 setCookie("ttrss_vf_test", "TEST");
308 if (getCookie("ttrss_vf_test") != "TEST") {
309
310 document.getElementById("headlines").innerHTML =
311 "<b>Fatal error:</b> This program requires cookies " +
312 "to function properly. Your browser doesn't seem to support them.";
313
314 return false;
315 }
316
317 return true;
318 }
319
320 function init() {
321
322 disableContainerChildren("headlinesToolbar", true);
323
324 if (!genericSanityCheck())
325 return;
326
327 setCookie("ttrss_vf_actfeed", "");
328
329 updateFeedList(false, false);
330 document.onkeydown = hotkey_handler;
331
332 setTimeout("timeout()", 1800*1000);
333 scheduleFeedUpdate(true);
334
335 var content = document.getElementById("content");
336
337 if (getCookie("ttrss_vf_vmode")) {
338 var viewbox = document.getElementById("viewbox");
339 viewbox.value = getCookie("ttrss_vf_vmode");
340 }
341
342 if (getCookie("ttrss_vf_limit")) {
343 var limitbox = document.getElementById("limitbox");
344 limitbox.value = getCookie("ttrss_vf_limit");
345 }
346
347 // if (getCookie("ttrss_vf_actfeed")) {
348 // viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
349 // }
350
351 }
352
353 function quickMenuGo() {
354
355 var chooser = document.getElementById("quickMenuChooser");
356 var opid = chooser[chooser.selectedIndex].id;
357
358 if (opid == "qmcPrefs") {
359 gotoPreferences();
360 }
361
362 if (opid == "qmcAdvSearch") {
363 displayDlg("search");
364 return;
365 }
366
367 if (opid == "qmcAddFeed") {
368 displayDlg("quickAddFeed");
369 return;
370 }
371
372 if (opid == "qmcRemoveFeed") {
373 var actid = getActiveFeedId();
374
375 if (!actid) {
376 notify("Please select some feed first.");
377 return;
378 }
379
380 displayDlg("quickDelFeed", actid);
381 return;
382 }
383
384 if (opid == "qmcUpdateFeeds") {
385 scheduleFeedUpdate(true);
386 return;
387 }
388
389 if (opid == "qmcCatchupAll") {
390 catchupAllFeeds();
391 return;
392 }
393
394 if (opid == "qmcShowOnlyUnread") {
395 toggleDispRead();
396 return;
397 }
398
399 }
400
401 function qafAdd() {
402
403 if (!xmlhttp_ready(xmlhttp)) {
404 printLockingError();
405 return
406 }
407
408 var link = document.getElementById("qafInput");
409
410 if (link.value.length == 0) {
411 notify("Missing feed URL.");
412 } else {
413 notify("Adding feed...");
414
415 var feeds_doc = window.frames["feeds-frame"].document;
416
417 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
418
419 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
420 param_escape(link.value), true);
421 xmlhttp.onreadystatechange=dlg_frefresh_callback;
422 xmlhttp.send(null);
423
424 link.value = "";
425
426 }
427 }
428
429 function displayDlg(id, param) {
430
431 notify("");
432
433 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
434 param_escape(id) + "&param=" + param_escape(param), true);
435 xmlhttp.onreadystatechange=dialog_refresh_callback;
436 xmlhttp.send(null);
437
438 }
439
440 function closeDlg() {
441 var dlg = document.getElementById("userDlg");
442 dlg.style.display = "none";
443 }
444
445 function qfdDelete(feed_id) {
446
447 notify("Removing feed...");
448
449 var feeds_doc = window.frames["feeds-frame"].document;
450 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
451
452 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids=" + feed_id);
453 xmlhttp.onreadystatechange=dlg_frefresh_callback;
454 xmlhttp.send(null);
455 }
456
457
458 function allFeedsMenuGo() {
459 var chooser = document.getElementById("allFeedsChooser");
460
461 var opname = chooser[chooser.selectedIndex].text;
462
463 if (opname == "Update") {
464 scheduleFeedUpdate(true);
465 return;
466 }
467
468 if (opname == "Mark as read") {
469 catchupAllFeeds();
470 return;
471 }
472
473 if (opname == "Show only read") {
474 toggleDispRead();
475 return;
476 }
477
478 }
479
480 function toggleDispRead() {
481 var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
482
483 hide_read_feeds = !hide_read_feeds;
484
485 var feeds_doc = window.frames["feeds-frame"].document;
486
487 hideOrShowFeeds(feeds_doc, hide_read_feeds);
488
489 if (hide_read_feeds) {
490 setCookie("ttrss_vf_hreadf", 1);
491 } else {
492 setCookie("ttrss_vf_hreadf", 0);
493 }
494
495 }