]> git.wh0rd.org - tt-rss.git/blame - tt-rss.js
parse author tag like dc:creator
[tt-rss.git] / tt-rss.js
CommitLineData
1cd17194 1var xmlhttp = false;
76798ff3 2var total_unread = 0;
525116d4 3var first_run = true;
8143ae1f 4var display_tags = false;
806a3d14 5var global_unread = -1;
21703604 6var active_title_text = "";
21703604 7var current_subtitle = "";
c6784aea 8var daemon_enabled = false;
0d51e25d 9var daemon_refresh_only = false;
15da5cc1 10var _qfd_deleted_feed = 0;
2bf6e0a8 11var firsttime_update = true;
c441662f 12var last_refetch = 0;
76b4eae1 13var cookie_lifetime = 0;
33d13e72 14var active_feed_id = 0;
0a6c4846 15var active_feed_is_cat = false;
9e397d0f 16var number_of_feeds = 0;
15da5cc1 17
a58069db 18var xmlhttp = Ajax.getTransport();
abbe0154 19var xmlhttp_ctr = Ajax.getTransport();
1cd17194 20
1035fcec 21var init_params = new Object();
3ac2b520 22
8143ae1f
AD
23function toggleTags() {
24 display_tags = !display_tags;
25
26 var p = document.getElementById("dispSwitchPrompt");
27
28 if (display_tags) {
29 p.innerHTML = "display feeds";
30 } else {
31 p.innerHTML = "display tags";
32 }
33
807f452a
AD
34 notify("Loading, please wait...");
35
8143ae1f
AD
36 updateFeedList();
37}
38
6de5d056 39function dlg_frefresh_callback() {
abbe0154 40 if (xmlhttp.readyState == 4) {
a58d997c 41// notify(xmlhttp.responseText);
abbe0154
AD
42
43 if (getActiveFeedId() == _qfd_deleted_feed) {
44 var h = document.getElementById("headlines-frame");
45 if (h) {
46 h.innerHTML = "<div class='whiteBox'>No feed selected.</div>";
47 }
48 }
49
0e9dd1ba 50 setTimeout('updateFeedList(false, false)', 50);
eff4997c 51 closeInfoBox();
c0e5a40e 52 }
1cd17194 53}
e2f8f7b4 54
8158c57a 55function refetch_callback() {
abbe0154 56 if (xmlhttp_ctr.readyState == 4) {
7719618b 57 try {
310da49d 58
c441662f
AD
59 var date = new Date();
60
61 last_refetch = date.getTime() / 1000;
62
abbe0154 63 if (!xmlhttp_ctr.responseXML) {
0530ddd8 64 notify("refetch_callback: backend did not return valid XML", true, true);
7719618b
AD
65 return;
66 }
67
abbe0154 68 var reply = xmlhttp_ctr.responseXML.firstChild;
262bd8ea 69
7719618b 70 if (!reply) {
0530ddd8 71 notify("refetch_callback: backend did not return expected XML object", true, true);
e2cb4c6d 72 updateTitle("");
7719618b
AD
73 return;
74 }
262bd8ea 75
4724a093
AD
76 var error_code = false;
77 var error_msg = false;
78
79 if (reply.firstChild) {
80 error_code = reply.firstChild.getAttribute("error-code");
81 error_msg = reply.firstChild.getAttribute("error-msg");
82 }
83
84 if (!error_code) {
85 error_code = reply.getAttribute("error-code");
86 error_msg = reply.getAttribute("error-msg");
87 }
88
7719618b 89 if (error_code && error_code != 0) {
4724a093
AD
90 debug("refetch_callback: got error code " + error_code);
91 return fatalError(error_code, error_msg);
7719618b 92 }
f54f515f
AD
93
94 var counters = reply.firstChild;
7719618b 95
f54f515f 96 parse_counters(counters, true);
c6784aea 97
71ad883b
AD
98 var runtime_info = counters.nextSibling;
99
100 parse_runtime_info(runtime_info);
101
0ee1d1a0
AD
102 debug("refetch_callback: done");
103
0d51e25d 104 if (!daemon_enabled && !daemon_refresh_only) {
c6784aea 105 notify("All feeds updated.");
5a180505 106 updateTitle("");
4c059b7b
AD
107 } else {
108 notify("");
c6784aea 109 }
7719618b
AD
110 } catch (e) {
111 exception_error("refetch_callback", e);
e2cb4c6d 112 updateTitle("");
7719618b 113 }
090e250b
AD
114 }
115}
1a66d16e 116
295f9b42
AD
117function backend_sanity_check_callback() {
118
119 if (xmlhttp.readyState == 4) {
295f9b42 120
7719618b
AD
121 try {
122
123 if (!xmlhttp.responseXML) {
462a192b 124 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp.responseText);
7719618b
AD
125 return;
126 }
295f9b42 127
3ac2b520 128 var reply = xmlhttp.responseXML.firstChild.firstChild;
7719618b
AD
129
130 if (!reply) {
af106b0e 131 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp.responseText);
7719618b
AD
132 return;
133 }
134
135 var error_code = reply.getAttribute("error-code");
136
137 if (error_code && error_code != 0) {
af106b0e 138 return fatalError(error_code, reply.getAttribute("error-msg"));
7719618b
AD
139 }
140
0ee1d1a0
AD
141 debug("sanity check ok");
142
3ac2b520
AD
143 var params = reply.nextSibling;
144
145 if (params) {
146 debug('reading init-params...');
147 var param = params.firstChild;
148
149 while (param) {
150 var k = param.getAttribute("key");
151 var v = param.getAttribute("value");
152 debug(k + " => " + v);
153 init_params[k] = v;
154 param = param.nextSibling;
155 }
156 }
157
7719618b 158 init_second_stage();
295f9b42 159
7719618b
AD
160 } catch (e) {
161 exception_error("backend_sanity_check_callback", e);
162 }
295f9b42
AD
163 }
164}
165
cb246176 166function scheduleFeedUpdate(force) {
525116d4 167
0d51e25d 168 if (!daemon_enabled && !daemon_refresh_only) {
4d4200a8 169 notify("Updating feeds, please wait.", true);
c6784aea
AD
170 updateTitle("Updating");
171 }
55193822 172
cb246176
AD
173 var query_str = "backend.php?op=rpc&subop=";
174
175 if (force) {
c3b81db0 176 query_str = query_str + "forceUpdateAllFeeds";
cb246176 177 } else {
c3b81db0 178 query_str = query_str + "updateAllFeeds";
cb246176 179 }
525116d4 180
9826bd2e
AD
181 var omode;
182
b6104dee 183 if (firsttime_update && !navigator.userAgent.match("Opera")) {
2bf6e0a8
AD
184 firsttime_update = false;
185 omode = "T";
9826bd2e 186 } else {
2bf6e0a8
AD
187 if (display_tags) {
188 omode = "t";
189 } else {
190 omode = "flc";
191 }
9826bd2e 192 }
2bf6e0a8 193
9826bd2e 194 query_str = query_str + "&omode=" + omode;
78ea1de0 195 query_str = query_str + "&uctr=" + global_unread;
9826bd2e 196
0ee1d1a0 197 debug("in scheduleFeedUpdate");
2bf6e0a8 198
c441662f
AD
199 var date = new Date();
200
abbe0154 201 if (!xmlhttp_ready(xmlhttp_ctr) && last_refetch < date.getTime() / 1000 - 60) {
a7565293 202 debug("<b>xmlhttp seems to be stuck, aborting</b>");
abbe0154 203 xmlhttp_ctr.abort();
c441662f
AD
204 }
205
52db9978
AD
206 debug("REFETCH query: " + query_str);
207
abbe0154
AD
208 if (xmlhttp_ready(xmlhttp_ctr)) {
209 xmlhttp_ctr.open("GET", query_str, true);
210 xmlhttp_ctr.onreadystatechange=refetch_callback;
211 xmlhttp_ctr.send(null);
525116d4 212 } else {
abbe0154 213 debug("xmlhttp_ctr busy");
bed0f18f 214 //printLockingError();
c0e5a40e 215 }
525116d4 216}
1cd17194 217
525116d4 218function updateFeedList(silent, fetch) {
c0e5a40e 219
1a66d16e
AD
220// if (silent != true) {
221// notify("Loading feed list...");
222// }
82baad4a 223
331900c6
AD
224 var query_str = "backend.php?op=feeds";
225
8143ae1f
AD
226 if (display_tags) {
227 query_str = query_str + "&tags=1";
228 }
229
5c365f60 230 if (getActiveFeedId() && !activeFeedIsCat()) {
86741347 231 query_str = query_str + "&actid=" + getActiveFeedId();
175847de
AD
232 }
233
59b8192f
AD
234 if (navigator.userAgent.match("Opera")) {
235 var date = new Date();
236 var timestamp = Math.round(date.getTime() / 1000);
237 query_str = query_str + "&ts=" + timestamp
238 }
239
1a66d16e 240 if (fetch) query_str = query_str + "&fetch=yes";
e1123aee 241
6b4163cb
AD
242// var feeds_frame = document.getElementById("feeds-frame");
243// feeds_frame.src = query_str;
244
0e9dd1ba 245 debug("updateFeedList Q=" + query_str);
6b4163cb
AD
246
247 if (xmlhttp_ready(xmlhttp)) {
248 xmlhttp.open("GET", query_str, true);
249 xmlhttp.onreadystatechange=feedlist_callback;
250 xmlhttp.send(null);
251 } else {
252 debug("xmlhttp busy");
253 //printLockingError();
254 }
e1123aee 255
1a66d16e 256}
175847de 257
476cac42 258function catchupAllFeeds() {
076682aa 259
476cac42
AD
260 var query_str = "backend.php?op=feeds&subop=catchupAll";
261
262 notify("Marking all feeds as read...");
263
ca2f46a7 264 debug("catchupAllFeeds Q=" + query_str);
1a66d16e 265
ca2f46a7
AD
266 if (xmlhttp_ready(xmlhttp)) {
267 xmlhttp.open("GET", query_str, true);
268 xmlhttp.onreadystatechange=feedlist_callback;
269 xmlhttp.send(null);
270 } else {
271 debug("xmlhttp busy");
272 //printLockingError();
273 }
476cac42 274
fc69e641 275 global_unread = 0;
21703604 276 updateTitle("");
fc69e641 277
476cac42 278}
1cd17194 279
767e2486 280function viewCurrentFeed(subop) {
1a66d16e 281
ec6e2fd3
AD
282// if (getActiveFeedId()) {
283 if (getActiveFeedId() != undefined) {
767e2486 284 viewfeed(getActiveFeedId(), subop);
033e47e0
AD
285 } else {
286 disableContainerChildren("headlinesToolbar", false, document);
ec6e2fd3 287// viewfeed(-1, subop); // FIXME
f0601b87 288 }
164f4738 289 return false; // block unneeded form submits
f0601b87
AD
290}
291
767e2486 292function viewfeed(feed, subop) {
db8d6f67 293 var f = window.frames["feeds-frame"];
767e2486 294 f.viewfeed(feed, subop);
9cfc649a
AD
295}
296
40d13c28 297function timeout() {
05732aa0 298 scheduleFeedUpdate(false);
f5de0d8d 299
3ac2b520 300 var refresh_time = getInitParam("feeds_frame_refresh");
f5de0d8d 301
3ac2b520 302 if (!refresh_time) refresh_time = 600;
f5de0d8d
AD
303
304 setTimeout("timeout()", refresh_time*1000);
ac53063a
AD
305}
306
c374a3fe 307function resetSearch() {
64c620ce
AD
308 var searchbox = document.getElementById("searchbox")
309
86741347 310 if (searchbox.value != "" && getActiveFeedId()) {
64c620ce 311 searchbox.value = "";
767e2486 312 viewfeed(getActiveFeedId(), "");
ac43eba1 313 }
c374a3fe 314}
ac53063a 315
86b682ce
AD
316function searchCancel() {
317 closeInfoBox(true);
318}
319
f0601b87 320function search() {
eff4997c 321 closeInfoBox();
4ce19859 322 viewCurrentFeed(0, "");
76798ff3 323}
1cd17194 324
13ad9102
AD
325function localPiggieFunction(enable) {
326 if (enable) {
327 var query_str = "backend.php?op=feeds&subop=piggie";
328
c0e5a40e 329 if (xmlhttp_ready(xmlhttp)) {
13ad9102
AD
330
331 xmlhttp.open("GET", query_str, true);
332 xmlhttp.onreadystatechange=feedlist_callback;
333 xmlhttp.send(null);
334 }
335 }
336}
337
806a3d14
AD
338// if argument is undefined, current subtitle is not updated
339// use blank string to clear subtitle
fc69e641
AD
340function updateTitle(s) {
341 var tmp = "Tiny Tiny RSS";
21703604 342
5a494a0b 343 if (s != undefined) {
21703604
AD
344 current_subtitle = s;
345 }
346
fc69e641
AD
347 if (global_unread > 0) {
348 tmp = tmp + " (" + global_unread + ")";
349 }
350
5a494a0b 351 if (current_subtitle) {
21703604 352 tmp = tmp + " - " + current_subtitle;
fc69e641 353 }
21703604
AD
354
355 if (active_title_text.length > 0) {
356 tmp = tmp + " > " + active_title_text;
357 }
358
fc69e641
AD
359 document.title = tmp;
360}
361
22a93ad8 362function genericSanityCheck() {
ac43eba1 363
295f9b42
AD
364 if (!xmlhttp) fatalError(1);
365
366 setCookie("ttrss_vf_test", "TEST");
367
368 if (getCookie("ttrss_vf_test") != "TEST") {
369 fatalError(2);
370 }
371
22a93ad8
AD
372 return true;
373}
374
375function init() {
376
7719618b 377 try {
fe2f1970 378
97dcd654
AD
379 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
380
381 if (arguments.callee.done) return;
382 arguments.callee.done = true;
383
7719618b 384 disableContainerChildren("headlinesToolbar", true);
70830c87 385
86b682ce
AD
386 Form.disable("main_toolbar_form");
387
7719618b
AD
388 if (!genericSanityCheck())
389 return;
ac43eba1 390
0ee1d1a0
AD
391 if (getURLParam('debug')) {
392 document.getElementById('debug_output').style.display = 'block';
393 debug('debug mode activated');
394 }
395
7719618b
AD
396 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
397 xmlhttp.onreadystatechange=backend_sanity_check_callback;
398 xmlhttp.send(null);
47179952 399
7719618b
AD
400 } catch (e) {
401 exception_error("init", e);
a8d28f48 402 }
7719618b 403}
86741347 404
7719618b 405function init_second_stage() {
295f9b42 406
7719618b 407 try {
2f587484 408
76b4eae1
AD
409 cookie_lifetime = getCookie("ttrss_cltime");
410
411 delCookie("ttrss_vf_test");
7719618b 412
7719618b 413 document.onkeydown = hotkey_handler;
1b0809ae 414
f31673f7
AD
415 var tb = parent.document.forms["main_toolbar_form"];
416
9f10e152
AD
417// dropboxSelect(tb.view_mode, getInitParam("toolbar_view_mode"));
418// dropboxSelect(tb.limit, getInitParam("toolbar_limit"));
c6784aea 419
0d51e25d
AD
420 daemon_enabled = getInitParam("daemon_enabled") == 1;
421 daemon_refresh_only = getInitParam("daemon_refresh_only") == 1;
5f136c9a 422
0e9dd1ba 423 setTimeout('updateFeedList(false, false)', 50);
0ee1d1a0
AD
424
425 debug("second stage ok");
7719618b 426
7719618b
AD
427 } catch (e) {
428 exception_error("init_second_stage", e);
2f587484 429 }
1cd17194 430}
ac43eba1 431
c09ec856 432function quickMenuChange() {
cbe45fa8 433 var chooser = document.getElementById("quickMenuChooser");
86b682ce 434 var opid = chooser[chooser.selectedIndex].value;
e2f8f7b4 435
c09ec856
AD
436 chooser.selectedIndex = 0;
437 quickMenuGo(opid);
438}
439
440function quickMenuGo(opid) {
bb3423cf 441 try {
c09ec856 442
bb3423cf
AD
443 if (opid == "qmcPrefs") {
444 gotoPreferences();
445 }
446
447 if (opid == "qmcSearch") {
0a6c4846 448 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
6de5d056
AD
449 return;
450 }
bb3423cf
AD
451
452 if (opid == "qmcAddFeed") {
453 displayDlg("quickAddFeed");
454 return;
69668465 455 }
6de5d056 456
bb3423cf
AD
457 if (opid == "qmcRemoveFeed") {
458 var actid = getActiveFeedId();
459
5c365f60 460 if (!actid || activeFeedIsCat()) {
0530ddd8 461 alert("Please select some feed first.");
bb3423cf
AD
462 return;
463 }
64a2875d
AD
464
465 var fn = getFeedName(actid);
bb3423cf 466
64a2875d 467 if (confirm("Unsubscribe from " + fn + "?")) {
bb3423cf
AD
468 qfdDelete(actid);
469 }
470
471 return;
472 }
473
474 if (opid == "qmcUpdateFeeds") {
475 scheduleFeedUpdate(true);
476 return;
477 }
478
479 if (opid == "qmcCatchupAll") {
480 catchupAllFeeds();
481 return;
482 }
483
484 if (opid == "qmcShowOnlyUnread") {
485 toggleDispRead();
486 return;
487 }
488
489 if (opid == "qmcAddFilter") {
490 displayDlg("quickAddFilter", getActiveFeedId());
491 }
492 } catch (e) {
493 exception_error("quickMenuGo", e);
a24f525c 494 }
e2f8f7b4
AD
495}
496
6de5d056
AD
497function qfdDelete(feed_id) {
498
499 notify("Removing feed...");
500
7f123cda
AD
501 if (!xmlhttp_ready(xmlhttp)) {
502 printLockingError();
503 return
504 }
505
15da5cc1
AD
506 _qfd_deleted_feed = feed_id;
507
69668465 508 xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id);
6de5d056
AD
509 xmlhttp.onreadystatechange=dlg_frefresh_callback;
510 xmlhttp.send(null);
7bc4f251
AD
511
512 return false;
6de5d056 513}
033e47e0 514
3745788e 515
21703604
AD
516function updateFeedTitle(t) {
517 active_title_text = t;
518 updateTitle();
519}
520
3745788e 521function toggleDispRead() {
7f123cda 522 try {
3745788e 523
7f123cda
AD
524 if (!xmlhttp_ready(xmlhttp)) {
525 printLockingError();
526 return
527 }
3745788e 528
e8bd0da9 529 var hide_read_feeds = (getInitParam("hide_read_feeds") == "1");
3745788e 530
7f123cda 531 hide_read_feeds = !hide_read_feeds;
e8bd0da9
AD
532
533 debug("toggle_disp_read => " + hide_read_feeds);
534
535 hideOrShowFeeds(getFeedsContext().document, hide_read_feeds);
536
7f123cda
AD
537 var query = "backend.php?op=rpc&subop=setpref" +
538 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds);
3745788e 539
e8bd0da9
AD
540 storeInitParam("hide_read_feeds", hide_read_feeds, true);
541
542 new Ajax.Request(query);
7f123cda
AD
543
544 } catch (e) {
545 exception_error("toggleDispRead", e);
3745788e 546 }
3745788e 547}
295f9b42 548
71ad883b 549function parse_runtime_info(elem) {
4724a093
AD
550 if (!elem) {
551 debug("parse_runtime_info: elem is null, aborting");
552 return;
553 }
554
71ad883b
AD
555 var param = elem.firstChild;
556
52db9978 557 debug("parse_runtime_info: " + param);
1cb7492d 558
71ad883b
AD
559 while (param) {
560 var k = param.getAttribute("key");
561 var v = param.getAttribute("value");
3ac2b520 562
1cb7492d
AD
563 debug("RI: " + k + " => " + v);
564
71ad883b
AD
565 var w = document.getElementById("noDaemonWarning");
566
567 if (w) {
568 if (k == "daemon_is_running" && v != 1) {
569 w.style.display = "block";
570 } else {
571 w.style.display = "none";
572 }
573 }
574 param = param.nextSibling;
575 }
576}
fce24838
AD
577
578function catchupCurrentFeed() {
579
234e467c 580 var fn = getFeedName(getActiveFeedId(), active_feed_is_cat);
fce24838 581
234e467c
AD
582 var str = "Mark all articles in " + fn + " as read?";
583
584/* if (active_feed_is_cat) {
585 str = "Mark all articles in this category as read?";
586 } */
587
f6d6e22f 588 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
28de3732 589 return viewCurrentFeed('MarkAllRead')
fce24838
AD
590 }
591}
88040f57 592
461766f3
AD
593function userSwitch() {
594 var chooser = document.getElementById("userSwitch");
595 var user = chooser[chooser.selectedIndex].value;
596 window.location = "tt-rss.php?swu=" + user;
597}
6e6504bc
AD
598
599