]> git.wh0rd.org - tt-rss.git/blame - tt-rss.js
add error.php
[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
295f9b42
AD
124function backend_sanity_check_callback() {
125
126 if (xmlhttp.readyState == 4) {
127
128 if (!xmlhttp.responseXML) {
129 fatalError(3);
130 return;
131 }
132
133 var reply = xmlhttp.responseXML.firstChild;
134
135 if (!reply) {
136 fatalError(3);
137 return;
138 }
139
140 var error_code = reply.getAttribute("code");
141
142 if (error_code && error_code != 0) {
143 return fatalError(error_code);
144 }
145
146 init_second_stage();
147 }
148}
149
caa4e57f
AD
150function updateFeed(feed_id) {
151
152 var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
153
29fb8c70
AD
154 if (xmlhttp_ready(xmlhttp)) {
155 xmlhttp.open("GET", query_str, true);
156 xmlhttp.onreadystatechange=feed_update_callback;
157 xmlhttp.send(null);
caa4e57f
AD
158 } else {
159 printLockingError();
160 }
161
162}
163
cb246176 164function scheduleFeedUpdate(force) {
525116d4
AD
165
166 notify("Updating feeds in background...");
167
fc69e641
AD
168// document.title = "Tiny Tiny RSS - Updating...";
169
170 updateTitle("Updating...");
55193822 171
cb246176
AD
172 var query_str = "backend.php?op=rpc&subop=";
173
174 if (force) {
c3b81db0 175 query_str = query_str + "forceUpdateAllFeeds";
cb246176 176 } else {
c3b81db0 177 query_str = query_str + "updateAllFeeds";
cb246176 178 }
525116d4 179
9826bd2e
AD
180 var omode;
181
182 if (display_tags) {
183 omode = "t";
184 } else {
185 omode = "fl";
186 }
187
188 query_str = query_str + "&omode=" + omode;
189
29fb8c70
AD
190 if (xmlhttp_ready(xmlhttp)) {
191 xmlhttp.open("GET", query_str, true);
192 xmlhttp.onreadystatechange=refetch_callback;
193 xmlhttp.send(null);
525116d4
AD
194 } else {
195 printLockingError();
c0e5a40e 196 }
525116d4 197}
1cd17194 198
525116d4 199function updateFeedList(silent, fetch) {
c0e5a40e 200
1a66d16e
AD
201// if (silent != true) {
202// notify("Loading feed list...");
203// }
82baad4a 204
331900c6
AD
205 var query_str = "backend.php?op=feeds";
206
8143ae1f
AD
207 if (display_tags) {
208 query_str = query_str + "&tags=1";
209 }
210
86741347
AD
211 if (getActiveFeedId()) {
212 query_str = query_str + "&actid=" + getActiveFeedId();
175847de
AD
213 }
214
1a66d16e 215 if (fetch) query_str = query_str + "&fetch=yes";
e1123aee 216
1a66d16e 217 var feeds_frame = document.getElementById("feeds-frame");
e1123aee 218
1a66d16e
AD
219 feeds_frame.src = query_str;
220}
175847de 221
476cac42 222function catchupAllFeeds() {
076682aa 223
476cac42
AD
224 var query_str = "backend.php?op=feeds&subop=catchupAll";
225
226 notify("Marking all feeds as read...");
227
1a66d16e
AD
228 var feeds_frame = document.getElementById("feeds-frame");
229
230 feeds_frame.src = query_str;
476cac42 231
fc69e641
AD
232 global_unread = 0;
233 updateTitle();
234
476cac42 235}
1cd17194 236
f0601b87 237function viewCurrentFeed(skip, subop) {
1a66d16e 238
86741347
AD
239 if (getActiveFeedId()) {
240 viewfeed(getActiveFeedId(), skip, subop);
033e47e0
AD
241 } else {
242 disableContainerChildren("headlinesToolbar", false, document);
243 viewfeed(-1, skip, subop); // FIXME
f0601b87
AD
244 }
245}
246
476cac42 247function viewfeed(feed, skip, subop) {
db8d6f67
AD
248 var f = window.frames["feeds-frame"];
249 f.viewfeed(feed, skip, subop);
9cfc649a
AD
250}
251
40d13c28 252function timeout() {
cb246176 253 scheduleFeedUpdate(true);
ac53063a 254 setTimeout("timeout()", 1800*1000);
ac53063a
AD
255}
256
c374a3fe 257function resetSearch() {
64c620ce
AD
258 var searchbox = document.getElementById("searchbox")
259
86741347 260 if (searchbox.value != "" && getActiveFeedId()) {
64c620ce 261 searchbox.value = "";
86741347 262 viewfeed(getActiveFeedId(), 0, "");
ac43eba1 263 }
c374a3fe 264}
ac53063a 265
f0601b87 266function search() {
4ce19859 267 viewCurrentFeed(0, "");
76798ff3 268}
1cd17194 269
13ad9102
AD
270function localPiggieFunction(enable) {
271 if (enable) {
272 var query_str = "backend.php?op=feeds&subop=piggie";
273
c0e5a40e 274 if (xmlhttp_ready(xmlhttp)) {
13ad9102
AD
275
276 xmlhttp.open("GET", query_str, true);
277 xmlhttp.onreadystatechange=feedlist_callback;
278 xmlhttp.send(null);
279 }
280 }
281}
282
9cfc649a
AD
283function localHotkeyHandler(keycode) {
284
f0601b87 285/* if (keycode == 78) {
c3a8d71a 286 return moveToPost('next');
9cfc649a
AD
287 }
288
289 if (keycode == 80) {
c3a8d71a 290 return moveToPost('prev');
f0601b87 291 } */
c3a8d71a 292
b623b3ed 293 if (keycode == 82) { // r
c3a8d71a
AD
294 return scheduleFeedUpdate(true);
295 }
296
b623b3ed
AD
297 if (keycode == 85) { // u
298 if (getActiveFeedId()) {
299 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
300 }
301 }
302
303 if (keycode == 65) { // a
304 return toggleDispRead();
c3a8d71a
AD
305 }
306
307// notify("KC: " + keycode);
308
9cfc649a
AD
309}
310
fc69e641
AD
311function updateTitle(s) {
312 var tmp = "Tiny Tiny RSS";
313
314 if (global_unread > 0) {
315 tmp = tmp + " (" + global_unread + ")";
316 }
317
318 if (s) {
319 tmp = tmp + " - " + s;
320 }
321 document.title = tmp;
322}
323
22a93ad8 324function genericSanityCheck() {
ac43eba1 325
295f9b42
AD
326 if (!xmlhttp) fatalError(1);
327
328 setCookie("ttrss_vf_test", "TEST");
329
330 if (getCookie("ttrss_vf_test") != "TEST") {
331 fatalError(2);
332 }
333
334/* if (!xmlhttp) {
c3a8d71a 335 document.getElementById("headlines").innerHTML =
29fb8c70 336 "<b>Fatal error:</b> This program requires XmlHttpRequest " +
c3a8d71a 337 "to function properly. Your browser doesn't seem to support it.";
22a93ad8
AD
338 return false;
339 }
340
341 setCookie("ttrss_vf_test", "TEST");
342 if (getCookie("ttrss_vf_test") != "TEST") {
343
344 document.getElementById("headlines").innerHTML =
345 "<b>Fatal error:</b> This program requires cookies " +
346 "to function properly. Your browser doesn't seem to support them.";
347
348 return false;
295f9b42 349 } */
c3a8d71a 350
22a93ad8
AD
351 return true;
352}
353
354function init() {
355
356 disableContainerChildren("headlinesToolbar", true);
357
358 if (!genericSanityCheck())
359 return;
360
295f9b42
AD
361 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
362 xmlhttp.onreadystatechange=backend_sanity_check_callback;
363 xmlhttp.send(null);
364
365}
366
367function init_second_stage() {
368
fe2f1970
AD
369 setCookie("ttrss_vf_actfeed", "");
370
476cac42 371 updateFeedList(false, false);
13ad9102 372 document.onkeydown = hotkey_handler;
70830c87
AD
373
374 var content = document.getElementById("content");
ac43eba1 375
ac43eba1
AD
376 if (getCookie("ttrss_vf_vmode")) {
377 var viewbox = document.getElementById("viewbox");
378 viewbox.value = getCookie("ttrss_vf_vmode");
379 }
47179952 380
a8d28f48
AD
381 if (getCookie("ttrss_vf_limit")) {
382 var limitbox = document.getElementById("limitbox");
383 limitbox.value = getCookie("ttrss_vf_limit");
384 }
86741347
AD
385
386// if (getCookie("ttrss_vf_actfeed")) {
387// viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
388// }
389
295f9b42
AD
390 setTimeout("timeout()", 2*1000);
391// scheduleFeedUpdate(true);
392
393
1cd17194 394}
ac43eba1 395
e2f8f7b4 396function quickMenuGo() {
e2f8f7b4 397
cbe45fa8
AD
398 var chooser = document.getElementById("quickMenuChooser");
399 var opid = chooser[chooser.selectedIndex].id;
e2f8f7b4 400
cbe45fa8 401 if (opid == "qmcPrefs") {
e2f8f7b4
AD
402 gotoPreferences();
403 }
404
cbe45fa8 405 if (opid == "qmcAdvSearch") {
033e47e0
AD
406 displayDlg("search");
407 return;
408 }
409
cbe45fa8 410 if (opid == "qmcAddFeed") {
f84a97a3 411 displayDlg("quickAddFeed");
6de5d056
AD
412 return;
413 }
414
cbe45fa8 415 if (opid == "qmcRemoveFeed") {
6de5d056
AD
416 var actid = getActiveFeedId();
417
418 if (!actid) {
419 notify("Please select some feed first.");
420 return;
421 }
422
423 displayDlg("quickDelFeed", actid);
424 return;
e2f8f7b4 425 }
7a991cac 426
cbe45fa8 427 if (opid == "qmcUpdateFeeds") {
7a991cac
AD
428 scheduleFeedUpdate(true);
429 return;
430 }
431
cbe45fa8 432 if (opid == "qmcCatchupAll") {
7a991cac
AD
433 catchupAllFeeds();
434 return;
435 }
436
cbe45fa8 437 if (opid == "qmcShowOnlyUnread") {
7a991cac
AD
438 toggleDispRead();
439 return;
440 }
441
e2f8f7b4
AD
442}
443
444function qafAdd() {
ac43eba1 445
e2f8f7b4
AD
446 if (!xmlhttp_ready(xmlhttp)) {
447 printLockingError();
448 return
449 }
450
451 var link = document.getElementById("qafInput");
452
453 if (link.value.length == 0) {
454 notify("Missing feed URL.");
455 } else {
456 notify("Adding feed...");
457
458 var feeds_doc = window.frames["feeds-frame"].document;
459
460 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
461
462 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
463 param_escape(link.value), true);
6de5d056 464 xmlhttp.onreadystatechange=dlg_frefresh_callback;
e2f8f7b4
AD
465 xmlhttp.send(null);
466
467 link.value = "";
468
469 }
f84a97a3
AD
470}
471
6de5d056 472function displayDlg(id, param) {
e2f8f7b4 473
40d601c5
AD
474 notify("");
475
f84a97a3 476 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
6de5d056 477 param_escape(id) + "&param=" + param_escape(param), true);
f84a97a3
AD
478 xmlhttp.onreadystatechange=dialog_refresh_callback;
479 xmlhttp.send(null);
e2f8f7b4
AD
480
481}
f84a97a3
AD
482
483function closeDlg() {
484 var dlg = document.getElementById("userDlg");
485 dlg.style.display = "none";
486}
487
6de5d056
AD
488function qfdDelete(feed_id) {
489
490 notify("Removing feed...");
491
492 var feeds_doc = window.frames["feeds-frame"].document;
493 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
494
495 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids=" + feed_id);
496 xmlhttp.onreadystatechange=dlg_frefresh_callback;
497 xmlhttp.send(null);
6de5d056 498}
033e47e0 499
3745788e
AD
500
501function allFeedsMenuGo() {
502 var chooser = document.getElementById("allFeedsChooser");
503
504 var opname = chooser[chooser.selectedIndex].text;
505
506 if (opname == "Update") {
507 scheduleFeedUpdate(true);
508 return;
509 }
510
511 if (opname == "Mark as read") {
512 catchupAllFeeds();
513 return;
514 }
515
cbe45fa8 516 if (opname == "Show only read") {
3745788e
AD
517 toggleDispRead();
518 return;
519 }
520
521}
522
523function toggleDispRead() {
524 var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
525
526 hide_read_feeds = !hide_read_feeds;
527
528 var feeds_doc = window.frames["feeds-frame"].document;
529
530 hideOrShowFeeds(feeds_doc, hide_read_feeds);
531
532 if (hide_read_feeds) {
533 setCookie("ttrss_vf_hreadf", 1);
534 } else {
535 setCookie("ttrss_vf_hreadf", 0);
536 }
537
538}
295f9b42
AD
539
540