]> git.wh0rd.org - tt-rss.git/blame - prefs.js
ajaxify prefs save/reset; update translations
[tt-rss.git] / prefs.js
CommitLineData
007bda35
AD
1var xmlhttp = false;
2
91ff844a 3var active_feed_cat = false;
48f0adb0 4var active_label = false;
f5a50b25 5var active_tab = false;
c6232e43 6var feed_to_expand = false;
f5a50b25 7
a58069db 8var xmlhttp = Ajax.getTransport();
007bda35 9
a7565293
AD
10var init_params = new Array();
11
e513a74a
AD
12var caller_subop = false;
13
7a09510c
AD
14var sanity_check_done = false;
15
e4f4b46f 16function replace_pubkey_callback() {
c6232e43
AD
17 if (xmlhttp.readyState == 4) {
18 try {
e4f4b46f
AD
19 var link = document.getElementById("pubGenAddress");
20
21 if (xmlhttp.responseXML) {
22
945c243e
AD
23 var new_link = xmlhttp.responseXML.getElementsByTagName("link")[0];
24
25 if (new_link) {
26 link.href = new_link.firstChild.nodeValue;
27 link.innerHTML = new_link.firstChild.nodeValue;
28
f56e3080 29 notify_info("Address changed.");
945c243e 30 } else {
f56e3080 31 notify_error("Could not change address.");
945c243e 32 }
e4f4b46f
AD
33
34 } else {
f56e3080 35 notify_error("Could not change address.");
e4f4b46f 36 }
c6232e43 37 } catch (e) {
e4f4b46f 38 exception_error("replace_pubkey_callback", e);
c6232e43
AD
39 }
40 }
945c243e 41}
c6232e43 42
e4f4b46f 43function expand_feed_callback() {
bc0ed820
AD
44 if (xmlhttp.readyState == 4) {
45 try {
e4f4b46f 46 var container = document.getElementById("BRDET-" + feed_to_expand);
bc0ed820 47 container.innerHTML=xmlhttp.responseText;
34a01a20 48// container.style.display = "block";
e4f4b46f 49// p_notify("");
051c4d56 50 Effect.Appear(container, {duration : 0.5});
bc0ed820 51 } catch (e) {
e4f4b46f 52 exception_error("expand_feed_callback", e);
bc0ed820
AD
53 }
54 }
55}
56
007bda35 57function feedlist_callback() {
007bda35 58 if (xmlhttp.readyState == 4) {
47c6c988
AD
59 try {
60 var container = document.getElementById('prefContent');
61 container.innerHTML=xmlhttp.responseText;
a7f22b70 62 selectTab("feedConfig", true);
e513a74a
AD
63
64 if (caller_subop) {
65 var tuple = caller_subop.split(":");
66 if (tuple[0] == 'editFeed') {
67 window.setTimeout('editFeed('+tuple[1]+')', 100);
68 }
69
70 caller_subop = false;
71 }
23943c9b
AD
72 if (typeof correctPNG != 'undefined') {
73 correctPNG();
74 }
7f74a9da 75 notify("");
47c6c988
AD
76 } catch (e) {
77 exception_error("feedlist_callback", e);
961513a3 78 }
007bda35
AD
79 }
80}
81
442d77f1
AD
82/* stub for subscription dialog */
83
84function dlg_frefresh_callback() {
85 if (xmlhttp.readyState == 4) {
86 // setTimeout("updateFeedList()", 500);
87
88 try {
89 var container = document.getElementById('prefContent');
90 container.innerHTML=xmlhttp.responseText;
91 selectTab("feedConfig", true);
92
93 if (caller_subop) {
94 var tuple = caller_subop.split(":");
95 if (tuple[0] == 'editFeed') {
96 window.setTimeout('editFeed('+tuple[1]+')', 100);
97 }
98
99 caller_subop = false;
100 }
101 if (typeof correctPNG != 'undefined') {
102 correctPNG();
103 }
104 notify("");
105 } catch (e) {
106 exception_error("feedlist_callback", e);
107 }
108 }
109}
110
a0d53889 111function filterlist_callback() {
f5a50b25 112 var container = document.getElementById('prefContent');
a0d53889
AD
113 if (xmlhttp.readyState == 4) {
114 container.innerHTML=xmlhttp.responseText;
23943c9b
AD
115 if (typeof correctPNG != 'undefined') {
116 correctPNG();
117 }
7f74a9da 118 notify("");
a0d53889
AD
119 }
120}
121
48f0adb0 122function labellist_callback() {
f5a50b25 123 var container = document.getElementById('prefContent');
48f0adb0 124 if (xmlhttp.readyState == 4) {
f156fd00 125 closeInfoBox();
48f0adb0 126 container.innerHTML=xmlhttp.responseText;
967955b7 127 if (active_label) {
48f0adb0
AD
128 var row = document.getElementById("LILRR-" + active_label);
129 if (row) {
130 if (!row.className.match("Selected")) {
131 row.className = row.className + "Selected";
132 }
133 }
134 var checkbox = document.getElementById("LICHK-" + active_label);
135
136 if (checkbox) {
137 checkbox.checked = true;
138 }
139 }
23943c9b
AD
140 if (typeof correctPNG != 'undefined') {
141 correctPNG();
142 }
7f74a9da 143 notify("");
48f0adb0
AD
144 }
145}
4255b24c 146
c6232e43
AD
147function feed_browser_callback() {
148 var container = document.getElementById('prefContent');
149 if (xmlhttp.readyState == 4) {
150 container.innerHTML=xmlhttp.responseText;
7f74a9da 151 notify("");
c6232e43
AD
152 }
153}
154
e6cb77a0
AD
155function userlist_callback() {
156 var container = document.getElementById('prefContent');
157 if (xmlhttp.readyState == 4) {
158 container.innerHTML=xmlhttp.responseText;
7f74a9da 159 notify("");
e6cb77a0
AD
160 }
161}
162
4255b24c
AD
163function prefslist_callback() {
164 var container = document.getElementById('prefContent');
165 if (xmlhttp.readyState == 4) {
166
167 container.innerHTML=xmlhttp.responseText;
7f74a9da
AD
168
169 notify("");
4255b24c
AD
170 }
171}
172
b1895692
AD
173function gethelp_callback() {
174 var container = document.getElementById('prefHelpBox');
175 if (xmlhttp.readyState == 4) {
176
177 container.innerHTML = xmlhttp.responseText;
178 container.style.display = "block";
179
180 }
181}
4255b24c 182
0e091d38 183function notify_callback() {
0e091d38 184 if (xmlhttp.readyState == 4) {
42c32916
AD
185 notify_info(xmlhttp.responseText);
186 }
0e091d38
AD
187}
188
b652c1b7
AD
189function prefs_reset_callback() {
190 if (xmlhttp.readyState == 4) {
191 notify_info(xmlhttp.responseText);
192 selectTab();
193 }
194}
195
d95bd220
AD
196
197function changepass_callback() {
42395d28
AD
198 try {
199 if (xmlhttp.readyState == 4) {
200
201 if (xmlhttp.responseText.indexOf("ERROR: ") == 0) {
202 notify_error(xmlhttp.responseText.replace("ERROR: ", ""));
203 } else {
204 notify_info(xmlhttp.responseText);
205 var warn = document.getElementById("default_pass_warning");
206 if (warn) warn.style.display = "none";
207 }
208
209 document.forms['change_pass_form'].reset();
d95bd220 210
42395d28
AD
211 }
212 } catch (e) {
213 exception_error("changepass_callback", e);
214 }
d95bd220
AD
215}
216
11f083e7
AD
217function infobox_feed_cat_callback() {
218 if (xmlhttp.readyState == 4) {
219 try {
220
221 infobox_callback();
222
223 if (document.getElementById("prefFeedCatList")) {
224 var elems = document.getElementById("prefFeedCatList").getElementsByTagName("SPAN");
225
226 for (var i = 0; i < elems.length; i++) {
227 if (elems[i].id && elems[i].id.match("FCATT-")) {
228 var cat_id = elems[i].id.replace("FCATT-", "");
229
230 new Ajax.InPlaceEditor(elems[i],
231 'backend.php?op=pref-feeds&subop=editCats&action=save&cid=' + cat_id);
232 }
233 }
234 }
235
236 } catch (e) {
237 exception_error("infobox_feed_cat_callback", e);
238 }
239 }
240}
241
b83c7545 242function updateFeedList(sort_key) {
007bda35 243
c0e5a40e 244 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
245 printLockingError();
246 return
247 }
248
f5a50b25
AD
249// document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
250
ce3bf408 251// p_notify("Loading, please wait...");
007bda35 252
f932bc9f
AD
253 var feed_search = document.getElementById("feed_search");
254 var search = "";
255 if (feed_search) { search = feed_search.value; }
256
400b60d8
AD
257 var slat = document.getElementById("show_last_article_times");
258
259 var slat_checked = false;
260 if (slat) {
261 slat_checked = slat.checked;
262 }
263
b83c7545 264 xmlhttp.open("GET", "backend.php?op=pref-feeds" +
f932bc9f 265 "&sort=" + param_escape(sort_key) +
400b60d8 266 "&slat=" + param_escape(slat_checked) +
f932bc9f 267 "&search=" + param_escape(search), true);
007bda35
AD
268 xmlhttp.onreadystatechange=feedlist_callback;
269 xmlhttp.send(null);
270
271}
272
79ec0f2f 273function updateUsersList(sort_key) {
e6cb77a0
AD
274
275 if (!xmlhttp_ready(xmlhttp)) {
276 printLockingError();
277 return
278 }
279
280// document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
281
ce3bf408 282// p_notify("Loading, please wait...");
e6cb77a0 283
79ec0f2f
AD
284 xmlhttp.open("GET", "backend.php?op=pref-users&sort="
285 + param_escape(sort_key), true);
e6cb77a0
AD
286 xmlhttp.onreadystatechange=userlist_callback;
287 xmlhttp.send(null);
288
289}
290
48f0adb0
AD
291function addLabel() {
292
293 if (!xmlhttp_ready(xmlhttp)) {
294 printLockingError();
295 return
296 }
297
f156fd00 298 var form = document.forms['label_edit_form'];
48f0adb0 299
f156fd00
AD
300 var sql_exp = form.sql_exp.value;
301 var description = form.description.value;
48f0adb0 302
f156fd00 303 if (sql_exp == "") {
89cb787e 304 alert(__("Can't create label: missing SQL expression."));
f156fd00 305 return false;
48f0adb0
AD
306 }
307
f156fd00 308 if (description == "") {
89cb787e 309 alert(__("Can't create label: missing caption."));
f156fd00 310 return false;
de435974
AD
311 }
312
f156fd00 313 var query = Form.serialize("label_edit_form");
de435974 314
f156fd00
AD
315 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=add&" + query, true);
316 xmlhttp.onreadystatechange=infobox_submit_callback;
317 xmlhttp.send(null);
de435974 318}
48f0adb0 319
71ad3959
AD
320function addFeed() {
321
c0e5a40e 322 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
323 printLockingError();
324 return
325 }
326
331900c6
AD
327 var link = document.getElementById("fadd_link");
328
83fe4d6d 329 if (link.value.length == 0) {
f3977cf5 330 alert(__("Error: No feed URL given."));
605f7d46 331 } else if (!isValidURL(link.value)) {
f3977cf5 332 alert(__("Error: Invalid feed URL."));
331900c6 333 } else {
42c32916 334 notify_progress("Adding feed...");
331900c6 335
e513a74a 336 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&from=tt-rss&feed_url=" +
331900c6
AD
337 param_escape(link.value), true);
338 xmlhttp.onreadystatechange=feedlist_callback;
339 xmlhttp.send(null);
340
341 link.value = "";
342
343 }
344
345}
346
91ff844a
AD
347function addFeedCat() {
348
349 if (!xmlhttp_ready(xmlhttp)) {
350 printLockingError();
351 return
352 }
353
354 var cat = document.getElementById("fadd_cat");
355
356 if (cat.value.length == 0) {
f3977cf5 357 alert(__("Can't add category: no name specified."));
91ff844a 358 } else {
42c32916 359 notify_progress("Adding feed category...");
91ff844a 360
9c483746 361 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=add&cat=" +
91ff844a 362 param_escape(cat.value), true);
9c483746 363 xmlhttp.onreadystatechange=infobox_callback;
91ff844a
AD
364 xmlhttp.send(null);
365
366 link.value = "";
367
368 }
369
370}
e6cb77a0
AD
371function addUser() {
372
373 if (!xmlhttp_ready(xmlhttp)) {
374 printLockingError();
375 return
376 }
377
378 var sqlexp = document.getElementById("uadd_box");
379
380 if (sqlexp.value.length == 0) {
89cb787e 381 alert(__("Can't add user: no login specified."));
e6cb77a0 382 } else {
42c32916 383 notify_progress("Adding user...");
e6cb77a0
AD
384
385 xmlhttp.open("GET", "backend.php?op=pref-users&subop=add&login=" +
386 param_escape(sqlexp.value), true);
387
388 xmlhttp.onreadystatechange=userlist_callback;
389 xmlhttp.send(null);
390
391 sqlexp.value = "";
392 }
393
394}
395
48f0adb0
AD
396function editLabel(id) {
397
398 if (!xmlhttp_ready(xmlhttp)) {
399 printLockingError();
400 return
401 }
402
9e31e1b9
AD
403 notify_progress("Loading, please wait...");
404
f156fd00
AD
405 document.getElementById("label_create_btn").disabled = true;
406
48f0adb0
AD
407 active_label = id;
408
a4dbc524
AD
409 selectTableRowsByIdPrefix('prefLabelList', 'LILRR-', 'LICHK-', false);
410 selectTableRowById('LILRR-'+id, 'LICHK-'+id, true);
411
48f0adb0
AD
412 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=edit&id=" +
413 param_escape(id), true);
a4dbc524 414 xmlhttp.onreadystatechange=infobox_callback;
48f0adb0
AD
415 xmlhttp.send(null);
416
417}
418
e6cb77a0
AD
419function editUser(id) {
420
421 if (!xmlhttp_ready(xmlhttp)) {
422 printLockingError();
423 return
424 }
425
9e31e1b9
AD
426 notify_progress("Loading, please wait...");
427
3c5783b7
AD
428 selectTableRowsByIdPrefix('prefUserList', 'UMRR-', 'UMCHK-', false);
429 selectTableRowById('UMRR-'+id, 'UMCHK-'+id, true);
e6cb77a0
AD
430
431 xmlhttp.open("GET", "backend.php?op=pref-users&subop=edit&id=" +
432 param_escape(id), true);
3c5783b7 433 xmlhttp.onreadystatechange=infobox_callback;
e6cb77a0
AD
434 xmlhttp.send(null);
435
436}
437
a0d53889
AD
438function editFilter(id) {
439
440 if (!xmlhttp_ready(xmlhttp)) {
441 printLockingError();
442 return
443 }
444
9e31e1b9
AD
445 notify_progress("Loading, please wait...");
446
4220b0bd
AD
447 document.getElementById("create_filter_btn").disabled = true;
448
07164479
AD
449 selectTableRowsByIdPrefix('prefFilterList', 'FILRR-', 'FICHK-', false);
450 selectTableRowById('FILRR-'+id, 'FICHK-'+id, true);
a0d53889 451
07164479
AD
452 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=edit&id=" + param_escape(id), true);
453 xmlhttp.onreadystatechange=infobox_callback;
a0d53889 454 xmlhttp.send(null);
a0d53889
AD
455}
456
331900c6
AD
457function editFeed(feed) {
458
508a81e1
AD
459// notify("Editing feed...");
460
c0e5a40e 461 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
462 printLockingError();
463 return
464 }
331900c6 465
9e31e1b9
AD
466 notify_progress("Loading, please wait...");
467
a349077c
AD
468 document.getElementById("subscribe_to_feed_btn").disabled = true;
469
470 try {
471 document.getElementById("top25_feeds_btn").disabled = true;
472 } catch (e) {
473 // this button is not always available, no-op if not found
474 }
475
673d54ca 476 // clean selection from all rows & select row being edited
0ea4fb50 477 selectTableRowsByIdPrefix('prefFeedList', 'FEEDR-', 'FRCHK-', false);
6c12c809 478 selectTableRowById('FEEDR-'+feed, 'FRCHK-'+feed, true);
0ea4fb50
AD
479
480 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
3c5783b7 481 param_escape(feed), true);
0ea4fb50
AD
482
483 xmlhttp.onreadystatechange=infobox_callback;
331900c6
AD
484 xmlhttp.send(null);
485
486}
487
91ff844a 488function editFeedCat(cat) {
48f0adb0 489
91ff844a
AD
490 if (!xmlhttp_ready(xmlhttp)) {
491 printLockingError();
492 return
48f0adb0
AD
493 }
494
9e31e1b9
AD
495 notify_progress("Loading, please wait...");
496
91ff844a 497 active_feed_cat = cat;
e6cb77a0 498
9c483746 499 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=edit&id=" +
91ff844a 500 param_escape(cat), true);
9c483746 501 xmlhttp.onreadystatechange=infobox_callback;
91ff844a 502 xmlhttp.send(null);
e6cb77a0 503
e6cb77a0
AD
504}
505
91ff844a
AD
506function getSelectedLabels() {
507 return getSelectedTableRowIds("prefLabelList", "LILRR");
508}
48f0adb0 509
91ff844a
AD
510function getSelectedUsers() {
511 return getSelectedTableRowIds("prefUserList", "UMRR");
a0d53889
AD
512}
513
83fe4d6d 514function getSelectedFeeds() {
91ff844a
AD
515 return getSelectedTableRowIds("prefFeedList", "FEEDR");
516}
331900c6 517
91ff844a
AD
518function getSelectedFilters() {
519 return getSelectedTableRowIds("prefFilterList", "FILRR");
520}
331900c6 521
91ff844a
AD
522function getSelectedFeedCats() {
523 return getSelectedTableRowIds("prefFeedCatList", "FCATR");
83fe4d6d
AD
524}
525
c0ae0fdb
AD
526function getSelectedFeedsFromBrowser() {
527
528 var list = document.getElementById("browseFeedList");
529 if (!list) list = document.getElementById("browseBigFeedList");
530
531 var selected = new Array();
532
533 for (i = 0; i < list.childNodes.length; i++) {
534 var child = list.childNodes[i];
535 if (child.id && child.id.match("FBROW-")) {
536 var id = child.id.replace("FBROW-", "");
537
538 var cb = document.getElementById("FBCHK-" + id);
539
540 if (cb.checked) {
541 selected.push(id);
542 }
543 }
544 }
545
546 return selected;
547}
548
48f0adb0
AD
549function removeSelectedLabels() {
550
551 if (!xmlhttp_ready(xmlhttp)) {
552 printLockingError();
553 return
554 }
555
556 var sel_rows = getSelectedLabels();
557
558 if (sel_rows.length > 0) {
559
f56e3080 560 var ok = confirm(__("Remove selected labels?"));
48f0adb0 561
69668465 562 if (ok) {
42c32916 563 notify_progress("Removing selected labels...");
69668465
AD
564
565 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
566 param_escape(sel_rows.toString()), true);
567 xmlhttp.onreadystatechange=labellist_callback;
568 xmlhttp.send(null);
569 }
48f0adb0 570 } else {
89cb787e 571 alert(__("No labels are selected."));
48f0adb0 572 }
90ac84df
AD
573
574 return false;
48f0adb0
AD
575}
576
e6cb77a0
AD
577function removeSelectedUsers() {
578
579 if (!xmlhttp_ready(xmlhttp)) {
580 printLockingError();
581 return
582 }
583
584 var sel_rows = getSelectedUsers();
585
586 if (sel_rows.length > 0) {
587
f56e3080 588 var ok = confirm(__("Remove selected users?"));
e6cb77a0 589
69668465 590 if (ok) {
42c32916 591 notify_progress("Removing selected users...");
69668465
AD
592
593 xmlhttp.open("GET", "backend.php?op=pref-users&subop=remove&ids="+
594 param_escape(sel_rows.toString()), true);
595 xmlhttp.onreadystatechange=userlist_callback;
596 xmlhttp.send(null);
597 }
e6cb77a0
AD
598
599 } else {
89cb787e 600 alert(__("No users are selected."));
e6cb77a0 601 }
90ac84df
AD
602
603 return false;
e6cb77a0
AD
604}
605
48f0adb0
AD
606function removeSelectedFilters() {
607
608 if (!xmlhttp_ready(xmlhttp)) {
609 printLockingError();
610 return
611 }
612
613 var sel_rows = getSelectedFilters();
614
615 if (sel_rows.length > 0) {
616
f56e3080 617 var ok = confirm(__("Remove selected filters?"));
48f0adb0 618
69668465 619 if (ok) {
42c32916 620 notify_progress("Removing selected filters...");
69668465
AD
621
622 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
623 param_escape(sel_rows.toString()), true);
624 xmlhttp.onreadystatechange=filterlist_callback;
625 xmlhttp.send(null);
626 }
48f0adb0 627 } else {
89cb787e 628 alert(__("No filters are selected."));
48f0adb0 629 }
90ac84df
AD
630
631 return false;
48f0adb0
AD
632}
633
634
83fe4d6d
AD
635function removeSelectedFeeds() {
636
c0e5a40e 637 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
638 printLockingError();
639 return
640 }
641
83fe4d6d
AD
642 var sel_rows = getSelectedFeeds();
643
331900c6
AD
644 if (sel_rows.length > 0) {
645
f56e3080 646 var ok = confirm(__("Unsubscribe from selected feeds?"));
331900c6 647
69668465
AD
648 if (ok) {
649
42c32916 650 notify_progress("Unsubscribing from selected feeds...");
69668465
AD
651
652 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
653 param_escape(sel_rows.toString()), true);
654 xmlhttp.onreadystatechange=feedlist_callback;
655 xmlhttp.send(null);
656 }
71ad3959 657
71ad3959 658 } else {
331900c6 659
89cb787e 660 alert(__("No feeds are selected."));
331900c6 661
71ad3959 662 }
90ac84df
AD
663
664 return false;
71ad3959 665}
007bda35 666
91ff844a
AD
667function removeSelectedFeedCats() {
668
669 if (!xmlhttp_ready(xmlhttp)) {
670 printLockingError();
671 return
672 }
673
674 var sel_rows = getSelectedFeedCats();
675
676 if (sel_rows.length > 0) {
677
f56e3080 678 var ok = confirm(__("Remove selected categories?"));
91ff844a 679
69668465 680 if (ok) {
42c32916 681 notify_progress("Removing selected categories...");
69668465 682
9c483746 683 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=remove&ids="+
69668465 684 param_escape(sel_rows.toString()), true);
9c483746 685 xmlhttp.onreadystatechange=infobox_callback;
69668465
AD
686 xmlhttp.send(null);
687 }
91ff844a
AD
688
689 } else {
690
89cb787e 691 alert(__("No categories are selected."));
91ff844a
AD
692
693 }
694
90ac84df 695 return false;
91ff844a
AD
696}
697
508a81e1
AD
698function feedEditCancel() {
699
c0e5a40e 700 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
701 printLockingError();
702 return
703 }
704
a349077c
AD
705 document.getElementById("subscribe_to_feed_btn").disabled = false;
706
707 try {
708 document.getElementById("top25_feeds_btn").disabled = false;
709 } catch (e) {
710 // this button is not always available, no-op if not found
711 }
712
327a3bbe
AD
713 closeInfoBox();
714
673d54ca 715 selectPrefRows('feed', false); // cleanup feed selection
508a81e1 716
90ac84df 717 return false;
508a81e1
AD
718}
719
91ff844a
AD
720function feedCatEditCancel() {
721
722 if (!xmlhttp_ready(xmlhttp)) {
723 printLockingError();
724 return
725 }
726
727 active_feed_cat = false;
728
0ceded7a 729// notify("Operation cancelled.");
91ff844a 730
9c483746
AD
731 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
732 xmlhttp.onreadystatechange=infobox_callback;
91ff844a
AD
733 xmlhttp.send(null);
734
90ac84df 735 return false;
91ff844a
AD
736}
737
603c27f8
AD
738function feedEditSave() {
739
47c6c988 740 try {
47c6c988
AD
741
742 if (!xmlhttp_ready(xmlhttp)) {
743 printLockingError();
744 return
745 }
ad815c71 746
14f69488 747 // FIXME: add parameter validation
e3c99f3b 748
14f69488 749 var query = Form.serialize("edit_feed_form");
b0da3a7b 750
42c32916 751 notify_progress("Saving feed...");
673d54ca 752
47c6c988
AD
753 xmlhttp.open("POST", "backend.php", true);
754 xmlhttp.onreadystatechange=feedlist_callback;
755 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
14f69488
AD
756 xmlhttp.send(query);
757
59a543f0
AD
758 closeInfoBox();
759
c14b5566
AD
760 return false;
761
47c6c988
AD
762 } catch (e) {
763 exception_error("feedEditSave", e);
b0da3a7b 764 }
508a81e1
AD
765}
766
5ddadb4c
AD
767function feedCatEditSave() {
768
769 if (!xmlhttp_ready(xmlhttp)) {
770 printLockingError();
771 return
772 }
773
42c32916 774 notify_progress("Saving category...");
5ddadb4c 775
0666e120
AD
776 var query = Form.serialize("feed_cat_edit_form");
777
778 xmlhttp.open("GET", "backend.php?" + query, true);
9c483746 779 xmlhttp.onreadystatechange=infobox_callback;
5ddadb4c
AD
780 xmlhttp.send(null);
781
782 active_feed_cat = false;
783
90ac84df 784 return false;
5ddadb4c
AD
785}
786
787
d9dde1d6 788
01c9c74a
AD
789function displayHelpInfobox(topic_id) {
790
442d77f1 791/* if (!xmlhttp_ready(xmlhttp)) {
9e31e1b9
AD
792 printLockingError();
793 return
794 }
795
796 notify_progress("Loading help...");
797
01c9c74a 798 xmlhttp.open("GET", "backend.php?op=help&tid=" +
442d77f1 799 param_escape(topic_id), true);
01c9c74a 800
442d77f1
AD
801 xmlhttp.onreadystatechange=helpbox_callback;
802 xmlhttp.send(null); */
803
804 var url = "backend.php?op=help&tid=" + param_escape(topic_id);
805
806 var w = window.open(url, "ttrss_help",
807 "status=0,toolbar=0,location=0,width=400,height=450,menubar=0");
01c9c74a
AD
808
809}
810
48f0adb0
AD
811function labelEditCancel() {
812
813 if (!xmlhttp_ready(xmlhttp)) {
814 printLockingError();
815 return
816 }
817
f156fd00
AD
818 document.getElementById("label_create_btn").disabled = false;
819
48f0adb0
AD
820 active_label = false;
821
a4dbc524 822 selectPrefRows('label', false); // cleanup feed selection
50bad812
AD
823 closeInfoBox();
824
90ac84df 825 return false;
48f0adb0
AD
826}
827
e6cb77a0
AD
828function userEditCancel() {
829
830 if (!xmlhttp_ready(xmlhttp)) {
831 printLockingError();
832 return
833 }
834
3c5783b7 835 selectPrefRows('user', false); // cleanup feed selection
3c5783b7 836 closeInfoBox();
90ac84df
AD
837
838 return false;
e6cb77a0 839}
48f0adb0 840
a0d53889
AD
841function filterEditCancel() {
842
843 if (!xmlhttp_ready(xmlhttp)) {
844 printLockingError();
845 return
846 }
4220b0bd
AD
847
848 document.getElementById("create_filter_btn").disabled = false;
07164479
AD
849
850 selectPrefRows('filter', false); // cleanup feed selection
851 closeInfoBox();
90ac84df
AD
852
853 return false;
a0d53889
AD
854}
855
48f0adb0
AD
856function labelEditSave() {
857
858 var label = active_label;
859
860 if (!xmlhttp_ready(xmlhttp)) {
861 printLockingError();
862 return
863 }
864
9ee3ac59 865/* if (!is_opera()) {
48f0adb0 866
7c620da8
AD
867 var sql_exp = document.forms["label_edit_form"].sql_exp.value;
868 var description = document.forms["label_edit_form"].description.value;
869
870 if (sql_exp.length == 0) {
871 alert("SQL Expression cannot be blank.");
872 return false;
873 }
874
875 if (description.length == 0) {
876 alert("Caption field cannot be blank.");
877 return false;
878 }
9ee3ac59 879 } */
48f0adb0 880
50bad812
AD
881 closeInfoBox();
882
42c32916 883 notify_progress("Saving label...");
dbd9e2f1 884
48f0adb0
AD
885 active_label = false;
886
f3120e5a
AD
887 query = Form.serialize("label_edit_form");
888
50bad812 889 xmlhttp.open("GET", "backend.php?" + query, true);
48f0adb0
AD
890 xmlhttp.onreadystatechange=labellist_callback;
891 xmlhttp.send(null);
892
90ac84df 893 return false;
48f0adb0
AD
894}
895
e6cb77a0
AD
896function userEditSave() {
897
e6cb77a0
AD
898 if (!xmlhttp_ready(xmlhttp)) {
899 printLockingError();
900 return
901 }
902
3c5783b7 903 var login = document.forms["user_edit_form"].login.value;
e6cb77a0
AD
904
905 if (login.length == 0) {
89cb787e 906 alert(__("Login field cannot be blank."));
e6cb77a0
AD
907 return;
908 }
3c5783b7 909
42c32916 910 notify_progress("Saving user...");
4220b0bd
AD
911
912 closeInfoBox();
913
3c5783b7
AD
914 var query = Form.serialize("user_edit_form");
915
916 xmlhttp.open("GET", "backend.php?" + query, true);
dbd9e2f1 917 xmlhttp.onreadystatechange=userlist_callback;
e6cb77a0 918 xmlhttp.send(null);
90ac84df
AD
919
920 return false;
e6cb77a0
AD
921}
922
923
a0d53889
AD
924function filterEditSave() {
925
a0d53889
AD
926 if (!xmlhttp_ready(xmlhttp)) {
927 printLockingError();
928 return
929 }
930
9ee3ac59 931/* if (!is_opera()) {
7c620da8
AD
932 var reg_exp = document.forms["filter_edit_form"].reg_exp.value;
933
934 if (reg_exp.length == 0) {
935 alert("Filter expression field cannot be blank.");
936 return;
937 }
9ee3ac59 938 } */
a0d53889 939
42c32916 940 notify_progress("Saving filter...");
a0d53889 941
7e939457 942 var query = Form.serialize("filter_edit_form");
dbd9e2f1 943
07164479
AD
944 closeInfoBox();
945
4220b0bd
AD
946 document.getElementById("create_filter_btn").disabled = false;
947
7e939457 948 xmlhttp.open("GET", "backend.php?" + query, true);
a0d53889 949 xmlhttp.onreadystatechange=filterlist_callback;
7e939457 950 xmlhttp.send(null);
a0d53889 951
90ac84df 952 return false;
a0d53889
AD
953}
954
48f0adb0
AD
955function editSelectedLabel() {
956 var rows = getSelectedLabels();
a0d53889 957
48f0adb0 958 if (rows.length == 0) {
f3977cf5 959 alert(__("No labels are selected."));
48f0adb0 960 return;
a0d53889
AD
961 }
962
48f0adb0 963 if (rows.length > 1) {
f3977cf5 964 alert(__("Please select only one label."));
48f0adb0
AD
965 return;
966 }
a0d53889 967
dbd9e2f1
AD
968 notify("");
969
48f0adb0 970 editLabel(rows[0]);
a0d53889 971
a0d53889
AD
972}
973
e6cb77a0
AD
974function editSelectedUser() {
975 var rows = getSelectedUsers();
976
977 if (rows.length == 0) {
f3977cf5 978 alert(__("No users are selected."));
e6cb77a0
AD
979 return;
980 }
981
982 if (rows.length > 1) {
f3977cf5 983 alert(__("Please select only one user."));
e6cb77a0
AD
984 return;
985 }
986
dbd9e2f1
AD
987 notify("");
988
e6cb77a0
AD
989 editUser(rows[0]);
990}
991
992function resetSelectedUserPass() {
993 var rows = getSelectedUsers();
994
995 if (rows.length == 0) {
f3977cf5 996 alert(__("No users are selected."));
e6cb77a0
AD
997 return;
998 }
999
1000 if (rows.length > 1) {
f3977cf5 1001 alert(__("Please select only one user."));
e6cb77a0
AD
1002 return;
1003 }
1004
f3977cf5 1005 var ok = confirm(__("Reset password of selected user?"));
e6cb77a0 1006
69668465 1007 if (ok) {
42c32916 1008 notify_progress("Resetting password for selected user...");
69668465
AD
1009
1010 var id = rows[0];
1011
1012 xmlhttp.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
1013 param_escape(id), true);
1014 xmlhttp.onreadystatechange=userlist_callback;
1015 xmlhttp.send(null);
1016 }
e6cb77a0
AD
1017}
1018
717f5e64 1019function selectedUserDetails() {
e6cb77a0 1020
1a7572cb
AD
1021 if (!xmlhttp_ready(xmlhttp)) {
1022 printLockingError();
1023 return
1024 }
1025
717f5e64
AD
1026 var rows = getSelectedUsers();
1027
1028 if (rows.length == 0) {
f3977cf5 1029 alert(__("No users are selected."));
717f5e64
AD
1030 return;
1031 }
1032
1033 if (rows.length > 1) {
f3977cf5 1034 alert(__("Please select only one user."));
717f5e64
AD
1035 return;
1036 }
1037
0077a65c 1038 notify_progress("Loading, please wait...");
717f5e64 1039
0077a65c 1040 var id = rows[0];
dbd9e2f1 1041
1a7572cb 1042 xmlhttp.open("GET", "backend.php?op=user-details&id=" + id, true);
c6c3a07f
AD
1043 xmlhttp.onreadystatechange=infobox_callback;
1044 xmlhttp.send(null);
1045
1046}
1047
1048function selectedFeedDetails() {
1049
1050 if (!xmlhttp_ready(xmlhttp)) {
1051 printLockingError();
1052 return
1053 }
1054
1055 var rows = getSelectedFeeds();
1056
1057 if (rows.length == 0) {
f3977cf5 1058 alert(__("No feeds are selected."));
c6c3a07f
AD
1059 return;
1060 }
1061
01b3e191 1062 if (rows.length > 1) {
f3977cf5 1063 alert(__("Please select only one feed."));
01b3e191
AD
1064 return;
1065 }
c6c3a07f 1066
df268d47 1067// var id = rows[0];
c6c3a07f 1068
dbd9e2f1
AD
1069 notify("");
1070
df268d47
AD
1071 xmlhttp.open("GET", "backend.php?op=feed-details&id=" +
1072 param_escape(rows.toString()), true);
c6c3a07f 1073 xmlhttp.onreadystatechange=infobox_callback;
1a7572cb 1074 xmlhttp.send(null);
717f5e64
AD
1075
1076}
a0d53889
AD
1077
1078function editSelectedFilter() {
1079 var rows = getSelectedFilters();
1080
1081 if (rows.length == 0) {
f3977cf5 1082 alert(__("No filters are selected."));
a0d53889
AD
1083 return;
1084 }
1085
1086 if (rows.length > 1) {
f3977cf5 1087 alert(__("Please select only one filter."));
a0d53889
AD
1088 return;
1089 }
1090
dbd9e2f1
AD
1091 notify("");
1092
a0d53889
AD
1093 editFilter(rows[0]);
1094
1095}
1096
1097
508a81e1
AD
1098function editSelectedFeed() {
1099 var rows = getSelectedFeeds();
1100
1101 if (rows.length == 0) {
f3977cf5 1102 alert(__("No feeds are selected."));
508a81e1
AD
1103 return;
1104 }
1105
1106 if (rows.length > 1) {
f3977cf5 1107 alert(__("Please select one feed."));
508a81e1
AD
1108 return;
1109 }
1110
dbd9e2f1
AD
1111 notify("");
1112
508a81e1 1113 editFeed(rows[0]);
91ff844a
AD
1114
1115}
1116
1117function editSelectedFeedCat() {
1118 var rows = getSelectedFeedCats();
1119
1120 if (rows.length == 0) {
f3977cf5 1121 alert(__("No categories are selected."));
91ff844a
AD
1122 return;
1123 }
1124
1125 if (rows.length > 1) {
f3977cf5 1126 alert(__("Please select only one category."));
91ff844a
AD
1127 return;
1128 }
1129
1130 notify("");
1131
1132 editFeedCat(rows[0]);
508a81e1
AD
1133
1134}
1135
13ad9102
AD
1136function localPiggieFunction(enable) {
1137 if (enable) {
d437c8cf 1138 debug("I LOVEDED IT!");
1cac3c31 1139 var piggie = document.getElementById("piggie");
33377ef3 1140
537625c6
AD
1141 Element.show(piggie);
1142 Position.Center(piggie);
1143 Effect.Puff(piggie);
1144
508a81e1 1145 }
508a81e1
AD
1146}
1147
9f311df6
AD
1148function validateOpmlImport() {
1149
1150 var opml_file = document.getElementById("opml_file");
1151
1152 if (opml_file.value.length == 0) {
f3977cf5 1153 alert(__("No OPML file to upload."));
9f311df6
AD
1154 return false;
1155 } else {
1156 return true;
1157 }
1158}
1159
0e317f9d 1160function updateFilterList(sort_key) {
a0d53889
AD
1161
1162 if (!xmlhttp_ready(xmlhttp)) {
1163 printLockingError();
1164 return
1165 }
1166
f5a50b25
AD
1167// document.getElementById("prefContent").innerHTML = "Loading filters, please wait...";
1168
ce3bf408 1169// p_notify("Loading, please wait...");
a0d53889 1170
e161a2cc
AD
1171 xmlhttp.open("GET", "backend.php?op=pref-filters&sort=" +
1172 param_escape(sort_key), true);
a0d53889
AD
1173 xmlhttp.onreadystatechange=filterlist_callback;
1174 xmlhttp.send(null);
1175
1176}
1177
e161a2cc 1178function updateLabelList(sort_key) {
48f0adb0
AD
1179
1180 if (!xmlhttp_ready(xmlhttp)) {
1181 printLockingError();
1182 return
1183 }
1184
ce3bf408 1185// p_notify("Loading, please wait...");
f5a50b25
AD
1186
1187// document.getElementById("prefContent").innerHTML = "Loading labels, please wait...";
48f0adb0 1188
e161a2cc
AD
1189 xmlhttp.open("GET", "backend.php?op=pref-labels&sort=" +
1190 param_escape(sort_key), true);
48f0adb0
AD
1191 xmlhttp.onreadystatechange=labellist_callback;
1192 xmlhttp.send(null);
48f0adb0
AD
1193}
1194
4255b24c
AD
1195function updatePrefsList() {
1196
1197 if (!xmlhttp_ready(xmlhttp)) {
1198 printLockingError();
1199 return
1200 }
1201
ce3bf408 1202// p_notify("Loading, please wait...");
4255b24c
AD
1203
1204 xmlhttp.open("GET", "backend.php?op=pref-prefs", true);
1205 xmlhttp.onreadystatechange=prefslist_callback;
1206 xmlhttp.send(null);
1207
1208}
1209
e513a74a 1210function selectTab(id, noupdate, subop) {
a7f22b70
AD
1211
1212// alert(id);
48f0adb0 1213
b2caf812 1214 if (!id) id = active_tab;
7f74a9da 1215
b2caf812 1216 try {
59a543f0 1217
b2caf812
AD
1218 if (!xmlhttp_ready(xmlhttp)) {
1219 printLockingError();
1220 return
a7f22b70 1221 }
f5a50b25 1222
a422968f
AD
1223 try {
1224 var c = document.getElementById('prefContent');
1225 c.scrollTop = 0;
1226 } catch (e) { };
1227
b2caf812 1228 if (!noupdate) {
f5a50b25 1229
b2caf812
AD
1230 debug("selectTab: " + id + "(NU: " + noupdate + ")");
1231
9e31e1b9 1232 notify_progress("Loading, please wait...");
b2caf812
AD
1233
1234 // close active infobox if needed
1235 closeInfoBox();
1236
1237 // clean up all current selections, just in case
1238 active_feed_cat = false;
1239 active_label = false;
1240
1241 if (id == "feedConfig") {
1242 updateFeedList();
1243 } else if (id == "filterConfig") {
1244 updateFilterList();
1245 } else if (id == "labelConfig") {
1246 updateLabelList();
1247 } else if (id == "genConfig") {
1248 updatePrefsList();
1249 } else if (id == "userConfig") {
1250 updateUsersList();
1251 } else if (id == "feedBrowser") {
1252 updateBigFeedBrowser();
1253 }
f5a50b25 1254 }
b2caf812
AD
1255
1256 var tab = document.getElementById(active_tab + "Tab");
1257
1258 if (tab) {
1259 if (tab.className.match("Selected")) {
1260 tab.className = "prefsTab";
1261 }
f5a50b25 1262 }
b2caf812
AD
1263
1264 tab = document.getElementById(id + "Tab");
1265
1266 if (tab) {
1267 if (!tab.className.match("Selected")) {
1268 tab.className = tab.className + "Selected";
1269 }
1270 }
1271
b2caf812 1272 active_tab = id;
f5a50b25 1273
b2caf812
AD
1274 } catch (e) {
1275 exception_error("selectTab", e);
a7565293 1276 }
a7565293
AD
1277}
1278
1279function backend_sanity_check_callback() {
f5a50b25 1280
a7565293
AD
1281 if (xmlhttp.readyState == 4) {
1282
1283 try {
7a09510c
AD
1284
1285 if (sanity_check_done) {
81352b54
AD
1286 fatalError(11, "Sanity check request received twice. This can indicate "+
1287 "presence of Firebug or some other disrupting extension. "+
1288 "Please disable it and try again.");
7a09510c
AD
1289 return;
1290 }
1291
a7565293
AD
1292 if (!xmlhttp.responseXML) {
1293 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp.responseText);
1294 return;
1295 }
1296
1297 var reply = xmlhttp.responseXML.firstChild.firstChild;
1298
1299 if (!reply) {
1300 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp.responseText);
1301 return;
1302 }
1303
1304 var error_code = reply.getAttribute("error-code");
1305
1306 if (error_code && error_code != 0) {
1307 return fatalError(error_code, reply.getAttribute("error-msg"));
1308 }
1309
1310 debug("sanity check ok");
1311
1312 var params = reply.nextSibling;
1313
1314 if (params) {
1315 debug('reading init-params...');
1316 var param = params.firstChild;
1317
1318 while (param) {
1319 var k = param.getAttribute("key");
1320 var v = param.getAttribute("value");
1321 debug(k + " => " + v);
1322 init_params[k] = v;
1323 param = param.nextSibling;
1324 }
1325 }
1326
7a09510c
AD
1327 sanity_check_done = true;
1328
a7565293
AD
1329 init_second_stage();
1330
1331 } catch (e) {
1332 exception_error("backend_sanity_check_callback", e);
1333 }
1334 }
1335}
1336
1337function init_second_stage() {
1338
b2caf812
AD
1339 try {
1340 active_tab = getInitParam("prefs_active_tab");
fe8d2059 1341 if (!active_tab || active_tab == '0') active_tab = "genConfig";
4da47970 1342
d437c8cf
AD
1343 document.onkeydown = pref_hotkey_handler;
1344
e513a74a
AD
1345 var tab = getURLParam('tab');
1346
1347 caller_subop = getURLParam('subop');
1348
1349 if (tab) {
1350 active_tab = tab;
1351 }
1352
b2caf812
AD
1353 if (navigator.userAgent.match("Opera")) {
1354 setTimeout("selectTab()", 500);
1355 } else {
1356 selectTab(active_tab);
1357 }
1358 notify("");
1359 } catch (e) {
1360 exception_error("init_second_stage", e);
1361 }
a0d53889
AD
1362}
1363
007bda35 1364function init() {
e2ec66a8 1365
7719618b
AD
1366 try {
1367
97dcd654
AD
1368 if (arguments.callee.done) return;
1369 arguments.callee.done = true;
1370
a7565293
AD
1371 if (getURLParam('debug')) {
1372 document.getElementById('debug_output').style.display = 'block';
1373 debug('debug mode activated');
1374 }
1375
7719618b
AD
1376 // IE kludge
1377 if (!xmlhttp) {
1378 document.getElementById("prefContent").innerHTML =
1379 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1380 "to function properly. Your browser doesn't seem to support it.";
1381 return;
1382 }
4da47970 1383
a7565293
AD
1384 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
1385 xmlhttp.onreadystatechange=backend_sanity_check_callback;
1386 xmlhttp.send(null);
1387
7719618b
AD
1388 } catch (e) {
1389 exception_error("init", e);
e2ec66a8 1390 }
007bda35 1391}
b1895692 1392
f932bc9f
AD
1393function categorizeSelectedFeeds() {
1394
1395 if (!xmlhttp_ready(xmlhttp)) {
1396 printLockingError();
1397 return
1398 }
1399
1400 var sel_rows = getSelectedFeeds();
1401
1402 var cat_sel = document.getElementById("sfeed_set_fcat");
79f3553b 1403 var cat_id = cat_sel[cat_sel.selectedIndex].value;
f932bc9f
AD
1404
1405 if (sel_rows.length > 0) {
1406
42c32916 1407 notify_progress("Changing category of selected feeds...");
f932bc9f
AD
1408
1409 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
1410 param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
1411 xmlhttp.onreadystatechange=feedlist_callback;
1412 xmlhttp.send(null);
1413
1414 } else {
1415
f3977cf5 1416 alert(__("No feeds are selected."));
f932bc9f
AD
1417
1418 }
1419
1420}
69668465
AD
1421
1422function validatePrefsReset() {
b652c1b7
AD
1423 try {
1424 var ok = confirm(__("Reset to defaults?"));
1425
1426 if (ok) {
1427
1428 var query = Form.serialize("pref_prefs_form");
1429 query = query + "&subop=reset-config";
1430 debug(query);
1431
1432 xmlhttp.open("POST", "backend.php", true);
1433 xmlhttp.onreadystatechange=prefs_reset_callback;
1434 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1435 xmlhttp.send(query);
1436 }
1437
1438 } catch (e) {
1439 exception_error("validatePrefsSave", e);
1440 }
1441
1442 return false;
1443
69668465 1444}
f9cb39ac 1445
6311acbe 1446function browseFeeds(limit) {
f9cb39ac
AD
1447
1448 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=browse", true);
1449 xmlhttp.onreadystatechange=infobox_callback;
1450 xmlhttp.send(null);
1451
1452}
a0476535
AD
1453
1454function feedBrowserSubscribe() {
1455 try {
a0476535 1456
c0ae0fdb 1457 var selected = getSelectedFeedsFromBrowser();
a0476535
AD
1458
1459 if (selected.length > 0) {
1460 closeInfoBox();
1461 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=massSubscribe&ids="+
1462 param_escape(selected.toString()), true);
1463 xmlhttp.onreadystatechange=feedlist_callback;
1464 xmlhttp.send(null);
1465 } else {
89cb787e 1466 alert(__("No feeds are selected."));
a0476535
AD
1467 }
1468
1469 } catch (e) {
1470 exception_error("feedBrowserSubscribe", e);
1471 }
1472}
c6232e43 1473
6311acbe 1474function updateBigFeedBrowser(limit) {
c6232e43
AD
1475
1476 if (!xmlhttp_ready(xmlhttp)) {
1477 printLockingError();
1478 return
1479 }
1480
ce3bf408 1481// p_notify("Loading, please wait...");
c6232e43 1482
6311acbe
AD
1483 var query = "backend.php?op=pref-feed-browser";
1484
1485 var limit_sel = document.getElementById("feedBrowserLimit");
1486
1487 if (limit_sel) {
1488 var limit = limit_sel[limit_sel.selectedIndex].value;
1489 query = query + "&limit=" + param_escape(limit);
1490 }
1491
1492 xmlhttp.open("GET", query, true);
c6232e43
AD
1493 xmlhttp.onreadystatechange=feed_browser_callback;
1494 xmlhttp.send(null);
c6232e43
AD
1495}
1496
c2b2aee0 1497function browserToggleExpand(id) {
c6232e43
AD
1498 try {
1499/* if (feed_to_expand && feed_to_expand != id) {
1500 var d = document.getElementById("BRDET-" + feed_to_expand);
1501 d.style.display = "none";
1502 } */
c2b2aee0 1503
ff725e9b
AD
1504 if (!xmlhttp_ready(xmlhttp)) {
1505 printLockingError();
1506 return
1507 }
1508
051c4d56
AD
1509/* if (feed_to_expand && id != feed_to_expand) {
1510 Effect.Fade('BRDET-' + feed_to_expand, {duration : 0.5});
1511 } */
c2b2aee0 1512
051c4d56 1513 var d = document.getElementById("BRDET-" + id);
c6232e43 1514
34a01a20 1515 if (Element.visible(d)) {
051c4d56 1516 Effect.Fade(d, {duration : 0.5});
34a01a20 1517 } else {
c2b2aee0 1518 feed_to_expand = id;
c6232e43 1519
c2b2aee0
AD
1520 xmlhttp.open("GET", "backend.php?op=pref-feed-browser&subop=details&id="
1521 + param_escape(id), true);
1522 xmlhttp.onreadystatechange=expand_feed_callback;
1523 xmlhttp.send(null);
1524 }
c6232e43
AD
1525
1526 } catch (e) {
34a01a20 1527 exception_error("browserToggleExpand", e);
c6232e43
AD
1528 }
1529}
64dc5976 1530
ce3bf408
AD
1531function selectPrefRows(kind, select) {
1532
1533 if (kind) {
1534 var opbarid = false;
1535 var nchk = false;
1536 var nrow = false;
1537 var lname = false;
1538
1539 if (kind == "feed") {
1540 opbarid = "feedOpToolbar";
1541 nrow = "FEEDR-";
1542 nchk = "FRCHK-";
1543 lname = "prefFeedList";
1544 } else if (kind == "fcat") {
1545 opbarid = "catOpToolbar";
1546 nrow = "FCATR-";
9c483746 1547 nchk = "FCCHK-";
ce3bf408
AD
1548 lname = "prefFeedCatList";
1549 } else if (kind == "filter") {
1550 opbarid = "filterOpToolbar";
1551 nrow = "FILRR-";
1552 nchk = "FICHK-";
1553 lname = "prefFilterList";
1554 } else if (kind == "label") {
1555 opbarid = "labelOpToolbar";
1556 nrow = "LILRR-";
a4dbc524 1557 nchk = "LICHK-";
ce3bf408
AD
1558 lname = "prefLabelList";
1559 } else if (kind == "user") {
1560 opbarid = "userOpToolbar";
1561 nrow = "UMRR-";
1562 nchk = "UMCHK-";
1563 lname = "prefUserList";
1564 }
1565
1566 if (opbarid) {
1567 selectTableRowsByIdPrefix(lname, nrow, nchk, select);
1568 disableContainerChildren(opbarid, !select);
1569 }
1570
1571 }
1572}
1573
1574
1575function toggleSelectPrefRow(sender, kind) {
1576
1577 toggleSelectRow(sender);
1578
1579 if (kind) {
1580 var opbarid = false;
1581 var nsel = -1;
1582
1583 if (kind == "feed") {
1584 opbarid = "feedOpToolbar";
1585 nsel = getSelectedFeeds();
1586 } else if (kind == "fcat") {
1587 opbarid = "catOpToolbar";
1588 nsel = getSelectedFeedCats();
1589 } else if (kind == "filter") {
1590 opbarid = "filterOpToolbar";
1591 nsel = getSelectedFilters();
1592 } else if (kind == "label") {
1593 opbarid = "labelOpToolbar";
1594 nsel = getSelectedLabels();
1595 } else if (kind == "user") {
1596 opbarid = "userOpToolbar";
1597 nsel = getSelectedUsers();
1598 }
1599
1600 if (opbarid && nsel != -1) {
1601 disableContainerChildren(opbarid, nsel == false);
1602 }
1603
1604 }
1605}
1606
c0ae0fdb
AD
1607function toggleSelectFBListRow(sender) {
1608 toggleSelectListRow(sender);
1609 disableContainerChildren("fbrOpToolbar", getSelectedFeedsFromBrowser() == 0);
1610}
d437c8cf
AD
1611
1612var seq = "";
1613
1614function pref_hotkey_handler(e) {
1615 try {
1616
1617 var keycode;
1618
1619 if (!hotkeys_enabled) return;
1620
1621 if (window.event) {
1622 keycode = window.event.keyCode;
1623 } else if (e) {
1624 keycode = e.which;
1625 }
1626
1627 if (keycode == 13 || keycode == 27) {
1628 seq = "";
1629 } else {
1630 seq = seq + "" + keycode;
1631 }
1632
1633
1634 if (document.getElementById("piggie")) {
1635
1636 if (seq.match("807371717369")) {
1637 seq = "";
1638 localPiggieFunction(true);
1639 } else {
1640 localPiggieFunction(false);
1641 }
1642 }
1643
1644 } catch (e) {
1645 exception_error("pref_hotkey_handler", e);
1646 }
1647}
1648
23c2a4e7
AD
1649function userSwitch() {
1650 var chooser = document.getElementById("userSwitch");
1651 var user = chooser[chooser.selectedIndex].value;
1652 window.location = "prefs.php?swu=" + user;
1653}
9c483746
AD
1654
1655function editFeedCats() {
1656 if (!xmlhttp_ready(xmlhttp)) {
1657 printLockingError();
1658 return
1659 }
1660
a349077c
AD
1661 document.getElementById("subscribe_to_feed_btn").disabled = true;
1662
1663 try {
1664 document.getElementById("top25_feeds_btn").disabled = true;
1665 } catch (e) {
1666 // this button is not always available, no-op if not found
1667 }
1668
9c483746 1669 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
11f083e7 1670 xmlhttp.onreadystatechange=infobox_feed_cat_callback;
9c483746
AD
1671 xmlhttp.send(null);
1672}
a3656a41
AD
1673
1674function showFeedsWithErrors() {
1675 displayDlg('feedUpdateErrors');
1676}
073ca0e6 1677
d95bd220
AD
1678function changeUserPassword() {
1679
1680 try {
1681
1682 if (!xmlhttp_ready(xmlhttp)) {
1683 printLockingError();
1684 return false;
1685 }
1686
1687 var query = Form.serialize("change_pass_form");
1688
1689 notify_progress("Trying to change password...");
1690
1691 xmlhttp.open("POST", "backend.php", true);
1692 xmlhttp.onreadystatechange=changepass_callback;
1693 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1694 xmlhttp.send(query);
1695
1696 } catch (e) {
1697 exception_error("changeUserPassword", e);
1698 }
1699
1700 return false;
1701}
073ca0e6 1702
42395d28
AD
1703function changeUserEmail() {
1704
1705 try {
1706
1707 if (!xmlhttp_ready(xmlhttp)) {
1708 printLockingError();
1709 return false;
1710 }
1711
1712 var query = Form.serialize("change_email_form");
1713
1714 notify_progress("Trying to change e-mail...");
1715
1716 xmlhttp.open("POST", "backend.php", true);
1717 xmlhttp.onreadystatechange=notify_callback;
1718 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1719 xmlhttp.send(query);
1720
1721 } catch (e) {
1722 exception_error("changeUserPassword", e);
1723 }
1724
1725 return false;
1726
1727}
400b60d8
AD
1728
1729function feedlistToggleSLAT() {
1730 notify_progress("Loading, please wait...");
1731 updateFeedList()
1732}
bc0ed820 1733
e4f4b46f
AD
1734function pubRegenKey() {
1735
bc0ed820
AD
1736 if (!xmlhttp_ready(xmlhttp)) {
1737 printLockingError();
e4f4b46f 1738 return false;
bc0ed820
AD
1739 }
1740
f56e3080 1741 var ok = confirm(__("Replace current publishing address with a new one?"));
bc0ed820 1742
e4f4b46f
AD
1743 if (ok) {
1744
1745 notify_progress("Trying to change address...");
1746
945c243e 1747 xmlhttp.open("GET", "backend.php?op=rpc&subop=regenPubKey");
e4f4b46f
AD
1748 xmlhttp.onreadystatechange=replace_pubkey_callback;
1749 xmlhttp.send(null);
1750 }
1751
1752 return false;
945c243e 1753}
b652c1b7
AD
1754
1755function validatePrefsSave() {
1756 try {
1757
1758 var ok = confirm(__("Save current configuration?"));
1759
1760 if (ok) {
1761
1762 var query = Form.serialize("pref_prefs_form");
1763 query = query + "&subop=save-config";
1764 debug(query);
1765
1766 xmlhttp.open("POST", "backend.php", true);
1767 xmlhttp.onreadystatechange=notify_callback;
1768 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1769 xmlhttp.send(query);
1770 }
1771
1772 } catch (e) {
1773 exception_error("validatePrefsSave", e);
1774 }
1775
1776 return false;
1777}