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