]> git.wh0rd.org - tt-rss.git/blob - tt-rss.js
fix adding feed w/o cat_id (closes #14)
[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 refetch_callback() {
76 if (xmlhttp.readyState == 4) {
77 try {
78
79 if (!xmlhttp.responseXML) {
80 notify("refetch_callback: backend did not return valid XML");
81 return;
82 }
83
84 var reply = xmlhttp.responseXML.firstChild;
85
86 if (!reply) {
87 notify("refetch_callback: backend did not return expected XML object");
88 return;
89 }
90
91 var error_code = reply.getAttribute("error-code");
92
93 if (error_code && error_code != 0) {
94 return fatalError(error_code);
95 }
96
97 var f_document = window.frames["feeds-frame"].document;
98
99 parse_counters(reply, f_document, window);
100
101 updateTitle("");
102 notify("All feeds updated.");
103 } catch (e) {
104 exception_error("refetch_callback", e);
105 }
106 }
107 }
108
109 function backend_sanity_check_callback() {
110
111 if (xmlhttp.readyState == 4) {
112
113 try {
114
115 if (!xmlhttp.responseXML) {
116 fatalError(3);
117 return;
118 }
119
120 var reply = xmlhttp.responseXML.firstChild;
121
122 if (!reply) {
123 fatalError(3);
124 return;
125 }
126
127 var error_code = reply.getAttribute("error-code");
128
129 if (error_code && error_code != 0) {
130 return fatalError(error_code);
131 }
132
133 init_second_stage();
134
135 } catch (e) {
136 exception_error("backend_sanity_check_callback", e);
137 }
138 }
139 }
140
141 function scheduleFeedUpdate(force) {
142
143 notify("Updating feeds, please wait.");
144
145 // document.title = "Tiny Tiny RSS - Updating...";
146
147 updateTitle("Updating");
148
149 var query_str = "backend.php?op=rpc&subop=";
150
151 if (force) {
152 query_str = query_str + "forceUpdateAllFeeds";
153 } else {
154 query_str = query_str + "updateAllFeeds";
155 }
156
157 var omode;
158
159 if (display_tags) {
160 omode = "t";
161 } else {
162 omode = "fl";
163 }
164
165 query_str = query_str + "&omode=" + omode;
166
167 if (xmlhttp_ready(xmlhttp)) {
168 xmlhttp.open("GET", query_str, true);
169 xmlhttp.onreadystatechange=refetch_callback;
170 xmlhttp.send(null);
171 } else {
172 printLockingError();
173 }
174 }
175
176 function updateFeedList(silent, fetch) {
177
178 // if (silent != true) {
179 // notify("Loading feed list...");
180 // }
181
182 var query_str = "backend.php?op=feeds";
183
184 if (display_tags) {
185 query_str = query_str + "&tags=1";
186 }
187
188 if (getActiveFeedId()) {
189 query_str = query_str + "&actid=" + getActiveFeedId();
190 }
191
192 if (fetch) query_str = query_str + "&fetch=yes";
193
194 var feeds_frame = document.getElementById("feeds-frame");
195
196 feeds_frame.src = query_str;
197 }
198
199 function catchupAllFeeds() {
200
201 var query_str = "backend.php?op=feeds&subop=catchupAll";
202
203 notify("Marking all feeds as read...");
204
205 var feeds_frame = document.getElementById("feeds-frame");
206
207 feeds_frame.src = query_str;
208
209 global_unread = 0;
210 updateTitle("");
211
212 }
213
214 function viewCurrentFeed(skip, subop) {
215
216 if (getActiveFeedId()) {
217 viewfeed(getActiveFeedId(), skip, subop);
218 } else {
219 disableContainerChildren("headlinesToolbar", false, document);
220 viewfeed(-1, skip, subop); // FIXME
221 }
222 }
223
224 function viewfeed(feed, skip, subop) {
225 var f = window.frames["feeds-frame"];
226 f.viewfeed(feed, skip, subop);
227 }
228
229 function timeout() {
230 scheduleFeedUpdate(false);
231 setTimeout("timeout()", 900*1000);
232 }
233
234 function resetSearch() {
235 var searchbox = document.getElementById("searchbox")
236
237 if (searchbox.value != "" && getActiveFeedId()) {
238 searchbox.value = "";
239 viewfeed(getActiveFeedId(), 0, "");
240 }
241 }
242
243 function search() {
244 closeDlg();
245 viewCurrentFeed(0, "");
246 }
247
248 function localPiggieFunction(enable) {
249 if (enable) {
250 var query_str = "backend.php?op=feeds&subop=piggie";
251
252 if (xmlhttp_ready(xmlhttp)) {
253
254 xmlhttp.open("GET", query_str, true);
255 xmlhttp.onreadystatechange=feedlist_callback;
256 xmlhttp.send(null);
257 }
258 }
259 }
260
261 function localHotkeyHandler(keycode) {
262
263 /* if (keycode == 78) {
264 return moveToPost('next');
265 }
266
267 if (keycode == 80) {
268 return moveToPost('prev');
269 } */
270
271 if (keycode == 82) { // r
272 return scheduleFeedUpdate(true);
273 }
274
275 if (keycode == 85) { // u
276 if (getActiveFeedId()) {
277 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
278 }
279 }
280
281 if (keycode == 65) { // a
282 return toggleDispRead();
283 }
284
285 var f_doc = window.frames["feeds-frame"].document;
286 var feedlist = f_doc.getElementById('feedList');
287
288 if (keycode == 74) { // j
289 var feed = getActiveFeedId();
290 var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
291 if (new_feed) viewfeed(new_feed, 0, '');
292 }
293
294 if (keycode == 75) { // k
295 var feed = getActiveFeedId();
296 var new_feed = getRelativeFeedId(feedlist, feed, 'next');
297 if (new_feed) viewfeed(new_feed, 0, '');
298 }
299
300 // notify("KC: " + keycode);
301
302 }
303
304 // if argument is undefined, current subtitle is not updated
305 // use blank string to clear subtitle
306 function updateTitle(s) {
307 var tmp = "Tiny Tiny RSS";
308
309 if (s && s.length > 0) {
310 current_subtitle = s;
311 }
312
313 if (global_unread > 0) {
314 tmp = tmp + " (" + global_unread + ")";
315 }
316
317 if (s) {
318 tmp = tmp + " - " + current_subtitle;
319 }
320
321 if (active_title_text.length > 0) {
322 tmp = tmp + " > " + active_title_text;
323 }
324
325 document.title = tmp;
326 }
327
328 function genericSanityCheck() {
329
330 if (!xmlhttp) fatalError(1);
331
332 setCookie("ttrss_vf_test", "TEST");
333
334 if (getCookie("ttrss_vf_test") != "TEST") {
335 fatalError(2);
336 }
337
338 return true;
339 }
340
341 function init() {
342
343 try {
344
345 disableContainerChildren("headlinesToolbar", true);
346
347 if (!genericSanityCheck())
348 return;
349
350 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
351 xmlhttp.onreadystatechange=backend_sanity_check_callback;
352 xmlhttp.send(null);
353
354 } catch (e) {
355 exception_error("init", e);
356 }
357 }
358
359 function init_second_stage() {
360
361 try {
362
363 setCookie("ttrss_vf_actfeed", "");
364
365 updateFeedList(false, false);
366 document.onkeydown = hotkey_handler;
367
368 var viewbox = document.getElementById("viewbox");
369 var limitbox = document.getElementById("limitbox");
370
371 dropboxSelect(viewbox, getCookie("ttrss_vf_vmode"));
372 dropboxSelect(limitbox, getCookie("ttrss_vf_limit"));
373
374 } catch (e) {
375 exception_error("init_second_stage", e);
376 }
377 }
378
379 function quickMenuGo() {
380
381 var chooser = document.getElementById("quickMenuChooser");
382 var opid = chooser[chooser.selectedIndex].id;
383
384 if (opid == "qmcPrefs") {
385 gotoPreferences();
386 }
387
388 if (opid == "qmcSearch") {
389 displayDlg("search");
390 return;
391 }
392
393 if (opid == "qmcAddFeed") {
394 displayDlg("quickAddFeed");
395 return;
396 }
397
398 if (opid == "qmcRemoveFeed") {
399 var actid = getActiveFeedId();
400
401 if (!actid) {
402 notify("Please select some feed first.");
403 return;
404 }
405
406 if (confirm("Remove current feed?")) {
407 qfdDelete(actid);
408 }
409
410 return;
411 }
412
413 if (opid == "qmcUpdateFeeds") {
414 scheduleFeedUpdate(true);
415 return;
416 }
417
418 if (opid == "qmcCatchupAll") {
419 catchupAllFeeds();
420 return;
421 }
422
423 if (opid == "qmcShowOnlyUnread") {
424 toggleDispRead();
425 return;
426 }
427
428 if (opid == "qmcAddFilter") {
429 displayDlg("quickAddFilter", getActiveFeedId());
430 }
431
432 }
433
434 function qafAdd() {
435
436 if (!xmlhttp_ready(xmlhttp)) {
437 printLockingError();
438 return
439 }
440
441 var link = document.getElementById("qafInput");
442
443 if (link.value.length == 0) {
444 notify("Missing feed URL.");
445 } else {
446 notify("Adding feed...");
447
448 var cat = document.getElementById("qafCat");
449 var cat_id = "";
450
451 if (cat) {
452 cat_id = cat[cat.selectedIndex].id;
453 } else {
454 cat_id = 0;
455 }
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
461 xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=add&link=" +
462 param_escape(link.value) + "&cid=" + param_escape(cat_id), true);
463 xmlhttp.onreadystatechange=dlg_frefresh_callback;
464 xmlhttp.send(null);
465
466 link.value = "";
467
468 }
469 }
470
471 function 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
505 function displayDlg(id, param) {
506
507 notify("");
508
509 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
510 param_escape(id) + "&param=" + param_escape(param), true);
511 xmlhttp.onreadystatechange=dlg_display_callback;
512 xmlhttp.send(null);
513
514 disableHotkeys();
515 }
516
517 function closeDlg() {
518 var dlg = document.getElementById("userDlgShadow");
519 dlg.style.display = "none";
520 enableHotkeys();
521 }
522
523 function qfdDelete(feed_id) {
524
525 notify("Removing feed...");
526
527 // var feeds_doc = window.frames["feeds-frame"].document;
528 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
529
530 _qfd_deleted_feed = feed_id;
531
532 xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id);
533 xmlhttp.onreadystatechange=dlg_frefresh_callback;
534 xmlhttp.send(null);
535 }
536
537
538 function allFeedsMenuGo() {
539 var chooser = document.getElementById("allFeedsChooser");
540
541 var opname = chooser[chooser.selectedIndex].text;
542
543 if (opname == "Update") {
544 scheduleFeedUpdate(true);
545 return;
546 }
547
548 if (opname == "Mark as read") {
549 catchupAllFeeds();
550 return;
551 }
552
553 if (opname == "Show only unread") {
554 toggleDispRead();
555 return;
556 }
557
558 }
559
560 function updateFeedTitle(t) {
561 active_title_text = t;
562 updateTitle();
563 }
564
565 function toggleDispRead() {
566 var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
567
568 hide_read_feeds = !hide_read_feeds;
569
570 var feeds_doc = window.frames["feeds-frame"].document;
571
572 hideOrShowFeeds(feeds_doc, hide_read_feeds);
573
574 if (hide_read_feeds) {
575 setCookie("ttrss_vf_hreadf", 1);
576 } else {
577 setCookie("ttrss_vf_hreadf", 0);
578 }
579
580 }
581