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