]> git.wh0rd.org - tt-rss.git/blame - prefs.js
prefs: code cleanup
[tt-rss.git] / prefs.js
CommitLineData
007bda35
AD
1var xmlhttp = false;
2
91ff844a 3var active_feed_cat = false;
f5a50b25
AD
4var active_tab = false;
5
a58069db 6var xmlhttp = Ajax.getTransport();
007bda35 7
a7565293
AD
8var init_params = new Array();
9
e513a74a 10var caller_subop = false;
7a09510c 11var sanity_check_done = false;
746dcf42 12var hotkey_prefix = false;
7a09510c 13
288487e4
AD
14function infobox_callback() {
15 if (xmlhttp.readyState == 4) {
16 infobox_callback2(xmlhttp);
17 }
18}
19
20function infobox_submit_callback() {
21 if (xmlhttp.readyState == 4) {
22 infobox_submit_callback2(xmlhttp);
23 }
24}
25
26
e4f4b46f 27function replace_pubkey_callback() {
c6232e43
AD
28 if (xmlhttp.readyState == 4) {
29 try {
e4f4b46f
AD
30 var link = document.getElementById("pubGenAddress");
31
32 if (xmlhttp.responseXML) {
33
945c243e
AD
34 var new_link = xmlhttp.responseXML.getElementsByTagName("link")[0];
35
36 if (new_link) {
37 link.href = new_link.firstChild.nodeValue;
e635d56a 38 //link.innerHTML = new_link.firstChild.nodeValue;
945c243e 39
3076c7b8
AD
40 new Effect.Highlight(link);
41
e635d56a 42 notify_info("Published feed URL changed.");
945c243e 43 } else {
e635d56a 44 notify_error("Could not change feed URL.");
945c243e 45 }
e4f4b46f
AD
46
47 } else {
e635d56a 48 notify_error("Could not change feed URL.");
e4f4b46f 49 }
c6232e43 50 } catch (e) {
e4f4b46f 51 exception_error("replace_pubkey_callback", e);
c6232e43
AD
52 }
53 }
945c243e 54}
c6232e43 55
007bda35 56function feedlist_callback() {
007bda35 57 if (xmlhttp.readyState == 4) {
47c6c988
AD
58 try {
59 var container = document.getElementById('prefContent');
60 container.innerHTML=xmlhttp.responseText;
a7f22b70 61 selectTab("feedConfig", true);
e513a74a
AD
62
63 if (caller_subop) {
64 var tuple = caller_subop.split(":");
65 if (tuple[0] == 'editFeed') {
66 window.setTimeout('editFeed('+tuple[1]+')', 100);
67 }
68
69 caller_subop = false;
70 }
23943c9b
AD
71 if (typeof correctPNG != 'undefined') {
72 correctPNG();
73 }
7f74a9da 74 notify("");
08827aaf
AD
75 remove_splash();
76
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
288487e4 85function dlg_frefresh_callback(transport) {
442d77f1 86
288487e4
AD
87 try {
88 var container = document.getElementById('prefContent');
89 container.innerHTML=transport.responseText;
90 selectTab("feedConfig", true);
442d77f1 91
288487e4
AD
92 if (caller_subop) {
93 var tuple = caller_subop.split(":");
94 if (tuple[0] == 'editFeed') {
95 window.setTimeout('editFeed('+tuple[1]+')', 100);
96 }
442d77f1 97
288487e4 98 caller_subop = false;
442d77f1 99 }
288487e4
AD
100 if (typeof correctPNG != 'undefined') {
101 correctPNG();
102 }
103 notify("");
104 } catch (e) {
105 exception_error("feedlist_callback", e);
442d77f1 106 }
288487e4 107
442d77f1
AD
108}
109
a0d53889 110function filterlist_callback() {
f5a50b25 111 var container = document.getElementById('prefContent');
a0d53889
AD
112 if (xmlhttp.readyState == 4) {
113 container.innerHTML=xmlhttp.responseText;
23943c9b
AD
114 if (typeof correctPNG != 'undefined') {
115 correctPNG();
116 }
7f74a9da 117 notify("");
08827aaf 118 remove_splash();
a0d53889
AD
119 }
120}
121
48f0adb0 122function labellist_callback() {
ceb30ba4
AD
123
124 try {
125
126 var container = document.getElementById('prefContent');
127 if (xmlhttp.readyState == 4) {
128 closeInfoBox();
129 container.innerHTML=xmlhttp.responseText;
130
131 if (document.getElementById("prefLabelList")) {
132 var elems = document.getElementById("prefLabelList").getElementsByTagName("SPAN");
133
134 for (var i = 0; i < elems.length; i++) {
135 if (elems[i].id && elems[i].id.match("LILT-")) {
136
137 var id = elems[i].id.replace("LILT-", "");
138 new Ajax.InPlaceEditor(elems[i],
9c5e85fe
AD
139 'backend.php?op=pref-labels&subop=save&id=' + id,
140 {cols: 20, rows: 1});
ceb30ba4
AD
141 }
142 }
48f0adb0 143 }
ceb30ba4
AD
144
145 if (typeof correctPNG != 'undefined') {
146 correctPNG();
48f0adb0 147 }
ceb30ba4
AD
148 notify("");
149 remove_splash();
48f0adb0 150 }
ceb30ba4
AD
151
152 } catch (e) {
153 exception_error("labellist_callback", e);
48f0adb0
AD
154 }
155}
4255b24c 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("");
08827aaf 162 remove_splash();
c6232e43
AD
163 }
164}
165
e6cb77a0
AD
166function userlist_callback() {
167 var container = document.getElementById('prefContent');
168 if (xmlhttp.readyState == 4) {
169 container.innerHTML=xmlhttp.responseText;
7f74a9da 170 notify("");
08827aaf 171 remove_splash();
e6cb77a0
AD
172 }
173}
174
4255b24c
AD
175function prefslist_callback() {
176 var container = document.getElementById('prefContent');
177 if (xmlhttp.readyState == 4) {
4255b24c 178 container.innerHTML=xmlhttp.responseText;
7f74a9da 179 notify("");
08827aaf 180 remove_splash();
4255b24c
AD
181 }
182}
183
b1895692
AD
184function gethelp_callback() {
185 var container = document.getElementById('prefHelpBox');
186 if (xmlhttp.readyState == 4) {
187
188 container.innerHTML = xmlhttp.responseText;
189 container.style.display = "block";
190
191 }
192}
4255b24c 193
0e091d38 194function notify_callback() {
0e091d38 195 if (xmlhttp.readyState == 4) {
42c32916
AD
196 notify_info(xmlhttp.responseText);
197 }
0e091d38
AD
198}
199
b652c1b7
AD
200function prefs_reset_callback() {
201 if (xmlhttp.readyState == 4) {
202 notify_info(xmlhttp.responseText);
203 selectTab();
204 }
205}
206
d95bd220
AD
207
208function changepass_callback() {
42395d28
AD
209 try {
210 if (xmlhttp.readyState == 4) {
211
212 if (xmlhttp.responseText.indexOf("ERROR: ") == 0) {
213 notify_error(xmlhttp.responseText.replace("ERROR: ", ""));
214 } else {
215 notify_info(xmlhttp.responseText);
216 var warn = document.getElementById("default_pass_warning");
217 if (warn) warn.style.display = "none";
218 }
219
220 document.forms['change_pass_form'].reset();
d95bd220 221
42395d28
AD
222 }
223 } catch (e) {
224 exception_error("changepass_callback", e);
225 }
d95bd220
AD
226}
227
8f708155
AD
228function init_cat_inline_editor() {
229 try {
11f083e7 230
8f708155
AD
231 if (document.getElementById("prefFeedCatList")) {
232 var elems = document.getElementById("prefFeedCatList").getElementsByTagName("SPAN");
11f083e7 233
8f708155
AD
234 for (var i = 0; i < elems.length; i++) {
235 if (elems[i].id && elems[i].id.match("FCATT-")) {
236 var cat_id = elems[i].id.replace("FCATT-", "");
11f083e7 237 new Ajax.InPlaceEditor(elems[i],
8f708155 238 'backend.php?op=pref-feeds&subop=editCats&action=save&cid=' + cat_id);
11f083e7
AD
239 }
240 }
8f708155
AD
241 }
242
243 } catch (e) {
244 exception_error("init_cat_inline_editor", e);
245 }
246}
247
248function infobox_feed_cat_callback() {
249 if (xmlhttp.readyState == 4) {
250 try {
251
252 infobox_callback();
253 init_cat_inline_editor();
11f083e7
AD
254
255 } catch (e) {
256 exception_error("infobox_feed_cat_callback", e);
257 }
258 }
259}
260
b83c7545 261function updateFeedList(sort_key) {
007bda35 262
c0e5a40e 263 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
264 printLockingError();
265 return
266 }
267
f932bc9f
AD
268 var feed_search = document.getElementById("feed_search");
269 var search = "";
270 if (feed_search) { search = feed_search.value; }
271
400b60d8
AD
272 var slat = document.getElementById("show_last_article_times");
273
274 var slat_checked = false;
275 if (slat) {
276 slat_checked = slat.checked;
277 }
278
b83c7545 279 xmlhttp.open("GET", "backend.php?op=pref-feeds" +
f932bc9f 280 "&sort=" + param_escape(sort_key) +
400b60d8 281 "&slat=" + param_escape(slat_checked) +
f932bc9f 282 "&search=" + param_escape(search), true);
007bda35
AD
283 xmlhttp.onreadystatechange=feedlist_callback;
284 xmlhttp.send(null);
285
286}
287
79ec0f2f 288function updateUsersList(sort_key) {
e6cb77a0
AD
289
290 if (!xmlhttp_ready(xmlhttp)) {
291 printLockingError();
292 return
293 }
294
a5bd7bf0
AD
295 var user_search = document.getElementById("user_search");
296 var search = "";
297 if (user_search) { search = user_search.value; }
298
79ec0f2f 299 xmlhttp.open("GET", "backend.php?op=pref-users&sort="
a5bd7bf0
AD
300 + param_escape(sort_key) +
301 "&search=" + param_escape(search), true);
e6cb77a0
AD
302 xmlhttp.onreadystatechange=userlist_callback;
303 xmlhttp.send(null);
304
305}
306
48f0adb0
AD
307function addLabel() {
308
ceb30ba4
AD
309 try {
310
48f0adb0
AD
311 if (!xmlhttp_ready(xmlhttp)) {
312 printLockingError();
313 return
314 }
315
ceb30ba4 316 var caption = prompt(__("Please enter label caption:"), "");
48f0adb0 317
4264f0b5
AD
318 if (caption == null) {
319 return false;
320 }
321
ceb30ba4 322 if (caption == "") {
89cb787e 323 alert(__("Can't create label: missing caption."));
f156fd00 324 return false;
de435974
AD
325 }
326
6068d33b
AD
327 // we can be called from some other tab
328 active_tab = "labelConfig";
329
ceb30ba4
AD
330 var query = "caption=" + param_escape(caption);
331
f156fd00
AD
332 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=add&" + query, true);
333 xmlhttp.onreadystatechange=infobox_submit_callback;
334 xmlhttp.send(null);
ceb30ba4
AD
335
336 } catch (e) {
337 exception_error("addLabel", e);
338 }
de435974 339}
48f0adb0 340
71ad3959
AD
341function addFeed() {
342
c0e5a40e 343 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
344 printLockingError();
345 return
346 }
347
331900c6
AD
348 var link = document.getElementById("fadd_link");
349
83fe4d6d 350 if (link.value.length == 0) {
f3977cf5 351 alert(__("Error: No feed URL given."));
605f7d46 352 } else if (!isValidURL(link.value)) {
f3977cf5 353 alert(__("Error: Invalid feed URL."));
331900c6 354 } else {
42c32916 355 notify_progress("Adding feed...");
331900c6 356
e513a74a 357 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&from=tt-rss&feed_url=" +
331900c6
AD
358 param_escape(link.value), true);
359 xmlhttp.onreadystatechange=feedlist_callback;
360 xmlhttp.send(null);
361
362 link.value = "";
363
364 }
365
366}
367
91ff844a
AD
368function addFeedCat() {
369
370 if (!xmlhttp_ready(xmlhttp)) {
371 printLockingError();
372 return
373 }
374
375 var cat = document.getElementById("fadd_cat");
376
377 if (cat.value.length == 0) {
f3977cf5 378 alert(__("Can't add category: no name specified."));
91ff844a 379 } else {
42c32916 380 notify_progress("Adding feed category...");
91ff844a 381
9c483746 382 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=add&cat=" +
91ff844a 383 param_escape(cat.value), true);
8f708155 384 xmlhttp.onreadystatechange=infobox_feed_cat_callback;
91ff844a
AD
385 xmlhttp.send(null);
386
387 link.value = "";
388
389 }
390
391}
e6cb77a0
AD
392function addUser() {
393
394 if (!xmlhttp_ready(xmlhttp)) {
395 printLockingError();
396 return
397 }
398
399 var sqlexp = document.getElementById("uadd_box");
400
401 if (sqlexp.value.length == 0) {
89cb787e 402 alert(__("Can't add user: no login specified."));
e6cb77a0 403 } else {
42c32916 404 notify_progress("Adding user...");
e6cb77a0
AD
405
406 xmlhttp.open("GET", "backend.php?op=pref-users&subop=add&login=" +
407 param_escape(sqlexp.value), true);
408
409 xmlhttp.onreadystatechange=userlist_callback;
410 xmlhttp.send(null);
411
412 sqlexp.value = "";
413 }
414
415}
416
e6cb77a0
AD
417function editUser(id) {
418
163723c4 419 try {
e6cb77a0 420
163723c4 421 disableHotkeys();
6068d33b 422
163723c4 423 notify_progress("Loading, please wait...");
9e31e1b9 424
163723c4
AD
425 selectTableRowsByIdPrefix('prefUserList', 'UMRR-', 'UMCHK-', false);
426 selectTableRowById('UMRR-'+id, 'UMCHK-'+id, true);
e6cb77a0 427
163723c4 428 disableContainerChildren("userOpToolbar", false);
3e36a4f4 429
163723c4
AD
430 var query = "backend.php?op=pref-users&subop=edit&id=" +
431 param_escape(id);
432
433 new Ajax.Request(query, {
434 onComplete: function(transport) {
435 infobox_callback2(transport);
436 } });
e6cb77a0 437
163723c4
AD
438 } catch (e) {
439 exception_error("editUser", e);
440 }
441
e6cb77a0
AD
442}
443
a0d53889
AD
444function editFilter(id) {
445
163723c4 446 try {
a0d53889 447
163723c4 448 disableHotkeys();
6068d33b 449
163723c4 450 notify_progress("Loading, please wait...");
9e31e1b9 451
163723c4 452 disableContainerChildren("filterOpToolbar", false);
4220b0bd 453
163723c4
AD
454 selectTableRowsByIdPrefix('prefFilterList', 'FILRR-', 'FICHK-', false);
455 selectTableRowById('FILRR-'+id, 'FICHK-'+id, true);
3e36a4f4 456
163723c4
AD
457 var query = "backend.php?op=pref-filters&subop=edit&id=" +
458 param_escape(id);
a0d53889 459
163723c4
AD
460 new Ajax.Request(query, {
461 onComplete: function(transport) {
462 infobox_callback2(transport);
463 } });
464 } catch (e) {
465 exception_error("editFilter", e);
466 }
a0d53889
AD
467}
468
331900c6
AD
469function editFeed(feed) {
470
a349077c 471 try {
a349077c 472
163723c4
AD
473 disableHotkeys();
474
475 notify_progress("Loading, please wait...");
476
477 // clean selection from all rows & select row being edited
478 selectTableRowsByIdPrefix('prefFeedList', 'FEEDR-', 'FRCHK-', false);
479 selectTableRowById('FEEDR-'+feed, 'FRCHK-'+feed, true);
480
481 disableContainerChildren("feedOpToolbar", false);
482
483 var query = "backend.php?op=pref-feeds&subop=editfeed&id=" +
484 param_escape(feed);
485
486 new Ajax.Request(query, {
487 onComplete: function(transport) {
488 infobox_callback2(transport);
489 } });
48f0adb0 490
163723c4
AD
491 } catch (e) {
492 exception_error("editFeed", e);
48f0adb0 493 }
e6cb77a0
AD
494}
495
91ff844a
AD
496function getSelectedLabels() {
497 return getSelectedTableRowIds("prefLabelList", "LILRR");
498}
48f0adb0 499
91ff844a
AD
500function getSelectedUsers() {
501 return getSelectedTableRowIds("prefUserList", "UMRR");
a0d53889
AD
502}
503
83fe4d6d 504function getSelectedFeeds() {
91ff844a
AD
505 return getSelectedTableRowIds("prefFeedList", "FEEDR");
506}
331900c6 507
91ff844a
AD
508function getSelectedFilters() {
509 return getSelectedTableRowIds("prefFilterList", "FILRR");
510}
331900c6 511
91ff844a
AD
512function getSelectedFeedCats() {
513 return getSelectedTableRowIds("prefFeedCatList", "FCATR");
83fe4d6d
AD
514}
515
c0ae0fdb 516
48f0adb0
AD
517function removeSelectedLabels() {
518
519 if (!xmlhttp_ready(xmlhttp)) {
520 printLockingError();
521 return
522 }
523
524 var sel_rows = getSelectedLabels();
525
526 if (sel_rows.length > 0) {
527
f56e3080 528 var ok = confirm(__("Remove selected labels?"));
48f0adb0 529
69668465 530 if (ok) {
42c32916 531 notify_progress("Removing selected labels...");
69668465
AD
532
533 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
534 param_escape(sel_rows.toString()), true);
535 xmlhttp.onreadystatechange=labellist_callback;
536 xmlhttp.send(null);
537 }
48f0adb0 538 } else {
89cb787e 539 alert(__("No labels are selected."));
48f0adb0 540 }
90ac84df
AD
541
542 return false;
48f0adb0
AD
543}
544
e6cb77a0
AD
545function removeSelectedUsers() {
546
547 if (!xmlhttp_ready(xmlhttp)) {
548 printLockingError();
549 return
550 }
551
552 var sel_rows = getSelectedUsers();
553
554 if (sel_rows.length > 0) {
555
f56e3080 556 var ok = confirm(__("Remove selected users?"));
e6cb77a0 557
69668465 558 if (ok) {
42c32916 559 notify_progress("Removing selected users...");
69668465
AD
560
561 xmlhttp.open("GET", "backend.php?op=pref-users&subop=remove&ids="+
562 param_escape(sel_rows.toString()), true);
563 xmlhttp.onreadystatechange=userlist_callback;
564 xmlhttp.send(null);
565 }
e6cb77a0
AD
566
567 } else {
89cb787e 568 alert(__("No users are selected."));
e6cb77a0 569 }
90ac84df
AD
570
571 return false;
e6cb77a0
AD
572}
573
48f0adb0
AD
574function removeSelectedFilters() {
575
576 if (!xmlhttp_ready(xmlhttp)) {
577 printLockingError();
578 return
579 }
580
581 var sel_rows = getSelectedFilters();
582
583 if (sel_rows.length > 0) {
584
f56e3080 585 var ok = confirm(__("Remove selected filters?"));
48f0adb0 586
69668465 587 if (ok) {
42c32916 588 notify_progress("Removing selected filters...");
69668465
AD
589
590 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
591 param_escape(sel_rows.toString()), true);
592 xmlhttp.onreadystatechange=filterlist_callback;
593 xmlhttp.send(null);
594 }
48f0adb0 595 } else {
89cb787e 596 alert(__("No filters are selected."));
48f0adb0 597 }
90ac84df
AD
598
599 return false;
48f0adb0
AD
600}
601
602
83fe4d6d
AD
603function removeSelectedFeeds() {
604
c0e5a40e 605 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
606 printLockingError();
607 return
608 }
609
83fe4d6d
AD
610 var sel_rows = getSelectedFeeds();
611
331900c6
AD
612 if (sel_rows.length > 0) {
613
f56e3080 614 var ok = confirm(__("Unsubscribe from selected feeds?"));
331900c6 615
69668465
AD
616 if (ok) {
617
42c32916 618 notify_progress("Unsubscribing from selected feeds...");
69668465
AD
619
620 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
621 param_escape(sel_rows.toString()), true);
622 xmlhttp.onreadystatechange=feedlist_callback;
623 xmlhttp.send(null);
624 }
71ad3959 625
71ad3959 626 } else {
331900c6 627
89cb787e 628 alert(__("No feeds are selected."));
331900c6 629
71ad3959 630 }
90ac84df
AD
631
632 return false;
71ad3959 633}
007bda35 634
c4a36709
AD
635function clearSelectedFeeds() {
636
637 if (!xmlhttp_ready(xmlhttp)) {
638 printLockingError();
639 return
640 }
641
642 var sel_rows = getSelectedFeeds();
643
644 if (sel_rows.length > 1) {
645 alert(__("Please select only one feed."));
646 return;
647 }
648
649 if (sel_rows.length > 0) {
650
651 var ok = confirm(__("Erase all non-starred articles in selected feed?"));
652
653 if (ok) {
654 notify_progress("Clearing selected feed...");
655 clearFeedArticles(sel_rows[0]);
656 }
657
658 } else {
659
660 alert(__("No feeds are selected."));
661
662 }
663
664 return false;
665}
666
e88a65f4
AD
667function purgeSelectedFeeds() {
668
669 if (!xmlhttp_ready(xmlhttp)) {
670 printLockingError();
671 return
672 }
673
674 var sel_rows = getSelectedFeeds();
675
676 if (sel_rows.length > 0) {
677
678 var pr = prompt(__("How many days of articles to keep (0 - use default)?"), "0");
679
680 if (pr != undefined) {
681 notify_progress("Purging selected feed...");
682
683 var query = "backend.php?op=rpc&subop=purge&ids="+
684 param_escape(sel_rows.toString()) + "&days=" + pr;
685
686 debug(query);
687
688 new Ajax.Request(query, {
689 onComplete: function(transport) {
690 notify('');
691 } });
692 }
693
694 } else {
695
696 alert(__("No feeds are selected."));
697
698 }
699
700 return false;
701}
702
91ff844a
AD
703function removeSelectedFeedCats() {
704
705 if (!xmlhttp_ready(xmlhttp)) {
706 printLockingError();
707 return
708 }
709
710 var sel_rows = getSelectedFeedCats();
711
712 if (sel_rows.length > 0) {
713
f56e3080 714 var ok = confirm(__("Remove selected categories?"));
91ff844a 715
69668465 716 if (ok) {
42c32916 717 notify_progress("Removing selected categories...");
69668465 718
9c483746 719 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=remove&ids="+
69668465 720 param_escape(sel_rows.toString()), true);
8f708155 721 xmlhttp.onreadystatechange=infobox_feed_cat_callback;
69668465
AD
722 xmlhttp.send(null);
723 }
91ff844a
AD
724
725 } else {
726
89cb787e 727 alert(__("No categories are selected."));
91ff844a
AD
728
729 }
730
90ac84df 731 return false;
91ff844a
AD
732}
733
508a81e1
AD
734function feedEditCancel() {
735
c0e5a40e 736 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
737 printLockingError();
738 return
739 }
740
a349077c 741 try {
57f734c8 742 document.getElementById("subscribe_to_feed_btn").disabled = false;
a349077c
AD
743 document.getElementById("top25_feeds_btn").disabled = false;
744 } catch (e) {
745 // this button is not always available, no-op if not found
746 }
747
327a3bbe
AD
748 closeInfoBox();
749
673d54ca 750 selectPrefRows('feed', false); // cleanup feed selection
508a81e1 751
90ac84df 752 return false;
508a81e1
AD
753}
754
603c27f8
AD
755function feedEditSave() {
756
47c6c988 757 try {
47c6c988
AD
758
759 if (!xmlhttp_ready(xmlhttp)) {
760 printLockingError();
761 return
762 }
ad815c71 763
14f69488 764 // FIXME: add parameter validation
e3c99f3b 765
14f69488 766 var query = Form.serialize("edit_feed_form");
b0da3a7b 767
42c32916 768 notify_progress("Saving feed...");
673d54ca 769
47c6c988
AD
770 xmlhttp.open("POST", "backend.php", true);
771 xmlhttp.onreadystatechange=feedlist_callback;
772 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
14f69488
AD
773 xmlhttp.send(query);
774
59a543f0
AD
775 closeInfoBox();
776
c14b5566
AD
777 return false;
778
47c6c988
AD
779 } catch (e) {
780 exception_error("feedEditSave", e);
b0da3a7b 781 }
508a81e1
AD
782}
783
e6cb77a0
AD
784function userEditCancel() {
785
786 if (!xmlhttp_ready(xmlhttp)) {
787 printLockingError();
788 return
789 }
790
3c5783b7 791 selectPrefRows('user', false); // cleanup feed selection
3c5783b7 792 closeInfoBox();
90ac84df
AD
793
794 return false;
e6cb77a0 795}
48f0adb0 796
a0d53889
AD
797function filterEditCancel() {
798
799 if (!xmlhttp_ready(xmlhttp)) {
800 printLockingError();
801 return
802 }
4220b0bd 803
57f734c8
AD
804 try {
805 document.getElementById("create_filter_btn").disabled = false;
806 selectPrefRows('filter', false); // cleanup feed selection
807 } catch (e) { }
808
07164479 809 closeInfoBox();
90ac84df
AD
810
811 return false;
a0d53889
AD
812}
813
e6cb77a0
AD
814function userEditSave() {
815
e6cb77a0
AD
816 if (!xmlhttp_ready(xmlhttp)) {
817 printLockingError();
818 return
819 }
820
3c5783b7 821 var login = document.forms["user_edit_form"].login.value;
e6cb77a0
AD
822
823 if (login.length == 0) {
89cb787e 824 alert(__("Login field cannot be blank."));
e6cb77a0
AD
825 return;
826 }
3c5783b7 827
42c32916 828 notify_progress("Saving user...");
4220b0bd
AD
829
830 closeInfoBox();
831
3c5783b7
AD
832 var query = Form.serialize("user_edit_form");
833
834 xmlhttp.open("GET", "backend.php?" + query, true);
dbd9e2f1 835 xmlhttp.onreadystatechange=userlist_callback;
e6cb77a0 836 xmlhttp.send(null);
90ac84df
AD
837
838 return false;
e6cb77a0
AD
839}
840
841
a0d53889
AD
842function filterEditSave() {
843
a0d53889
AD
844 if (!xmlhttp_ready(xmlhttp)) {
845 printLockingError();
846 return
847 }
848
9ee3ac59 849/* if (!is_opera()) {
7c620da8
AD
850 var reg_exp = document.forms["filter_edit_form"].reg_exp.value;
851
852 if (reg_exp.length == 0) {
853 alert("Filter expression field cannot be blank.");
854 return;
855 }
9ee3ac59 856 } */
a0d53889 857
42c32916 858 notify_progress("Saving filter...");
a0d53889 859
7e939457 860 var query = Form.serialize("filter_edit_form");
dbd9e2f1 861
07164479
AD
862 closeInfoBox();
863
4220b0bd
AD
864 document.getElementById("create_filter_btn").disabled = false;
865
7e939457 866 xmlhttp.open("GET", "backend.php?" + query, true);
a0d53889 867 xmlhttp.onreadystatechange=filterlist_callback;
7e939457 868 xmlhttp.send(null);
a0d53889 869
90ac84df 870 return false;
a0d53889
AD
871}
872
a0d53889 873
e6cb77a0
AD
874function editSelectedUser() {
875 var rows = getSelectedUsers();
876
877 if (rows.length == 0) {
f3977cf5 878 alert(__("No users are selected."));
e6cb77a0
AD
879 return;
880 }
881
882 if (rows.length > 1) {
f3977cf5 883 alert(__("Please select only one user."));
e6cb77a0
AD
884 return;
885 }
886
dbd9e2f1
AD
887 notify("");
888
e6cb77a0
AD
889 editUser(rows[0]);
890}
891
892function resetSelectedUserPass() {
893 var rows = getSelectedUsers();
894
895 if (rows.length == 0) {
f3977cf5 896 alert(__("No users are selected."));
e6cb77a0
AD
897 return;
898 }
899
900 if (rows.length > 1) {
f3977cf5 901 alert(__("Please select only one user."));
e6cb77a0
AD
902 return;
903 }
904
f3977cf5 905 var ok = confirm(__("Reset password of selected user?"));
e6cb77a0 906
69668465 907 if (ok) {
42c32916 908 notify_progress("Resetting password for selected user...");
69668465
AD
909
910 var id = rows[0];
911
912 xmlhttp.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
913 param_escape(id), true);
914 xmlhttp.onreadystatechange=userlist_callback;
915 xmlhttp.send(null);
916 }
e6cb77a0
AD
917}
918
717f5e64 919function selectedUserDetails() {
e6cb77a0 920
1a7572cb
AD
921 if (!xmlhttp_ready(xmlhttp)) {
922 printLockingError();
923 return
924 }
925
717f5e64
AD
926 var rows = getSelectedUsers();
927
928 if (rows.length == 0) {
f3977cf5 929 alert(__("No users are selected."));
717f5e64
AD
930 return;
931 }
932
933 if (rows.length > 1) {
f3977cf5 934 alert(__("Please select only one user."));
717f5e64
AD
935 return;
936 }
937
0077a65c 938 notify_progress("Loading, please wait...");
717f5e64 939
0077a65c 940 var id = rows[0];
dbd9e2f1 941
5a437c88 942 xmlhttp.open("GET", "backend.php?op=pref-users&subop=user-details&id=" + id, true);
c6c3a07f
AD
943 xmlhttp.onreadystatechange=infobox_callback;
944 xmlhttp.send(null);
945
946}
947
948function selectedFeedDetails() {
949
950 if (!xmlhttp_ready(xmlhttp)) {
951 printLockingError();
952 return
953 }
954
955 var rows = getSelectedFeeds();
956
957 if (rows.length == 0) {
f3977cf5 958 alert(__("No feeds are selected."));
c6c3a07f
AD
959 return;
960 }
961
01b3e191 962 if (rows.length > 1) {
f3977cf5 963 alert(__("Please select only one feed."));
01b3e191
AD
964 return;
965 }
c6c3a07f 966
df268d47 967// var id = rows[0];
c6c3a07f 968
dbd9e2f1
AD
969 notify("");
970
df268d47
AD
971 xmlhttp.open("GET", "backend.php?op=feed-details&id=" +
972 param_escape(rows.toString()), true);
c6c3a07f 973 xmlhttp.onreadystatechange=infobox_callback;
1a7572cb 974 xmlhttp.send(null);
717f5e64
AD
975
976}
a0d53889
AD
977
978function editSelectedFilter() {
979 var rows = getSelectedFilters();
980
981 if (rows.length == 0) {
f3977cf5 982 alert(__("No filters are selected."));
a0d53889
AD
983 return;
984 }
985
986 if (rows.length > 1) {
f3977cf5 987 alert(__("Please select only one filter."));
a0d53889
AD
988 return;
989 }
990
dbd9e2f1
AD
991 notify("");
992
a0d53889
AD
993 editFilter(rows[0]);
994
995}
996
997
508a81e1
AD
998function editSelectedFeed() {
999 var rows = getSelectedFeeds();
1000
1001 if (rows.length == 0) {
f3977cf5 1002 alert(__("No feeds are selected."));
508a81e1
AD
1003 return;
1004 }
1005
1006 if (rows.length > 1) {
f3977cf5 1007 alert(__("Please select one feed."));
508a81e1
AD
1008 return;
1009 }
1010
dbd9e2f1
AD
1011 notify("");
1012
508a81e1 1013 editFeed(rows[0]);
91ff844a
AD
1014
1015}
1016
758e1c4a
AD
1017function editSelectedFeeds() {
1018
1019 if (!xmlhttp_ready(xmlhttp)) {
1020 printLockingError();
1021 return
1022 }
1023
1024 var rows = getSelectedFeeds();
1025
1026 if (rows.length == 0) {
1027 alert(__("No feeds are selected."));
1028 return;
1029 }
1030
1031 notify("");
1032
1033 disableHotkeys();
1034
1035 notify_progress("Loading, please wait...");
1036
1037 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeeds&ids=" +
1038 param_escape(rows.toString()), true);
1039
1040 xmlhttp.onreadystatechange=infobox_callback;
1041 xmlhttp.send(null);
1042
1043}
1044
eec498c3 1045function piggie(enable) {
13ad9102 1046 if (enable) {
d437c8cf 1047 debug("I LOVEDED IT!");
1cac3c31 1048 var piggie = document.getElementById("piggie");
33377ef3 1049
537625c6
AD
1050 Element.show(piggie);
1051 Position.Center(piggie);
1052 Effect.Puff(piggie);
1053
508a81e1 1054 }
508a81e1
AD
1055}
1056
9f311df6
AD
1057function validateOpmlImport() {
1058
1059 var opml_file = document.getElementById("opml_file");
1060
1061 if (opml_file.value.length == 0) {
f3977cf5 1062 alert(__("No OPML file to upload."));
9f311df6
AD
1063 return false;
1064 } else {
1065 return true;
1066 }
1067}
1068
0e317f9d 1069function updateFilterList(sort_key) {
a0d53889
AD
1070
1071 if (!xmlhttp_ready(xmlhttp)) {
1072 printLockingError();
1073 return
1074 }
1075
9c87d75c
AD
1076 var filter_search = document.getElementById("filter_search");
1077 var search = "";
1078 if (filter_search) { search = filter_search.value; }
1079
e161a2cc 1080 xmlhttp.open("GET", "backend.php?op=pref-filters&sort=" +
9c87d75c
AD
1081 param_escape(sort_key) +
1082 "&search=" + param_escape(search), true);
a0d53889
AD
1083 xmlhttp.onreadystatechange=filterlist_callback;
1084 xmlhttp.send(null);
1085
1086}
1087
e161a2cc 1088function updateLabelList(sort_key) {
48f0adb0
AD
1089
1090 if (!xmlhttp_ready(xmlhttp)) {
1091 printLockingError();
1092 return
1093 }
1094
112d2aec
AD
1095 var label_search = document.getElementById("label_search");
1096 var search = "";
1097 if (label_search) { search = label_search.value; }
1098
e161a2cc 1099 xmlhttp.open("GET", "backend.php?op=pref-labels&sort=" +
112d2aec
AD
1100 param_escape(sort_key) +
1101 "&search=" + param_escape(search), true);
48f0adb0
AD
1102 xmlhttp.onreadystatechange=labellist_callback;
1103 xmlhttp.send(null);
48f0adb0
AD
1104}
1105
4255b24c
AD
1106function updatePrefsList() {
1107
1108 if (!xmlhttp_ready(xmlhttp)) {
1109 printLockingError();
1110 return
1111 }
1112
4255b24c
AD
1113 xmlhttp.open("GET", "backend.php?op=pref-prefs", true);
1114 xmlhttp.onreadystatechange=prefslist_callback;
1115 xmlhttp.send(null);
1116
1117}
1118
e513a74a 1119function selectTab(id, noupdate, subop) {
a7f22b70
AD
1120
1121// alert(id);
48f0adb0 1122
b2caf812 1123 if (!id) id = active_tab;
7f74a9da 1124
b2caf812 1125 try {
59a543f0 1126
b2caf812
AD
1127 if (!xmlhttp_ready(xmlhttp)) {
1128 printLockingError();
1129 return
a7f22b70 1130 }
f5a50b25 1131
a422968f
AD
1132 try {
1133 var c = document.getElementById('prefContent');
1134 c.scrollTop = 0;
1135 } catch (e) { };
1136
b2caf812 1137 if (!noupdate) {
f5a50b25 1138
b2caf812
AD
1139 debug("selectTab: " + id + "(NU: " + noupdate + ")");
1140
9e31e1b9 1141 notify_progress("Loading, please wait...");
b2caf812
AD
1142
1143 // close active infobox if needed
1144 closeInfoBox();
1145
1146 // clean up all current selections, just in case
1147 active_feed_cat = false;
d15f8675
AD
1148
1149// Effect.Fade("prefContent", {duration: 1, to: 0.01,
1150// queue: { position:'end', scope: 'FEED_TAB', limit: 1 } } );
1151
b2caf812
AD
1152 if (id == "feedConfig") {
1153 updateFeedList();
1154 } else if (id == "filterConfig") {
1155 updateFilterList();
1156 } else if (id == "labelConfig") {
1157 updateLabelList();
1158 } else if (id == "genConfig") {
1159 updatePrefsList();
1160 } else if (id == "userConfig") {
1161 updateUsersList();
b2caf812 1162 }
f5a50b25 1163 }
6068d33b
AD
1164
1165 /* clean selection from all tabs */
b2caf812 1166
6068d33b
AD
1167 var tabs_holder = document.getElementById("prefTabs");
1168 var tab = tabs_holder.firstChild;
1169
1170 while (tab) {
1171 if (tab.className && tab.className.match("prefsTabSelected")) {
b2caf812
AD
1172 tab.className = "prefsTab";
1173 }
6068d33b 1174 tab = tab.nextSibling;
f5a50b25 1175 }
6068d33b
AD
1176
1177 /* mark new tab as selected */
1178
b2caf812
AD
1179 tab = document.getElementById(id + "Tab");
1180
1181 if (tab) {
1182 if (!tab.className.match("Selected")) {
1183 tab.className = tab.className + "Selected";
1184 }
1185 }
1186
b2caf812 1187 active_tab = id;
f5a50b25 1188
b2caf812
AD
1189 } catch (e) {
1190 exception_error("selectTab", e);
a7565293 1191 }
a7565293
AD
1192}
1193
1194function backend_sanity_check_callback() {
f5a50b25 1195
a7565293
AD
1196 if (xmlhttp.readyState == 4) {
1197
1198 try {
7a09510c
AD
1199
1200 if (sanity_check_done) {
81352b54
AD
1201 fatalError(11, "Sanity check request received twice. This can indicate "+
1202 "presence of Firebug or some other disrupting extension. "+
1203 "Please disable it and try again.");
7a09510c
AD
1204 return;
1205 }
1206
a7565293 1207 if (!xmlhttp.responseXML) {
64b3069d
AD
1208 fatalError(3, "Sanity Check: Received reply is not XML",
1209 xmlhttp.responseText);
a7565293
AD
1210 return;
1211 }
1212
1213 var reply = xmlhttp.responseXML.firstChild.firstChild;
1214
1215 if (!reply) {
64b3069d 1216 fatalError(3, "Sanity Check: Invalid RPC reply", xmlhttp.responseText);
a7565293
AD
1217 return;
1218 }
1219
1220 var error_code = reply.getAttribute("error-code");
1221
1222 if (error_code && error_code != 0) {
1223 return fatalError(error_code, reply.getAttribute("error-msg"));
1224 }
1225
1226 debug("sanity check ok");
1227
1228 var params = reply.nextSibling;
1229
1230 if (params) {
1231 debug('reading init-params...');
1232 var param = params.firstChild;
1233
1234 while (param) {
1235 var k = param.getAttribute("key");
1236 var v = param.getAttribute("value");
1237 debug(k + " => " + v);
1238 init_params[k] = v;
1239 param = param.nextSibling;
1240 }
1241 }
1242
7a09510c
AD
1243 sanity_check_done = true;
1244
a7565293
AD
1245 init_second_stage();
1246
1247 } catch (e) {
1248 exception_error("backend_sanity_check_callback", e);
1249 }
1250 }
1251}
1252
1253function init_second_stage() {
1254
b2caf812
AD
1255 try {
1256 active_tab = getInitParam("prefs_active_tab");
e8375afe 1257 if (!document.getElementById(active_tab+"Tab")) active_tab = "genConfig";
fe8d2059 1258 if (!active_tab || active_tab == '0') active_tab = "genConfig";
4da47970 1259
d437c8cf
AD
1260 document.onkeydown = pref_hotkey_handler;
1261
e513a74a
AD
1262 var tab = getURLParam('tab');
1263
1264 caller_subop = getURLParam('subop');
1265
6906f145
AD
1266 if (getURLParam("subopparam")) {
1267 caller_subop = caller_subop + ":" + getURLParam("subopparam");
1268 }
1269
e513a74a
AD
1270 if (tab) {
1271 active_tab = tab;
1272 }
1273
b2caf812
AD
1274 if (navigator.userAgent.match("Opera")) {
1275 setTimeout("selectTab()", 500);
1276 } else {
1277 selectTab(active_tab);
1278 }
1279 notify("");
08827aaf
AD
1280
1281 loading_set_progress(60);
1282
b2caf812
AD
1283 } catch (e) {
1284 exception_error("init_second_stage", e);
1285 }
a0d53889
AD
1286}
1287
007bda35 1288function init() {
e2ec66a8 1289
7719618b
AD
1290 try {
1291
97dcd654
AD
1292 if (arguments.callee.done) return;
1293 arguments.callee.done = true;
1294
a7565293 1295 if (getURLParam('debug')) {
8836613c 1296 Element.show("debug_output");
a7565293
AD
1297 debug('debug mode activated');
1298 }
1299
7719618b
AD
1300 // IE kludge
1301 if (!xmlhttp) {
1302 document.getElementById("prefContent").innerHTML =
1303 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1304 "to function properly. Your browser doesn't seem to support it.";
1305 return;
1306 }
4da47970 1307
08827aaf
AD
1308 loading_set_progress(30);
1309
a7565293
AD
1310 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
1311 xmlhttp.onreadystatechange=backend_sanity_check_callback;
1312 xmlhttp.send(null);
1313
7719618b
AD
1314 } catch (e) {
1315 exception_error("init", e);
e2ec66a8 1316 }
007bda35 1317}
b1895692 1318
f932bc9f
AD
1319function categorizeSelectedFeeds() {
1320
1321 if (!xmlhttp_ready(xmlhttp)) {
1322 printLockingError();
1323 return
1324 }
1325
1326 var sel_rows = getSelectedFeeds();
1327
1328 var cat_sel = document.getElementById("sfeed_set_fcat");
79f3553b 1329 var cat_id = cat_sel[cat_sel.selectedIndex].value;
f932bc9f
AD
1330
1331 if (sel_rows.length > 0) {
1332
42c32916 1333 notify_progress("Changing category of selected feeds...");
f932bc9f
AD
1334
1335 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
1336 param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
1337 xmlhttp.onreadystatechange=feedlist_callback;
1338 xmlhttp.send(null);
1339
1340 } else {
1341
f3977cf5 1342 alert(__("No feeds are selected."));
f932bc9f
AD
1343
1344 }
1345
1346}
69668465
AD
1347
1348function validatePrefsReset() {
b652c1b7
AD
1349 try {
1350 var ok = confirm(__("Reset to defaults?"));
1351
1352 if (ok) {
1353
1354 var query = Form.serialize("pref_prefs_form");
1355 query = query + "&subop=reset-config";
1356 debug(query);
1357
1358 xmlhttp.open("POST", "backend.php", true);
1359 xmlhttp.onreadystatechange=prefs_reset_callback;
1360 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1361 xmlhttp.send(query);
1362 }
1363
1364 } catch (e) {
1365 exception_error("validatePrefsSave", e);
1366 }
1367
1368 return false;
1369
69668465 1370}
f9cb39ac 1371
6311acbe 1372function browseFeeds(limit) {
f9cb39ac
AD
1373
1374 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=browse", true);
1375 xmlhttp.onreadystatechange=infobox_callback;
1376 xmlhttp.send(null);
1377
1378}
a0476535
AD
1379
1380function feedBrowserSubscribe() {
1381 try {
a0476535 1382
c0ae0fdb 1383 var selected = getSelectedFeedsFromBrowser();
a0476535
AD
1384
1385 if (selected.length > 0) {
1386 closeInfoBox();
1387 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=massSubscribe&ids="+
1388 param_escape(selected.toString()), true);
1389 xmlhttp.onreadystatechange=feedlist_callback;
1390 xmlhttp.send(null);
1391 } else {
89cb787e 1392 alert(__("No feeds are selected."));
a0476535
AD
1393 }
1394
1395 } catch (e) {
1396 exception_error("feedBrowserSubscribe", e);
1397 }
1398}
c6232e43 1399
ce8de904
AD
1400function updateBigFeedBrowserBtn() {
1401 notify_progress("Loading, please wait...");
1402 return updateBigFeedBrowser();
1403}
1404
ce3bf408
AD
1405function selectPrefRows(kind, select) {
1406
1407 if (kind) {
1408 var opbarid = false;
1409 var nchk = false;
1410 var nrow = false;
1411 var lname = false;
1412
1413 if (kind == "feed") {
1414 opbarid = "feedOpToolbar";
1415 nrow = "FEEDR-";
1416 nchk = "FRCHK-";
1417 lname = "prefFeedList";
1418 } else if (kind == "fcat") {
1419 opbarid = "catOpToolbar";
1420 nrow = "FCATR-";
9c483746 1421 nchk = "FCCHK-";
ce3bf408
AD
1422 lname = "prefFeedCatList";
1423 } else if (kind == "filter") {
1424 opbarid = "filterOpToolbar";
1425 nrow = "FILRR-";
1426 nchk = "FICHK-";
1427 lname = "prefFilterList";
1428 } else if (kind == "label") {
1429 opbarid = "labelOpToolbar";
1430 nrow = "LILRR-";
a4dbc524 1431 nchk = "LICHK-";
ce3bf408
AD
1432 lname = "prefLabelList";
1433 } else if (kind == "user") {
1434 opbarid = "userOpToolbar";
1435 nrow = "UMRR-";
1436 nchk = "UMCHK-";
1437 lname = "prefUserList";
1438 }
1439
1440 if (opbarid) {
1441 selectTableRowsByIdPrefix(lname, nrow, nchk, select);
1442 disableContainerChildren(opbarid, !select);
1443 }
1444
1445 }
1446}
1447
1448
1449function toggleSelectPrefRow(sender, kind) {
1450
1451 toggleSelectRow(sender);
1452
1453 if (kind) {
1454 var opbarid = false;
1455 var nsel = -1;
1456
1457 if (kind == "feed") {
1458 opbarid = "feedOpToolbar";
1459 nsel = getSelectedFeeds();
1460 } else if (kind == "fcat") {
1461 opbarid = "catOpToolbar";
1462 nsel = getSelectedFeedCats();
1463 } else if (kind == "filter") {
1464 opbarid = "filterOpToolbar";
1465 nsel = getSelectedFilters();
1466 } else if (kind == "label") {
1467 opbarid = "labelOpToolbar";
1468 nsel = getSelectedLabels();
1469 } else if (kind == "user") {
1470 opbarid = "userOpToolbar";
1471 nsel = getSelectedUsers();
1472 }
1473
1474 if (opbarid && nsel != -1) {
1475 disableContainerChildren(opbarid, nsel == false);
1476 }
1477
1478 }
1479}
1480
c0ae0fdb
AD
1481function toggleSelectFBListRow(sender) {
1482 toggleSelectListRow(sender);
1483 disableContainerChildren("fbrOpToolbar", getSelectedFeedsFromBrowser() == 0);
1484}
d437c8cf
AD
1485
1486var seq = "";
1487
1488function pref_hotkey_handler(e) {
1489 try {
1490
1491 var keycode;
746dcf42
AD
1492 var shift_key = false;
1493
1494 try {
1495 shift_key = e.shiftKey;
1496 } catch (e) {
1497
1498 }
1499
d437c8cf
AD
1500 if (window.event) {
1501 keycode = window.event.keyCode;
1502 } else if (e) {
1503 keycode = e.which;
1504 }
746dcf42 1505
eec498c3
AD
1506 var keychar = String.fromCharCode(keycode);
1507
746dcf42
AD
1508 if (keycode == 27) { // escape
1509 if (Element.visible("hotkey_help_overlay")) {
1510 Element.hide("hotkey_help_overlay");
1511 }
1512 hotkey_prefix = false;
1513 closeInfoBox();
1514 }
1515
1516 if (!hotkeys_enabled) {
1517 debug("hotkeys disabled");
1518 return;
1519 }
1520
1521 if (keycode == 16) return; // ignore lone shift
1522
6068d33b
AD
1523 if ((keycode == 67 || keycode == 71) && !hotkey_prefix) {
1524 hotkey_prefix = keycode;
eec498c3 1525 debug("KP: PREFIX=" + keycode + " CHAR=" + keychar);
6068d33b
AD
1526 return;
1527 }
1528
746dcf42
AD
1529 if (Element.visible("hotkey_help_overlay")) {
1530 Element.hide("hotkey_help_overlay");
1531 }
1532
d437c8cf
AD
1533 if (keycode == 13 || keycode == 27) {
1534 seq = "";
1535 } else {
1536 seq = seq + "" + keycode;
1537 }
1538
746dcf42 1539 /* Global hotkeys */
d437c8cf 1540
746dcf42
AD
1541 if (!hotkey_prefix) {
1542
1543 if (keycode == 68 && shift_key) { // d
8836613c
AD
1544 if (!Element.visible("debug_output")) {
1545 Element.show("debug_output");
746dcf42
AD
1546 debug('debug mode activated');
1547 } else {
8836613c 1548 Element.hide("debug_output");
746dcf42 1549 }
746dcf42
AD
1550 return;
1551 }
1552
eec498c3 1553 if ((keycode == 191 || keychar == '?') && shift_key) { // ?
746dcf42 1554 if (!Element.visible("hotkey_help_overlay")) {
86deaa0e
AD
1555 //Element.show("hotkey_help_overlay");
1556 Effect.Appear("hotkey_help_overlay", {duration : 0.3});
746dcf42
AD
1557 } else {
1558 Element.hide("hotkey_help_overlay");
1559 }
eec498c3 1560 return false;
746dcf42
AD
1561 }
1562
eec498c3 1563 if (keycode == 191 || keychar == '/') { // /
477402d8 1564 var search_boxes = new Array("label_search",
e8be0f5b 1565 "feed_search", "filter_search", "user_search", "feed_browser_search");
477402d8
AD
1566
1567 for (var i = 0; i < search_boxes.length; i++) {
1568 var elem = document.getElementById(search_boxes[i]);
1569 if (elem) {
eec498c3
AD
1570 focus_element(search_boxes[i]);
1571 return false;
477402d8
AD
1572 }
1573 }
477402d8 1574 }
6068d33b
AD
1575 }
1576
1577 /* Prefix c */
1578
1579 if (hotkey_prefix == 67) { // c
1580 hotkey_prefix = false;
1581
1582 if (keycode == 70) { // f
eec498c3
AD
1583 displayDlg("quickAddFilter");
1584 return false;
6068d33b
AD
1585 }
1586
1587 if (keycode == 83) { // s
eec498c3
AD
1588 displayDlg("quickAddFeed");
1589 return false;
6068d33b
AD
1590 }
1591
ceb30ba4 1592/* if (keycode == 76) { // l
eec498c3
AD
1593 displayDlg("quickAddLabel");
1594 return false;
ceb30ba4 1595 } */
6068d33b
AD
1596
1597 if (keycode == 85) { // u
1598 // no-op
1599 }
1600
57f734c8 1601 if (keycode == 67) { // c
eec498c3
AD
1602 editFeedCats();
1603 return false;
57f734c8
AD
1604 }
1605
a80b05ea 1606 if (keycode == 84 && shift_key) { // T
eec498c3
AD
1607 browseFeeds();
1608 return false;
a80b05ea
AD
1609 }
1610
6068d33b
AD
1611 }
1612
1613 /* Prefix g */
1614
1615 if (hotkey_prefix == 71) { // g
1616
1617 hotkey_prefix = false;
1618
1619 if (keycode == 49 && document.getElementById("genConfigTab")) { // 1
746dcf42 1620 selectTab("genConfig");
eec498c3 1621 return false;
746dcf42
AD
1622 }
1623
1624 if (keycode == 50 && document.getElementById("feedConfigTab")) { // 2
eec498c3
AD
1625 selectTab("feedConfig");
1626 return false;
746dcf42
AD
1627 }
1628
3a6521f0 1629 if (keycode == 51 && document.getElementById("filterConfigTab")) { // 4
eec498c3
AD
1630 selectTab("filterConfig");
1631 return false;
746dcf42
AD
1632 }
1633
3a6521f0 1634 if (keycode == 52 && document.getElementById("labelConfigTab")) { // 5
eec498c3
AD
1635 selectTab("labelConfig");
1636 return false;
746dcf42
AD
1637 }
1638
3a6521f0 1639 if (keycode == 53 && document.getElementById("userConfigTab")) { // 6
eec498c3
AD
1640 selectTab("userConfig");
1641 return false;
746dcf42
AD
1642 }
1643
8d727bfc
AD
1644 if (keycode == 88) { // x
1645 return gotoMain();
1646 }
1647
746dcf42
AD
1648 }
1649
1650 if (document.getElementById("piggie")) {
1651
1652 if (seq.match("807371717369")) {
1653 seq = "";
eec498c3 1654 piggie(true);
746dcf42 1655 } else {
eec498c3 1656 piggie(false);
746dcf42
AD
1657 }
1658 }
1659
1660 if (hotkey_prefix) {
eec498c3 1661 debug("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar);
d437c8cf 1662 } else {
eec498c3 1663 debug("KP: CODE=" + keycode + " CHAR=" + keychar);
d437c8cf 1664 }
d437c8cf
AD
1665
1666 } catch (e) {
1667 exception_error("pref_hotkey_handler", e);
1668 }
1669}
1670
9c483746
AD
1671function editFeedCats() {
1672 if (!xmlhttp_ready(xmlhttp)) {
1673 printLockingError();
1674 return
1675 }
1676
a349077c
AD
1677 document.getElementById("subscribe_to_feed_btn").disabled = true;
1678
1679 try {
1680 document.getElementById("top25_feeds_btn").disabled = true;
1681 } catch (e) {
1682 // this button is not always available, no-op if not found
1683 }
1684
9c483746 1685 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
11f083e7 1686 xmlhttp.onreadystatechange=infobox_feed_cat_callback;
9c483746
AD
1687 xmlhttp.send(null);
1688}
a3656a41
AD
1689
1690function showFeedsWithErrors() {
1691 displayDlg('feedUpdateErrors');
1692}
073ca0e6 1693
d95bd220
AD
1694function changeUserPassword() {
1695
1696 try {
1697
1698 if (!xmlhttp_ready(xmlhttp)) {
1699 printLockingError();
1700 return false;
1701 }
1702
ae661a8c
AD
1703 var f = document.forms["change_pass_form"];
1704
1705 if (f) {
1706 if (f.OLD_PASSWORD.value == "") {
1707 new Effect.Highlight(f.OLD_PASSWORD);
1708 notify_error("Old password cannot be blank.");
1709 return false;
1710 }
1711
1712 if (f.NEW_PASSWORD.value == "") {
1713 new Effect.Highlight(f.NEW_PASSWORD);
1714 notify_error("New password cannot be blank.");
1715 return false;
1716 }
1717
1718 if (f.CONFIRM_PASSWORD.value == "") {
1719 new Effect.Highlight(f.CONFIRM_PASSWORD);
1720 notify_error("Entered passwords do not match.");
1721 return false;
1722 }
1723
1724 if (f.CONFIRM_PASSWORD.value != f.NEW_PASSWORD.value) {
1725 new Effect.Highlight(f.CONFIRM_PASSWORD);
1726 new Effect.Highlight(f.NEW_PASSWORD);
1727 notify_error("Entered passwords do not match.");
1728 return false;
1729 }
1730
1731 }
1732
d95bd220
AD
1733 var query = Form.serialize("change_pass_form");
1734
1735 notify_progress("Trying to change password...");
1736
1737 xmlhttp.open("POST", "backend.php", true);
1738 xmlhttp.onreadystatechange=changepass_callback;
1739 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1740 xmlhttp.send(query);
1741
1742 } catch (e) {
1743 exception_error("changeUserPassword", e);
1744 }
1745
1746 return false;
1747}
073ca0e6 1748
42395d28
AD
1749function changeUserEmail() {
1750
1751 try {
1752
1753 if (!xmlhttp_ready(xmlhttp)) {
1754 printLockingError();
1755 return false;
1756 }
1757
1758 var query = Form.serialize("change_email_form");
1759
1760 notify_progress("Trying to change e-mail...");
1761
1762 xmlhttp.open("POST", "backend.php", true);
1763 xmlhttp.onreadystatechange=notify_callback;
1764 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1765 xmlhttp.send(query);
1766
1767 } catch (e) {
1768 exception_error("changeUserPassword", e);
1769 }
1770
1771 return false;
1772
1773}
400b60d8
AD
1774
1775function feedlistToggleSLAT() {
1776 notify_progress("Loading, please wait...");
1777 updateFeedList()
1778}
bc0ed820 1779
e4f4b46f
AD
1780function pubRegenKey() {
1781
bc0ed820
AD
1782 if (!xmlhttp_ready(xmlhttp)) {
1783 printLockingError();
e4f4b46f 1784 return false;
bc0ed820
AD
1785 }
1786
f56e3080 1787 var ok = confirm(__("Replace current publishing address with a new one?"));
bc0ed820 1788
e4f4b46f
AD
1789 if (ok) {
1790
1791 notify_progress("Trying to change address...");
1792
945c243e 1793 xmlhttp.open("GET", "backend.php?op=rpc&subop=regenPubKey");
e4f4b46f
AD
1794 xmlhttp.onreadystatechange=replace_pubkey_callback;
1795 xmlhttp.send(null);
1796 }
1797
1798 return false;
945c243e 1799}
b652c1b7 1800
e635d56a
AD
1801function pubToClipboard() {
1802
1803 try {
1804
1805 if (!xmlhttp_ready(xmlhttp)) {
1806 printLockingError();
1807 return false;
1808 }
1809
1810 var link = document.getElementById("pubGenAddress");
1811 alert(link.href);
1812
1813 } catch (e) {
1814 exception_error("pubToClipboard", e);
1815 }
1816
1817 return false;
1818}
1819
b652c1b7
AD
1820function validatePrefsSave() {
1821 try {
1822
1823 var ok = confirm(__("Save current configuration?"));
1824
1825 if (ok) {
1826
1827 var query = Form.serialize("pref_prefs_form");
1828 query = query + "&subop=save-config";
1829 debug(query);
1830
1831 xmlhttp.open("POST", "backend.php", true);
1832 xmlhttp.onreadystatechange=notify_callback;
1833 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1834 xmlhttp.send(query);
1835 }
1836
1837 } catch (e) {
1838 exception_error("validatePrefsSave", e);
1839 }
1840
1841 return false;
1842}
c4a36709
AD
1843
1844function feedActionChange() {
1845 try {
1846 var chooser = document.getElementById("feedActionChooser");
1847 var opid = chooser[chooser.selectedIndex].value;
1848
1849 chooser.selectedIndex = 0;
1850 feedActionGo(opid);
1851 } catch (e) {
1852 exception_error("feedActionChange", e);
1853 }
1854}
1855
1856function feedActionGo(op) {
1857 try {
1858 if (op == "facEdit") {
cd935c42
AD
1859
1860 var rows = getSelectedFeeds();
1861
1862 if (rows.length > 1) {
1863 editSelectedFeeds();
1864 } else {
1865 editSelectedFeed();
1866 }
c4a36709
AD
1867 }
1868
1869 if (op == "facClear") {
1870 clearSelectedFeeds();
1871 }
1872
1873 if (op == "facPurge") {
1874 purgeSelectedFeeds();
1875 }
1876
e88a65f4
AD
1877 if (op == "facEditCats") {
1878 editFeedCats();
1879 }
1880
fee840fb
AD
1881 if (op == "facRescore") {
1882 rescoreSelectedFeeds();
1883 }
1884
c4a36709
AD
1885 if (op == "facUnsubscribe") {
1886 removeSelectedFeeds();
1887 }
1888
1889 } catch (e) {
1890 exception_error("feedActionGo", e);
1891
1892 }
1893}
1894
1895function clearFeedArticles(feed_id) {
1896
1897 notify_progress("Clearing feed...");
1898
1899 var query = "backend.php?op=pref-feeds&quiet=1&subop=clear&id=" + feed_id;
1900
1901 new Ajax.Request(query, {
1902 onComplete: function(transport) {
1903 notify('');
1904 } });
1905
1906 return false;
1907}
1908
fee840fb
AD
1909function rescoreSelectedFeeds() {
1910
1911 if (!xmlhttp_ready(xmlhttp)) {
1912 printLockingError();
1913 return
1914 }
1915
1916 var sel_rows = getSelectedFeeds();
1917
1918 if (sel_rows.length > 0) {
1919
ef1b0366
AD
1920 //var ok = confirm(__("Rescore last 100 articles in selected feeds?"));
1921 var ok = confirm(__("Rescore articles in selected feeds?"));
fee840fb
AD
1922
1923 if (ok) {
3df4869b 1924 notify_progress("Rescoring selected feeds...", true);
fee840fb
AD
1925
1926 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=rescore&quiet=1&ids="+
1927 param_escape(sel_rows.toString()), true);
1928 xmlhttp.onreadystatechange=notify_callback;
1929 xmlhttp.send(null);
1930 }
1931 } else {
1932 alert(__("No feeds are selected."));
1933 }
1934
1935 return false;
1936}
c4a36709 1937
95a948a5
AD
1938function rescore_all_feeds() {
1939 var ok = confirm(__("Rescore all articles? This operation may take a lot of time."));
1940
1941 if (ok) {
3df4869b 1942 notify_progress("Rescoring feeds...", true);
95a948a5
AD
1943
1944 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=rescoreAll&quiet=1", true);
1945 xmlhttp.onreadystatechange=notify_callback;
1946 xmlhttp.send(null);
1947 }
a80b05ea 1948}
a44db887
AD
1949
1950function removeFilter(id, title) {
1951
1952 if (!xmlhttp_ready(xmlhttp)) {
1953 printLockingError();
1954 return
1955 }
1956
1957 var msg = __("Remove filter %s?").replace("%s", title);
1958
1959 var ok = confirm(msg);
1960
1961 if (ok) {
1962 closeInfoBox();
1963
1964 notify_progress("Removing filter...");
1965
1966 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
1967 param_escape(id), true);
1968 xmlhttp.onreadystatechange=filterlist_callback;
1969 xmlhttp.send(null);
1970 }
1971
1972 return false;
1973}
1974
c8d5dcfe
AD
1975function unsubscribeFeed(id, title) {
1976
1977 if (!xmlhttp_ready(xmlhttp)) {
1978 printLockingError();
1979 return
1980 }
1981
1982 var msg = __("Unsubscribe from %s?").replace("%s", title);
1983
1984 var ok = confirm(msg);
1985
1986 if (ok) {
1987 closeInfoBox();
1988
1989 notify_progress("Removing feed...");
1990
1991 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
1992 param_escape(id), true);
1993 xmlhttp.onreadystatechange=filterlist_callback;
1994 xmlhttp.send(null);
1995 }
1996
1997 return false;
1998
1999 return false;
2000
2001}
2002
758e1c4a
AD
2003function feedsEditSave() {
2004 try {
2005
2006 if (!xmlhttp_ready(xmlhttp)) {
2007 printLockingError();
2008 return
2009 }
2010
cd935c42 2011 var ok = confirm(__("Save changes to selected feeds?"));
758e1c4a 2012
b0f015a2
AD
2013 if (ok) {
2014
5d538f4f
AD
2015 var f = document.forms["batch_edit_feed_form"];
2016
b0f015a2 2017 var query = Form.serialize("batch_edit_feed_form");
5d538f4f
AD
2018
2019 /* Form.serialize ignores unchecked checkboxes */
2020
cd935c42 2021 if (!query.match("&hidden=") &&
5d538f4f
AD
2022 f.hidden.disabled == false) {
2023 query = query + "&hidden=false";
2024 }
2025
cd935c42 2026 if (!query.match("&rtl_content=") &&
5d538f4f
AD
2027 f.rtl_content.disabled == false) {
2028 query = query + "&rtl_content=false";
2029 }
2030
cd935c42 2031 if (!query.match("&private=") &&
5d538f4f
AD
2032 f.private.disabled == false) {
2033 query = query + "&private=false";
2034 }
2035
cd935c42 2036 if (!query.match("&cache_images=") &&
5d538f4f
AD
2037 f.cache_images.disabled == false) {
2038 query = query + "&cache_images=false";
2039 }
2040
cd935c42 2041 if (!query.match("&include_in_digest=") &&
5d538f4f
AD
2042 f.include_in_digest.disabled == false) {
2043 query = query + "&include_in_digest=false";
2044 }
b0f015a2
AD
2045
2046 closeInfoBox();
2047
2048 notify_progress("Saving feeds...");
2049
2050 xmlhttp.open("POST", "backend.php", true);
2051 xmlhttp.onreadystatechange=feedlist_callback;
2052 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
2053 xmlhttp.send(query);
2054 }
758e1c4a
AD
2055
2056 return false;
2057 } catch (e) {
2058 exception_error("feedsEditSave", e);
2059 }
2060}
2061
2062function batchFeedsToggleField(cb, elem, label) {
2063 try {
2064 var f = document.forms["batch_edit_feed_form"];
2065 var l = document.getElementById(label);
2066
2067 if (cb.checked) {
2068 f[elem].disabled = false;
2069
2070 if (l) {
2071 l.className = "";
2072 };
2073
2074// new Effect.Highlight(f[elem], {duration: 1, startcolor: "#fff7d5",
2075// queue: { position:'end', scope: 'BPEFQ', limit: 1 } } );
2076
2077 } else {
2078 f[elem].disabled = true;
2079
2080 if (l) {
2081 l.className = "insensitive";
2082 };
2083
2084 }
2085 } catch (e) {
2086 exception_error("batchFeedsToggleField", e);
2087 }
2088}
2089
b56465dd 2090