]> git.wh0rd.org - tt-rss.git/blame - tt-rss.js
option MAIL_RESET_PASS (closes #11)
[tt-rss.git] / tt-rss.js
CommitLineData
1cd17194
AD
1var xmlhttp = false;
2
76798ff3 3var total_unread = 0;
525116d4 4var first_run = true;
76798ff3 5
8143ae1f
AD
6var display_tags = false;
7
806a3d14 8var global_unread = -1;
fc69e641 9
21703604
AD
10var active_title_text = "";
11
12var current_subtitle = "";
13
1cd17194
AD
14/*@cc_on @*/
15/*@if (@_jscript_version >= 5)
16// JScript gives us Conditional compilation, we can cope with old IE versions.
17// and security blocked creation of the objects.
18try {
19 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
20} catch (e) {
21 try {
22 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
23 } catch (E) {
24 xmlhttp = false;
25 }
26}
27@end @*/
28
29if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
30 xmlhttp = new XMLHttpRequest();
31}
32
8143ae1f
AD
33function toggleTags() {
34 display_tags = !display_tags;
35
36 var p = document.getElementById("dispSwitchPrompt");
37
38 if (display_tags) {
39 p.innerHTML = "display feeds";
40 } else {
41 p.innerHTML = "display tags";
42 }
43
44 updateFeedList();
45}
46
6de5d056 47function dlg_frefresh_callback() {
1cd17194 48 if (xmlhttp.readyState == 4) {
a24f525c 49 notify(xmlhttp.responseText);
e2f8f7b4 50 updateFeedList(false, false);
f84a97a3 51 closeDlg();
c0e5a40e 52 }
1cd17194 53}
e2f8f7b4 54
a24f525c
AD
55function dlg_submit_callback() {
56 if (xmlhttp.readyState == 4) {
57 notify(xmlhttp.responseText);
58 closeDlg();
59 }
60}
61
62function dlg_display_callback() {
f84a97a3
AD
63 if (xmlhttp.readyState == 4) {
64 var dlg = document.getElementById("userDlg");
76332f3c 65 var dlg_s = document.getElementById("userDlgShadow");
f84a97a3
AD
66
67 dlg.innerHTML = xmlhttp.responseText;
76332f3c 68 dlg_s.style.display = "block";
f84a97a3
AD
69 }
70}
1a66d16e 71
8158c57a 72function refetch_callback() {
29fb8c70 73 if (xmlhttp.readyState == 4) {
7719618b 74 try {
310da49d 75
7719618b
AD
76 if (!xmlhttp.responseXML) {
77 notify("refetch_callback: backend did not return valid XML");
78 return;
79 }
80
81 var reply = xmlhttp.responseXML.firstChild;
262bd8ea 82
7719618b
AD
83 if (!reply) {
84 notify("refetch_callback: backend did not return expected XML object");
85 return;
86 }
262bd8ea 87
7719618b
AD
88 var error_code = reply.getAttribute("error-code");
89
90 if (error_code && error_code != 0) {
91 return fatalError(error_code);
92 }
93
94 var f_document = window.frames["feeds-frame"].document;
1a6a9555
AD
95
96 parse_counters(reply, f_document);
7719618b
AD
97
98 updateTitle("");
99 notify("All feeds updated.");
100 } catch (e) {
101 exception_error("refetch_callback", e);
102 }
090e250b
AD
103 }
104}
1a66d16e 105
295f9b42
AD
106function backend_sanity_check_callback() {
107
108 if (xmlhttp.readyState == 4) {
295f9b42 109
7719618b
AD
110 try {
111
112 if (!xmlhttp.responseXML) {
113 fatalError(3);
114 return;
115 }
295f9b42 116
7719618b
AD
117 var reply = xmlhttp.responseXML.firstChild;
118
119 if (!reply) {
120 fatalError(3);
121 return;
122 }
123
124 var error_code = reply.getAttribute("error-code");
125
126 if (error_code && error_code != 0) {
127 return fatalError(error_code);
128 }
129
130 init_second_stage();
295f9b42 131
7719618b
AD
132 } catch (e) {
133 exception_error("backend_sanity_check_callback", e);
134 }
295f9b42
AD
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
21703604 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 206 global_unread = 0;
21703604 207 updateTitle("");
fc69e641 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() {
05732aa0 227 scheduleFeedUpdate(false);
d2afdfa0 228 setTimeout("timeout()", 900*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
7b433d8c
AD
281 var f_doc = window.frames["feeds-frame"].document;
282 var feedlist = f_doc.getElementById('feedList');
283
284 if (keycode == 74) { // j
285 var feed = getActiveFeedId();
286 var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
287 if (new_feed) viewfeed(new_feed, 0, '');
288 }
289
290 if (keycode == 75) { // k
291 var feed = getActiveFeedId();
292 var new_feed = getRelativeFeedId(feedlist, feed, 'next');
293 if (new_feed) viewfeed(new_feed, 0, '');
294 }
295
c3a8d71a
AD
296// notify("KC: " + keycode);
297
9cfc649a
AD
298}
299
806a3d14
AD
300// if argument is undefined, current subtitle is not updated
301// use blank string to clear subtitle
fc69e641
AD
302function updateTitle(s) {
303 var tmp = "Tiny Tiny RSS";
21703604
AD
304
305 if (s && s.length > 0) {
306 current_subtitle = s;
307 }
308
fc69e641
AD
309 if (global_unread > 0) {
310 tmp = tmp + " (" + global_unread + ")";
311 }
312
313 if (s) {
21703604 314 tmp = tmp + " - " + current_subtitle;
fc69e641 315 }
21703604
AD
316
317 if (active_title_text.length > 0) {
318 tmp = tmp + " > " + active_title_text;
319 }
320
fc69e641
AD
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
22a93ad8
AD
334 return true;
335}
336
337function init() {
338
7719618b 339 try {
fe2f1970 340
7719618b 341 disableContainerChildren("headlinesToolbar", true);
70830c87 342
7719618b
AD
343 if (!genericSanityCheck())
344 return;
ac43eba1 345
7719618b
AD
346 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
347 xmlhttp.onreadystatechange=backend_sanity_check_callback;
348 xmlhttp.send(null);
47179952 349
7719618b
AD
350 } catch (e) {
351 exception_error("init", e);
a8d28f48 352 }
7719618b 353}
86741347 354
7719618b 355function init_second_stage() {
295f9b42 356
7719618b 357 try {
2f587484 358
7719618b
AD
359 setCookie("ttrss_vf_actfeed", "");
360
361 updateFeedList(false, false);
362 document.onkeydown = hotkey_handler;
363
364 var content = document.getElementById("content");
365
366 if (getCookie("ttrss_vf_vmode")) {
367 var viewbox = document.getElementById("viewbox");
368 viewbox.value = getCookie("ttrss_vf_vmode");
369 }
370
371 if (getCookie("ttrss_vf_limit")) {
372 var limitbox = document.getElementById("limitbox");
373 limitbox.value = getCookie("ttrss_vf_limit");
374 }
375
376 // if (getCookie("ttrss_vf_actfeed")) {
377 // viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
378 // }
379
380 // setTimeout("timeout()", 2*1000);
381 // scheduleFeedUpdate(true);
382
7719618b
AD
383 } catch (e) {
384 exception_error("init_second_stage", e);
2f587484 385 }
1cd17194 386}
ac43eba1 387
e2f8f7b4 388function quickMenuGo() {
e2f8f7b4 389
cbe45fa8
AD
390 var chooser = document.getElementById("quickMenuChooser");
391 var opid = chooser[chooser.selectedIndex].id;
e2f8f7b4 392
cbe45fa8 393 if (opid == "qmcPrefs") {
e2f8f7b4
AD
394 gotoPreferences();
395 }
396
cbe45fa8 397 if (opid == "qmcAdvSearch") {
033e47e0
AD
398 displayDlg("search");
399 return;
400 }
401
cbe45fa8 402 if (opid == "qmcAddFeed") {
f84a97a3 403 displayDlg("quickAddFeed");
6de5d056
AD
404 return;
405 }
406
cbe45fa8 407 if (opid == "qmcRemoveFeed") {
6de5d056
AD
408 var actid = getActiveFeedId();
409
410 if (!actid) {
411 notify("Please select some feed first.");
412 return;
413 }
69668465
AD
414
415 if (confirm("Remove current feed?")) {
416 qfdDelete(actid);
417 }
6de5d056 418
6de5d056 419 return;
e2f8f7b4 420 }
7a991cac 421
cbe45fa8 422 if (opid == "qmcUpdateFeeds") {
7a991cac
AD
423 scheduleFeedUpdate(true);
424 return;
425 }
426
cbe45fa8 427 if (opid == "qmcCatchupAll") {
7a991cac
AD
428 catchupAllFeeds();
429 return;
430 }
431
cbe45fa8 432 if (opid == "qmcShowOnlyUnread") {
7a991cac
AD
433 toggleDispRead();
434 return;
435 }
436
a24f525c
AD
437 if (opid == "qmcAddFilter") {
438 displayDlg("quickAddFilter", getActiveFeedId());
439 }
440
e2f8f7b4
AD
441}
442
443function qafAdd() {
ac43eba1 444
e2f8f7b4
AD
445 if (!xmlhttp_ready(xmlhttp)) {
446 printLockingError();
447 return
448 }
449
450 var link = document.getElementById("qafInput");
451
452 if (link.value.length == 0) {
453 notify("Missing feed URL.");
454 } else {
455 notify("Adding feed...");
456
457 var feeds_doc = window.frames["feeds-frame"].document;
458
459 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
460
a24f525c 461 xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=add&link=" +
e2f8f7b4 462 param_escape(link.value), true);
6de5d056 463 xmlhttp.onreadystatechange=dlg_frefresh_callback;
e2f8f7b4
AD
464 xmlhttp.send(null);
465
466 link.value = "";
467
468 }
f84a97a3
AD
469}
470
a24f525c
AD
471function qaddFilter() {
472
473 if (!xmlhttp_ready(xmlhttp)) {
474 printLockingError();
475 return
476 }
477
478 var regexp = document.getElementById("fadd_regexp");
479 var match = document.getElementById("fadd_match");
480 var feed = document.getElementById("fadd_feed");
481 var action = document.getElementById("fadd_action");
482
483 if (regexp.value.length == 0) {
484 notify("Missing filter expression.");
485 } else {
486 notify("Adding filter...");
487
488 var v_match = match[match.selectedIndex].text;
489 var feed_id = feed[feed.selectedIndex].id;
490 var action_id = action[action.selectedIndex].id;
491
492 xmlhttp.open("GET", "backend.php?op=pref-filters&quiet=1&subop=add&regexp=" +
493 param_escape(regexp.value) + "&match=" + v_match +
494 "&fid=" + param_escape(feed_id) + "&aid=" + param_escape(action_id), true);
495
496 xmlhttp.onreadystatechange=dlg_submit_callback;
497 xmlhttp.send(null);
498
499 regexp.value = "";
500 }
501
502}
503
504
6de5d056 505function displayDlg(id, param) {
e2f8f7b4 506
40d601c5
AD
507 notify("");
508
f84a97a3 509 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
6de5d056 510 param_escape(id) + "&param=" + param_escape(param), true);
a24f525c 511 xmlhttp.onreadystatechange=dlg_display_callback;
f84a97a3 512 xmlhttp.send(null);
e2f8f7b4 513
ccedfddd 514 disableHotkeys();
e2f8f7b4 515}
f84a97a3
AD
516
517function closeDlg() {
76332f3c 518 var dlg = document.getElementById("userDlgShadow");
f84a97a3 519 dlg.style.display = "none";
ccedfddd 520 enableHotkeys();
f84a97a3
AD
521}
522
6de5d056
AD
523function qfdDelete(feed_id) {
524
525 notify("Removing feed...");
526
69668465
AD
527// var feeds_doc = window.frames["feeds-frame"].document;
528// feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
6de5d056 529
69668465 530 xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id);
6de5d056
AD
531 xmlhttp.onreadystatechange=dlg_frefresh_callback;
532 xmlhttp.send(null);
6de5d056 533}
033e47e0 534
3745788e
AD
535
536function allFeedsMenuGo() {
537 var chooser = document.getElementById("allFeedsChooser");
538
539 var opname = chooser[chooser.selectedIndex].text;
540
541 if (opname == "Update") {
542 scheduleFeedUpdate(true);
543 return;
544 }
545
546 if (opname == "Mark as read") {
547 catchupAllFeeds();
548 return;
549 }
550
bdf7f1bc 551 if (opname == "Show only unread") {
3745788e
AD
552 toggleDispRead();
553 return;
554 }
555
556}
557
21703604
AD
558function updateFeedTitle(t) {
559 active_title_text = t;
560 updateTitle();
561}
562
3745788e
AD
563function toggleDispRead() {
564 var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
565
566 hide_read_feeds = !hide_read_feeds;
567
568 var feeds_doc = window.frames["feeds-frame"].document;
569
570 hideOrShowFeeds(feeds_doc, hide_read_feeds);
571
572 if (hide_read_feeds) {
573 setCookie("ttrss_vf_hreadf", 1);
574 } else {
575 setCookie("ttrss_vf_hreadf", 0);
576 }
577
578}
295f9b42 579