]> git.wh0rd.org - tt-rss.git/blame - tt-rss.js
add purge_interval in ttrss_feeds (schema updated)
[tt-rss.git] / tt-rss.js
CommitLineData
1cd17194
AD
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
6var xmlhttp = false;
7
76798ff3 8var total_unread = 0;
525116d4 9var first_run = true;
76798ff3 10
c374a3fe 11var search_query = "";
52b51244 12var search_mode = "";
c374a3fe 13
8143ae1f 14var display_tags = false;
3745788e 15//var display_read_feeds = true;
8143ae1f 16
fc69e641
AD
17var global_unread = 0;
18
1cd17194
AD
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.
23try {
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
34if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
35 xmlhttp = new XMLHttpRequest();
36}
37
8143ae1f
AD
38function 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
6de5d056 52function dlg_frefresh_callback() {
1cd17194 53 if (xmlhttp.readyState == 4) {
e2f8f7b4 54 updateFeedList(false, false);
f84a97a3 55 closeDlg();
c0e5a40e 56 }
1cd17194 57}
e2f8f7b4 58
f84a97a3
AD
59function 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}
1a66d16e 67
8158c57a 68function refetch_callback() {
29fb8c70 69 if (xmlhttp.readyState == 4) {
310da49d 70
fc69e641 71// document.title = "Tiny Tiny RSS";
310da49d 72
bc18bcdd
AD
73 if (!xmlhttp.responseXML) {
74 notify("refetch_callback: backend did not return valid XML");
75 return;
76 }
77
090e250b
AD
78 var reply = xmlhttp.responseXML.firstChild;
79
bc18bcdd
AD
80 if (!reply) {
81 notify("refetch_callback: backend did not return expected XML object");
82 return;
9cab3250 83 }
bc18bcdd 84
090e250b
AD
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");
525116d4 90
090e250b
AD
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
fc69e641
AD
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
8143ae1f
AD
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", "");
090e250b 114 }
090e250b
AD
115 }
116 }
fc69e641
AD
117
118 updateTitle("");
119 notify("All feeds updated.");
120
090e250b
AD
121 }
122}
1a66d16e 123
caa4e57f
AD
124function updateFeed(feed_id) {
125
126 var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
127
29fb8c70
AD
128 if (xmlhttp_ready(xmlhttp)) {
129 xmlhttp.open("GET", query_str, true);
130 xmlhttp.onreadystatechange=feed_update_callback;
131 xmlhttp.send(null);
caa4e57f
AD
132 } else {
133 printLockingError();
134 }
135
136}
137
cb246176 138function scheduleFeedUpdate(force) {
525116d4
AD
139
140 notify("Updating feeds in background...");
141
fc69e641
AD
142// document.title = "Tiny Tiny RSS - Updating...";
143
144 updateTitle("Updating...");
55193822 145
cb246176
AD
146 var query_str = "backend.php?op=rpc&subop=";
147
148 if (force) {
c3b81db0 149 query_str = query_str + "forceUpdateAllFeeds";
cb246176 150 } else {
c3b81db0 151 query_str = query_str + "updateAllFeeds";
cb246176 152 }
525116d4 153
9826bd2e
AD
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
29fb8c70
AD
164 if (xmlhttp_ready(xmlhttp)) {
165 xmlhttp.open("GET", query_str, true);
166 xmlhttp.onreadystatechange=refetch_callback;
167 xmlhttp.send(null);
525116d4
AD
168 } else {
169 printLockingError();
c0e5a40e 170 }
525116d4 171}
1cd17194 172
525116d4 173function updateFeedList(silent, fetch) {
c0e5a40e 174
1a66d16e
AD
175// if (silent != true) {
176// notify("Loading feed list...");
177// }
82baad4a 178
331900c6
AD
179 var query_str = "backend.php?op=feeds";
180
8143ae1f
AD
181 if (display_tags) {
182 query_str = query_str + "&tags=1";
183 }
184
86741347
AD
185 if (getActiveFeedId()) {
186 query_str = query_str + "&actid=" + getActiveFeedId();
175847de
AD
187 }
188
1a66d16e 189 if (fetch) query_str = query_str + "&fetch=yes";
e1123aee 190
1a66d16e 191 var feeds_frame = document.getElementById("feeds-frame");
e1123aee 192
1a66d16e
AD
193 feeds_frame.src = query_str;
194}
175847de 195
476cac42 196function catchupAllFeeds() {
076682aa 197
476cac42
AD
198 var query_str = "backend.php?op=feeds&subop=catchupAll";
199
200 notify("Marking all feeds as read...");
201
1a66d16e
AD
202 var feeds_frame = document.getElementById("feeds-frame");
203
204 feeds_frame.src = query_str;
476cac42 205
fc69e641
AD
206 global_unread = 0;
207 updateTitle();
208
476cac42 209}
1cd17194 210
f0601b87 211function viewCurrentFeed(skip, subop) {
1a66d16e 212
86741347
AD
213 if (getActiveFeedId()) {
214 viewfeed(getActiveFeedId(), skip, subop);
033e47e0
AD
215 } else {
216 disableContainerChildren("headlinesToolbar", false, document);
217 viewfeed(-1, skip, subop); // FIXME
f0601b87
AD
218 }
219}
220
476cac42 221function viewfeed(feed, skip, subop) {
db8d6f67
AD
222 var f = window.frames["feeds-frame"];
223 f.viewfeed(feed, skip, subop);
9cfc649a
AD
224}
225
40d13c28 226function timeout() {
cb246176 227 scheduleFeedUpdate(true);
ac53063a 228 setTimeout("timeout()", 1800*1000);
ac53063a
AD
229}
230
c374a3fe 231function resetSearch() {
64c620ce
AD
232 var searchbox = document.getElementById("searchbox")
233
86741347 234 if (searchbox.value != "" && getActiveFeedId()) {
64c620ce 235 searchbox.value = "";
86741347 236 viewfeed(getActiveFeedId(), 0, "");
ac43eba1 237 }
c374a3fe 238}
ac53063a 239
f0601b87 240function search() {
4ce19859 241 viewCurrentFeed(0, "");
76798ff3 242}
1cd17194 243
13ad9102
AD
244function localPiggieFunction(enable) {
245 if (enable) {
246 var query_str = "backend.php?op=feeds&subop=piggie";
247
c0e5a40e 248 if (xmlhttp_ready(xmlhttp)) {
13ad9102
AD
249
250 xmlhttp.open("GET", query_str, true);
251 xmlhttp.onreadystatechange=feedlist_callback;
252 xmlhttp.send(null);
253 }
254 }
255}
256
9cfc649a
AD
257function localHotkeyHandler(keycode) {
258
f0601b87 259/* if (keycode == 78) {
c3a8d71a 260 return moveToPost('next');
9cfc649a
AD
261 }
262
263 if (keycode == 80) {
c3a8d71a 264 return moveToPost('prev');
f0601b87 265 } */
c3a8d71a 266
b623b3ed 267 if (keycode == 82) { // r
c3a8d71a
AD
268 return scheduleFeedUpdate(true);
269 }
270
b623b3ed
AD
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();
c3a8d71a
AD
279 }
280
281// notify("KC: " + keycode);
282
9cfc649a
AD
283}
284
fc69e641
AD
285function 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
22a93ad8 298function genericSanityCheck() {
ac43eba1 299
29fb8c70 300 if (!xmlhttp) {
c3a8d71a 301 document.getElementById("headlines").innerHTML =
29fb8c70 302 "<b>Fatal error:</b> This program requires XmlHttpRequest " +
c3a8d71a 303 "to function properly. Your browser doesn't seem to support it.";
22a93ad8
AD
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;
c3a8d71a
AD
315 }
316
22a93ad8
AD
317 return true;
318}
319
320function init() {
321
322 disableContainerChildren("headlinesToolbar", true);
323
324 if (!genericSanityCheck())
325 return;
326
fe2f1970
AD
327 setCookie("ttrss_vf_actfeed", "");
328
476cac42 329 updateFeedList(false, false);
13ad9102 330 document.onkeydown = hotkey_handler;
70830c87 331
77a1bf8b
AD
332 setTimeout("timeout()", 1800*1000);
333 scheduleFeedUpdate(true);
1a66d16e 334
70830c87 335 var content = document.getElementById("content");
ac43eba1 336
ac43eba1
AD
337 if (getCookie("ttrss_vf_vmode")) {
338 var viewbox = document.getElementById("viewbox");
339 viewbox.value = getCookie("ttrss_vf_vmode");
340 }
47179952 341
a8d28f48
AD
342 if (getCookie("ttrss_vf_limit")) {
343 var limitbox = document.getElementById("limitbox");
344 limitbox.value = getCookie("ttrss_vf_limit");
345 }
86741347
AD
346
347// if (getCookie("ttrss_vf_actfeed")) {
348// viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
349// }
350
1cd17194 351}
ac43eba1 352
e2f8f7b4 353function quickMenuGo() {
e2f8f7b4 354
cbe45fa8
AD
355 var chooser = document.getElementById("quickMenuChooser");
356 var opid = chooser[chooser.selectedIndex].id;
e2f8f7b4 357
cbe45fa8 358 if (opid == "qmcPrefs") {
e2f8f7b4
AD
359 gotoPreferences();
360 }
361
cbe45fa8 362 if (opid == "qmcAdvSearch") {
033e47e0
AD
363 displayDlg("search");
364 return;
365 }
366
cbe45fa8 367 if (opid == "qmcAddFeed") {
f84a97a3 368 displayDlg("quickAddFeed");
6de5d056
AD
369 return;
370 }
371
cbe45fa8 372 if (opid == "qmcRemoveFeed") {
6de5d056
AD
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;
e2f8f7b4 382 }
7a991cac 383
cbe45fa8 384 if (opid == "qmcUpdateFeeds") {
7a991cac
AD
385 scheduleFeedUpdate(true);
386 return;
387 }
388
cbe45fa8 389 if (opid == "qmcCatchupAll") {
7a991cac
AD
390 catchupAllFeeds();
391 return;
392 }
393
cbe45fa8 394 if (opid == "qmcShowOnlyUnread") {
7a991cac
AD
395 toggleDispRead();
396 return;
397 }
398
e2f8f7b4
AD
399}
400
401function qafAdd() {
ac43eba1 402
e2f8f7b4
AD
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);
6de5d056 421 xmlhttp.onreadystatechange=dlg_frefresh_callback;
e2f8f7b4
AD
422 xmlhttp.send(null);
423
424 link.value = "";
425
426 }
f84a97a3
AD
427}
428
6de5d056 429function displayDlg(id, param) {
e2f8f7b4 430
40d601c5
AD
431 notify("");
432
f84a97a3 433 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
6de5d056 434 param_escape(id) + "&param=" + param_escape(param), true);
f84a97a3
AD
435 xmlhttp.onreadystatechange=dialog_refresh_callback;
436 xmlhttp.send(null);
e2f8f7b4
AD
437
438}
f84a97a3
AD
439
440function closeDlg() {
441 var dlg = document.getElementById("userDlg");
442 dlg.style.display = "none";
443}
444
6de5d056
AD
445function 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);
6de5d056 455}
033e47e0 456
3745788e
AD
457
458function 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
cbe45fa8 473 if (opname == "Show only read") {
3745788e
AD
474 toggleDispRead();
475 return;
476 }
477
478}
479
480function 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}