]> git.wh0rd.org - tt-rss.git/blob - tt-rss.js
cleanup title even if refetch_callback failed
[tt-rss.git] / tt-rss.js
1 var xmlhttp = false;
2 var total_unread = 0;
3 var first_run = true;
4 var display_tags = false;
5 var global_unread = -1;
6 var active_title_text = "";
7 var current_subtitle = "";
8
9 var _qfd_deleted_feed = 0;
10
11 /*@cc_on @*/
12 /*@if (@_jscript_version >= 5)
13 // JScript gives us Conditional compilation, we can cope with old IE versions.
14 // and security blocked creation of the objects.
15 try {
16 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
17 } catch (e) {
18 try {
19 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
20 } catch (E) {
21 xmlhttp = false;
22 }
23 }
24 @end @*/
25
26 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
27 xmlhttp = new XMLHttpRequest();
28 }
29
30 function toggleTags() {
31 display_tags = !display_tags;
32
33 var p = document.getElementById("dispSwitchPrompt");
34
35 if (display_tags) {
36 p.innerHTML = "display feeds";
37 } else {
38 p.innerHTML = "display tags";
39 }
40
41 updateFeedList();
42 }
43
44 function dlg_frefresh_callback() {
45 if (xmlhttp.readyState == 4) {
46 notify(xmlhttp.responseText);
47 updateFeedList(false, false);
48 if (_qfd_deleted_feed) {
49 var hframe = document.getElementById("headlines-frame");
50 if (hframe) {
51 hframe.src = "backend.php?op=error&msg=No%20feed%20selected.";
52 }
53 }
54 closeDlg();
55 }
56 }
57
58 function dlg_submit_callback() {
59 if (xmlhttp.readyState == 4) {
60 notify(xmlhttp.responseText);
61 closeDlg();
62 }
63 }
64
65 function dlg_display_callback() {
66 if (xmlhttp.readyState == 4) {
67 var dlg = document.getElementById("userDlg");
68 var dlg_s = document.getElementById("userDlgShadow");
69
70 dlg.innerHTML = xmlhttp.responseText;
71 dlg_s.style.display = "block";
72 }
73 }
74
75 function hide_unread_callback() {
76 if (xmlhttp.readyState == 4) {
77
78 try {
79
80 var reply = xmlhttp.responseXML.firstChild.firstChild;
81 var value = reply.getAttribute("value");
82 var hide_read_feeds = (value != "false")
83 var feeds_doc = window.frames["feeds-frame"].document;
84
85 hideOrShowFeeds(feeds_doc, hide_read_feeds);
86
87 if (hide_read_feeds) {
88 setCookie("ttrss_vf_hreadf", 1);
89 } else {
90 setCookie("ttrss_vf_hreadf", 0);
91 }
92
93 } catch (e) {
94 exception_error("hide_unread_callback", e);
95 }
96
97 }
98 }
99
100 function refetch_callback() {
101 if (xmlhttp.readyState == 4) {
102 try {
103
104 if (!xmlhttp.responseXML) {
105 notify("refetch_callback: backend did not return valid XML");
106 return;
107 }
108
109 var reply = xmlhttp.responseXML.firstChild;
110
111 if (!reply) {
112 notify("refetch_callback: backend did not return expected XML object");
113 updateTitle("");
114 return;
115 }
116
117 var error_code = reply.getAttribute("error-code");
118
119 if (error_code && error_code != 0) {
120 return fatalError(error_code);
121 }
122
123 var f_document = window.frames["feeds-frame"].document;
124
125 parse_counters(reply, f_document, window);
126
127 updateTitle("");
128 notify("All feeds updated.");
129 } catch (e) {
130 exception_error("refetch_callback", e);
131 updateTitle("");
132 }
133 }
134 }
135
136 function backend_sanity_check_callback() {
137
138 if (xmlhttp.readyState == 4) {
139
140 try {
141
142 if (!xmlhttp.responseXML) {
143 fatalError(3);
144 return;
145 }
146
147 var reply = xmlhttp.responseXML.firstChild;
148
149 if (!reply) {
150 fatalError(3);
151 return;
152 }
153
154 var error_code = reply.getAttribute("error-code");
155
156 if (error_code && error_code != 0) {
157 return fatalError(error_code);
158 }
159
160 init_second_stage();
161
162 } catch (e) {
163 exception_error("backend_sanity_check_callback", e);
164 }
165 }
166 }
167
168 function scheduleFeedUpdate(force) {
169
170 notify("Updating feeds, please wait.");
171
172 // document.title = "Tiny Tiny RSS - Updating...";
173
174 updateTitle("Updating");
175
176 var query_str = "backend.php?op=rpc&subop=";
177
178 if (force) {
179 query_str = query_str + "forceUpdateAllFeeds";
180 } else {
181 query_str = query_str + "updateAllFeeds";
182 }
183
184 var omode;
185
186 if (display_tags) {
187 omode = "t";
188 } else {
189 omode = "fl";
190 }
191
192 query_str = query_str + "&omode=" + omode;
193
194 if (xmlhttp_ready(xmlhttp)) {
195 xmlhttp.open("GET", query_str, true);
196 xmlhttp.onreadystatechange=refetch_callback;
197 xmlhttp.send(null);
198 } else {
199 printLockingError();
200 }
201 }
202
203 function updateFeedList(silent, fetch) {
204
205 // if (silent != true) {
206 // notify("Loading feed list...");
207 // }
208
209 var query_str = "backend.php?op=feeds";
210
211 if (display_tags) {
212 query_str = query_str + "&tags=1";
213 }
214
215 if (getActiveFeedId()) {
216 query_str = query_str + "&actid=" + getActiveFeedId();
217 }
218
219 if (fetch) query_str = query_str + "&fetch=yes";
220
221 var feeds_frame = document.getElementById("feeds-frame");
222
223 feeds_frame.src = query_str;
224 }
225
226 function catchupAllFeeds() {
227
228 var query_str = "backend.php?op=feeds&subop=catchupAll";
229
230 notify("Marking all feeds as read...");
231
232 var feeds_frame = document.getElementById("feeds-frame");
233
234 feeds_frame.src = query_str;
235
236 global_unread = 0;
237 updateTitle("");
238
239 }
240
241 function viewCurrentFeed(skip, subop) {
242
243 if (getActiveFeedId()) {
244 viewfeed(getActiveFeedId(), skip, subop);
245 } else {
246 disableContainerChildren("headlinesToolbar", false, document);
247 viewfeed(-1, skip, subop); // FIXME
248 }
249 }
250
251 function viewfeed(feed, skip, subop) {
252 var f = window.frames["feeds-frame"];
253 f.viewfeed(feed, skip, subop);
254 }
255
256 function timeout() {
257 scheduleFeedUpdate(false);
258
259 var refresh_time = getCookie('ttrss_vf_refresh');
260
261 if (!refresh_time) refresh_time = 600;
262
263 setTimeout("timeout()", refresh_time*1000);
264 }
265
266 function resetSearch() {
267 var searchbox = document.getElementById("searchbox")
268
269 if (searchbox.value != "" && getActiveFeedId()) {
270 searchbox.value = "";
271 viewfeed(getActiveFeedId(), 0, "");
272 }
273 }
274
275 function search() {
276 closeDlg();
277 viewCurrentFeed(0, "");
278 }
279
280 function localPiggieFunction(enable) {
281 if (enable) {
282 var query_str = "backend.php?op=feeds&subop=piggie";
283
284 if (xmlhttp_ready(xmlhttp)) {
285
286 xmlhttp.open("GET", query_str, true);
287 xmlhttp.onreadystatechange=feedlist_callback;
288 xmlhttp.send(null);
289 }
290 }
291 }
292
293 function localHotkeyHandler(keycode) {
294
295 /* if (keycode == 78) {
296 return moveToPost('next');
297 }
298
299 if (keycode == 80) {
300 return moveToPost('prev');
301 } */
302
303 if (keycode == 82) { // r
304 return scheduleFeedUpdate(true);
305 }
306
307 if (keycode == 85) { // u
308 if (getActiveFeedId()) {
309 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
310 }
311 }
312
313 if (keycode == 65) { // a
314 return toggleDispRead();
315 }
316
317 var f_doc = window.frames["feeds-frame"].document;
318 var feedlist = f_doc.getElementById('feedList');
319
320 if (keycode == 74) { // j
321 var feed = getActiveFeedId();
322 var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
323 if (new_feed) viewfeed(new_feed, 0, '');
324 }
325
326 if (keycode == 75) { // k
327 var feed = getActiveFeedId();
328 var new_feed = getRelativeFeedId(feedlist, feed, 'next');
329 if (new_feed) viewfeed(new_feed, 0, '');
330 }
331
332 // notify("KC: " + keycode);
333
334 }
335
336 // if argument is undefined, current subtitle is not updated
337 // use blank string to clear subtitle
338 function updateTitle(s) {
339 var tmp = "Tiny Tiny RSS";
340
341 if (s && s.length > 0) {
342 current_subtitle = s;
343 }
344
345 if (global_unread > 0) {
346 tmp = tmp + " (" + global_unread + ")";
347 }
348
349 if (s) {
350 tmp = tmp + " - " + current_subtitle;
351 }
352
353 if (active_title_text.length > 0) {
354 tmp = tmp + " > " + active_title_text;
355 }
356
357 document.title = tmp;
358 }
359
360 function genericSanityCheck() {
361
362 if (!xmlhttp) fatalError(1);
363
364 setCookie("ttrss_vf_test", "TEST");
365
366 if (getCookie("ttrss_vf_test") != "TEST") {
367 fatalError(2);
368 }
369
370 return true;
371 }
372
373 function init() {
374
375 try {
376
377 disableContainerChildren("headlinesToolbar", true);
378
379 if (!genericSanityCheck())
380 return;
381
382 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
383 xmlhttp.onreadystatechange=backend_sanity_check_callback;
384 xmlhttp.send(null);
385
386 } catch (e) {
387 exception_error("init", e);
388 }
389 }
390
391 function init_second_stage() {
392
393 try {
394
395 setCookie("ttrss_vf_actfeed", "");
396
397 updateFeedList(false, false);
398 document.onkeydown = hotkey_handler;
399
400 var viewbox = document.getElementById("viewbox");
401 var limitbox = document.getElementById("limitbox");
402
403 dropboxSelect(viewbox, getCookie("ttrss_vf_vmode"));
404 dropboxSelect(limitbox, getCookie("ttrss_vf_limit"));
405
406 } catch (e) {
407 exception_error("init_second_stage", e);
408 }
409 }
410
411 function quickMenuChange() {
412 var chooser = document.getElementById("quickMenuChooser");
413 var opid = chooser[chooser.selectedIndex].id;
414
415 chooser.selectedIndex = 0;
416 quickMenuGo(opid);
417 }
418
419 function quickMenuGo(opid) {
420
421
422 if (opid == "qmcPrefs") {
423 gotoPreferences();
424 }
425
426 if (opid == "qmcSearch") {
427 displayDlg("search", getActiveFeedId());
428 return;
429 }
430
431 if (opid == "qmcAddFeed") {
432 displayDlg("quickAddFeed");
433 return;
434 }
435
436 if (opid == "qmcRemoveFeed") {
437 var actid = getActiveFeedId();
438
439 if (!actid) {
440 notify("Please select some feed first.");
441 return;
442 }
443
444 if (confirm("Remove current feed?")) {
445 qfdDelete(actid);
446 }
447
448 return;
449 }
450
451 if (opid == "qmcUpdateFeeds") {
452 scheduleFeedUpdate(true);
453 return;
454 }
455
456 if (opid == "qmcCatchupAll") {
457 catchupAllFeeds();
458 return;
459 }
460
461 if (opid == "qmcShowOnlyUnread") {
462 toggleDispRead();
463 return;
464 }
465
466 if (opid == "qmcAddFilter") {
467 displayDlg("quickAddFilter", getActiveFeedId());
468 }
469
470 }
471
472 function qafAdd() {
473
474 if (!xmlhttp_ready(xmlhttp)) {
475 printLockingError();
476 return
477 }
478
479 var link = document.getElementById("qafInput");
480
481 if (link.value.length == 0) {
482 notify("Missing feed URL.");
483 } else {
484 notify("Adding feed...");
485
486 var cat = document.getElementById("qafCat");
487 var cat_id = "";
488
489 if (cat) {
490 cat_id = cat[cat.selectedIndex].id;
491 } else {
492 cat_id = 0;
493 }
494
495 var feeds_doc = window.frames["feeds-frame"].document;
496
497 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
498
499 xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=add&link=" +
500 param_escape(link.value) + "&cid=" + param_escape(cat_id), true);
501 xmlhttp.onreadystatechange=dlg_frefresh_callback;
502 xmlhttp.send(null);
503
504 link.value = "";
505
506 }
507 }
508
509 function qaddFilter() {
510
511 if (!xmlhttp_ready(xmlhttp)) {
512 printLockingError();
513 return
514 }
515
516 var regexp = document.getElementById("fadd_regexp");
517 var match = document.getElementById("fadd_match");
518 var feed = document.getElementById("fadd_feed");
519 var action = document.getElementById("fadd_action");
520
521 if (regexp.value.length == 0) {
522 notify("Missing filter expression.");
523 } else {
524 notify("Adding filter...");
525
526 var v_match = match[match.selectedIndex].text;
527 var feed_id = feed[feed.selectedIndex].id;
528 var action_id = action[action.selectedIndex].id;
529
530 xmlhttp.open("GET", "backend.php?op=pref-filters&quiet=1&subop=add&regexp=" +
531 param_escape(regexp.value) + "&match=" + v_match +
532 "&fid=" + param_escape(feed_id) + "&aid=" + param_escape(action_id), true);
533
534 xmlhttp.onreadystatechange=dlg_submit_callback;
535 xmlhttp.send(null);
536
537 regexp.value = "";
538 }
539
540 }
541
542
543 function displayDlg(id, param) {
544
545 if (!xmlhttp_ready(xmlhttp)) {
546 printLockingError();
547 return
548 }
549
550 notify("");
551
552 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
553 param_escape(id) + "&param=" + param_escape(param), true);
554 xmlhttp.onreadystatechange=dlg_display_callback;
555 xmlhttp.send(null);
556
557 disableHotkeys();
558 }
559
560 function closeDlg() {
561 var dlg = document.getElementById("userDlgShadow");
562 dlg.style.display = "none";
563 enableHotkeys();
564 }
565
566 function qfdDelete(feed_id) {
567
568 notify("Removing feed...");
569
570 if (!xmlhttp_ready(xmlhttp)) {
571 printLockingError();
572 return
573 }
574
575 // var feeds_doc = window.frames["feeds-frame"].document;
576 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
577
578 _qfd_deleted_feed = feed_id;
579
580 xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id);
581 xmlhttp.onreadystatechange=dlg_frefresh_callback;
582 xmlhttp.send(null);
583 }
584
585
586 function allFeedsMenuChange() {
587 var chooser = document.getElementById("allFeedsChooser");
588
589 var opname = chooser[chooser.selectedIndex].text;
590
591 chooser.selectedIndex = 0;
592
593 if (opname == "Update") {
594 scheduleFeedUpdate(true);
595 return;
596 }
597
598 if (opname == "Mark as read") {
599 catchupAllFeeds();
600 return;
601 }
602
603 if (opname == "Show only unread") {
604 toggleDispRead();
605 return;
606 }
607
608 }
609
610 function updateFeedTitle(t) {
611 active_title_text = t;
612 updateTitle();
613 }
614
615 function toggleDispRead() {
616 try {
617
618 if (!xmlhttp_ready(xmlhttp)) {
619 printLockingError();
620 return
621 }
622
623 var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
624
625 hide_read_feeds = !hide_read_feeds;
626
627 var query = "backend.php?op=rpc&subop=setpref" +
628 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds);
629
630 xmlhttp.open("GET", query);
631 xmlhttp.onreadystatechange=hide_unread_callback;
632 xmlhttp.send(null);
633
634 } catch (e) {
635 exception_error("toggleDispRead", e);
636 }
637 }
638