]> git.wh0rd.org - tt-rss.git/blame - prefs.js
confirm dangerous actions in prefs, main quick-delete action change
[tt-rss.git] / prefs.js
CommitLineData
007bda35
AD
1var xmlhttp = false;
2
961513a3 3var active_feed = false;
91ff844a 4var active_feed_cat = false;
a0d53889 5var active_filter = false;
48f0adb0 6var active_label = false;
e6cb77a0 7var active_user = false;
961513a3 8
f5a50b25
AD
9var active_tab = false;
10
007bda35
AD
11/*@cc_on @*/
12/*@if (@_jscript_version >= 5)
13// JScript gives us Conditional compilation, we can cope with old IE versions.
14// and security blocked creation of the objects.
15try {
16 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
17} catch (e) {
18 try {
19 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
20 } catch (E) {
21 xmlhttp = false;
22 }
23}
24@end @*/
25
26if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
27 xmlhttp = new XMLHttpRequest();
28}
29
007bda35 30function feedlist_callback() {
007bda35 31 if (xmlhttp.readyState == 4) {
7719618b 32 var container = document.getElementById('prefContent');
007bda35 33 container.innerHTML=xmlhttp.responseText;
961513a3
AD
34 if (active_feed) {
35 var row = document.getElementById("FEEDR-" + active_feed);
36 if (row) {
37 if (!row.className.match("Selected")) {
38 row.className = row.className + "Selected";
39 }
40 }
41 var checkbox = document.getElementById("FRCHK-" + active_feed);
42 if (checkbox) {
43 checkbox.checked = true;
44 }
45 }
f5a50b25 46 p_notify("");
007bda35
AD
47 }
48}
49
a0d53889 50function filterlist_callback() {
f5a50b25 51 var container = document.getElementById('prefContent');
a0d53889 52 if (xmlhttp.readyState == 4) {
f5a50b25 53
a0d53889
AD
54 container.innerHTML=xmlhttp.responseText;
55
56 if (active_filter) {
57 var row = document.getElementById("FILRR-" + active_filter);
58 if (row) {
59 if (!row.className.match("Selected")) {
60 row.className = row.className + "Selected";
61 }
62 }
63 var checkbox = document.getElementById("FICHK-" + active_filter);
64
65 if (checkbox) {
66 checkbox.checked = true;
67 }
68 }
f5a50b25 69 p_notify("");
a0d53889
AD
70 }
71}
72
48f0adb0 73function labellist_callback() {
f5a50b25 74 var container = document.getElementById('prefContent');
48f0adb0
AD
75 if (xmlhttp.readyState == 4) {
76 container.innerHTML=xmlhttp.responseText;
77
967955b7 78 if (active_label) {
48f0adb0
AD
79 var row = document.getElementById("LILRR-" + active_label);
80 if (row) {
81 if (!row.className.match("Selected")) {
82 row.className = row.className + "Selected";
83 }
84 }
85 var checkbox = document.getElementById("LICHK-" + active_label);
86
87 if (checkbox) {
88 checkbox.checked = true;
89 }
90 }
f5a50b25 91 p_notify("");
48f0adb0
AD
92 }
93}
4255b24c 94
e6cb77a0
AD
95function userlist_callback() {
96 var container = document.getElementById('prefContent');
97 if (xmlhttp.readyState == 4) {
98 container.innerHTML=xmlhttp.responseText;
99
1a7572cb
AD
100 if (active_user) {
101 var row = document.getElementById("UMRR-" + active_user);
e6cb77a0
AD
102 if (row) {
103 if (!row.className.match("Selected")) {
104 row.className = row.className + "Selected";
105 }
106 }
1a7572cb 107 var checkbox = document.getElementById("UMCHK-" + active_user);
e6cb77a0
AD
108
109 if (checkbox) {
110 checkbox.checked = true;
111 }
1a7572cb
AD
112 }
113
e6cb77a0
AD
114 p_notify("");
115 }
116}
117
c6c3a07f 118function infobox_callback() {
1a7572cb 119 if (xmlhttp.readyState == 4) {
2317ffaa
AD
120 var box = document.getElementById('infoBox');
121 var shadow = document.getElementById('infoBoxShadow');
122
123 if (box) {
124 box.innerHTML=xmlhttp.responseText;
125 if (shadow) {
126 shadow.style.display = "block";
127 } else {
128 box.style.display = "block";
129 }
c6c3a07f 130 }
1a7572cb
AD
131 }
132}
133
134
4255b24c
AD
135function prefslist_callback() {
136 var container = document.getElementById('prefContent');
137 if (xmlhttp.readyState == 4) {
138
139 container.innerHTML=xmlhttp.responseText;
140
141 p_notify("");
142 }
143}
144
b1895692
AD
145function gethelp_callback() {
146 var container = document.getElementById('prefHelpBox');
147 if (xmlhttp.readyState == 4) {
148
149 container.innerHTML = xmlhttp.responseText;
150 container.style.display = "block";
151
152 }
153}
4255b24c
AD
154
155
0e091d38
AD
156function notify_callback() {
157 var container = document.getElementById('notify');
158 if (xmlhttp.readyState == 4) {
159 container.innerHTML=xmlhttp.responseText;
160 }
161}
162
b83c7545 163function updateFeedList(sort_key) {
007bda35 164
c0e5a40e 165 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
166 printLockingError();
167 return
168 }
169
f5a50b25
AD
170// document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
171
172 p_notify("Loading, please wait...");
007bda35 173
f932bc9f
AD
174 var feed_search = document.getElementById("feed_search");
175 var search = "";
176 if (feed_search) { search = feed_search.value; }
177
b83c7545 178 xmlhttp.open("GET", "backend.php?op=pref-feeds" +
f932bc9f
AD
179 "&sort=" + param_escape(sort_key) +
180 "&search=" + param_escape(search), true);
007bda35
AD
181 xmlhttp.onreadystatechange=feedlist_callback;
182 xmlhttp.send(null);
183
184}
185
e6cb77a0
AD
186function updateUsersList() {
187
188 if (!xmlhttp_ready(xmlhttp)) {
189 printLockingError();
190 return
191 }
192
193// document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
194
195 p_notify("Loading, please wait...");
196
197 xmlhttp.open("GET", "backend.php?op=pref-users", true);
198 xmlhttp.onreadystatechange=userlist_callback;
199 xmlhttp.send(null);
200
201}
202
48f0adb0
AD
203function addLabel() {
204
205 if (!xmlhttp_ready(xmlhttp)) {
206 printLockingError();
207 return
208 }
209
210 var sqlexp = document.getElementById("ladd_expr");
211
212 if (sqlexp.value.length == 0) {
213 notify("Missing SQL expression.");
214 } else {
215 notify("Adding label...");
216
217 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=add&exp=" +
218 param_escape(sqlexp.value), true);
219
220 xmlhttp.onreadystatechange=labellist_callback;
221 xmlhttp.send(null);
222
223 sqlexp.value = "";
224 }
225
226}
227
de435974
AD
228function addFilter() {
229
230 if (!xmlhttp_ready(xmlhttp)) {
231 printLockingError();
232 return
233 }
234
235 var regexp = document.getElementById("fadd_regexp");
236 var match = document.getElementById("fadd_match");
ead60402 237 var feed = document.getElementById("fadd_feed");
19c9cb11 238 var action = document.getElementById("fadd_action");
de435974
AD
239
240 if (regexp.value.length == 0) {
241 notify("Missing filter expression.");
242 } else {
243 notify("Adding filter...");
244
25cb5736 245 var v_match = match[match.selectedIndex].text;
ead60402 246 var feed_id = feed[feed.selectedIndex].id;
19c9cb11 247 var action_id = action[action.selectedIndex].id;
ead60402 248
de435974 249 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=add&regexp=" +
ead60402 250 param_escape(regexp.value) + "&match=" + v_match +
19c9cb11 251 "&fid=" + param_escape(feed_id) + "&aid=" + param_escape(action_id), true);
de435974
AD
252
253 xmlhttp.onreadystatechange=filterlist_callback;
254 xmlhttp.send(null);
255
256 regexp.value = "";
257 }
258
259}
48f0adb0 260
71ad3959
AD
261function addFeed() {
262
c0e5a40e 263 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
264 printLockingError();
265 return
266 }
267
331900c6
AD
268 var link = document.getElementById("fadd_link");
269
83fe4d6d 270 if (link.value.length == 0) {
c753cd32 271 notify("Missing feed URL.");
331900c6
AD
272 } else {
273 notify("Adding feed...");
274
275 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
276 param_escape(link.value), true);
277 xmlhttp.onreadystatechange=feedlist_callback;
278 xmlhttp.send(null);
279
280 link.value = "";
281
282 }
283
284}
285
91ff844a
AD
286function addFeedCat() {
287
288 if (!xmlhttp_ready(xmlhttp)) {
289 printLockingError();
290 return
291 }
292
293 var cat = document.getElementById("fadd_cat");
294
295 if (cat.value.length == 0) {
296 notify("Missing feed category.");
297 } else {
298 notify("Adding feed category...");
299
300 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=addCat&cat=" +
301 param_escape(cat.value), true);
302 xmlhttp.onreadystatechange=feedlist_callback;
303 xmlhttp.send(null);
304
305 link.value = "";
306
307 }
308
309}
e6cb77a0
AD
310function addUser() {
311
312 if (!xmlhttp_ready(xmlhttp)) {
313 printLockingError();
314 return
315 }
316
317 var sqlexp = document.getElementById("uadd_box");
318
319 if (sqlexp.value.length == 0) {
320 notify("Missing user login.");
321 } else {
322 notify("Adding user...");
323
324 xmlhttp.open("GET", "backend.php?op=pref-users&subop=add&login=" +
325 param_escape(sqlexp.value), true);
326
327 xmlhttp.onreadystatechange=userlist_callback;
328 xmlhttp.send(null);
329
330 sqlexp.value = "";
331 }
332
333}
334
48f0adb0
AD
335function editLabel(id) {
336
337 if (!xmlhttp_ready(xmlhttp)) {
338 printLockingError();
339 return
340 }
341
342 active_label = id;
343
344 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=edit&id=" +
345 param_escape(id), true);
346 xmlhttp.onreadystatechange=labellist_callback;
347 xmlhttp.send(null);
348
349}
350
e6cb77a0
AD
351function editUser(id) {
352
353 if (!xmlhttp_ready(xmlhttp)) {
354 printLockingError();
355 return
356 }
357
358 active_user = id;
359
360 xmlhttp.open("GET", "backend.php?op=pref-users&subop=edit&id=" +
361 param_escape(id), true);
362 xmlhttp.onreadystatechange=userlist_callback;
363 xmlhttp.send(null);
364
365}
366
a0d53889
AD
367function editFilter(id) {
368
369 if (!xmlhttp_ready(xmlhttp)) {
370 printLockingError();
371 return
372 }
373
374 active_filter = id;
375
376 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=edit&id=" +
377 param_escape(id), true);
378 xmlhttp.onreadystatechange=filterlist_callback;
379 xmlhttp.send(null);
380
381}
382
331900c6
AD
383function editFeed(feed) {
384
508a81e1
AD
385// notify("Editing feed...");
386
c0e5a40e 387 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
388 printLockingError();
389 return
390 }
331900c6 391
961513a3
AD
392 active_feed = feed;
393
0ea4fb50 394/* xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=edit&id=" +
331900c6
AD
395 param_escape(feed), true);
396 xmlhttp.onreadystatechange=feedlist_callback;
0ea4fb50
AD
397 xmlhttp.send(null); */
398
399 selectTableRowsByIdPrefix('prefFeedList', 'FEEDR-', 'FRCHK-', false);
400 selectTableRowsByIdPrefix('prefFeedList', 'FEEDR-'+feed, 'FRCHK-'+feed, true);
401
402 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
403 param_escape(active_feed), true);
404
405 xmlhttp.onreadystatechange=infobox_callback;
331900c6
AD
406 xmlhttp.send(null);
407
408}
409
91ff844a 410function editFeedCat(cat) {
48f0adb0 411
91ff844a
AD
412 if (!xmlhttp_ready(xmlhttp)) {
413 printLockingError();
414 return
48f0adb0
AD
415 }
416
91ff844a 417 active_feed_cat = cat;
e6cb77a0 418
91ff844a
AD
419 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCat&id=" +
420 param_escape(cat), true);
421 xmlhttp.onreadystatechange=feedlist_callback;
422 xmlhttp.send(null);
e6cb77a0 423
e6cb77a0
AD
424}
425
91ff844a
AD
426function getSelectedLabels() {
427 return getSelectedTableRowIds("prefLabelList", "LILRR");
428}
48f0adb0 429
91ff844a
AD
430function getSelectedUsers() {
431 return getSelectedTableRowIds("prefUserList", "UMRR");
a0d53889
AD
432}
433
83fe4d6d 434function getSelectedFeeds() {
91ff844a
AD
435 return getSelectedTableRowIds("prefFeedList", "FEEDR");
436}
331900c6 437
91ff844a
AD
438function getSelectedFilters() {
439 return getSelectedTableRowIds("prefFilterList", "FILRR");
440}
331900c6 441
91ff844a
AD
442function getSelectedFeedCats() {
443 return getSelectedTableRowIds("prefFeedCatList", "FCATR");
83fe4d6d
AD
444}
445
91ff844a 446
4f3a84f4 447function readSelectedFeeds(read) {
83fe4d6d 448
c0e5a40e 449 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
450 printLockingError();
451 return
452 }
453
83fe4d6d
AD
454 var sel_rows = getSelectedFeeds();
455
456 if (sel_rows.length > 0) {
457
4f3a84f4
AD
458 if (!read) {
459 op = "unread";
460 } else {
461 op = "read";
462 }
83fe4d6d 463
4f3a84f4 464 notify("Marking selected feeds as " + op + "...");
83fe4d6d 465
4f3a84f4 466 xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=" + op + "&ids="+
83fe4d6d 467 param_escape(sel_rows.toString()), true);
0e091d38 468 xmlhttp.onreadystatechange=notify_callback;
83fe4d6d
AD
469 xmlhttp.send(null);
470
471 } else {
472
c753cd32 473 notify("Please select some feeds first.");
83fe4d6d
AD
474
475 }
476}
477
48f0adb0
AD
478function removeSelectedLabels() {
479
480 if (!xmlhttp_ready(xmlhttp)) {
481 printLockingError();
482 return
483 }
484
485 var sel_rows = getSelectedLabels();
486
487 if (sel_rows.length > 0) {
488
69668465 489 var ok = confirm("Remove selected labels?");
48f0adb0 490
69668465
AD
491 if (ok) {
492 notify("Removing selected labels...");
493
494 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
495 param_escape(sel_rows.toString()), true);
496 xmlhttp.onreadystatechange=labellist_callback;
497 xmlhttp.send(null);
498 }
48f0adb0
AD
499 } else {
500 notify("Please select some labels first.");
501 }
502}
503
e6cb77a0
AD
504function removeSelectedUsers() {
505
506 if (!xmlhttp_ready(xmlhttp)) {
507 printLockingError();
508 return
509 }
510
511 var sel_rows = getSelectedUsers();
512
513 if (sel_rows.length > 0) {
514
69668465 515 var ok = confirm("Remove selected users?");
e6cb77a0 516
69668465
AD
517 if (ok) {
518 notify("Removing selected users...");
519
520 xmlhttp.open("GET", "backend.php?op=pref-users&subop=remove&ids="+
521 param_escape(sel_rows.toString()), true);
522 xmlhttp.onreadystatechange=userlist_callback;
523 xmlhttp.send(null);
524 }
e6cb77a0
AD
525
526 } else {
527 notify("Please select some labels first.");
528 }
529}
530
48f0adb0
AD
531function removeSelectedFilters() {
532
533 if (!xmlhttp_ready(xmlhttp)) {
534 printLockingError();
535 return
536 }
537
538 var sel_rows = getSelectedFilters();
539
540 if (sel_rows.length > 0) {
541
69668465 542 var ok = confirm("Remove selected filters?");
48f0adb0 543
69668465
AD
544 if (ok) {
545 notify("Removing selected filters...");
546
547 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
548 param_escape(sel_rows.toString()), true);
549 xmlhttp.onreadystatechange=filterlist_callback;
550 xmlhttp.send(null);
551 }
48f0adb0
AD
552 } else {
553 notify("Please select some filters first.");
554 }
555}
556
557
83fe4d6d
AD
558function removeSelectedFeeds() {
559
c0e5a40e 560 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
561 printLockingError();
562 return
563 }
564
83fe4d6d
AD
565 var sel_rows = getSelectedFeeds();
566
331900c6
AD
567 if (sel_rows.length > 0) {
568
69668465 569 var ok = confirm("Remove selected feeds?");
331900c6 570
69668465
AD
571 if (ok) {
572
573 notify("Removing selected feeds...");
574
575 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
576 param_escape(sel_rows.toString()), true);
577 xmlhttp.onreadystatechange=feedlist_callback;
578 xmlhttp.send(null);
579 }
71ad3959 580
71ad3959 581 } else {
331900c6 582
c753cd32 583 notify("Please select some feeds first.");
331900c6 584
71ad3959
AD
585 }
586
587}
007bda35 588
91ff844a
AD
589function removeSelectedFeedCats() {
590
591 if (!xmlhttp_ready(xmlhttp)) {
592 printLockingError();
593 return
594 }
595
596 var sel_rows = getSelectedFeedCats();
597
598 if (sel_rows.length > 0) {
599
69668465 600 var ok = confirm("Remove selected categories?");
91ff844a 601
69668465
AD
602 if (ok) {
603 notify("Removing selected categories...");
604
605 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=removeCats&ids="+
606 param_escape(sel_rows.toString()), true);
607 xmlhttp.onreadystatechange=feedlist_callback;
608 xmlhttp.send(null);
609 }
91ff844a
AD
610
611 } else {
612
613 notify("Please select some feeds first.");
614
615 }
616
617}
618
508a81e1
AD
619function feedEditCancel() {
620
c0e5a40e 621 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
622 printLockingError();
623 return
624 }
625
327a3bbe
AD
626 closeInfoBox();
627
961513a3
AD
628 active_feed = false;
629
508a81e1
AD
630 notify("Operation cancelled.");
631
327a3bbe 632/* xmlhttp.open("GET", "backend.php?op=pref-feeds", true);
508a81e1 633 xmlhttp.onreadystatechange=feedlist_callback;
327a3bbe 634 xmlhttp.send(null); */
508a81e1
AD
635
636}
637
91ff844a
AD
638function feedCatEditCancel() {
639
640 if (!xmlhttp_ready(xmlhttp)) {
641 printLockingError();
642 return
643 }
644
645 active_feed_cat = false;
646
647 notify("Operation cancelled.");
648
649 xmlhttp.open("GET", "backend.php?op=pref-feeds", true);
650 xmlhttp.onreadystatechange=feedlist_callback;
651 xmlhttp.send(null);
652
653}
654
603c27f8
AD
655function feedEditSave() {
656
657 var feed = active_feed;
508a81e1 658
c0e5a40e 659 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
660 printLockingError();
661 return
662 }
663
603c27f8
AD
664 var link = document.getElementById("iedit_link").value;
665 var title = document.getElementById("iedit_title").value;
d148926e 666 var upd_intl = document.getElementById("iedit_updintl").value;
5d73494a 667 var purge_intl = document.getElementById("iedit_purgintl").value;
91ff844a
AD
668 var fcat = document.getElementById("iedit_fcat");
669
670 var fcat_id = fcat[fcat.selectedIndex].id;
508a81e1 671
603c27f8 672// notify("Saving feed.");
508a81e1 673
140aae81 674/* if (upd_intl < 0) {
d148926e
AD
675 notify("Update interval must be &gt;= 0 (0 = default)");
676 return;
677 }
678
5d73494a
AD
679 if (purge_intl < 0) {
680 notify("Purge days must be &gt;= 0 (0 = default)");
681 return;
140aae81 682 } */
d148926e 683
508a81e1
AD
684 if (link.length == 0) {
685 notify("Feed link cannot be blank.");
686 return;
687 }
688
689 if (title.length == 0) {
690 notify("Feed title cannot be blank.");
691 return;
692 }
693
603c27f8
AD
694 active_feed = false;
695
dbd9e2f1
AD
696 notify("");
697
508a81e1 698 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editSave&id=" +
d148926e 699 feed + "&l=" + param_escape(link) + "&t=" + param_escape(title) +
91ff844a
AD
700 "&ui=" + param_escape(upd_intl) + "&pi=" + param_escape(purge_intl) +
701 "&catid=" + param_escape(fcat_id), true);
508a81e1
AD
702 xmlhttp.onreadystatechange=feedlist_callback;
703 xmlhttp.send(null);
704
705}
706
5ddadb4c
AD
707function feedCatEditSave() {
708
709 if (!xmlhttp_ready(xmlhttp)) {
710 printLockingError();
711 return
712 }
713
714 notify("");
715
716 var cat_title = document.getElementById("iedit_title").value;
717
718 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=saveCat&id=" +
719 param_escape(active_feed_cat) + "&title=" + param_escape(cat_title),
720 true);
721 xmlhttp.onreadystatechange=feedlist_callback;
722 xmlhttp.send(null);
723
724 active_feed_cat = false;
725
726}
727
728
d9dde1d6
AD
729function labelTest() {
730
731 var sqlexp = document.getElementById("iedit_expr").value;
732 var descr = document.getElementById("iedit_descr").value;
733
734 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=test&expr=" +
735 param_escape(sqlexp) + "&descr=" + param_escape(descr), true);
736
737 xmlhttp.onreadystatechange=infobox_callback;
738 xmlhttp.send(null);
739
740}
741
01c9c74a
AD
742function displayHelpInfobox(topic_id) {
743
744 xmlhttp.open("GET", "backend.php?op=help&tid=" +
745 param_escape(topic_id) + "&noheaders=1", true);
746
747 xmlhttp.onreadystatechange=infobox_callback;
748 xmlhttp.send(null);
749
750}
751
48f0adb0
AD
752function labelEditCancel() {
753
754 if (!xmlhttp_ready(xmlhttp)) {
755 printLockingError();
756 return
757 }
758
759 active_label = false;
760
761 notify("Operation cancelled.");
762
763 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
764 xmlhttp.onreadystatechange=labellist_callback;
765 xmlhttp.send(null);
766
767}
768
e6cb77a0
AD
769function userEditCancel() {
770
771 if (!xmlhttp_ready(xmlhttp)) {
772 printLockingError();
773 return
774 }
775
776 active_user = false;
777
778 notify("Operation cancelled.");
779
780 xmlhttp.open("GET", "backend.php?op=pref-users", true);
781 xmlhttp.onreadystatechange=userlist_callback;
782 xmlhttp.send(null);
783
784}
48f0adb0 785
a0d53889
AD
786function filterEditCancel() {
787
788 if (!xmlhttp_ready(xmlhttp)) {
789 printLockingError();
790 return
791 }
792
793 active_filter = false;
794
795 notify("Operation cancelled.");
796
797 xmlhttp.open("GET", "backend.php?op=pref-filters", true);
798 xmlhttp.onreadystatechange=filterlist_callback;
799 xmlhttp.send(null);
800
801}
802
48f0adb0
AD
803function labelEditSave() {
804
805 var label = active_label;
806
807 if (!xmlhttp_ready(xmlhttp)) {
808 printLockingError();
809 return
810 }
811
812 var sqlexp = document.getElementById("iedit_expr").value;
813 var descr = document.getElementById("iedit_descr").value;
814
815// notify("Saving label " + sqlexp + ": " + descr);
816
817 if (sqlexp.length == 0) {
818 notify("SQL expression cannot be blank.");
819 return;
820 }
821
822 if (descr.length == 0) {
823 notify("Caption cannot be blank.");
824 return;
825 }
826
dbd9e2f1
AD
827 notify("");
828
48f0adb0
AD
829 active_label = false;
830
831 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=editSave&id=" +
832 label + "&s=" + param_escape(sqlexp) + "&d=" + param_escape(descr),
833 true);
834
835 xmlhttp.onreadystatechange=labellist_callback;
836 xmlhttp.send(null);
837
838}
839
e6cb77a0
AD
840function userEditSave() {
841
842 var user = active_user;
843
844 if (!xmlhttp_ready(xmlhttp)) {
845 printLockingError();
846 return
847 }
848
849 var login = document.getElementById("iedit_ulogin").value;
850 var level = document.getElementById("iedit_ulevel").value;
851
852 if (login.length == 0) {
853 notify("Login cannot be blank.");
854 return;
855 }
856
857 if (level.length == 0) {
858 notify("User level cannot be blank.");
859 return;
860 }
861
862 active_user = false;
863
dbd9e2f1
AD
864 notify("");
865
e6cb77a0
AD
866 xmlhttp.open("GET", "backend.php?op=pref-users&subop=editSave&id=" +
867 user + "&l=" + param_escape(login) + "&al=" + param_escape(level),
868 true);
869
dbd9e2f1 870 xmlhttp.onreadystatechange=userlist_callback;
e6cb77a0
AD
871 xmlhttp.send(null);
872
873}
874
875
a0d53889
AD
876function filterEditSave() {
877
878 var filter = active_filter;
879
880 if (!xmlhttp_ready(xmlhttp)) {
881 printLockingError();
882 return
883 }
884
885 var regexp = document.getElementById("iedit_regexp").value;
886 var descr = document.getElementById("iedit_descr").value;
25cb5736 887 var match = document.getElementById("iedit_match");
19c9cb11 888
25cb5736 889 var v_match = match[match.selectedIndex].text;
a0d53889 890
ead60402
AD
891 var feed = document.getElementById("iedit_feed");
892 var feed_id = feed[feed.selectedIndex].id;
893
19c9cb11
AD
894 var action = document.getElementById("iedit_filter_action");
895 var action_id = action[action.selectedIndex].id;
896
a0d53889
AD
897// notify("Saving filter " + filter + ": " + regexp + ", " + descr + ", " + match);
898
899 if (regexp.length == 0) {
900 notify("Filter expression cannot be blank.");
901 return;
902 }
903
904 active_filter = false;
905
906 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=editSave&id=" +
907 filter + "&r=" + param_escape(regexp) + "&d=" + param_escape(descr) +
19c9cb11
AD
908 "&m=" + param_escape(v_match) + "&fid=" + param_escape(feed_id) +
909 "&aid=" + param_escape(action_id), true);
dbd9e2f1
AD
910
911 notify("");
912
a0d53889
AD
913 xmlhttp.onreadystatechange=filterlist_callback;
914 xmlhttp.send(null);
915
916}
917
48f0adb0
AD
918function editSelectedLabel() {
919 var rows = getSelectedLabels();
a0d53889 920
48f0adb0
AD
921 if (rows.length == 0) {
922 notify("No labels are selected.");
923 return;
a0d53889
AD
924 }
925
48f0adb0
AD
926 if (rows.length > 1) {
927 notify("Please select one label.");
928 return;
929 }
a0d53889 930
dbd9e2f1
AD
931 notify("");
932
48f0adb0 933 editLabel(rows[0]);
a0d53889 934
a0d53889
AD
935}
936
e6cb77a0
AD
937function editSelectedUser() {
938 var rows = getSelectedUsers();
939
940 if (rows.length == 0) {
941 notify("No users are selected.");
942 return;
943 }
944
945 if (rows.length > 1) {
946 notify("Please select one user.");
947 return;
948 }
949
dbd9e2f1
AD
950 notify("");
951
e6cb77a0
AD
952 editUser(rows[0]);
953}
954
955function resetSelectedUserPass() {
956 var rows = getSelectedUsers();
957
958 if (rows.length == 0) {
959 notify("No users are selected.");
960 return;
961 }
962
963 if (rows.length > 1) {
964 notify("Please select one user.");
965 return;
966 }
967
69668465 968 var ok = confirm("Reset password of selected user?");
e6cb77a0 969
69668465
AD
970 if (ok) {
971 notify("Resetting password for selected user...");
972
973 var id = rows[0];
974
975 xmlhttp.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
976 param_escape(id), true);
977 xmlhttp.onreadystatechange=userlist_callback;
978 xmlhttp.send(null);
979 }
e6cb77a0
AD
980}
981
717f5e64 982function selectedUserDetails() {
e6cb77a0 983
1a7572cb
AD
984 if (!xmlhttp_ready(xmlhttp)) {
985 printLockingError();
986 return
987 }
988
717f5e64
AD
989 var rows = getSelectedUsers();
990
991 if (rows.length == 0) {
992 notify("No users are selected.");
993 return;
994 }
995
996 if (rows.length > 1) {
997 notify("Please select one user.");
998 return;
999 }
1000
1001 var id = rows[0];
1002
dbd9e2f1
AD
1003 notify("");
1004
1a7572cb 1005 xmlhttp.open("GET", "backend.php?op=user-details&id=" + id, true);
c6c3a07f
AD
1006 xmlhttp.onreadystatechange=infobox_callback;
1007 xmlhttp.send(null);
1008
1009}
1010
1011function selectedFeedDetails() {
1012
1013 if (!xmlhttp_ready(xmlhttp)) {
1014 printLockingError();
1015 return
1016 }
1017
1018 var rows = getSelectedFeeds();
1019
1020 if (rows.length == 0) {
1021 notify("No feeds are selected.");
1022 return;
1023 }
1024
df268d47
AD
1025// if (rows.length > 1) {
1026// notify("Please select one feed.");
1027// return;
1028// }
c6c3a07f 1029
df268d47 1030// var id = rows[0];
c6c3a07f 1031
dbd9e2f1
AD
1032 notify("");
1033
df268d47
AD
1034 xmlhttp.open("GET", "backend.php?op=feed-details&id=" +
1035 param_escape(rows.toString()), true);
c6c3a07f 1036 xmlhttp.onreadystatechange=infobox_callback;
1a7572cb 1037 xmlhttp.send(null);
717f5e64
AD
1038
1039}
a0d53889
AD
1040
1041function editSelectedFilter() {
1042 var rows = getSelectedFilters();
1043
1044 if (rows.length == 0) {
1045 notify("No filters are selected.");
1046 return;
1047 }
1048
1049 if (rows.length > 1) {
1050 notify("Please select one filter.");
1051 return;
1052 }
1053
dbd9e2f1
AD
1054 notify("");
1055
a0d53889
AD
1056 editFilter(rows[0]);
1057
1058}
1059
1060
508a81e1
AD
1061function editSelectedFeed() {
1062 var rows = getSelectedFeeds();
1063
1064 if (rows.length == 0) {
1065 notify("No feeds are selected.");
1066 return;
1067 }
1068
1069 if (rows.length > 1) {
1070 notify("Please select one feed.");
1071 return;
1072 }
1073
dbd9e2f1
AD
1074 notify("");
1075
508a81e1 1076 editFeed(rows[0]);
91ff844a
AD
1077
1078}
1079
1080function editSelectedFeedCat() {
1081 var rows = getSelectedFeedCats();
1082
1083 if (rows.length == 0) {
1084 notify("No categories are selected.");
1085 return;
1086 }
1087
1088 if (rows.length > 1) {
1089 notify("Please select one category.");
1090 return;
1091 }
1092
1093 notify("");
1094
1095 editFeedCat(rows[0]);
508a81e1
AD
1096
1097}
1098
13ad9102
AD
1099function localPiggieFunction(enable) {
1100 if (enable) {
508a81e1
AD
1101 piggie.style.display = "block";
1102 seq = "";
1103 notify("I loveded it!!!");
1104 } else {
1105 piggie.style.display = "none";
1106 notify("");
1107 }
508a81e1
AD
1108}
1109
9f311df6
AD
1110function validateOpmlImport() {
1111
1112 var opml_file = document.getElementById("opml_file");
1113
1114 if (opml_file.value.length == 0) {
1115 notify("Please select OPML file to upload.");
1116 return false;
1117 } else {
1118 return true;
1119 }
1120}
1121
a0d53889
AD
1122function updateFilterList() {
1123
1124 if (!xmlhttp_ready(xmlhttp)) {
1125 printLockingError();
1126 return
1127 }
1128
f5a50b25
AD
1129// document.getElementById("prefContent").innerHTML = "Loading filters, please wait...";
1130
1131 p_notify("Loading, please wait...");
a0d53889
AD
1132
1133 xmlhttp.open("GET", "backend.php?op=pref-filters", true);
1134 xmlhttp.onreadystatechange=filterlist_callback;
1135 xmlhttp.send(null);
1136
1137}
1138
48f0adb0
AD
1139function updateLabelList() {
1140
1141 if (!xmlhttp_ready(xmlhttp)) {
1142 printLockingError();
1143 return
1144 }
1145
f5a50b25
AD
1146 p_notify("Loading, please wait...");
1147
1148// document.getElementById("prefContent").innerHTML = "Loading labels, please wait...";
48f0adb0
AD
1149
1150 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
1151 xmlhttp.onreadystatechange=labellist_callback;
1152 xmlhttp.send(null);
48f0adb0
AD
1153}
1154
4255b24c
AD
1155function updatePrefsList() {
1156
1157 if (!xmlhttp_ready(xmlhttp)) {
1158 printLockingError();
1159 return
1160 }
1161
1162 p_notify("Loading, please wait...");
1163
1164 xmlhttp.open("GET", "backend.php?op=pref-prefs", true);
1165 xmlhttp.onreadystatechange=prefslist_callback;
1166 xmlhttp.send(null);
1167
1168}
1169
f5a50b25 1170function selectTab(id) {
48f0adb0 1171
c6c3a07f
AD
1172 if (!xmlhttp_ready(xmlhttp)) {
1173 printLockingError();
1174 return
1175 }
1176
f5a50b25 1177 if (id == "feedConfig") {
a0d53889 1178 updateFeedList();
f5a50b25 1179 } else if (id == "filterConfig") {
a0d53889 1180 updateFilterList();
f5a50b25 1181 } else if (id == "labelConfig") {
48f0adb0 1182 updateLabelList();
4255b24c
AD
1183 } else if (id == "genConfig") {
1184 updatePrefsList();
e6cb77a0
AD
1185 } else if (id == "userConfig") {
1186 updateUsersList();
a0d53889 1187 }
f5a50b25
AD
1188
1189 var tab = document.getElementById(active_tab + "Tab");
1190
1191 if (tab) {
1192 if (tab.className.match("Selected")) {
1193 tab.className = "prefsTab";
1194 }
1195 }
1196
1197 tab = document.getElementById(id + "Tab");
1198
1199 if (tab) {
1200 if (!tab.className.match("Selected")) {
1201 tab.className = tab.className + "Selected";
1202 }
1203 }
1204
1205 active_tab = id;
1206
4da47970
AD
1207 setCookie('ttrss_pref_acttab', active_tab);
1208
a0d53889
AD
1209}
1210
007bda35 1211function init() {
e2ec66a8 1212
7719618b
AD
1213 try {
1214
1215 // IE kludge
1216 if (!xmlhttp) {
1217 document.getElementById("prefContent").innerHTML =
1218 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1219 "to function properly. Your browser doesn't seem to support it.";
1220 return;
1221 }
4da47970
AD
1222
1223 active_tab = getCookie("ttrss_pref_acttab");
1224 if (!active_tab) active_tab = "genConfig";
1225 selectTab(active_tab);
7719618b
AD
1226
1227 document.onkeydown = hotkey_handler;
1228 notify("");
1229 } catch (e) {
1230 exception_error("init", e);
e2ec66a8 1231 }
007bda35 1232}
b1895692 1233
c6c3a07f 1234function closeInfoBox() {
2317ffaa
AD
1235 var box = document.getElementById('infoBox');
1236 var shadow = document.getElementById('infoBoxShadow');
1237
1238 if (shadow) {
1239 shadow.style.display = "none";
1240 } else if (box) {
1241 box.style.display = "none";
1242 }
1a7572cb 1243}
f932bc9f
AD
1244
1245function categorizeSelectedFeeds() {
1246
1247 if (!xmlhttp_ready(xmlhttp)) {
1248 printLockingError();
1249 return
1250 }
1251
1252 var sel_rows = getSelectedFeeds();
1253
1254 var cat_sel = document.getElementById("sfeed_set_fcat");
1255 var cat_id = cat_sel[cat_sel.selectedIndex].id;
1256
1257 if (sel_rows.length > 0) {
1258
1259 notify("Changing category of selected feeds...");
1260
1261 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
1262 param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
1263 xmlhttp.onreadystatechange=feedlist_callback;
1264 xmlhttp.send(null);
1265
1266 } else {
1267
1268 notify("Please select some feeds first.");
1269
1270 }
1271
1272}
69668465
AD
1273
1274function validatePrefsReset() {
1275 return confirm("Reset to defaults?");
1276}