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