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