]> git.wh0rd.org - tt-rss.git/blame - prefs.js
refresh feeds frame if number of subscriptions failed
[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
1cac3c31
AD
8var piggie_top = -400;
9var piggie_fwd = true;
10
a58069db 11var xmlhttp = Ajax.getTransport();
007bda35 12
a7565293
AD
13var init_params = new Array();
14
c6232e43
AD
15function expand_feed_callback() {
16 if (xmlhttp.readyState == 4) {
17 try {
18 var container = document.getElementById("BRDET-" + feed_to_expand);
19 container.innerHTML=xmlhttp.responseText;
20 container.style.display = "block";
4d4200a8 21// p_notify("");
c6232e43
AD
22 } catch (e) {
23 exception_error("expand_feed_callback", e);
24 }
25 }
26}
27
007bda35 28function feedlist_callback() {
007bda35 29 if (xmlhttp.readyState == 4) {
47c6c988
AD
30 try {
31 var container = document.getElementById('prefContent');
32 container.innerHTML=xmlhttp.responseText;
a7f22b70
AD
33 selectTab("feedConfig", true);
34
3c5783b7
AD
35 if (active_feed_cat) {
36 var row = document.getElementById("FCATR-" + active_feed_cat);
47c6c988
AD
37 if (row) {
38 if (!row.className.match("Selected")) {
39 row.className = row.className + "Selected";
40 }
41 }
3c5783b7 42 var checkbox = document.getElementById("FCCHK-" + active_feed_cat);
47c6c988
AD
43 if (checkbox) {
44 checkbox.checked = true;
45 }
961513a3 46 }
3c5783b7 47
7f74a9da 48 notify("");
47c6c988
AD
49 } catch (e) {
50 exception_error("feedlist_callback", e);
961513a3 51 }
007bda35
AD
52 }
53}
54
a0d53889 55function filterlist_callback() {
f5a50b25 56 var container = document.getElementById('prefContent');
a0d53889
AD
57 if (xmlhttp.readyState == 4) {
58 container.innerHTML=xmlhttp.responseText;
7f74a9da 59 notify("");
a0d53889
AD
60 }
61}
62
48f0adb0 63function labellist_callback() {
f5a50b25 64 var container = document.getElementById('prefContent');
48f0adb0
AD
65 if (xmlhttp.readyState == 4) {
66 container.innerHTML=xmlhttp.responseText;
67
967955b7 68 if (active_label) {
48f0adb0
AD
69 var row = document.getElementById("LILRR-" + active_label);
70 if (row) {
71 if (!row.className.match("Selected")) {
72 row.className = row.className + "Selected";
73 }
74 }
75 var checkbox = document.getElementById("LICHK-" + active_label);
76
77 if (checkbox) {
78 checkbox.checked = true;
79 }
80 }
7f74a9da 81 notify("");
48f0adb0
AD
82 }
83}
4255b24c 84
c6232e43
AD
85function feed_browser_callback() {
86 var container = document.getElementById('prefContent');
87 if (xmlhttp.readyState == 4) {
88 container.innerHTML=xmlhttp.responseText;
7f74a9da 89 notify("");
c6232e43
AD
90 }
91}
92
e6cb77a0
AD
93function userlist_callback() {
94 var container = document.getElementById('prefContent');
95 if (xmlhttp.readyState == 4) {
96 container.innerHTML=xmlhttp.responseText;
7f74a9da 97 notify("");
e6cb77a0
AD
98 }
99}
100
4255b24c
AD
101function prefslist_callback() {
102 var container = document.getElementById('prefContent');
103 if (xmlhttp.readyState == 4) {
104
105 container.innerHTML=xmlhttp.responseText;
7f74a9da
AD
106
107 notify("");
4255b24c
AD
108 }
109}
110
b1895692
AD
111function gethelp_callback() {
112 var container = document.getElementById('prefHelpBox');
113 if (xmlhttp.readyState == 4) {
114
115 container.innerHTML = xmlhttp.responseText;
116 container.style.display = "block";
117
118 }
119}
4255b24c
AD
120
121
0e091d38
AD
122function notify_callback() {
123 var container = document.getElementById('notify');
124 if (xmlhttp.readyState == 4) {
125 container.innerHTML=xmlhttp.responseText;
126 }
127}
128
b83c7545 129function updateFeedList(sort_key) {
007bda35 130
c0e5a40e 131 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
132 printLockingError();
133 return
134 }
135
f5a50b25
AD
136// document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
137
ce3bf408 138// p_notify("Loading, please wait...");
007bda35 139
f932bc9f
AD
140 var feed_search = document.getElementById("feed_search");
141 var search = "";
142 if (feed_search) { search = feed_search.value; }
143
b83c7545 144 xmlhttp.open("GET", "backend.php?op=pref-feeds" +
f932bc9f
AD
145 "&sort=" + param_escape(sort_key) +
146 "&search=" + param_escape(search), true);
007bda35
AD
147 xmlhttp.onreadystatechange=feedlist_callback;
148 xmlhttp.send(null);
149
150}
151
e6cb77a0
AD
152function updateUsersList() {
153
154 if (!xmlhttp_ready(xmlhttp)) {
155 printLockingError();
156 return
157 }
158
159// document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
160
ce3bf408 161// p_notify("Loading, please wait...");
e6cb77a0
AD
162
163 xmlhttp.open("GET", "backend.php?op=pref-users", true);
164 xmlhttp.onreadystatechange=userlist_callback;
165 xmlhttp.send(null);
166
167}
168
48f0adb0
AD
169function addLabel() {
170
171 if (!xmlhttp_ready(xmlhttp)) {
172 printLockingError();
173 return
174 }
175
176 var sqlexp = document.getElementById("ladd_expr");
177
178 if (sqlexp.value.length == 0) {
01b3e191 179 alert("Can't add label: missing SQL expression.");
48f0adb0
AD
180 } else {
181 notify("Adding label...");
182
183 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=add&exp=" +
184 param_escape(sqlexp.value), true);
185
186 xmlhttp.onreadystatechange=labellist_callback;
187 xmlhttp.send(null);
188
189 sqlexp.value = "";
190 }
191
192}
193
de435974
AD
194function addFilter() {
195
196 if (!xmlhttp_ready(xmlhttp)) {
197 printLockingError();
198 return
199 }
200
201 var regexp = document.getElementById("fadd_regexp");
202 var match = document.getElementById("fadd_match");
ead60402 203 var feed = document.getElementById("fadd_feed");
19c9cb11 204 var action = document.getElementById("fadd_action");
de435974
AD
205
206 if (regexp.value.length == 0) {
01b3e191 207 alert("Can't add filter: missing filter expression.");
de435974
AD
208 } else {
209 notify("Adding filter...");
210
25cb5736 211 var v_match = match[match.selectedIndex].text;
ead60402 212 var feed_id = feed[feed.selectedIndex].id;
19c9cb11 213 var action_id = action[action.selectedIndex].id;
ead60402 214
de435974 215 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=add&regexp=" +
ead60402 216 param_escape(regexp.value) + "&match=" + v_match +
19c9cb11 217 "&fid=" + param_escape(feed_id) + "&aid=" + param_escape(action_id), true);
de435974
AD
218
219 xmlhttp.onreadystatechange=filterlist_callback;
220 xmlhttp.send(null);
221
222 regexp.value = "";
223 }
224
225}
48f0adb0 226
71ad3959
AD
227function addFeed() {
228
c0e5a40e 229 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
230 printLockingError();
231 return
232 }
233
331900c6
AD
234 var link = document.getElementById("fadd_link");
235
83fe4d6d 236 if (link.value.length == 0) {
0ceded7a 237 alert("Error: No feed URL given.");
605f7d46 238 } else if (!isValidURL(link.value)) {
2371c520 239 alert("Error: Invalid feed URL.");
331900c6
AD
240 } else {
241 notify("Adding feed...");
242
07eb9178 243 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&feed_url=" +
331900c6
AD
244 param_escape(link.value), true);
245 xmlhttp.onreadystatechange=feedlist_callback;
246 xmlhttp.send(null);
247
248 link.value = "";
249
250 }
251
252}
253
91ff844a
AD
254function addFeedCat() {
255
256 if (!xmlhttp_ready(xmlhttp)) {
257 printLockingError();
258 return
259 }
260
261 var cat = document.getElementById("fadd_cat");
262
263 if (cat.value.length == 0) {
01b3e191 264 alert("Can't add category: no name specified.");
91ff844a
AD
265 } else {
266 notify("Adding feed category...");
267
268 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=addCat&cat=" +
269 param_escape(cat.value), true);
270 xmlhttp.onreadystatechange=feedlist_callback;
271 xmlhttp.send(null);
272
273 link.value = "";
274
275 }
276
277}
e6cb77a0
AD
278function addUser() {
279
280 if (!xmlhttp_ready(xmlhttp)) {
281 printLockingError();
282 return
283 }
284
285 var sqlexp = document.getElementById("uadd_box");
286
287 if (sqlexp.value.length == 0) {
01b3e191 288 alert("Can't add user: no login specified.");
e6cb77a0
AD
289 } else {
290 notify("Adding user...");
291
292 xmlhttp.open("GET", "backend.php?op=pref-users&subop=add&login=" +
293 param_escape(sqlexp.value), true);
294
295 xmlhttp.onreadystatechange=userlist_callback;
296 xmlhttp.send(null);
297
298 sqlexp.value = "";
299 }
300
301}
302
48f0adb0
AD
303function editLabel(id) {
304
305 if (!xmlhttp_ready(xmlhttp)) {
306 printLockingError();
307 return
308 }
309
310 active_label = id;
311
312 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=edit&id=" +
313 param_escape(id), true);
314 xmlhttp.onreadystatechange=labellist_callback;
315 xmlhttp.send(null);
316
317}
318
e6cb77a0
AD
319function editUser(id) {
320
321 if (!xmlhttp_ready(xmlhttp)) {
322 printLockingError();
323 return
324 }
325
3c5783b7
AD
326 selectTableRowsByIdPrefix('prefUserList', 'UMRR-', 'UMCHK-', false);
327 selectTableRowById('UMRR-'+id, 'UMCHK-'+id, true);
e6cb77a0
AD
328
329 xmlhttp.open("GET", "backend.php?op=pref-users&subop=edit&id=" +
330 param_escape(id), true);
3c5783b7 331 xmlhttp.onreadystatechange=infobox_callback;
e6cb77a0
AD
332 xmlhttp.send(null);
333
334}
335
a0d53889
AD
336function editFilter(id) {
337
338 if (!xmlhttp_ready(xmlhttp)) {
339 printLockingError();
340 return
341 }
342
4220b0bd
AD
343 document.getElementById("create_filter_btn").disabled = true;
344
07164479
AD
345 selectTableRowsByIdPrefix('prefFilterList', 'FILRR-', 'FICHK-', false);
346 selectTableRowById('FILRR-'+id, 'FICHK-'+id, true);
a0d53889 347
07164479
AD
348 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=edit&id=" + param_escape(id), true);
349 xmlhttp.onreadystatechange=infobox_callback;
a0d53889 350 xmlhttp.send(null);
a0d53889
AD
351}
352
331900c6
AD
353function editFeed(feed) {
354
508a81e1
AD
355// notify("Editing feed...");
356
c0e5a40e 357 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
358 printLockingError();
359 return
360 }
331900c6 361
673d54ca 362 // clean selection from all rows & select row being edited
0ea4fb50 363 selectTableRowsByIdPrefix('prefFeedList', 'FEEDR-', 'FRCHK-', false);
6c12c809 364 selectTableRowById('FEEDR-'+feed, 'FRCHK-'+feed, true);
0ea4fb50
AD
365
366 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
3c5783b7 367 param_escape(feed), true);
0ea4fb50
AD
368
369 xmlhttp.onreadystatechange=infobox_callback;
331900c6
AD
370 xmlhttp.send(null);
371
372}
373
91ff844a 374function editFeedCat(cat) {
48f0adb0 375
91ff844a
AD
376 if (!xmlhttp_ready(xmlhttp)) {
377 printLockingError();
378 return
48f0adb0
AD
379 }
380
91ff844a 381 active_feed_cat = cat;
e6cb77a0 382
91ff844a
AD
383 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCat&id=" +
384 param_escape(cat), true);
385 xmlhttp.onreadystatechange=feedlist_callback;
386 xmlhttp.send(null);
e6cb77a0 387
e6cb77a0
AD
388}
389
91ff844a
AD
390function getSelectedLabels() {
391 return getSelectedTableRowIds("prefLabelList", "LILRR");
392}
48f0adb0 393
91ff844a
AD
394function getSelectedUsers() {
395 return getSelectedTableRowIds("prefUserList", "UMRR");
a0d53889
AD
396}
397
83fe4d6d 398function getSelectedFeeds() {
91ff844a
AD
399 return getSelectedTableRowIds("prefFeedList", "FEEDR");
400}
331900c6 401
91ff844a
AD
402function getSelectedFilters() {
403 return getSelectedTableRowIds("prefFilterList", "FILRR");
404}
331900c6 405
91ff844a
AD
406function getSelectedFeedCats() {
407 return getSelectedTableRowIds("prefFeedCatList", "FCATR");
83fe4d6d
AD
408}
409
c0ae0fdb
AD
410function getSelectedFeedsFromBrowser() {
411
412 var list = document.getElementById("browseFeedList");
413 if (!list) list = document.getElementById("browseBigFeedList");
414
415 var selected = new Array();
416
417 for (i = 0; i < list.childNodes.length; i++) {
418 var child = list.childNodes[i];
419 if (child.id && child.id.match("FBROW-")) {
420 var id = child.id.replace("FBROW-", "");
421
422 var cb = document.getElementById("FBCHK-" + id);
423
424 if (cb.checked) {
425 selected.push(id);
426 }
427 }
428 }
429
430 return selected;
431}
432
48f0adb0
AD
433function removeSelectedLabels() {
434
435 if (!xmlhttp_ready(xmlhttp)) {
436 printLockingError();
437 return
438 }
439
440 var sel_rows = getSelectedLabels();
441
442 if (sel_rows.length > 0) {
443
69668465 444 var ok = confirm("Remove selected labels?");
48f0adb0 445
69668465
AD
446 if (ok) {
447 notify("Removing selected labels...");
448
449 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
450 param_escape(sel_rows.toString()), true);
451 xmlhttp.onreadystatechange=labellist_callback;
452 xmlhttp.send(null);
453 }
48f0adb0 454 } else {
01b3e191 455 alert("No labels are selected.");
48f0adb0 456 }
90ac84df
AD
457
458 return false;
48f0adb0
AD
459}
460
e6cb77a0
AD
461function removeSelectedUsers() {
462
463 if (!xmlhttp_ready(xmlhttp)) {
464 printLockingError();
465 return
466 }
467
468 var sel_rows = getSelectedUsers();
469
470 if (sel_rows.length > 0) {
471
69668465 472 var ok = confirm("Remove selected users?");
e6cb77a0 473
69668465
AD
474 if (ok) {
475 notify("Removing selected users...");
476
477 xmlhttp.open("GET", "backend.php?op=pref-users&subop=remove&ids="+
478 param_escape(sel_rows.toString()), true);
479 xmlhttp.onreadystatechange=userlist_callback;
480 xmlhttp.send(null);
481 }
e6cb77a0
AD
482
483 } else {
01b3e191 484 alert("No users are selected.");
e6cb77a0 485 }
90ac84df
AD
486
487 return false;
e6cb77a0
AD
488}
489
48f0adb0
AD
490function removeSelectedFilters() {
491
492 if (!xmlhttp_ready(xmlhttp)) {
493 printLockingError();
494 return
495 }
496
497 var sel_rows = getSelectedFilters();
498
499 if (sel_rows.length > 0) {
500
69668465 501 var ok = confirm("Remove selected filters?");
48f0adb0 502
69668465
AD
503 if (ok) {
504 notify("Removing selected filters...");
505
506 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
507 param_escape(sel_rows.toString()), true);
508 xmlhttp.onreadystatechange=filterlist_callback;
509 xmlhttp.send(null);
510 }
48f0adb0 511 } else {
01b3e191 512 alert("No filters are selected.");
48f0adb0 513 }
90ac84df
AD
514
515 return false;
48f0adb0
AD
516}
517
518
83fe4d6d
AD
519function removeSelectedFeeds() {
520
c0e5a40e 521 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
522 printLockingError();
523 return
524 }
525
83fe4d6d
AD
526 var sel_rows = getSelectedFeeds();
527
331900c6
AD
528 if (sel_rows.length > 0) {
529
1d7bf5a0 530 var ok = confirm("Unsubscribe from selected feeds?");
331900c6 531
69668465
AD
532 if (ok) {
533
1d7bf5a0 534 notify("Unsubscribing from selected feeds...");
69668465
AD
535
536 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
537 param_escape(sel_rows.toString()), true);
538 xmlhttp.onreadystatechange=feedlist_callback;
539 xmlhttp.send(null);
540 }
71ad3959 541
71ad3959 542 } else {
331900c6 543
01b3e191 544 alert("No feeds are selected.");
331900c6 545
71ad3959 546 }
90ac84df
AD
547
548 return false;
71ad3959 549}
007bda35 550
91ff844a
AD
551function removeSelectedFeedCats() {
552
553 if (!xmlhttp_ready(xmlhttp)) {
554 printLockingError();
555 return
556 }
557
558 var sel_rows = getSelectedFeedCats();
559
560 if (sel_rows.length > 0) {
561
69668465 562 var ok = confirm("Remove selected categories?");
91ff844a 563
69668465
AD
564 if (ok) {
565 notify("Removing selected categories...");
566
567 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=removeCats&ids="+
568 param_escape(sel_rows.toString()), true);
569 xmlhttp.onreadystatechange=feedlist_callback;
570 xmlhttp.send(null);
571 }
91ff844a
AD
572
573 } else {
574
01b3e191 575 alert("No categories are selected.");
91ff844a
AD
576
577 }
578
90ac84df 579 return false;
91ff844a
AD
580}
581
508a81e1
AD
582function feedEditCancel() {
583
c0e5a40e 584 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
585 printLockingError();
586 return
587 }
588
327a3bbe
AD
589 closeInfoBox();
590
673d54ca 591 selectPrefRows('feed', false); // cleanup feed selection
508a81e1 592
90ac84df 593 return false;
508a81e1
AD
594}
595
91ff844a
AD
596function feedCatEditCancel() {
597
598 if (!xmlhttp_ready(xmlhttp)) {
599 printLockingError();
600 return
601 }
602
603 active_feed_cat = false;
604
0ceded7a 605// notify("Operation cancelled.");
91ff844a
AD
606
607 xmlhttp.open("GET", "backend.php?op=pref-feeds", true);
608 xmlhttp.onreadystatechange=feedlist_callback;
609 xmlhttp.send(null);
610
90ac84df 611 return false;
91ff844a
AD
612}
613
603c27f8
AD
614function feedEditSave() {
615
47c6c988 616 try {
47c6c988
AD
617
618 if (!xmlhttp_ready(xmlhttp)) {
619 printLockingError();
620 return
621 }
ad815c71 622
14f69488 623 // FIXME: add parameter validation
e3c99f3b 624
14f69488 625 var query = Form.serialize("edit_feed_form");
b0da3a7b 626
14f69488 627 notify("Saving feed...");
673d54ca 628
47c6c988
AD
629 xmlhttp.open("POST", "backend.php", true);
630 xmlhttp.onreadystatechange=feedlist_callback;
631 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
14f69488
AD
632 xmlhttp.send(query);
633
59a543f0
AD
634 closeInfoBox();
635
c14b5566
AD
636 return false;
637
47c6c988
AD
638 } catch (e) {
639 exception_error("feedEditSave", e);
b0da3a7b 640 }
508a81e1
AD
641}
642
5ddadb4c
AD
643function feedCatEditSave() {
644
645 if (!xmlhttp_ready(xmlhttp)) {
646 printLockingError();
647 return
648 }
649
f0e81ffe 650 notify("Saving category...");
5ddadb4c 651
0666e120
AD
652 var query = Form.serialize("feed_cat_edit_form");
653
654 xmlhttp.open("GET", "backend.php?" + query, true);
5ddadb4c
AD
655 xmlhttp.onreadystatechange=feedlist_callback;
656 xmlhttp.send(null);
657
658 active_feed_cat = false;
659
90ac84df 660 return false;
5ddadb4c
AD
661}
662
663
d9dde1d6
AD
664function labelTest() {
665
f3120e5a
AD
666 var form = document.forms['label_edit_form'];
667
668 var sql_exp = form.sql_exp.value;
669 var description = form.description.value;
d9dde1d6
AD
670
671 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=test&expr=" +
f3120e5a 672 param_escape(sql_exp) + "&descr=" + param_escape(description), true);
d9dde1d6
AD
673
674 xmlhttp.onreadystatechange=infobox_callback;
675 xmlhttp.send(null);
676
90ac84df 677 return false;
d9dde1d6
AD
678}
679
01c9c74a
AD
680function displayHelpInfobox(topic_id) {
681
682 xmlhttp.open("GET", "backend.php?op=help&tid=" +
683 param_escape(topic_id) + "&noheaders=1", true);
684
685 xmlhttp.onreadystatechange=infobox_callback;
686 xmlhttp.send(null);
687
688}
689
48f0adb0
AD
690function labelEditCancel() {
691
692 if (!xmlhttp_ready(xmlhttp)) {
693 printLockingError();
694 return
695 }
696
697 active_label = false;
698
0ceded7a 699// notify("Operation cancelled.");
48f0adb0 700
50bad812
AD
701 closeInfoBox();
702
48f0adb0
AD
703 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
704 xmlhttp.onreadystatechange=labellist_callback;
705 xmlhttp.send(null);
706
90ac84df 707 return false;
48f0adb0
AD
708}
709
e6cb77a0
AD
710function userEditCancel() {
711
712 if (!xmlhttp_ready(xmlhttp)) {
713 printLockingError();
714 return
715 }
716
3c5783b7 717 selectPrefRows('user', false); // cleanup feed selection
3c5783b7 718 closeInfoBox();
90ac84df
AD
719
720 return false;
e6cb77a0 721}
48f0adb0 722
a0d53889
AD
723function filterEditCancel() {
724
725 if (!xmlhttp_ready(xmlhttp)) {
726 printLockingError();
727 return
728 }
4220b0bd
AD
729
730 document.getElementById("create_filter_btn").disabled = false;
07164479
AD
731
732 selectPrefRows('filter', false); // cleanup feed selection
733 closeInfoBox();
90ac84df
AD
734
735 return false;
a0d53889
AD
736}
737
48f0adb0
AD
738function labelEditSave() {
739
740 var label = active_label;
741
742 if (!xmlhttp_ready(xmlhttp)) {
743 printLockingError();
744 return
745 }
746
3c5783b7
AD
747 var sql_exp = document.forms["label_edit_form"].sql_exp.value;
748 var description = document.forms["label_edit_form"].description.value;
48f0adb0 749
3c5783b7
AD
750 if (sql_exp.length == 0) {
751 alert("SQL Expression cannot be blank.");
48f0adb0
AD
752 return;
753 }
754
3c5783b7
AD
755 if (description.length == 0) {
756 alert("Caption field cannot be blank.");
48f0adb0 757 return;
3c5783b7 758 }
48f0adb0 759
50bad812
AD
760 closeInfoBox();
761
f0e81ffe 762 notify("Saving label...");
dbd9e2f1 763
48f0adb0
AD
764 active_label = false;
765
f3120e5a
AD
766 query = Form.serialize("label_edit_form");
767
50bad812 768 xmlhttp.open("GET", "backend.php?" + query, true);
48f0adb0
AD
769 xmlhttp.onreadystatechange=labellist_callback;
770 xmlhttp.send(null);
771
90ac84df 772 return false;
48f0adb0
AD
773}
774
e6cb77a0
AD
775function userEditSave() {
776
e6cb77a0
AD
777 if (!xmlhttp_ready(xmlhttp)) {
778 printLockingError();
779 return
780 }
781
3c5783b7 782 var login = document.forms["user_edit_form"].login.value;
e6cb77a0
AD
783
784 if (login.length == 0) {
3c5783b7 785 alert("Login field cannot be blank.");
e6cb77a0
AD
786 return;
787 }
3c5783b7 788
f0e81ffe 789 notify("Saving user...");
4220b0bd
AD
790
791 closeInfoBox();
792
3c5783b7
AD
793 var query = Form.serialize("user_edit_form");
794
795 xmlhttp.open("GET", "backend.php?" + query, true);
dbd9e2f1 796 xmlhttp.onreadystatechange=userlist_callback;
e6cb77a0 797 xmlhttp.send(null);
90ac84df
AD
798
799 return false;
e6cb77a0
AD
800}
801
802
a0d53889
AD
803function filterEditSave() {
804
a0d53889
AD
805 if (!xmlhttp_ready(xmlhttp)) {
806 printLockingError();
807 return
808 }
809
3c5783b7
AD
810 var reg_exp = document.forms["filter_edit_form"].reg_exp.value;
811
812 if (reg_exp.length == 0) {
813 alert("Filter expression field cannot be blank.");
814 return;
815 }
a0d53889 816
7e939457 817 notify("Saving filter...");
a0d53889 818
7e939457 819 var query = Form.serialize("filter_edit_form");
dbd9e2f1 820
07164479
AD
821 closeInfoBox();
822
4220b0bd
AD
823 document.getElementById("create_filter_btn").disabled = false;
824
7e939457 825 xmlhttp.open("GET", "backend.php?" + query, true);
a0d53889 826 xmlhttp.onreadystatechange=filterlist_callback;
7e939457 827 xmlhttp.send(null);
a0d53889 828
90ac84df 829 return false;
a0d53889
AD
830}
831
48f0adb0
AD
832function editSelectedLabel() {
833 var rows = getSelectedLabels();
a0d53889 834
48f0adb0 835 if (rows.length == 0) {
01b3e191 836 alert("No labels are selected.");
48f0adb0 837 return;
a0d53889
AD
838 }
839
48f0adb0 840 if (rows.length > 1) {
01b3e191 841 alert("Please select only one label.");
48f0adb0
AD
842 return;
843 }
a0d53889 844
dbd9e2f1
AD
845 notify("");
846
48f0adb0 847 editLabel(rows[0]);
a0d53889 848
a0d53889
AD
849}
850
e6cb77a0
AD
851function editSelectedUser() {
852 var rows = getSelectedUsers();
853
854 if (rows.length == 0) {
01b3e191 855 alert("No users are selected.");
e6cb77a0
AD
856 return;
857 }
858
859 if (rows.length > 1) {
01b3e191 860 alert("Please select only one user.");
e6cb77a0
AD
861 return;
862 }
863
dbd9e2f1
AD
864 notify("");
865
e6cb77a0
AD
866 editUser(rows[0]);
867}
868
869function resetSelectedUserPass() {
870 var rows = getSelectedUsers();
871
872 if (rows.length == 0) {
01b3e191 873 alert("No users are selected.");
e6cb77a0
AD
874 return;
875 }
876
877 if (rows.length > 1) {
01b3e191 878 alert("Please select only one user.");
e6cb77a0
AD
879 return;
880 }
881
69668465 882 var ok = confirm("Reset password of selected user?");
e6cb77a0 883
69668465
AD
884 if (ok) {
885 notify("Resetting password for selected user...");
886
887 var id = rows[0];
888
889 xmlhttp.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
890 param_escape(id), true);
891 xmlhttp.onreadystatechange=userlist_callback;
892 xmlhttp.send(null);
893 }
e6cb77a0
AD
894}
895
717f5e64 896function selectedUserDetails() {
e6cb77a0 897
1a7572cb
AD
898 if (!xmlhttp_ready(xmlhttp)) {
899 printLockingError();
900 return
901 }
902
717f5e64
AD
903 var rows = getSelectedUsers();
904
905 if (rows.length == 0) {
01b3e191 906 alert("No users are selected.");
717f5e64
AD
907 return;
908 }
909
910 if (rows.length > 1) {
01b3e191 911 alert("Please select only one user.");
717f5e64
AD
912 return;
913 }
914
915 var id = rows[0];
916
dbd9e2f1
AD
917 notify("");
918
1a7572cb 919 xmlhttp.open("GET", "backend.php?op=user-details&id=" + id, true);
c6c3a07f
AD
920 xmlhttp.onreadystatechange=infobox_callback;
921 xmlhttp.send(null);
922
923}
924
925function selectedFeedDetails() {
926
927 if (!xmlhttp_ready(xmlhttp)) {
928 printLockingError();
929 return
930 }
931
932 var rows = getSelectedFeeds();
933
934 if (rows.length == 0) {
01b3e191 935 alert("No feeds are selected.");
c6c3a07f
AD
936 return;
937 }
938
01b3e191
AD
939 if (rows.length > 1) {
940 notify("Please select only one feed.");
941 return;
942 }
c6c3a07f 943
df268d47 944// var id = rows[0];
c6c3a07f 945
dbd9e2f1
AD
946 notify("");
947
df268d47
AD
948 xmlhttp.open("GET", "backend.php?op=feed-details&id=" +
949 param_escape(rows.toString()), true);
c6c3a07f 950 xmlhttp.onreadystatechange=infobox_callback;
1a7572cb 951 xmlhttp.send(null);
717f5e64
AD
952
953}
a0d53889
AD
954
955function editSelectedFilter() {
956 var rows = getSelectedFilters();
957
958 if (rows.length == 0) {
01b3e191 959 alert("No filters are selected.");
a0d53889
AD
960 return;
961 }
962
963 if (rows.length > 1) {
01b3e191 964 alert("Please select only one filter.");
a0d53889
AD
965 return;
966 }
967
dbd9e2f1
AD
968 notify("");
969
a0d53889
AD
970 editFilter(rows[0]);
971
972}
973
974
508a81e1
AD
975function editSelectedFeed() {
976 var rows = getSelectedFeeds();
977
978 if (rows.length == 0) {
979 notify("No feeds are selected.");
980 return;
981 }
982
983 if (rows.length > 1) {
984 notify("Please select one feed.");
985 return;
986 }
987
dbd9e2f1
AD
988 notify("");
989
508a81e1 990 editFeed(rows[0]);
91ff844a
AD
991
992}
993
994function editSelectedFeedCat() {
995 var rows = getSelectedFeedCats();
996
997 if (rows.length == 0) {
01b3e191 998 alert("No categories are selected.");
91ff844a
AD
999 return;
1000 }
1001
1002 if (rows.length > 1) {
01b3e191 1003 alert("Please select only one category.");
91ff844a
AD
1004 return;
1005 }
1006
1007 notify("");
1008
1009 editFeedCat(rows[0]);
508a81e1
AD
1010
1011}
1012
1cac3c31
AD
1013function piggie_callback() {
1014 var piggie = document.getElementById("piggie");
1015
1016 piggie.style.top = piggie_top;
e0b6a737
AD
1017 piggie.style.backgroundColor = "white";
1018 piggie.style.borderWidth = "1px";
1cac3c31
AD
1019
1020 if (piggie_fwd && piggie_top < 0) {
1021 setTimeout("piggie_callback()", 50);
1022 piggie_top = piggie_top + 10;
1023 } else if (piggie_fwd && piggie_top >= 0) {
1024 piggie_fwd = false;
1025 setTimeout("piggie_callback()", 50);
1026 } else if (!piggie_fwd && piggie_top > -400) {
1027 setTimeout("piggie_callback()", 50);
1028 piggie_top = piggie_top - 10;
1029 } else if (!piggie_fwd && piggie_top <= -400) {
1030 piggie.style.display = "none";
1031 piggie_fwd = true;
1032 }
1033}
1034
33377ef3
AD
1035var piggie_opacity = 0;
1036
1037function piggie2_callback() {
1038 var piggie = document.getElementById("piggie");
1039 piggie.style.top = 0;
1040 piggie.style.opacity = piggie_opacity;
e0b6a737
AD
1041 piggie.style.backgroundColor = "transparent";
1042 piggie.style.borderWidth = "0px";
33377ef3
AD
1043
1044 if (piggie_fwd && piggie_opacity < 1) {
1045 setTimeout("piggie2_callback()", 50);
1046 piggie_opacity = piggie_opacity + 0.03;
1047 } else if (piggie_fwd && piggie_opacity >= 1) {
1048 piggie_fwd = false;
1049 setTimeout("piggie2_callback()", 50);
1050 } else if (!piggie_fwd && piggie_opacity > 0) {
1051 setTimeout("piggie2_callback()", 50);
1052 piggie_opacity = piggie_opacity - 0.03;
1053 } else if (!piggie_fwd && piggie_opacity <= 0) {
1054 piggie.style.display = "none";
1055 piggie_fwd = true;
1056 }
1057}
1058
13ad9102
AD
1059function localPiggieFunction(enable) {
1060 if (enable) {
1cac3c31 1061 var piggie = document.getElementById("piggie");
508a81e1 1062 piggie.style.display = "block";
33377ef3 1063
292a8a12 1064 if (navigator.userAgent.match("Gecko") && Math.random(1) > 0.5) {
33377ef3
AD
1065 piggie2_callback();
1066 } else {
1067 piggie_callback();
1068 }
508a81e1 1069 }
508a81e1
AD
1070}
1071
9f311df6
AD
1072function validateOpmlImport() {
1073
1074 var opml_file = document.getElementById("opml_file");
1075
1076 if (opml_file.value.length == 0) {
01b3e191 1077 alert("No OPML file to upload.");
9f311df6
AD
1078 return false;
1079 } else {
1080 return true;
1081 }
1082}
1083
a0d53889
AD
1084function updateFilterList() {
1085
1086 if (!xmlhttp_ready(xmlhttp)) {
1087 printLockingError();
1088 return
1089 }
1090
f5a50b25
AD
1091// document.getElementById("prefContent").innerHTML = "Loading filters, please wait...";
1092
ce3bf408 1093// p_notify("Loading, please wait...");
a0d53889
AD
1094
1095 xmlhttp.open("GET", "backend.php?op=pref-filters", true);
1096 xmlhttp.onreadystatechange=filterlist_callback;
1097 xmlhttp.send(null);
1098
1099}
1100
48f0adb0
AD
1101function updateLabelList() {
1102
1103 if (!xmlhttp_ready(xmlhttp)) {
1104 printLockingError();
1105 return
1106 }
1107
ce3bf408 1108// p_notify("Loading, please wait...");
f5a50b25
AD
1109
1110// document.getElementById("prefContent").innerHTML = "Loading labels, please wait...";
48f0adb0
AD
1111
1112 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
1113 xmlhttp.onreadystatechange=labellist_callback;
1114 xmlhttp.send(null);
48f0adb0
AD
1115}
1116
4255b24c
AD
1117function updatePrefsList() {
1118
1119 if (!xmlhttp_ready(xmlhttp)) {
1120 printLockingError();
1121 return
1122 }
1123
ce3bf408 1124// p_notify("Loading, please wait...");
4255b24c
AD
1125
1126 xmlhttp.open("GET", "backend.php?op=pref-prefs", true);
1127 xmlhttp.onreadystatechange=prefslist_callback;
1128 xmlhttp.send(null);
1129
1130}
1131
a7f22b70
AD
1132function selectTab(id, noupdate) {
1133
1134// alert(id);
48f0adb0 1135
b2caf812 1136 if (!id) id = active_tab;
7f74a9da 1137
b2caf812 1138 try {
59a543f0 1139
b2caf812
AD
1140 if (!xmlhttp_ready(xmlhttp)) {
1141 printLockingError();
1142 return
a7f22b70 1143 }
f5a50b25 1144
b2caf812 1145 if (!noupdate) {
f5a50b25 1146
b2caf812
AD
1147 debug("selectTab: " + id + "(NU: " + noupdate + ")");
1148
1149 notify("Loading, please wait...", true);
1150
1151 // close active infobox if needed
1152 closeInfoBox();
1153
1154 // clean up all current selections, just in case
1155 active_feed_cat = false;
1156 active_label = false;
1157
1158 if (id == "feedConfig") {
1159 updateFeedList();
1160 } else if (id == "filterConfig") {
1161 updateFilterList();
1162 } else if (id == "labelConfig") {
1163 updateLabelList();
1164 } else if (id == "genConfig") {
1165 updatePrefsList();
1166 } else if (id == "userConfig") {
1167 updateUsersList();
1168 } else if (id == "feedBrowser") {
1169 updateBigFeedBrowser();
1170 }
f5a50b25 1171 }
b2caf812
AD
1172
1173 var tab = document.getElementById(active_tab + "Tab");
1174
1175 if (tab) {
1176 if (tab.className.match("Selected")) {
1177 tab.className = "prefsTab";
1178 }
f5a50b25 1179 }
b2caf812
AD
1180
1181 tab = document.getElementById(id + "Tab");
1182
1183 if (tab) {
1184 if (!tab.className.match("Selected")) {
1185 tab.className = tab.className + "Selected";
1186 }
1187 }
1188
1189 if (active_tab != id) {
1190 storeInitParam("prefs_active_tab", id);
1191 }
1192
1193 active_tab = id;
f5a50b25 1194
b2caf812
AD
1195 } catch (e) {
1196 exception_error("selectTab", e);
a7565293 1197 }
a7565293
AD
1198}
1199
1200function backend_sanity_check_callback() {
f5a50b25 1201
a7565293
AD
1202 if (xmlhttp.readyState == 4) {
1203
1204 try {
1205
1206 if (!xmlhttp.responseXML) {
1207 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp.responseText);
1208 return;
1209 }
1210
1211 var reply = xmlhttp.responseXML.firstChild.firstChild;
1212
1213 if (!reply) {
1214 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp.responseText);
1215 return;
1216 }
1217
1218 var error_code = reply.getAttribute("error-code");
1219
1220 if (error_code && error_code != 0) {
1221 return fatalError(error_code, reply.getAttribute("error-msg"));
1222 }
1223
1224 debug("sanity check ok");
1225
1226 var params = reply.nextSibling;
1227
1228 if (params) {
1229 debug('reading init-params...');
1230 var param = params.firstChild;
1231
1232 while (param) {
1233 var k = param.getAttribute("key");
1234 var v = param.getAttribute("value");
1235 debug(k + " => " + v);
1236 init_params[k] = v;
1237 param = param.nextSibling;
1238 }
1239 }
1240
1241 init_second_stage();
1242
1243 } catch (e) {
1244 exception_error("backend_sanity_check_callback", e);
1245 }
1246 }
1247}
1248
1249function init_second_stage() {
1250
b2caf812
AD
1251 try {
1252 active_tab = getInitParam("prefs_active_tab");
1253 if (!active_tab) active_tab = "genConfig";
4da47970 1254
b2caf812
AD
1255 if (navigator.userAgent.match("Opera")) {
1256 setTimeout("selectTab()", 500);
1257 } else {
1258 selectTab(active_tab);
1259 }
1260 notify("");
1261 } catch (e) {
1262 exception_error("init_second_stage", e);
1263 }
a0d53889
AD
1264}
1265
007bda35 1266function init() {
e2ec66a8 1267
7719618b
AD
1268 try {
1269
97dcd654
AD
1270 if (arguments.callee.done) return;
1271 arguments.callee.done = true;
1272
a7565293
AD
1273 if (getURLParam('debug')) {
1274 document.getElementById('debug_output').style.display = 'block';
1275 debug('debug mode activated');
1276 }
1277
7719618b
AD
1278 // IE kludge
1279 if (!xmlhttp) {
1280 document.getElementById("prefContent").innerHTML =
1281 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1282 "to function properly. Your browser doesn't seem to support it.";
1283 return;
1284 }
4da47970 1285
a7565293
AD
1286 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
1287 xmlhttp.onreadystatechange=backend_sanity_check_callback;
1288 xmlhttp.send(null);
1289
7719618b
AD
1290 } catch (e) {
1291 exception_error("init", e);
e2ec66a8 1292 }
007bda35 1293}
b1895692 1294
f932bc9f
AD
1295function categorizeSelectedFeeds() {
1296
1297 if (!xmlhttp_ready(xmlhttp)) {
1298 printLockingError();
1299 return
1300 }
1301
1302 var sel_rows = getSelectedFeeds();
1303
1304 var cat_sel = document.getElementById("sfeed_set_fcat");
79f3553b 1305 var cat_id = cat_sel[cat_sel.selectedIndex].value;
f932bc9f
AD
1306
1307 if (sel_rows.length > 0) {
1308
1309 notify("Changing category of selected feeds...");
1310
1311 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
1312 param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
1313 xmlhttp.onreadystatechange=feedlist_callback;
1314 xmlhttp.send(null);
1315
1316 } else {
1317
01b3e191 1318 alert("No feeds are selected.");
f932bc9f
AD
1319
1320 }
1321
1322}
69668465
AD
1323
1324function validatePrefsReset() {
1325 return confirm("Reset to defaults?");
1326}
f9cb39ac 1327
6311acbe 1328function browseFeeds(limit) {
f9cb39ac
AD
1329
1330 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=browse", true);
1331 xmlhttp.onreadystatechange=infobox_callback;
1332 xmlhttp.send(null);
1333
1334}
a0476535
AD
1335
1336function feedBrowserSubscribe() {
1337 try {
a0476535 1338
c0ae0fdb 1339 var selected = getSelectedFeedsFromBrowser();
a0476535
AD
1340
1341 if (selected.length > 0) {
1342 closeInfoBox();
1343 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=massSubscribe&ids="+
1344 param_escape(selected.toString()), true);
1345 xmlhttp.onreadystatechange=feedlist_callback;
1346 xmlhttp.send(null);
1347 } else {
1348 alert("No feeds are selected.");
1349 }
1350
1351 } catch (e) {
1352 exception_error("feedBrowserSubscribe", e);
1353 }
1354}
c6232e43 1355
6311acbe 1356function updateBigFeedBrowser(limit) {
c6232e43
AD
1357
1358 if (!xmlhttp_ready(xmlhttp)) {
1359 printLockingError();
1360 return
1361 }
1362
ce3bf408 1363// p_notify("Loading, please wait...");
c6232e43 1364
6311acbe
AD
1365 var query = "backend.php?op=pref-feed-browser";
1366
1367 var limit_sel = document.getElementById("feedBrowserLimit");
1368
1369 if (limit_sel) {
1370 var limit = limit_sel[limit_sel.selectedIndex].value;
1371 query = query + "&limit=" + param_escape(limit);
1372 }
1373
1374 xmlhttp.open("GET", query, true);
c6232e43
AD
1375 xmlhttp.onreadystatechange=feed_browser_callback;
1376 xmlhttp.send(null);
c6232e43
AD
1377}
1378
c2b2aee0 1379function browserToggleExpand(id) {
c6232e43
AD
1380 try {
1381/* if (feed_to_expand && feed_to_expand != id) {
1382 var d = document.getElementById("BRDET-" + feed_to_expand);
1383 d.style.display = "none";
1384 } */
c2b2aee0 1385
ff725e9b
AD
1386 if (!xmlhttp_ready(xmlhttp)) {
1387 printLockingError();
1388 return
1389 }
1390
c2b2aee0
AD
1391 var d = document.getElementById("BRDET-" + id);
1392
1393 if (d.style.display == "block") {
1394 d.style.display = "none";
1395
1396 } else {
c6232e43 1397
c2b2aee0 1398 feed_to_expand = id;
c6232e43 1399
ff725e9b
AD
1400 d.style.display = "block";
1401 d.innerHTML = "Loading, please wait...";
1402
c2b2aee0
AD
1403 xmlhttp.open("GET", "backend.php?op=pref-feed-browser&subop=details&id="
1404 + param_escape(id), true);
1405 xmlhttp.onreadystatechange=expand_feed_callback;
1406 xmlhttp.send(null);
1407 }
c6232e43
AD
1408
1409 } catch (e) {
1410 exception_error("browserExpand", e);
1411 }
1412}
64dc5976
AD
1413
1414function validateNewPassword(form) {
1415 if (form.OLD_PASSWORD.value == "") {
88103301 1416 alert("Old password cannot be blank");
64dc5976
AD
1417 return false;
1418 }
1419 if (form.NEW_PASSWORD.value == "") {
1420 alert("New password cannot be blank");
1421 return false;
1422 }
1423 return true;
1424}
ce3bf408
AD
1425
1426function selectPrefRows(kind, select) {
1427
1428 if (kind) {
1429 var opbarid = false;
1430 var nchk = false;
1431 var nrow = false;
1432 var lname = false;
1433
1434 if (kind == "feed") {
1435 opbarid = "feedOpToolbar";
1436 nrow = "FEEDR-";
1437 nchk = "FRCHK-";
1438 lname = "prefFeedList";
1439 } else if (kind == "fcat") {
1440 opbarid = "catOpToolbar";
1441 nrow = "FCATR-";
1442 nchk = "FCHK-";
1443 lname = "prefFeedCatList";
1444 } else if (kind == "filter") {
1445 opbarid = "filterOpToolbar";
1446 nrow = "FILRR-";
1447 nchk = "FICHK-";
1448 lname = "prefFilterList";
1449 } else if (kind == "label") {
1450 opbarid = "labelOpToolbar";
1451 nrow = "LILRR-";
1452 nchk = "LCHK-";
1453 lname = "prefLabelList";
1454 } else if (kind == "user") {
1455 opbarid = "userOpToolbar";
1456 nrow = "UMRR-";
1457 nchk = "UMCHK-";
1458 lname = "prefUserList";
1459 }
1460
1461 if (opbarid) {
1462 selectTableRowsByIdPrefix(lname, nrow, nchk, select);
1463 disableContainerChildren(opbarid, !select);
1464 }
1465
1466 }
1467}
1468
1469
1470function toggleSelectPrefRow(sender, kind) {
1471
1472 toggleSelectRow(sender);
1473
1474 if (kind) {
1475 var opbarid = false;
1476 var nsel = -1;
1477
1478 if (kind == "feed") {
1479 opbarid = "feedOpToolbar";
1480 nsel = getSelectedFeeds();
1481 } else if (kind == "fcat") {
1482 opbarid = "catOpToolbar";
1483 nsel = getSelectedFeedCats();
1484 } else if (kind == "filter") {
1485 opbarid = "filterOpToolbar";
1486 nsel = getSelectedFilters();
1487 } else if (kind == "label") {
1488 opbarid = "labelOpToolbar";
1489 nsel = getSelectedLabels();
1490 } else if (kind == "user") {
1491 opbarid = "userOpToolbar";
1492 nsel = getSelectedUsers();
1493 }
1494
1495 if (opbarid && nsel != -1) {
1496 disableContainerChildren(opbarid, nsel == false);
1497 }
1498
1499 }
1500}
1501
c0ae0fdb
AD
1502function toggleSelectFBListRow(sender) {
1503 toggleSelectListRow(sender);
1504 disableContainerChildren("fbrOpToolbar", getSelectedFeedsFromBrowser() == 0);
1505}