]> git.wh0rd.org - tt-rss.git/blame - functions.js
rework login process, drop http auth
[tt-rss.git] / functions.js
CommitLineData
760966c1 1var hotkeys_enabled = true;
d96d11f4 2var debug_mode_enabled = false;
a7565293
AD
3var xmlhttp_rpc = Ajax.getTransport();
4
292a8a12 5function browser_has_opacity() {
605f7d46
AD
6 return navigator.userAgent.match("Gecko") != null ||
7 navigator.userAgent.match("Opera") != null;
292a8a12
AD
8}
9
7c620da8
AD
10function is_opera() {
11 return navigator.userAgent.match("Opera");
12}
13
583c58b8
AD
14function is_khtml() {
15 return navigator.userAgent.match("KHTML");
16}
17
18function is_safari() {
19 return navigator.userAgent.match("Safari");
20}
21
55160955 22function exception_error(location, e, silent) {
83f043bb
AD
23 var msg;
24
25 if (e.fileName) {
26 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
27
28 msg = "Exception: " + e.name + ", " + e.message +
29 "\nFunction: " + location + "()" +
30 "\nLocation: " + base_fname + ":" + e.lineNumber;
ee1f45f4 31
83f043bb
AD
32 } else {
33 msg = "Exception: " + e + "\nFunction: " + location + "()";
34 }
35
ee1f45f4
AD
36 debug("<b>EXCEPTION: " + msg + "</b>");
37
55160955
AD
38 if (!silent) {
39 alert(msg);
40 }
7719618b
AD
41}
42
760966c1
AD
43function disableHotkeys() {
44 hotkeys_enabled = false;
45}
46
47function enableHotkeys() {
48 hotkeys_enabled = true;
49}
50
c0e5a40e
AD
51function xmlhttp_ready(obj) {
52 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
53}
54
01a87dff
AD
55function logout_callback() {
56 var container = document.getElementById('notify');
57 if (xmlhttp.readyState == 4) {
58 try {
59 window.location.reload(true);
60 } catch (e) {
61 exception_error("logout_callback", e);
62 }
63 }
64}
65
9cfc649a
AD
66function notify_callback() {
67 var container = document.getElementById('notify');
68 if (xmlhttp.readyState == 4) {
69 container.innerHTML=xmlhttp.responseText;
70 }
71}
72
73function rpc_notify_callback() {
74 var container = document.getElementById('notify');
75 if (xmlhttp_rpc.readyState == 4) {
76 container.innerHTML=xmlhttp_rpc.responseText;
77 }
78}
79
7726fa02
AD
80function param_escape(arg) {
81 if (typeof encodeURIComponent != 'undefined')
82 return encodeURIComponent(arg);
83 else
84 return escape(arg);
85}
86
87function param_unescape(arg) {
88 if (typeof decodeURIComponent != 'undefined')
89 return decodeURIComponent(arg);
90 else
91 return unescape(arg);
92}
93
508a81e1
AD
94function delay(gap) {
95 var then,now;
96 then=new Date().getTime();
97 now=then;
98 while((now-then)<gap) {
99 now=new Date().getTime();
100 }
101}
7726fa02 102
ce3bf408
AD
103var notify_hide_timerid = false;
104var notify_last_doc = false;
105
d05514a4 106var notify_effect = false;
59a543f0 107
ce3bf408
AD
108function hide_notify() {
109 if (notify_last_doc) {
110 var n = notify_last_doc.getElementById("notify");
d05514a4
AD
111 n.style.display = "none";
112
113/* if (browser_has_opacity()) {
ce3bf408 114 if (notify_opacity >= 0) {
0655a1d5 115 notify_opacity = notify_opacity - 0.1;
ce3bf408 116 n.style.opacity = notify_opacity;
292a8a12 117 notify_hide_timerid = window.setTimeout("hide_notify()", 20);
ce3bf408
AD
118 } else {
119 n.style.display = "none";
292a8a12 120 n.style.opacity = 1;
ce3bf408
AD
121 }
122 } else {
123 n.style.display = "none";
d05514a4 124 } */
8dcfffd0 125 }
d05514a4 126}
c05608c2 127
0530ddd8 128function notify_real(msg, doc, no_hide, is_err) {
7726fa02 129
ce3bf408
AD
130 var n = doc.getElementById("notify");
131 var nb = doc.getElementById("notify_body");
7726fa02 132
c05608c2 133 if (!n || !nb) return;
f0601b87 134
0655a1d5
AD
135 if (notify_hide_timerid) {
136 window.clearTimeout(notify_hide_timerid);
137 }
138
139 notify_last_doc = doc;
140 notify_opacity = 1;
141
8dcfffd0 142 if (msg == "") {
0655a1d5
AD
143 if (n.style.display == "block") {
144 notify_hide_timerid = window.setTimeout("hide_notify()", 0);
145 }
146 return;
7726fa02 147 } else {
0ceded7a 148 n.style.display = "block";
8dcfffd0 149 }
7726fa02 150
0530ddd8 151 if (is_err) {
f407c086
AD
152 n.className = "notifyError";
153// n.style.backgroundColor = "#ffcccc";
154// n.style.color = "black";
155// n.style.borderColor = "#ff0000";
0530ddd8 156 } else {
f407c086
AD
157 n.className = "notify";
158// n.style.backgroundColor = "#fff7d5";
159// n.style.borderColor = "#d7c47a";
160// n.style.color = "black";
0530ddd8
AD
161 }
162
106689b0
AD
163// msg = "<img src='images/live_com_loading.gif'> " + msg;
164
0ceded7a
AD
165 nb.innerHTML = msg;
166
4d4200a8 167 if (!no_hide) {
292a8a12 168 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
4d4200a8 169 }
ce3bf408
AD
170}
171
0530ddd8 172function p_notify(msg, no_hide, is_err) {
9cb99906 173 notify_real(msg, document, no_hide, is_err);
ce3bf408
AD
174}
175
0530ddd8
AD
176function notify(msg, no_hide, is_err) {
177 notify_real(msg, document, no_hide, is_err);
7726fa02
AD
178}
179
508a81e1 180function printLockingError() {
f0601b87 181 notify("Please wait until operation finishes");}
508a81e1 182
13ad9102 183function hotkey_handler(e) {
760966c1 184
ee1f45f4 185 try {
2e02b896 186
ee1f45f4 187 var keycode;
d96d11f4
AD
188 var shift_key = false;
189
190 try {
191 shift_key = e.shiftKey;
192 } catch (e) {
193
194 }
ee1f45f4
AD
195
196 if (!hotkeys_enabled) return;
197
198 if (window.event) {
199 keycode = window.event.keyCode;
200 } else if (e) {
201 keycode = e.which;
202 }
d437c8cf 203
ee1f45f4 204 if (keycode == 82) { // r
0feab655 205 return scheduleFeedUpdate(true);
ee1f45f4 206 }
0a383013 207
e3612080 208 if (keycode == 83) { // s
0feab655 209 return displayDlg("search", getActiveFeedId());
0a383013
AD
210 }
211
ee1f45f4
AD
212 if (keycode == 85) { // u
213 if (getActiveFeedId()) {
0feab655 214 return viewfeed(getActiveFeedId(), "ForceUpdate");
ee1f45f4
AD
215 }
216 }
217
218 if (keycode == 65) { // a
0feab655 219 return toggleDispRead();
ee1f45f4
AD
220 }
221
0feab655 222 var feedlist = document.getElementById('feedList');
ee1f45f4
AD
223
224 if (keycode == 74) { // j
225 var feed = getActiveFeedId();
226 var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
767e2486 227 if (new_feed) viewfeed(new_feed, '');
ee1f45f4
AD
228 }
229
230 if (keycode == 75) { // k
231 var feed = getActiveFeedId();
232 var new_feed = getRelativeFeedId(feedlist, feed, 'next');
767e2486 233 if (new_feed) viewfeed(new_feed, '');
7b433d8c 234 }
9cfc649a 235
583c58b8 236 if (!is_safari() && (keycode == 78 || keycode == 40)) { // n, down
0feab655
AD
237 if (typeof moveToPost != 'undefined') {
238 return moveToPost('next');
e59a2f12 239 }
ee1f45f4
AD
240 }
241
583c58b8 242 if (!is_safari() && (keycode == 80 || keycode == 38)) { // p, up
0feab655
AD
243 if (typeof moveToPost != 'undefined') {
244 return moveToPost('prev');
e59a2f12 245 }
ee1f45f4
AD
246 }
247
d96d11f4
AD
248 if (keycode == 68 && shift_key) { // d
249 if (!debug_mode_enabled) {
250 document.getElementById('debug_output').style.display = 'block';
251 debug('debug mode activated');
252 } else {
253 document.getElementById('debug_output').style.display = 'none';
254 }
255
256 debug_mode_enabled = !debug_mode_enabled;
257 }
258
50a2595d
AD
259 if (keycode == 190 && shift_key) { // >
260 viewFeedGoPage(1);
261 }
262
263 if (keycode == 188 && shift_key) { // <
264 viewFeedGoPage(-1);
265 }
266
267 if (keycode == 191 && shift_key) { // ?
268 viewFeedGoPage(0);
269 }
270
57c9393e 271 if (keycode == 69 && shift_key) { // e
e46cdbb0
AD
272 return editFeedDlg(getActiveFeedId());
273 }
274
57c9393e 275 if (keycode == 70 && shift_key) { // f
e30a61d4
AD
276 if (getActiveFeedId()) {
277 return catchupCurrentFeed();
278 }
279 }
280
57c9393e 281 if (keycode == 80 && shift_key) { // p
e30a61d4
AD
282 if (getActiveFeedId()) {
283 return catchupPage();
284 }
285 }
286
1dc8dba0
AD
287 if (typeof localHotkeyHandler != 'undefined') {
288 try {
289 return localHotkeyHandler(e);
290 } catch (e) {
291 exception_error("hotkey_handler, local:", e);
292 }
293 }
294
d96d11f4 295 debug("KP=" + keycode);
ee1f45f4
AD
296 } catch (e) {
297 exception_error("hotkey_handler", e);
298 }
13ad9102
AD
299}
300
e828e31e 301function cleanSelectedList(element) {
f0601b87
AD
302 var content = document.getElementById(element);
303
703b632e
AD
304 if (!document.getElementById("feedCatHolder")) {
305 for (i = 0; i < content.childNodes.length; i++) {
306 var child = content.childNodes[i];
d0bb308e
AD
307 try {
308 child.className = child.className.replace("Selected", "");
309 } catch (e) {
310 //
311 }
703b632e
AD
312 }
313 } else {
314 for (i = 0; i < content.childNodes.length; i++) {
315 var child = content.childNodes[i];
703b632e 316 if (child.id == "feedCatHolder") {
9cb99906 317 debug(child.id);
c3f348c2 318 var fcat = child.lastChild;
703b632e 319 for (j = 0; j < fcat.childNodes.length; j++) {
befc807f 320 var feed = fcat.childNodes[j];
703b632e
AD
321 feed.className = feed.className.replace("Selected", "");
322 }
323 }
befc807f 324 }
703b632e 325 }
e828e31e
AD
326}
327
328
329function cleanSelected(element) {
330 var content = document.getElementById(element);
f0601b87
AD
331
332 for (i = 0; i < content.rows.length; i++) {
333 content.rows[i].className = content.rows[i].className.replace("Selected", "");
334 }
f0601b87
AD
335}
336
337function getVisibleUnreadHeadlines() {
338 var content = document.getElementById("headlinesList");
339
340 var rows = new Array();
341
342 for (i = 0; i < content.rows.length; i++) {
343 var row_id = content.rows[i].id.replace("RROW-", "");
344 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
345 rows.push(row_id);
346 }
347 }
348 return rows;
349}
350
351function getVisibleHeadlineIds() {
352
353 var content = document.getElementById("headlinesList");
354
355 var rows = new Array();
356
357 for (i = 0; i < content.rows.length; i++) {
358 var row_id = content.rows[i].id.replace("RROW-", "");
359 if (row_id.length > 0) {
360 rows.push(row_id);
361 }
362 }
363 return rows;
364}
365
366function getFirstVisibleHeadlineId() {
367 var rows = getVisibleHeadlineIds();
368 return rows[0];
369}
370
371function getLastVisibleHeadlineId() {
372 var rows = getVisibleHeadlineIds();
373 return rows[rows.length-1];
374}
375
376function markHeadline(id) {
377 var row = document.getElementById("RROW-" + id);
378 if (row) {
35f3c923
AD
379 var is_active = false;
380
381 if (row.className.match("Active")) {
382 is_active = true;
383 }
384 row.className = row.className.replace("Selected", "");
385 row.className = row.className.replace("Active", "");
386 row.className = row.className.replace("Insensitive", "");
387
388 if (is_active) {
389 row.className = row.className = "Active";
390 }
391
72020095
AD
392 var check = document.getElementById("RCHK-" + id);
393
394 if (check) {
395 check.checked = true;
396 }
397
35f3c923
AD
398 row.className = row.className + "Selected";
399
f0601b87
AD
400 }
401}
402
403function getFeedIds() {
404 var content = document.getElementById("feedsList");
405
406 var rows = new Array();
407
408 for (i = 0; i < content.rows.length; i++) {
409 var id = content.rows[i].id.replace("FEEDR-", "");
410 if (id.length > 0) {
411 rows.push(id);
412 }
413 }
414
415 return rows;
416}
13ad9102 417
76b4eae1
AD
418function setCookie(name, value, lifetime, path, domain, secure) {
419
420 var d = false;
421
422 if (lifetime) {
423 d = new Date();
424 d.setTime(lifetime * 1000);
425 }
426
427 int_setCookie(name, value, d, path, domain, secure);
428
429}
430
431function int_setCookie(name, value, expires, path, domain, secure) {
ac43eba1
AD
432 document.cookie= name + "=" + escape(value) +
433 ((expires) ? "; expires=" + expires.toGMTString() : "") +
434 ((path) ? "; path=" + path : "") +
435 ((domain) ? "; domain=" + domain : "") +
436 ((secure) ? "; secure" : "");
437}
438
76b4eae1
AD
439function delCookie(name, path, domain) {
440 if (getCookie(name)) {
441 document.cookie = name + "=" +
442 ((path) ? ";path=" + path : "") +
443 ((domain) ? ";domain=" + domain : "" ) +
444 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
445 }
446}
447
448
ac43eba1
AD
449function getCookie(name) {
450
451 var dc = document.cookie;
452 var prefix = name + "=";
453 var begin = dc.indexOf("; " + prefix);
454 if (begin == -1) {
455 begin = dc.indexOf(prefix);
456 if (begin != 0) return null;
457 }
458 else {
459 begin += 2;
460 }
461 var end = document.cookie.indexOf(";", begin);
462 if (end == -1) {
463 end = dc.length;
464 }
465 return unescape(dc.substring(begin + prefix.length, end));
466}
467
1a66d16e
AD
468function disableContainerChildren(id, disable, doc) {
469
470 if (!doc) doc = document;
471
472 var container = doc.getElementById(id);
ac43eba1 473
4220b0bd
AD
474 if (!container) {
475 //alert("disableContainerChildren: element " + id + " not found");
476 return;
477 }
478
ac43eba1
AD
479 for (var i = 0; i < container.childNodes.length; i++) {
480 var child = container.childNodes[i];
481
d5224f0d
AD
482 try {
483 child.disabled = disable;
484 } catch (E) {
485
486 }
ac43eba1
AD
487
488 if (disable) {
489 if (child.className && child.className.match("button")) {
490 child.className = "disabledButton";
491 }
492 } else {
493 if (child.className && child.className.match("disabledButton")) {
494 child.className = "button";
495 }
d5224f0d 496 }
ac43eba1
AD
497 }
498
499}
7726fa02 500
e828e31e
AD
501function gotoPreferences() {
502 document.location.href = "prefs.php";
503}
504
505function gotoMain() {
506 document.location.href = "tt-rss.php";
507}
508
8158c57a
AD
509function gotoExportOpml() {
510 document.location.href = "opml.php?op=Export";
511}
86741347
AD
512
513function getActiveFeedId() {
33d13e72
AD
514// return getCookie("ttrss_vf_actfeed");
515 try {
0feab655
AD
516 debug("gAFID: " + active_feed_id);
517 return active_feed_id;
33d13e72
AD
518 } catch (e) {
519 exception_error("getActiveFeedId", e);
520 }
86741347
AD
521}
522
0a6c4846 523function activeFeedIsCat() {
0feab655 524 return active_feed_is_cat;
0a6c4846
AD
525}
526
86741347 527function setActiveFeedId(id) {
33d13e72
AD
528// return setCookie("ttrss_vf_actfeed", id);
529 try {
5c365f60 530 debug("sAFID(" + id + ")");
0feab655 531 active_feed_id = id;
33d13e72
AD
532 } catch (e) {
533 exception_error("setActiveFeedId", e);
534 }
86741347 535}
090e250b 536
ac378ad4 537function parse_counters(reply, scheduled_call) {
1a6a9555 538 try {
ac378ad4 539
9e397d0f
AD
540 var feeds_found = 0;
541
f54f515f
AD
542 if (reply.firstChild && reply.firstChild.firstChild) {
543 debug("<b>wrong element passed to parse_counters, adjusting.</b>");
544 reply = reply.firstChild;
545 }
546
1a6a9555 547 for (var l = 0; l < reply.childNodes.length; l++) {
9cbca41f
AD
548 if (!reply.childNodes[l] ||
549 typeof(reply.childNodes[l].getAttribute) == "undefined") {
6043fb7e
AD
550 // where did this come from?
551 continue;
552 }
553
1a6a9555
AD
554 var id = reply.childNodes[l].getAttribute("id");
555 var t = reply.childNodes[l].getAttribute("type");
556 var ctr = reply.childNodes[l].getAttribute("counter");
023fe037
AD
557 var error = reply.childNodes[l].getAttribute("error");
558 var has_img = reply.childNodes[l].getAttribute("hi");
fb1fb4ab 559 var updated = reply.childNodes[l].getAttribute("updated");
1a6a9555
AD
560
561 if (id == "global-unread") {
0feab655
AD
562 global_unread = ctr;
563 updateTitle();
1a6a9555
AD
564 continue;
565 }
7bf7e4d3
AD
566
567 if (id == "subscribed-feeds") {
568 feeds_found = ctr;
569 continue;
570 }
1a6a9555
AD
571
572 if (t == "category") {
0feab655 573 var catctr = document.getElementById("FCATCTR-" + id);
1a6a9555 574 if (catctr) {
67dabe1a
AD
575 catctr.innerHTML = "(" + ctr + ")";
576 if (ctr > 0) {
577 catctr.className = "catCtrHasUnread";
578 } else {
579 catctr.className = "catCtrNoUnread";
580 }
1a6a9555
AD
581 }
582 continue;
583 }
584
0feab655
AD
585 var feedctr = document.getElementById("FEEDCTR-" + id);
586 var feedu = document.getElementById("FEEDU-" + id);
587 var feedr = document.getElementById("FEEDR-" + id);
588 var feed_img = document.getElementById("FIMG-" + id);
589 var feedlink = document.getElementById("FEEDL-" + id);
590 var feedupd = document.getElementById("FLUPD-" + id);
fb1fb4ab
AD
591
592 if (updated && feedlink) {
593 if (error) {
594 feedlink.title = "Error: " + error + " (" + updated + ")";
595 } else {
596 feedlink.title = "Updated: " + updated;
597 }
598 }
023fe037 599
78d5212c
AD
600 if (updated && feedupd) {
601 if (error) {
602 feedupd.innerHTML = updated + " (Error)";
603 } else {
604 feedupd.innerHTML = updated;
605 }
606 }
607
1a6a9555 608 if (feedctr && feedu && feedr) {
e8ef3b97
AD
609
610 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
5b064721 611 viewCurrentFeed();
e8ef3b97 612 }
1a6a9555
AD
613
614 feedu.innerHTML = ctr;
023fe037 615
426d3c57
AD
616 if (error) {
617 feedr.className = feedr.className.replace("feed", "error");
618 } else if (id > 0) {
619 feedr.className = feedr.className.replace("error", "feed");
023fe037 620 }
1a6a9555
AD
621
622 if (ctr > 0) {
623 feedctr.className = "odd";
624 if (!feedr.className.match("Unread")) {
625 var is_selected = feedr.className.match("Selected");
626
627 feedr.className = feedr.className.replace("Selected", "");
628 feedr.className = feedr.className.replace("Unread", "");
629
630 feedr.className = feedr.className + "Unread";
631
632 if (is_selected) {
633 feedr.className = feedr.className + "Selected";
634 }
635
636 }
637 } else {
638 feedctr.className = "invisible";
639 feedr.className = feedr.className.replace("Unread", "");
640 }
641 }
642 }
9e397d0f 643
0feab655 644 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
7553dd8b 645
0feab655 646 var feeds_stored = number_of_feeds;
9e397d0f
AD
647
648 debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
649
650 if (feeds_stored != feeds_found) {
0feab655 651 number_of_feeds = feeds_found;
7bf7e4d3
AD
652
653 if (feeds_stored != 0) {
9e397d0f 654 debug("Subscribed feed number changed, refreshing feedlist");
0e9dd1ba 655 setTimeout('updateFeedList(false, false)', 50);
9e397d0f
AD
656 }
657 }
658
1a6a9555 659 } catch (e) {
83f043bb 660 exception_error("parse_counters", e);
1a6a9555
AD
661 }
662}
663
3ac2f3c7 664function parse_counters_reply(xmlhttp, scheduled_call) {
5854573a
AD
665
666 if (!xmlhttp.responseXML) {
667 notify("refetch_callback: backend did not return valid XML", true, true);
668 return;
669 }
670
671 var reply = xmlhttp.responseXML.firstChild;
672
673 if (!reply) {
674 notify("refetch_callback: backend did not return expected XML object", true, true);
675 updateTitle("");
676 return;
677 }
678
679 var error_code = false;
680 var error_msg = false;
681
682 if (reply.firstChild) {
683 error_code = reply.firstChild.getAttribute("error-code");
684 error_msg = reply.firstChild.getAttribute("error-msg");
685 }
686
687 if (!error_code) {
688 error_code = reply.getAttribute("error-code");
689 error_msg = reply.getAttribute("error-msg");
690 }
691
692 if (error_code && error_code != 0) {
693 debug("refetch_callback: got error code " + error_code);
694 return fatalError(error_code, error_msg);
695 }
696
697 var counters = reply.firstChild;
698
3ac2f3c7 699 parse_counters(counters, scheduled_call);
5854573a
AD
700
701 var runtime_info = counters.nextSibling;
702
703 parse_runtime_info(runtime_info);
704
705 if (getInitParam("feeds_sort_by_unread") == 1) {
706 resort_feedlist();
707 }
708
709 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
710
711}
712
4f3a84f4 713function all_counters_callback() {
090e250b 714 if (xmlhttp_rpc.readyState == 4) {
7719618b 715 try {
5854573a 716/* if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
b00ed196 717 debug("[all_counters_callback] backend did not return valid XML");
7719618b
AD
718 return;
719 }
894ebcf5 720
6b4163cb 721 debug("in all_counters_callback : " + xmlhttp_rpc.responseXML);
1cb7492d 722
7719618b 723 var reply = xmlhttp_rpc.responseXML.firstChild;
280ee9a3 724
f54f515f
AD
725 var counters = reply.firstChild;
726
727 parse_counters(counters);
1cb7492d
AD
728
729 var runtime = counters.nextSibling;
730
731 if (runtime) {
0feab655 732 parse_runtime_info(runtime);
1cb7492d 733 }
c9268ed5 734
cea51014 735 if (getInitParam("feeds_sort_by_unread") == 1) {
c9268ed5
AD
736 resort_feedlist();
737 }
293fa942 738
5854573a
AD
739 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1); */
740
741 debug("in all_counters_callback");
742
743 parse_counters_reply(xmlhttp_rpc);
293fa942 744
7719618b
AD
745 } catch (e) {
746 exception_error("all_counters_callback", e);
090e250b
AD
747 }
748 }
749}
750
c9268ed5
AD
751function get_feed_entry_unread(doc, elem) {
752
753 var id = elem.id.replace("FEEDR-", "");
754
755 if (id <= 0) {
756 return -1;
757 }
758
759 try {
760 return parseInt(doc.getElementById("FEEDU-" + id).innerHTML);
761 } catch (e) {
762 return -1;
763 }
764}
765
766function resort_category(doc, node) {
767 debug("resort_category: " + node);
768
769 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
770 for (i = 0; i < node.childNodes.length; i++) {
771 if (node.childNodes[i].nodeName != "LI") { continue; }
772
773 if (get_feed_entry_unread(doc, node.childNodes[i]) < 0) {
774 continue;
775 }
776
777 for (j = i+1; j < node.childNodes.length; j++) {
778 if (node.childNodes[j].nodeName != "LI") { continue; }
779
780 var tmp_val = get_feed_entry_unread(doc, node.childNodes[i]);
781 var cur_val = get_feed_entry_unread(doc, node.childNodes[j]);
782
783 if (cur_val > tmp_val) {
784 tempnode_i = node.childNodes[i].cloneNode(true);
785 tempnode_j = node.childNodes[j].cloneNode(true);
786 node.replaceChild(tempnode_i, node.childNodes[j]);
787 node.replaceChild(tempnode_j, node.childNodes[i]);
788 }
789 }
790
791 }
792 }
793
794}
795
796function resort_feedlist() {
797 debug("resort_feedlist");
798
0feab655 799 var fd = document;
c9268ed5
AD
800
801 if (fd.getElementById("feedCatHolder")) {
802
803 var feeds = fd.getElementById("feedList");
804 var child = feeds.firstChild;
805
806 while (child) {
807
808 if (child.id == "feedCatHolder") {
809 resort_category(fd, child.firstChild);
810 }
811
812 child = child.nextSibling;
813 }
814
815 } else {
816 resort_category(fd, fd.getElementById("feedList"));
817 }
818}
819
4f3a84f4 820function update_all_counters(feed) {
090e250b 821 if (xmlhttp_ready(xmlhttp_rpc)) {
8143ae1f 822 var query = "backend.php?op=rpc&subop=getAllCounters";
e47cfe37
AD
823
824 if (feed > 0) {
825 query = query + "&aid=" + feed;
826 }
827
cf4d339c
AD
828 if (tagsAreDisplayed()) {
829 query = query + "&omode=lt";
3fd7138f
AD
830 } else {
831 query = query + "&omode=flc";
cf4d339c
AD
832 }
833
834 debug("update_all_counters QUERY: " + query);
835
86173d9a
AD
836 var date = new Date();
837 var timestamp = Math.round(date.getTime() / 1000);
838 query = query + "&ts=" + timestamp
839
090e250b 840 xmlhttp_rpc.open("GET", query, true);
4f3a84f4 841 xmlhttp_rpc.onreadystatechange=all_counters_callback;
090e250b
AD
842 xmlhttp_rpc.send(null);
843 }
844}
7dc66a61
AD
845
846function popupHelp(tid) {
847 var w = window.open("backend.php?op=help&tid=" + tid,
848 "Popup Help",
849 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
850}
b6644d29
AD
851
852/** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
853 * * @author Sundar Dorai-Raj
854 * * Email: sdoraira@vt.edu
855 * * This program is free software; you can redistribute it and/or
856 * * modify it under the terms of the GNU General Public License
857 * * as published by the Free Software Foundation; either version 2
858 * * of the License, or (at your option) any later version,
859 * * provided that any use properly credits the author.
860 * * This program is distributed in the hope that it will be useful,
861 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
862 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
863 * * GNU General Public License for more details at http://www.gnu.org * * */
864
865 var numbers=".0123456789";
866 function isNumeric(x) {
867 // is x a String or a character?
868 if(x.length>1) {
869 // remove negative sign
870 x=Math.abs(x)+"";
871 for(j=0;j<x.length;j++) {
872 // call isNumeric recursively for each character
873 number=isNumeric(x.substring(j,j+1));
874 if(!number) return number;
875 }
876 return number;
877 }
878 else {
879 // if x is number return true
880 if(numbers.indexOf(x)>=0) return true;
881 return false;
882 }
883 }
884
3745788e
AD
885
886function hideOrShowFeeds(doc, hide) {
887
7553dd8b
AD
888 debug("hideOrShowFeeds: " + doc + ", " + hide);
889
0feab655 890 var fd = document;
293fa942
AD
891
892 var list = fd.getElementById("feedList");
893
894 if (fd.getElementById("feedCatHolder")) {
895
896 var feeds = fd.getElementById("feedList");
897 var child = feeds.firstChild;
898
899 while (child) {
900
901 if (child.id == "feedCatHolder") {
902 hideOrShowFeedsCategory(fd, child.firstChild, hide, child.previousSibling);
903 }
904
905 child = child.nextSibling;
906 }
907
908 } else {
909 hideOrShowFeedsCategory(fd, fd.getElementById("feedList"), hide);
910 }
911}
912
913function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
914
915// debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
3ed751d4 916
293fa942 917 var cat_unread = 0;
3745788e 918
4724a093
AD
919 if (!node) {
920 debug("hideOrShowFeeds: passed node is null, aborting");
921 return;
922 }
923
293fa942
AD
924 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
925 for (i = 0; i < node.childNodes.length; i++) {
926 if (node.childNodes[i].nodeName != "LI") { continue; }
bbf4d0b2 927
b31c2311 928 if (node.childNodes[i].style != undefined) {
293fa942 929
b31c2311
AD
930 var has_unread = (node.childNodes[i].className != "feed");
931
932 // debug(node.childNodes[i].id + " --> " + has_unread);
933
934 if (hide && !has_unread) {
935 node.childNodes[i].style.display = "none";
936 }
937
938 if (!hide) {
939 node.childNodes[i].style.display = "list-item";
940 }
941
942 if (has_unread) {
7553dd8b 943 node.childNodes[i].style.display = "list-item";
b31c2311
AD
944 cat_unread++;
945 }
293fa942 946 }
3745788e 947 }
b31c2311 948 }
3745788e 949
293fa942 950 if (cat_unread == 0) {
b31c2311
AD
951 if (cat_node.style == undefined) {
952 debug("ERROR: supplied cat_node " + cat_node +
953 " has no styles. WTF?");
954 return;
955 }
293fa942
AD
956 if (hide) {
957 cat_node.style.display = "none";
958 } else {
959 cat_node.style.display = "list-item";
960 }
7553dd8b 961 } else {
0ac2faea
AD
962 try {
963 cat_node.style.display = "list-item";
964 } catch (e) {
965 debug(e);
966 }
293fa942 967 }
3745788e 968
293fa942 969// debug("unread for category: " + cat_unread);
3745788e
AD
970}
971
35f3c923
AD
972function selectTableRow(r, do_select) {
973 r.className = r.className.replace("Selected", "");
974
975 if (do_select) {
976 r.className = r.className + "Selected";
977 }
978}
979
6c12c809
AD
980function selectTableRowById(elem_id, check_id, do_select) {
981
982 try {
983
984 var row = document.getElementById(elem_id);
985
986 if (row) {
987 selectTableRow(row, do_select);
988 }
989
990 var check = document.getElementById(check_id);
991
992 if (check) {
993 check.checked = do_select;
994 }
995 } catch (e) {
996 exception_error("selectTableRowById", e);
997 }
998}
999
1572afe5 1000function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
649e0af9 1001 classcheck, reset_others) {
3745788e 1002
35f3c923
AD
1003 var content = document.getElementById(content_id);
1004
1005 if (!content) {
1006 alert("[selectTableRows] Element " + content_id + " not found.");
1007 return;
1008 }
1009
1010 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
1011 if (!classcheck || content.rows[i].className.match(classcheck)) {
1012
1013 if (content.rows[i].id.match(prefix)) {
1014 selectTableRow(content.rows[i], do_select);
649e0af9
AD
1015
1016 var row_id = content.rows[i].id.replace(prefix, "");
1017 var check = document.getElementById(check_prefix + row_id);
3055bc41 1018
649e0af9
AD
1019 if (check) {
1020 check.checked = do_select;
1021 }
1022 } else if (reset_others) {
1023 selectTableRow(content.rows[i], false);
7d8d10c6
AD
1024
1025 var row_id = content.rows[i].id.replace(prefix, "");
1026 var check = document.getElementById(check_prefix + row_id);
1027
1028 if (check) {
1029 check.checked = false;
1030 }
1031
1572afe5 1032 }
649e0af9
AD
1033 } else if (reset_others) {
1034 selectTableRow(content.rows[i], false);
7d8d10c6
AD
1035
1036 var row_id = content.rows[i].id.replace(prefix, "");
1037 var check = document.getElementById(check_prefix + row_id);
1038
1039 if (check) {
1040 check.checked = false;
1041 }
1042
3055bc41 1043 }
35f3c923 1044 }
295f9b42 1045}
91ff844a
AD
1046
1047function getSelectedTableRowIds(content_id, prefix) {
1048
1049 var content = document.getElementById(content_id);
1050
1051 if (!content) {
1052 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
1053 return;
1054 }
1055
1056 var sel_rows = new Array();
1057
1058 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
1059 if (content.rows[i].id.match(prefix) &&
1060 content.rows[i].className.match("Selected")) {
1061
91ff844a
AD
1062 var row_id = content.rows[i].id.replace(prefix + "-", "");
1063 sel_rows.push(row_id);
1064 }
1065 }
1066
1067 return sel_rows;
1068
1069}
1070
386cbf27
AD
1071function toggleSelectRowById(sender, id) {
1072 var row = document.getElementById(id);
1073
1074 if (sender.checked) {
1075 if (!row.className.match("Selected")) {
1076 row.className = row.className + "Selected";
1077 }
1078 } else {
1079 if (row.className.match("Selected")) {
1080 row.className = row.className.replace("Selected", "");
1081 }
1082 }
1083}
1084
b92e6209
AD
1085function toggleSelectListRow(sender) {
1086 var parent_row = sender.parentNode;
1087
1088 if (sender.checked) {
1089 if (!parent_row.className.match("Selected")) {
1090 parent_row.className = parent_row.className + "Selected";
1091 }
1092 } else {
1093 if (parent_row.className.match("Selected")) {
1094 parent_row.className = parent_row.className.replace("Selected", "");
1095 }
1096 }
1097}
1098
386cbf27 1099
1572afe5
AD
1100function toggleSelectRow(sender) {
1101 var parent_row = sender.parentNode.parentNode;
1102
1103 if (sender.checked) {
1104 if (!parent_row.className.match("Selected")) {
1105 parent_row.className = parent_row.className + "Selected";
1106 }
1107 } else {
1108 if (parent_row.className.match("Selected")) {
1109 parent_row.className = parent_row.className.replace("Selected", "");
1110 }
1111 }
1112}
1113
3866b046
AD
1114function openExternalUrl(url) {
1115 var w = window.open(url);
1116}
1572afe5 1117
1da76274 1118function getRelativeFeedId(list, id, direction, unread_only) {
7b433d8c
AD
1119 if (!id) {
1120 if (direction == "next") {
1121 for (i = 0; i < list.childNodes.length; i++) {
1122 var child = list.childNodes[i];
1da76274 1123 if (child.id && child.id == "feedCatHolder") {
c3f348c2 1124 if (child.lastChild) {
d05514a4 1125 var cr = getRelativeFeedId(child.firstChild, id, direction, unread_only);
7b433d8c
AD
1126 if (cr) return cr;
1127 }
1da76274 1128 } else if (child.id && child.id.match("FEEDR-")) {
7b433d8c
AD
1129 return child.id.replace('FEEDR-', '');
1130 }
1131 }
1132 }
1133
1134 // FIXME select last feed doesn't work when only unread feeds are visible
1135
1136 if (direction == "prev") {
1137 for (i = list.childNodes.length-1; i >= 0; i--) {
1138 var child = list.childNodes[i];
1139 if (child.id == "feedCatHolder") {
1140 if (child.firstChild) {
1141 var cr = getRelativeFeedId(child.firstChild, id, direction);
1142 if (cr) return cr;
1143 }
1144 } else if (child.id.match("FEEDR-")) {
1145
e8bd0da9 1146 if (getInitParam("hide_read_feeds") == 1) {
7b433d8c
AD
1147 if (child.className != "feed") {
1148 alert(child.className);
1149 return child.id.replace('FEEDR-', '');
1150 }
1151 } else {
1152 return child.id.replace('FEEDR-', '');
1153 }
1154 }
1155 }
1156 }
1157 } else {
1158
d05514a4 1159 var feed = list.ownerDocument.getElementById("FEEDR-" + id);
7b433d8c 1160
e8bd0da9 1161 if (getInitParam("hide_read_feeds") == 1) {
1da76274
AD
1162 unread_only = true;
1163 }
1164
7b433d8c
AD
1165 if (direction == "next") {
1166
1da76274 1167 var e = feed;
7b433d8c 1168
1da76274 1169 while (e) {
7b433d8c 1170
1da76274
AD
1171 if (e.nextSibling) {
1172
1173 e = e.nextSibling;
1174
1175 } else if (e.parentNode.parentNode.nextSibling) {
7b433d8c 1176
1da76274 1177 var this_cat = e.parentNode.parentNode;
7b433d8c 1178
1da76274 1179 e = false;
7b433d8c 1180
1da76274
AD
1181 if (this_cat && this_cat.nextSibling) {
1182 while (!e && this_cat.nextSibling) {
1183 this_cat = this_cat.nextSibling;
1184 if (this_cat.id == "feedCatHolder") {
1185 e = this_cat.firstChild.firstChild;
7b433d8c
AD
1186 }
1187 }
7b433d8c 1188 }
1da76274
AD
1189
1190 } else {
1191 e = false;
1192 }
1193
1194 if (e) {
d05514a4 1195 if (!unread_only || (unread_only && e.className != "feed" &&
cabffe9d 1196 e.className.match("feed"))) {
1da76274
AD
1197 return e.id.replace("FEEDR-", "");
1198 }
1199 }
7b433d8c 1200 }
1da76274 1201
7b433d8c
AD
1202 } else if (direction == "prev") {
1203
1da76274 1204 var e = feed;
7b433d8c 1205
1da76274 1206 while (e) {
7b433d8c 1207
1da76274
AD
1208 if (e.previousSibling) {
1209
1210 e = e.previousSibling;
1211
1212 } else if (e.parentNode.parentNode.previousSibling) {
7b433d8c 1213
1da76274 1214 var this_cat = e.parentNode.parentNode;
7b433d8c 1215
1da76274
AD
1216 e = false;
1217
1218 if (this_cat && this_cat.previousSibling) {
1219 while (!e && this_cat.previousSibling) {
1220 this_cat = this_cat.previousSibling;
1221 if (this_cat.id == "feedCatHolder") {
1222 e = this_cat.firstChild.lastChild;
7b433d8c
AD
1223 }
1224 }
7b433d8c 1225 }
1da76274
AD
1226
1227 } else {
1228 e = false;
1229 }
1230
1231 if (e) {
e686782e 1232 if (!unread_only || (unread_only && e.className != "feed" &&
cabffe9d 1233 e.className.match("feed"))) {
1da76274
AD
1234 return e.id.replace("FEEDR-", "");
1235 }
1236 }
1237 }
7b433d8c
AD
1238 }
1239 }
1240}
36aab70f
AD
1241
1242function showBlockElement(id) {
1243 var elem = document.getElementById(id);
1244
1245 if (elem) {
1246 elem.style.display = "block";
1247 } else {
1248 alert("[showBlockElement] can't find element with id " + id);
1249 }
1250}
1251
a9b0bfd5
AD
1252function hideParentElement(e) {
1253 e.parentNode.style.display = "none";
1254}
1b0809ae
AD
1255
1256function dropboxSelect(e, v) {
1257 for (i = 0; i < e.length; i++) {
1258 if (e[i].value == v) {
1259 e.selectedIndex = i;
1260 break;
1261 }
1262 }
1263}
0ee1d1a0
AD
1264
1265// originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1266// bugfixed just a little bit :-)
1267function getURLParam(strParamName){
1268 var strReturn = "";
1269 var strHref = window.location.href;
1270
1271 if (strHref.indexOf("#") == strHref.length-1) {
1272 strHref = strHref.substring(0, strHref.length-1);
1273 }
1274
1275 if ( strHref.indexOf("?") > -1 ){
1276 var strQueryString = strHref.substr(strHref.indexOf("?"));
1277 var aQueryString = strQueryString.split("&");
1278 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1279 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1280 var aParam = aQueryString[iParam].split("=");
1281 strReturn = aParam[1];
1282 break;
1283 }
1284 }
1285 }
1286 return strReturn;
1287}
1288
cf1bc085
AD
1289function leading_zero(p) {
1290 var s = String(p);
1291 if (s.length == 1) s = "0" + s;
1292 return s;
1293}
c38c2b69 1294
86b682ce 1295function closeInfoBox(cleanup) {
e5d758e3
AD
1296 var box = document.getElementById('infoBox');
1297 var shadow = document.getElementById('infoBoxShadow');
1298
1299 if (shadow) {
1300 shadow.style.display = "none";
1301 } else if (box) {
1302 box.style.display = "none";
1303 }
1304
86b682ce
AD
1305 if (cleanup) box.innerHTML = "&nbsp;";
1306
e5d758e3 1307 enableHotkeys();
c14b5566 1308
90ac84df 1309 return false;
e5d758e3
AD
1310}
1311
1312
7b5c6012
AD
1313function displayDlg(id, param) {
1314
1315 if (!xmlhttp_ready(xmlhttp)) {
1316 printLockingError();
1317 return
1318 }
1319
1320 notify("");
1321
1322 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
1323 param_escape(id) + "&param=" + param_escape(param), true);
e5d758e3 1324 xmlhttp.onreadystatechange=infobox_callback;
7b5c6012
AD
1325 xmlhttp.send(null);
1326
1327 disableHotkeys();
2371c520 1328
90ac84df 1329 return false;
7b5c6012
AD
1330}
1331
e5d758e3 1332function infobox_submit_callback() {
7b5c6012 1333 if (xmlhttp.readyState == 4) {
e5d758e3 1334 closeInfoBox();
7b5c6012 1335
6e6504bc
AD
1336 try {
1337 // called from prefs, reload tab
1338 if (active_tab) {
1339 selectTab(active_tab, false);
1340 }
1341 } catch (e) { }
79f3553b
AD
1342
1343 notify(xmlhttp.responseText);
1344
7b5c6012
AD
1345 }
1346}
1347
e5d758e3 1348function infobox_callback() {
7b5c6012 1349 if (xmlhttp.readyState == 4) {
e5d758e3
AD
1350 var box = document.getElementById('infoBox');
1351 var shadow = document.getElementById('infoBoxShadow');
1352 if (box) {
1353 box.innerHTML=xmlhttp.responseText;
1354 if (shadow) {
1355 shadow.style.display = "block";
1356 } else {
1357 box.style.display = "block";
1358 }
1359 }
9c483746 1360 notify("");
e5d758e3 1361 }
7b5c6012
AD
1362}
1363
1364function qaddFilter() {
1365
1366 if (!xmlhttp_ready(xmlhttp)) {
1367 printLockingError();
1368 return
1369 }
1370
c91c2249
AD
1371 var form = document.forms['filter_add_form'];
1372 var reg_exp = form.reg_exp.value;
1373
1374 if (reg_exp == "") {
1375 alert("Can't add filter: nothing to match on.");
1376 return false;
1377 }
1378
79f3553b 1379 var query = Form.serialize("filter_add_form");
7b5c6012 1380
79f3553b
AD
1381 xmlhttp.open("GET", "backend.php?" + query, true);
1382 xmlhttp.onreadystatechange=infobox_submit_callback;
1383 xmlhttp.send(null);
7b5c6012 1384
c14b5566 1385 return true;
7b5c6012
AD
1386}
1387
2371c520
AD
1388function toggleSubmitNotEmpty(e, submit_id) {
1389 try {
1390 document.getElementById(submit_id).disabled = (e.value == "")
1391 } catch (e) {
1392 exception_error("toggleSubmitNotEmpty", e);
1393 }
1394}
1d7bf5a0 1395
605f7d46
AD
1396function isValidURL(s) {
1397 return s.match("http://") != null || s.match("https://") != null;
1398}
07eb9178
AD
1399
1400function qafAdd() {
1401
1402 if (!xmlhttp_ready(xmlhttp)) {
1403 printLockingError();
1404 return
1405 }
1406
c91c2249
AD
1407 var form = document.forms['feed_add_form'];
1408 var feed_url = form.feed_url.value;
1409
1410 if (feed_url == "") {
1411 alert("Can't subscribe: no feed URL given.");
1412 return false;
1413 }
1414
a58d997c 1415 notify("Adding feed...", true);
07eb9178
AD
1416
1417 closeInfoBox();
1418
0feab655 1419 var feeds_doc = document;
07eb9178 1420
80e4dc34 1421// feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
07eb9178
AD
1422
1423 var query = Form.serialize("feed_add_form");
1424
1425 xmlhttp.open("GET", "backend.php?" + query, true);
1426 xmlhttp.onreadystatechange=dlg_frefresh_callback;
1427 xmlhttp.send(null);
7bc4f251
AD
1428
1429 return false;
07eb9178
AD
1430}
1431
6e6504bc 1432function filterCR(e, f)
86b682ce
AD
1433{
1434 var key;
1435
1436 if(window.event)
1437 key = window.event.keyCode; //IE
1438 else
1439 key = e.which; //firefox
1440
6e6504bc
AD
1441 if (key == 13) {
1442 if (typeof f != 'undefined') {
1443 f();
1444 return false;
1445 } else {
1446 return false;
1447 }
1448 } else {
1449 return true;
1450 }
86b682ce
AD
1451}
1452
ac378ad4 1453function getMainContext() {
6b4163cb 1454 return this.window;
ac378ad4
AD
1455}
1456
33d13e72 1457function getFeedsContext() {
6b4163cb 1458 return this.window;
33d13e72
AD
1459}
1460
0bd411db 1461function getContentContext() {
6b4163cb 1462 return this.window;
0bd411db
AD
1463}
1464
ee1f45f4 1465function getHeadlinesContext() {
6b4163cb 1466 return this.window;
ee1f45f4
AD
1467}
1468
e8614131
AD
1469var debug_last_class = "even";
1470
ac378ad4 1471function debug(msg) {
ac378ad4 1472
0feab655
AD
1473 if (debug_last_class == "even") {
1474 debug_last_class = "odd";
e8614131 1475 } else {
0feab655 1476 debug_last_class = "even";
e8614131
AD
1477 }
1478
0feab655 1479 var c = document.getElementById('debug_output');
ac378ad4 1480 if (c && c.style.display == "block") {
c9268ed5 1481 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
ac378ad4
AD
1482 c.removeChild(c.lastChild);
1483 }
1484
1485 var d = new Date();
1486 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1487 ":" + leading_zero(d.getSeconds());
0feab655 1488 c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
e8614131 1489 msg + "</li>" + c.innerHTML;
ac378ad4
AD
1490 }
1491}
1492
33d13e72
AD
1493function getInitParam(key) {
1494 return getMainContext().init_params[key];
1495}
3ac2b520 1496
e8bd0da9 1497function storeInitParam(key, value, is_client) {
33d13e72 1498 try {
e8bd0da9 1499 if (!is_client) {
1035fcec
AD
1500 if (getMainContext().init_params[key] != value) {
1501 debug("storeInitParam: " + key + " => " + value);
0b7cb301
AD
1502 //new Ajax.Request("backend.php?op=rpc&subop=storeParam&key=" +
1503 // param_escape(key) + "&value=" + param_escape(value));
1504 var f = getMainContext().document.getElementById("backReqBox");
1505 f.src = "backend.php?op=rpc&subop=storeParam&key=" +
1506 param_escape(key) + "&value=" + param_escape(value);
1035fcec 1507 }
e8bd0da9 1508 }
1035fcec 1509 getMainContext().init_params[key] = value;
33d13e72
AD
1510 } catch (e) {
1511 exception_error("storeInitParam", e);
1512 }
1513}
a7565293 1514
1035fcec
AD
1515/*
1516function storeInitParams(params, is_client) {
1517 try {
1518 var s = "";
1519
1520 for (k in params) {
1521 if (getMainContext().init_params[k] != params[k]) {
1522 s += k + "=" + params[k] + ";";
1523 getMainContext().init_params[k] = params[k];
1524 }
1525 }
1526
1527 debug("storeInitParams: " + s);
1528
1529 if (!is_client) {
1530 new Ajax.Request("backend.php?op=rpc&subop=storeParams&str=" + s);
1531 }
1532 } catch (e) {
1533 exception_error("storeInitParams", e);
1534 }
1535}*/
1536
a7565293
AD
1537function fatalError(code, message) {
1538 try {
a7565293 1539
b4c27af7 1540 if (code == 6) {
01a87dff 1541 //window.location.href = "login.php?rt=none";
b4c27af7
AD
1542 } else if (code == 5) {
1543 window.location.href = "update.php";
1544 } else {
4724a093
AD
1545 var fe = document.getElementById("fatal_error");
1546 var fc = document.getElementById("fatal_error_msg");
1547
1548 fc.innerHTML = "Code " + code + ": " + message;
1549
1550 fe.style.display = "block";
4724a093 1551 }
a7565293
AD
1552
1553 } catch (e) {
1554 exception_error("fatalError", e);
1555 }
1556}
1557
234e467c 1558function getFeedName(id, is_cat) {
64a2875d 1559 var d = getFeedsContext().document;
234e467c
AD
1560
1561 var e;
1562
1563 if (is_cat) {
1564 e = d.getElementById("FCATN-" + id);
1565 } else {
1566 e = d.getElementById("FEEDN-" + id);
1567 }
64a2875d
AD
1568 if (e) {
1569 return e.innerHTML.stripTags();
1570 } else {
1571 return null;
1572 }
1573}
0bd411db
AD
1574
1575function viewContentUrl(url) {
1576 getContentContext().location = url;
1577}
350f0ad1
AD
1578
1579function filterDlgCheckAction(sender) {
1580
1581 try {
1582
1583 var action = sender[sender.selectedIndex].value;
1584
1585 var form = document.forms["filter_add_form"];
1586
1587 if (!form) {
1588 form = document.forms["filter_edit_form"];
1589 }
1590
1591 if (!form) {
1592 debug("filterDlgCheckAction: can't find form!");
1593 return;
1594 }
1595
1596 var action_param = form.action_param;
1597
1598 if (!action_param) {
1599 debug("filterDlgCheckAction: can't find action param!");
1600 return;
1601 }
1602
1603 // if selected action supports parameters, enable params field
1604 if (action == 4) {
1605 action_param.disabled = false;
1606 } else {
1607 action_param.disabled = true;
1608 }
1609
1610 } catch (e) {
1611 exception_error(e, "filterDlgCheckAction");
1612 }
1613
1614}
ef16ae37
AD
1615
1616function explainError(code) {
1617 return displayDlg("explainError", code);
1618}
01a87dff
AD
1619
1620function logoutUser() {
1621 try {
1622 if (xmlhttp_ready(xmlhttp_rpc)) {
1623 xmlhttp_rpc.open("GET", "backend.php?op=rpc&subop=logout", true);
1624 xmlhttp_rpc.onreadystatechange=logout_callback;
1625 xmlhttp_rpc.send(null);
1626 } else {
1627 printLockingError();
1628 }
1629 } catch (e) {
1630 exception_error("logoutUser", e);
1631 }
1632}