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