]> git.wh0rd.org Git - tt-rss.git/blob - js/prefs.js
e226459fc24fa0386b479ea53e20b464256b6560
[tt-rss.git] / js / prefs.js
1 var init_params = new Array();
2
3 var hotkey_prefix = false;
4 var hotkey_prefix_pressed = false;
5
6 var seq = "";
7
8 function notify_callback2(transport, sticky) {
9         notify_info(transport.responseText, sticky);
10 }
11
12 function updateFeedList(sort_key) {
13
14         var user_search = $("feed_search");
15         var search = "";
16         if (user_search) { search = user_search.value; }
17
18         new Ajax.Request("backend.php", {
19                 parameters: "?op=pref-feeds&search=" + param_escape(search),
20                 onComplete: function(transport) {
21                         dijit.byId('feedConfigTab').attr('content', transport.responseText);
22                         selectTab("feedConfig", true);
23                         notify("");
24                 } });
25 }
26
27
28 function updateUsersList(sort_key) {
29         try {
30                 var user_search = $("user_search");
31                 var search = "";
32                 if (user_search) { search = user_search.value; }
33
34                 var query = "?op=pref-users&sort="
35                         + param_escape(sort_key) +
36                         "&search=" + param_escape(search);
37
38                 new Ajax.Request("backend.php", {
39                         parameters: query,
40                         onComplete: function(transport) {
41                                 dijit.byId('userConfigTab').attr('content', transport.responseText);
42                                 selectTab("userConfig", true)
43                                 notify("");
44                         } });
45
46         } catch (e) {
47                 exception_error("updateUsersList", e);
48         }
49 }
50
51 function addUser() {
52
53         try {
54
55                 var login = prompt(__("Please enter login:"), "");
56
57                 if (login == null) {
58                         return false;
59                 }
60
61                 if (login == "") {
62                         alert(__("Can't create user: no login specified."));
63                         return false;
64                 }
65
66                 notify_progress("Adding user...");
67
68                 var query = "?op=pref-users&method=add&login=" +
69                         param_escape(login);
70
71                 new Ajax.Request("backend.php", {
72                         parameters: query,
73                         onComplete: function(transport) {
74                                 notify_callback2(transport);
75                                 updateUsersList();
76                         } });
77
78         } catch (e) {
79                 exception_error("addUser", e);
80         }
81 }
82
83 function editUser(id, event) {
84
85         try {
86                 notify_progress("Loading, please wait...");
87
88                 var query = "?op=pref-users&method=edit&id=" +
89                         param_escape(id);
90
91                 new Ajax.Request("backend.php", {
92                         parameters: query,
93                         onComplete: function(transport) {
94                                         infobox_callback2(transport, __("User Editor"));
95                                         document.forms['user_edit_form'].login.focus();
96                                 } });
97
98         } catch (e) {
99                 exception_error("editUser", e);
100         }
101
102 }
103
104 function editFilter(id) {
105         try {
106
107                 var query = "backend.php?op=pref-filters&method=edit&id=" + param_escape(id);
108
109                 if (dijit.byId("feedEditDlg"))
110                         dijit.byId("feedEditDlg").destroyRecursive();
111
112                 if (dijit.byId("filterEditDlg"))
113                         dijit.byId("filterEditDlg").destroyRecursive();
114
115                 dialog = new dijit.Dialog({
116                         id: "filterEditDlg",
117                         title: __("Edit Filter"),
118                         style: "width: 600px",
119                         test: function() {
120                                 var query = "backend.php?" + dojo.formToQuery("filter_edit_form") + "&savemode=test";
121
122                                 if (dijit.byId("filterTestDlg"))
123                                         dijit.byId("filterTestDlg").destroyRecursive();
124
125                                 var test_dlg = new dijit.Dialog({
126                                         id: "filterTestDlg",
127                                         title: "Test Filter",
128                                         style: "width: 600px",
129                                         href: query});
130
131                                 test_dlg.show();
132                         },
133                         selectRules: function(select) {
134                                 $$("#filterDlg_Matches input[type=checkbox]").each(function(e) {
135                                         e.checked = select;
136                                         if (select)
137                                                 e.parentNode.addClassName("Selected");
138                                         else
139                                                 e.parentNode.removeClassName("Selected");
140                                 });
141                         },
142                         selectActions: function(select) {
143                                 $$("#filterDlg_Actions input[type=checkbox]").each(function(e) {
144                                         e.checked = select;
145
146                                         if (select)
147                                                 e.parentNode.addClassName("Selected");
148                                         else
149                                                 e.parentNode.removeClassName("Selected");
150
151                                 });
152                         },
153                         editRule: function(e) {
154                                 var li = e.parentNode;
155                                 var rule = li.getElementsByTagName("INPUT")[1].value;
156                                 addFilterRule(li, rule);
157                         },
158                         editAction: function(e) {
159                                 var li = e.parentNode;
160                                 var action = li.getElementsByTagName("INPUT")[1].value;
161                                 addFilterAction(li, action);
162                         },
163                         removeFilter: function() {
164                                 var msg = __("Remove filter?");
165
166                                 if (confirm(msg)) {
167                                         this.hide();
168
169                                         notify_progress("Removing filter...");
170
171                                         var id = this.attr('value').id;
172
173                                         var query = "?op=pref-filters&method=remove&ids="+
174                                                 param_escape(id);
175
176                                         new Ajax.Request("backend.php", {
177                                                 parameters: query,
178                                                 onComplete: function(transport) {
179                                                         updateFilterList();
180                                                 } });
181                                 }
182                         },
183                         addAction: function() { addFilterAction(); },
184                         addRule: function() { addFilterRule(); },
185                         deleteAction: function() {
186                                 $$("#filterDlg_Actions li.[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) });
187                         },
188                         deleteRule: function() {
189                                 $$("#filterDlg_Matches li.[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) });
190                         },
191                         execute: function() {
192                                 if (this.validate()) {
193
194                                         notify_progress("Saving data...", true);
195
196                                         var query = dojo.formToQuery("filter_edit_form");
197
198                                         console.log(query);
199
200                                         new Ajax.Request("backend.php", {
201                                                 parameters: query,
202                                                 onComplete: function(transport) {
203                                                         dialog.hide();
204                                                         updateFilterList();
205                                                 }});
206                                 }
207                         },
208                         href: query});
209
210                 dialog.show();
211
212
213         } catch (e) {
214                 exception_error("editFilter", e);
215         }
216 }
217
218 function getSelectedLabels() {
219         var tree = dijit.byId("labelTree");
220         var items = tree.model.getCheckedItems();
221         var rv = [];
222
223         items.each(function(item) {
224                 rv.push(tree.model.store.getValue(item, 'bare_id'));
225         });
226
227         return rv;
228 }
229
230 function getSelectedUsers() {
231         return getSelectedTableRowIds("prefUserList");
232 }
233
234 function getSelectedFeeds() {
235         var tree = dijit.byId("feedTree");
236         var items = tree.model.getCheckedItems();
237         var rv = [];
238
239         items.each(function(item) {
240                 if (item.id[0].match("FEED:"))
241                         rv.push(tree.model.store.getValue(item, 'bare_id'));
242         });
243
244         return rv;
245 }
246
247 function getSelectedCategories() {
248         var tree = dijit.byId("feedTree");
249         var items = tree.model.getCheckedItems();
250         var rv = [];
251
252         items.each(function(item) {
253                 if (item.id[0].match("CAT:"))
254                         rv.push(tree.model.store.getValue(item, 'bare_id'));
255         });
256
257         return rv;
258 }
259
260 function getSelectedFilters() {
261         var tree = dijit.byId("filterTree");
262         var items = tree.model.getCheckedItems();
263         var rv = [];
264
265         items.each(function(item) {
266                 rv.push(tree.model.store.getValue(item, 'bare_id'));
267         });
268
269         return rv;
270
271 }
272
273 function removeSelectedLabels() {
274
275         var sel_rows = getSelectedLabels();
276
277         if (sel_rows.length > 0) {
278
279                 var ok = confirm(__("Remove selected labels?"));
280
281                 if (ok) {
282                         notify_progress("Removing selected labels...");
283
284                         var query = "?op=pref-labels&method=remove&ids="+
285                                 param_escape(sel_rows.toString());
286
287                         new Ajax.Request("backend.php", {
288                                 parameters: query,
289                                 onComplete: function(transport) {
290                                                 updateLabelList();
291                                         } });
292
293                 }
294         } else {
295                 alert(__("No labels are selected."));
296         }
297
298         return false;
299 }
300
301 function removeSelectedUsers() {
302
303         try {
304
305                 var sel_rows = getSelectedUsers();
306
307                 if (sel_rows.length > 0) {
308
309                         var ok = confirm(__("Remove selected users? Neither default admin nor your account will be removed."));
310
311                         if (ok) {
312                                 notify_progress("Removing selected users...");
313
314                                 var query = "?op=pref-users&method=remove&ids="+
315                                         param_escape(sel_rows.toString());
316
317                                 new Ajax.Request("backend.php", {
318                                         parameters: query,
319                                         onComplete: function(transport) {
320                                                 updateUsersList();
321                                         } });
322
323                         }
324
325                 } else {
326                         alert(__("No users are selected."));
327                 }
328
329         } catch (e) {
330                 exception_error("removeSelectedUsers", e);
331         }
332
333         return false;
334 }
335
336 function removeSelectedFilters() {
337
338         try {
339
340                 var sel_rows = getSelectedFilters();
341
342                 if (sel_rows.length > 0) {
343
344                         var ok = confirm(__("Remove selected filters?"));
345
346                         if (ok) {
347                                 notify_progress("Removing selected filters...");
348
349                                 var query = "?op=pref-filters&method=remove&ids="+
350                                         param_escape(sel_rows.toString());
351
352                                 new Ajax.Request("backend.php", {
353                                                 parameters: query,
354                                                 onComplete: function(transport) {
355                                                         updateFilterList();
356                                                 } });
357                         }
358                 } else {
359                         alert(__("No filters are selected."));
360                 }
361
362         } catch (e) {
363                 exception_error("removeSelectedFilters", e);
364         }
365
366         return false;
367 }
368
369
370 function removeSelectedFeeds() {
371
372         try {
373
374                 var sel_rows = getSelectedFeeds();
375
376                 if (sel_rows.length > 0) {
377
378                         var ok = confirm(__("Unsubscribe from selected feeds?"));
379
380                         if (ok) {
381
382                                 notify_progress("Unsubscribing from selected feeds...", true);
383
384                                 var query = "?op=pref-feeds&method=remove&ids="+
385                                         param_escape(sel_rows.toString());
386
387                                 console.log(query);
388
389                                 new Ajax.Request("backend.php", {
390                                         parameters: query,
391                                         onComplete: function(transport) {
392                                                 updateFeedList();
393                                                 } });
394                         }
395
396                 } else {
397                         alert(__("No feeds are selected."));
398                 }
399
400         } catch (e) {
401                 exception_error("removeSelectedFeeds", e);
402         }
403
404         return false;
405 }
406
407 function clearSelectedFeeds() {
408
409         var sel_rows = getSelectedFeeds();
410
411         if (sel_rows.length > 1) {
412                 alert(__("Please select only one feed."));
413                 return;
414         }
415
416         if (sel_rows.length > 0) {
417
418                 var ok = confirm(__("Erase all non-starred articles in selected feed?"));
419
420                 if (ok) {
421                         notify_progress("Clearing selected feed...");
422                         clearFeedArticles(sel_rows[0]);
423                 }
424
425         } else {
426
427                 alert(__("No feeds are selected."));
428
429         }
430
431         return false;
432 }
433
434 function purgeSelectedFeeds() {
435
436         var sel_rows = getSelectedFeeds();
437
438         if (sel_rows.length > 0) {
439
440                 var pr = prompt(__("How many days of articles to keep (0 - use default)?"), "0");
441
442                 if (pr != undefined) {
443                         notify_progress("Purging selected feed...");
444
445                         var query = "?op=rpc&method=purge&ids="+
446                                 param_escape(sel_rows.toString()) + "&days=" + pr;
447
448                         console.log(query);
449
450                         new Ajax.Request("prefs.php",   {
451                                 parameters: query,
452                                 onComplete: function(transport) {
453                                         notify('');
454                                 } });
455                 }
456
457         } else {
458
459                 alert(__("No feeds are selected."));
460
461         }
462
463         return false;
464 }
465
466 function userEditCancel() {
467         closeInfoBox();
468         return false;
469 }
470
471 function userEditSave() {
472
473         try {
474
475                 var login = document.forms["user_edit_form"].login.value;
476
477                 if (login.length == 0) {
478                         alert(__("Login field cannot be blank."));
479                         return;
480                 }
481
482                 notify_progress("Saving user...");
483
484                 closeInfoBox();
485
486                 var query = Form.serialize("user_edit_form");
487
488                 new Ajax.Request("backend.php", {
489                         parameters: query,
490                         onComplete: function(transport) {
491                                 updateUsersList();
492                         } });
493
494         } catch (e) {
495                 exception_error("userEditSave", e);
496         }
497
498         return false;
499
500 }
501
502
503 function editSelectedUser() {
504         var rows = getSelectedUsers();
505
506         if (rows.length == 0) {
507                 alert(__("No users are selected."));
508                 return;
509         }
510
511         if (rows.length > 1) {
512                 alert(__("Please select only one user."));
513                 return;
514         }
515
516         notify("");
517
518         editUser(rows[0]);
519 }
520
521 function resetSelectedUserPass() {
522
523         try {
524
525                 var rows = getSelectedUsers();
526
527                 if (rows.length == 0) {
528                         alert(__("No users are selected."));
529                         return;
530                 }
531
532                 if (rows.length > 1) {
533                         alert(__("Please select only one user."));
534                         return;
535                 }
536
537                 var ok = confirm(__("Reset password of selected user?"));
538
539                 if (ok) {
540                         notify_progress("Resetting password for selected user...");
541
542                         var id = rows[0];
543
544                         var query = "?op=pref-users&method=resetPass&id=" +
545                                 param_escape(id);
546
547                         new Ajax.Request("backend.php", {
548                                 parameters: query,
549                                 onComplete: function(transport) {
550                                         notify_info(transport.responseText, true);
551                                 } });
552
553                 }
554
555         } catch (e) {
556                 exception_error("resetSelectedUserPass", e);
557         }
558 }
559
560 function selectedUserDetails() {
561
562         try {
563
564                 var rows = getSelectedUsers();
565
566                 if (rows.length == 0) {
567                         alert(__("No users are selected."));
568                         return;
569                 }
570
571                 if (rows.length > 1) {
572                         alert(__("Please select only one user."));
573                         return;
574                 }
575
576                 notify_progress("Loading, please wait...");
577
578                 var id = rows[0];
579
580                 var query = "?op=pref-users&method=userdetails&id=" + id;
581
582                 new Ajax.Request("backend.php", {
583                         parameters: query,
584                         onComplete: function(transport) {
585                                         infobox_callback2(transport, __("User details"));
586                                 } });
587         } catch (e) {
588                 exception_error("selectedUserDetails", e);
589         }
590 }
591
592
593 function editSelectedFilter() {
594         var rows = getSelectedFilters();
595
596         if (rows.length == 0) {
597                 alert(__("No filters are selected."));
598                 return;
599         }
600
601         if (rows.length > 1) {
602                 alert(__("Please select only one filter."));
603                 return;
604         }
605
606         notify("");
607
608         editFilter(rows[0]);
609
610 }
611
612 function joinSelectedFilters() {
613         var rows = getSelectedFilters();
614
615         if (rows.length == 0) {
616                 alert(__("No filters are selected."));
617                 return;
618         }
619
620         var ok = confirm(__("Combine selected filters?"));
621
622         if (ok) {
623                 notify_progress("Joining filters...");
624
625                 var query = "?op=pref-filters&method=join&ids="+
626                         param_escape(rows.toString());
627
628                 console.log(query);
629
630                 new Ajax.Request("backend.php", {
631                         parameters: query,
632                         onComplete: function(transport) {
633                                         updateFilterList();
634                         } });
635         }
636 }
637
638 function editSelectedFeed() {
639         var rows = getSelectedFeeds();
640
641         if (rows.length == 0) {
642                 alert(__("No feeds are selected."));
643                 return;
644         }
645
646         if (rows.length > 1) {
647                 return editSelectedFeeds();
648         }
649
650         notify("");
651
652         editFeed(rows[0], {});
653
654 }
655
656 function editSelectedFeeds() {
657
658         try {
659                 var rows = getSelectedFeeds();
660
661                 if (rows.length == 0) {
662                         alert(__("No feeds are selected."));
663                         return;
664                 }
665
666                 notify_progress("Loading, please wait...");
667
668                 var query = "backend.php?op=pref-feeds&method=editfeeds&ids=" +
669                         param_escape(rows.toString());
670
671                 console.log(query);
672
673                 if (dijit.byId("feedEditDlg"))
674                         dijit.byId("feedEditDlg").destroyRecursive();
675
676                 new Ajax.Request("backend.php", {
677                         parameters: query,
678                         onComplete: function(transport) {
679
680                                 notify("");
681
682                                 var dialog = new dijit.Dialog({
683                                         id: "feedEditDlg",
684                                         title: __("Edit Multiple Feeds"),
685                                         style: "width: 600px",
686                                         getChildByName: function (name) {
687                                                 var rv = null;
688                                                 this.getChildren().each(
689                                                         function(child) {
690                                                                 if (child.name == name) {
691                                                                         rv = child;
692                                                                         return;
693                                                                 }
694                                                         });
695                                                 return rv;
696                                         },
697                                         toggleField: function (checkbox, elem, label) {
698                                                 this.getChildByName(elem).attr('disabled', !checkbox.checked);
699
700                                                 if ($(label))
701                                                         if (checkbox.checked)
702                                                                 $(label).removeClassName('insensitive');
703                                                         else
704                                                                 $(label).addClassName('insensitive');
705
706                                         },
707                                         execute: function() {
708                                                 if (this.validate() && confirm(__("Save changes to selected feeds?"))) {
709                                                         var query = dojo.objectToQuery(this.attr('value'));
710
711                                                         /* Form.serialize ignores unchecked checkboxes */
712
713                                                         if (!query.match("&private=") &&
714                                                                         this.getChildByName('private').attr('disabled') == false) {
715                                                                 query = query + "&private=false";
716                                                         }
717
718                                                         try {
719                                                                 if (!query.match("&cache_images=") &&
720                                                                                 this.getChildByName('cache_images').attr('disabled') == false) {
721                                                                         query = query + "&cache_images=false";
722                                                                 }
723                                                         } catch (e) { }
724
725                                                         try {
726                                                                 if (!query.match("&hide_images=") &&
727                                                                                 this.getChildByName('hide_images').attr('disabled') == false) {
728                                                                         query = query + "&hide_images=false";
729                                                                 }
730                                                         } catch (e) { }
731
732                                                         if (!query.match("&include_in_digest=") &&
733                                                                         this.getChildByName('include_in_digest').attr('disabled') == false) {
734                                                                 query = query + "&include_in_digest=false";
735                                                         }
736
737                                                         if (!query.match("&always_display_enclosures=") &&
738                                                                         this.getChildByName('always_display_enclosures').attr('disabled') == false) {
739                                                                 query = query + "&always_display_enclosures=false";
740                                                         }
741
742                                                         if (!query.match("&mark_unread_on_update=") &&
743                                                                         this.getChildByName('mark_unread_on_update').attr('disabled') == false) {
744                                                                 query = query + "&mark_unread_on_update=false";
745                                                         }
746
747                                                         console.log(query);
748
749                                                         notify_progress("Saving data...", true);
750
751                                                         new Ajax.Request("backend.php", {
752                                                                 parameters: query,
753                                                                 onComplete: function(transport) {
754                                                                         dialog.hide();
755                                                                         updateFeedList();
756                                                         }});
757                                                 }
758                                         },
759                                         content: transport.responseText});
760
761                                         dialog.show();
762
763                         } });
764
765         } catch (e) {
766                 exception_error("editSelectedFeeds", e);
767         }
768 }
769
770 function opmlImportComplete(iframe) {
771         try {
772                 if (!iframe.contentDocument.body.innerHTML) return false;
773
774                 Element.show(iframe);
775
776                 notify('');
777
778                 if (dijit.byId('opmlImportDlg'))
779                         dijit.byId('opmlImportDlg').destroyRecursive();
780
781                 var content = iframe.contentDocument.body.innerHTML;
782
783                 dialog = new dijit.Dialog({
784                         id: "opmlImportDlg",
785                         title: __("OPML Import"),
786                         style: "width: 600px",
787                         onCancel: function() {
788                                 updateFeedList();
789                                 updateFilterList();
790                                 updateLabelList();
791                         },
792                         execute: function() {
793                                 updateFeedList();
794                                 updateFilterList();
795                                 updateLabelList();
796                                 this.hide();
797                         },
798                         content: content});
799
800                 dialog.show();
801
802         } catch (e) {
803                 exception_error("opmlImportComplete", e);
804         }
805 }
806
807 function opmlImport() {
808
809         var opml_file = $("opml_file");
810
811         if (opml_file.value.length == 0) {
812                 alert(__("Please choose an OPML file first."));
813                 return false;
814         } else {
815                 notify_progress("Importing, please wait...", true);
816
817                 Element.show("upload_iframe");
818
819                 return true;
820         }
821 }
822
823
824 function updateFilterList() {
825         var user_search = $("filter_search");
826         var search = "";
827         if (user_search) { search = user_search.value; }
828
829         new Ajax.Request("backend.php", {
830                 parameters: "?op=pref-filters&search=" + param_escape(search),
831                 onComplete: function(transport) {
832                         dijit.byId('filterConfigTab').attr('content', transport.responseText);
833                         notify("");
834                 } });
835 }
836
837 function updateLabelList() {
838         new Ajax.Request("backend.php", {
839                 parameters: "?op=pref-labels",
840                 onComplete: function(transport) {
841                         dijit.byId('labelConfigTab').attr('content', transport.responseText);
842                         notify("");
843                 } });
844 }
845
846 function updatePrefsList() {
847         new Ajax.Request("backend.php", {
848                 parameters: "?op=pref-prefs",
849                 onComplete: function(transport) {
850                         dijit.byId('genConfigTab').attr('content', transport.responseText);
851                         notify("");
852                 } });
853 }
854
855 function updateSystemList() {
856         new Ajax.Request("backend.php", {
857                 parameters: "?op=pref-system",
858                 onComplete: function(transport) {
859                         dijit.byId('systemConfigTab').attr('content', transport.responseText);
860                         notify("");
861                 } });
862 }
863
864 function selectTab(id, noupdate, method) {
865         try {
866                 if (!noupdate) {
867                         notify_progress("Loading, please wait...");
868
869                         if (id == "feedConfig") {
870                                 updateFeedList();
871                         } else if (id == "filterConfig") {
872                                 updateFilterList();
873                         } else if (id == "labelConfig") {
874                                 updateLabelList();
875                         } else if (id == "genConfig") {
876                                 updatePrefsList();
877                         } else if (id == "userConfig") {
878                                 updateUsersList();
879                         } else if (id == "systemConfig") {
880                                 updateSystemList();
881                         }
882
883                         var tab = dijit.byId(id + "Tab");
884                         dijit.byId("pref-tabs").selectChild(tab);
885
886                 }
887
888         } catch (e) {
889                 exception_error("selectTab", e);
890         }
891 }
892
893 function init_second_stage() {
894         try {
895
896                 document.onkeydown = pref_hotkey_handler;
897                 loading_set_progress(50);
898                 notify("");
899
900                 dojo.addOnLoad(function() {
901                         var tab = getURLParam('tab');
902
903                         if (tab) {
904                                 tab = dijit.byId(tab + "Tab");
905                                 if (tab) dijit.byId("pref-tabs").selectChild(tab);
906                         }
907
908                         var method = getURLParam('method');
909
910                         if (method == 'editFeed') {
911                                 var param = getURLParam('methodparam');
912
913                                 window.setTimeout('editFeed(' + param + ')', 100);
914                         }
915                 });
916
917                 setTimeout("hotkey_prefix_timeout()", 5*1000);
918
919         } catch (e) {
920                 exception_error("init_second_stage", e);
921         }
922 }
923
924 function init() {
925
926         try {
927                 dojo.registerModulePath("lib", "..");
928                 dojo.registerModulePath("fox", "../../js/");
929
930                 dojo.require("dijit.ColorPalette");
931                 dojo.require("dijit.Dialog");
932                 dojo.require("dijit.form.Button");
933                 dojo.require("dijit.form.CheckBox");
934                 dojo.require("dijit.form.DropDownButton");
935                 dojo.require("dijit.form.FilteringSelect");
936                 dojo.require("dijit.form.Form");
937                 dojo.require("dijit.form.RadioButton");
938                 dojo.require("dijit.form.Select");
939                 dojo.require("dijit.form.SimpleTextarea");
940                 dojo.require("dijit.form.TextBox");
941                 dojo.require("dijit.form.ValidationTextBox");
942                 dojo.require("dijit.InlineEditBox");
943                 dojo.require("dijit.layout.AccordionContainer");
944                 dojo.require("dijit.layout.BorderContainer");
945                 dojo.require("dijit.layout.ContentPane");
946                 dojo.require("dijit.layout.TabContainer");
947                 dojo.require("dijit.Menu");
948                 dojo.require("dijit.ProgressBar");
949                 dojo.require("dijit.ProgressBar");
950                 dojo.require("dijit.Toolbar");
951                 dojo.require("dijit.Tree");
952                 dojo.require("dijit.tree.dndSource");
953                 dojo.require("dojo.data.ItemFileWriteStore");
954
955                 dojo.require("lib.CheckBoxTree");
956                 dojo.require("fox.PrefFeedTree");
957                 dojo.require("fox.PrefFilterTree");
958                 dojo.require("fox.PrefLabelTree");
959
960                 dojo.parser.parse();
961
962                 dojo.addOnLoad(function() {
963                         loading_set_progress(50);
964
965                         var clientTzOffset = new Date().getTimezoneOffset() * 60;
966
967                         new Ajax.Request("backend.php", {
968                                 parameters: {op: "rpc", method: "sanityCheck",
969                                         clientTzOffset: clientTzOffset },
970                                         onComplete: function(transport) {
971                                         backend_sanity_check_callback(transport);
972                                 } });
973                 });
974
975         } catch (e) {
976                 exception_error("init", e);
977         }
978 }
979
980 function validatePrefsReset() {
981         try {
982                 var ok = confirm(__("Reset to defaults?"));
983
984                 if (ok) {
985
986                         query = "?op=pref-prefs&method=resetconfig";
987                         console.log(query);
988
989                         new Ajax.Request("backend.php", {
990                                 parameters: query,
991                                 onComplete: function(transport) {
992                                         updatePrefsList();
993                                         notify_info(transport.responseText);
994                                 } });
995
996                 }
997
998         } catch (e) {
999                 exception_error("validatePrefsReset", e);
1000         }
1001
1002         return false;
1003
1004 }
1005
1006 function pref_hotkey_handler(e) {
1007         try {
1008
1009                 if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return;
1010
1011                 var keycode = false;
1012                 var shift_key = false;
1013
1014                 var cmdline = $('cmdline');
1015
1016                 try {
1017                         shift_key = e.shiftKey;
1018                 } catch (e) {
1019
1020                 }
1021
1022                 if (window.event) {
1023                         keycode = window.event.keyCode;
1024                 } else if (e) {
1025                         keycode = e.which;
1026                 }
1027
1028                 var keychar = String.fromCharCode(keycode);
1029
1030                 if (keycode == 27) { // escape
1031                         hotkey_prefix = false;
1032                 }
1033
1034                 if (keycode == 16) return; // ignore lone shift
1035                 if (keycode == 17) return; // ignore lone ctrl
1036
1037                 if (!shift_key) keychar = keychar.toLowerCase();
1038
1039                 var hotkeys = getInitParam("hotkeys");
1040
1041                 if (!hotkey_prefix && hotkeys[0].indexOf(keychar) != -1) {
1042
1043                         var date = new Date();
1044                         var ts = Math.round(date.getTime() / 1000);
1045
1046                         hotkey_prefix = keychar;
1047                         hotkey_prefix_pressed = ts;
1048
1049                         cmdline.innerHTML = keychar;
1050                         Element.show(cmdline);
1051
1052                         return true;
1053                 }
1054
1055                 Element.hide(cmdline);
1056
1057                 var hotkey = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")";
1058                 hotkey = hotkey_prefix ? hotkey_prefix + " " + hotkey : hotkey;
1059                 hotkey_prefix = false;
1060
1061                 var hotkey_action = false;
1062                 var hotkeys = getInitParam("hotkeys");
1063
1064                 for (sequence in hotkeys[1]) {
1065                         if (sequence == hotkey) {
1066                                 hotkey_action = hotkeys[1][sequence];
1067                                 break;
1068                         }
1069                 }
1070
1071                 switch (hotkey_action) {
1072                 case "feed_subscribe":
1073                         quickAddFeed();
1074                         return false;
1075                 case "create_label":
1076                         addLabel();
1077                         return false;
1078                 case "create_filter":
1079                         quickAddFilter();
1080                         return false;
1081                 case "help_dialog":
1082                         //helpDialog("prefs");
1083                         return false;
1084                 default:
1085                         console.log("unhandled action: " + hotkey_action + "; hotkey: " + hotkey);
1086                 }
1087
1088         } catch (e) {
1089                 exception_error("hotkey_handler", e);
1090         }
1091 }
1092
1093 function removeCategory(id, item) {
1094         try {
1095
1096                 var ok = confirm(__("Remove category %s? Any nested feeds would be placed into Uncategorized.").replace("%s", item.name));
1097
1098                 if (ok) {
1099                         var query = "?op=pref-feeds&method=removeCat&ids="+
1100                                 param_escape(id);
1101
1102                         notify_progress("Removing category...");
1103
1104                         new Ajax.Request("backend.php", {
1105                                 parameters: query,
1106                                 onComplete: function(transport) {
1107                                         notify('');
1108                                         updateFeedList();
1109                                 } });
1110                         }
1111
1112         } catch (e) {
1113                 exception_error("removeCategory", e);
1114         }
1115 }
1116
1117 function removeSelectedCategories() {
1118
1119         var sel_rows = getSelectedCategories();
1120
1121         if (sel_rows.length > 0) {
1122
1123                 var ok = confirm(__("Remove selected categories?"));
1124
1125                 if (ok) {
1126                         notify_progress("Removing selected categories...");
1127
1128                         var query = "?op=pref-feeds&method=removeCat&ids="+
1129                                 param_escape(sel_rows.toString());
1130
1131                         new Ajax.Request("backend.php", {
1132                                 parameters: query,
1133                                 onComplete: function(transport) {
1134                                                 updateFeedList();
1135                                         } });
1136
1137                 }
1138         } else {
1139                 alert(__("No categories are selected."));
1140         }
1141
1142         return false;
1143 }
1144
1145 function createCategory() {
1146         try {
1147                 var title = prompt(__("Category title:"));
1148
1149                 if (title) {
1150
1151                         notify_progress("Creating category...");
1152
1153                         var query = "?op=pref-feeds&method=addCat&cat=" +
1154                                 param_escape(title);
1155
1156                         new Ajax.Request("backend.php", {
1157                                 parameters: query,
1158                                 onComplete: function(transport) {
1159                                         notify('');
1160                                         updateFeedList();
1161                                 } });
1162                 }
1163
1164         } catch (e) {
1165                 exception_error("createCategory", e);
1166         }
1167 }
1168
1169 function showInactiveFeeds() {
1170         try {
1171                 var query = "backend.php?op=pref-feeds&method=inactiveFeeds";
1172
1173                 if (dijit.byId("inactiveFeedsDlg"))
1174                         dijit.byId("inactiveFeedsDlg").destroyRecursive();
1175
1176                 dialog = new dijit.Dialog({
1177                         id: "inactiveFeedsDlg",
1178                         title: __("Feeds without recent updates"),
1179                         style: "width: 600px",
1180                         getSelectedFeeds: function() {
1181                                 return getSelectedTableRowIds("prefInactiveFeedList");
1182                         },
1183                         removeSelected: function() {
1184                                 var sel_rows = this.getSelectedFeeds();
1185
1186                                 console.log(sel_rows);
1187
1188                                 if (sel_rows.length > 0) {
1189                                         var ok = confirm(__("Remove selected feeds?"));
1190
1191                                         if (ok) {
1192                                                 notify_progress("Removing selected feeds...", true);
1193
1194                                                 var query = "?op=pref-feeds&method=remove&ids="+
1195                                                         param_escape(sel_rows.toString());
1196
1197                                                 new Ajax.Request("backend.php", {
1198                                                         parameters: query,
1199                                                         onComplete: function(transport) {
1200                                                                 notify('');
1201                                                                 dialog.hide();
1202                                                                 updateFeedList();
1203                                                         } });
1204                                         }
1205
1206                                 } else {
1207                                         alert(__("No feeds are selected."));
1208                                 }
1209                         },
1210                         execute: function() {
1211                                 if (this.validate()) {
1212                                 }
1213                         },
1214                         href: query});
1215
1216                 dialog.show();
1217
1218         } catch (e) {
1219                 exception_error("showInactiveFeeds", e);
1220         }
1221
1222 }
1223
1224 function opmlRegenKey() {
1225
1226         try {
1227                 var ok = confirm(__("Replace current OPML publishing address with a new one?"));
1228
1229                 if (ok) {
1230
1231                         notify_progress("Trying to change address...", true);
1232
1233                         var query = "?op=pref-feeds&method=regenOPMLKey";
1234
1235                         new Ajax.Request("backend.php", {
1236                                 parameters: query,
1237                                 onComplete: function(transport) {
1238                                                 var reply = JSON.parse(transport.responseText);
1239
1240                                                 var new_link = reply.link;
1241
1242                                                 var e = $('pub_opml_url');
1243
1244                                                 if (new_link) {
1245                                                         e.href = new_link;
1246                                                         e.innerHTML = new_link;
1247
1248                                                         new Effect.Highlight(e);
1249
1250                                                         notify('');
1251
1252                                                 } else {
1253                                                         notify_error("Could not change feed URL.");
1254                                                 }
1255                                 } });
1256                 }
1257         } catch (e) {
1258                 exception_error("opmlRegenKey", e);
1259         }
1260         return false;
1261 }
1262
1263 function feedActionChange() {
1264         try {
1265                 var chooser = $("feedActionChooser");
1266                 var opid = chooser[chooser.selectedIndex].value;
1267
1268                 chooser.selectedIndex = 0;
1269                 feedActionGo(opid);
1270         } catch (e) {
1271                 exception_error("feedActionChange", e);
1272         }
1273 }
1274
1275 function feedActionGo(op) {
1276         try {
1277                 if (op == "facEdit") {
1278
1279                         var rows = getSelectedFeeds();
1280
1281                         if (rows.length > 1) {
1282                                 editSelectedFeeds();
1283                         } else {
1284                                 editSelectedFeed();
1285                         }
1286                 }
1287
1288                 if (op == "facClear") {
1289                         clearSelectedFeeds();
1290                 }
1291
1292                 if (op == "facPurge") {
1293                         purgeSelectedFeeds();
1294                 }
1295
1296                 if (op == "facEditCats") {
1297                         editFeedCats();
1298                 }
1299
1300                 if (op == "facRescore") {
1301                         rescoreSelectedFeeds();
1302                 }
1303
1304                 if (op == "facUnsubscribe") {
1305                         removeSelectedFeeds();
1306                 }
1307
1308         } catch (e) {
1309                 exception_error("feedActionGo", e);
1310
1311         }
1312 }
1313
1314 function clearFeedArticles(feed_id) {
1315
1316         notify_progress("Clearing feed...");
1317
1318         var query = "?op=pref-feeds&quiet=1&method=clear&id=" + feed_id;
1319
1320         new Ajax.Request("backend.php", {
1321                 parameters: query,
1322                 onComplete: function(transport) {
1323                                 notify('');
1324                         } });
1325
1326         return false;
1327 }
1328
1329 function rescoreSelectedFeeds() {
1330
1331         var sel_rows = getSelectedFeeds();
1332
1333         if (sel_rows.length > 0) {
1334
1335                 //var ok = confirm(__("Rescore last 100 articles in selected feeds?"));
1336                 var ok = confirm(__("Rescore articles in selected feeds?"));
1337
1338                 if (ok) {
1339                         notify_progress("Rescoring selected feeds...", true);
1340
1341                         var query = "?op=pref-feeds&method=rescore&quiet=1&ids="+
1342                                 param_escape(sel_rows.toString());
1343
1344                         new Ajax.Request("backend.php", {
1345                                 parameters: query,
1346                                 onComplete: function(transport) {
1347                                                 notify_callback2(transport);
1348                         } });
1349
1350                 }
1351         } else {
1352                 alert(__("No feeds are selected."));
1353         }
1354
1355         return false;
1356 }
1357
1358 function rescore_all_feeds() {
1359         var ok = confirm(__("Rescore all articles? This operation may take a lot of time."));
1360
1361         if (ok) {
1362                 notify_progress("Rescoring feeds...", true);
1363
1364                 var query = "?op=pref-feeds&method=rescoreAll&quiet=1";
1365
1366                 new Ajax.Request("backend.php", {
1367                         parameters: query,
1368                         onComplete: function(transport) {
1369                                         notify_callback2(transport);
1370                 } });
1371         }
1372 }
1373
1374 function labelColorReset() {
1375         try {
1376                 var labels = getSelectedLabels();
1377
1378                 if (labels.length > 0) {
1379                         var ok = confirm(__("Reset selected labels to default colors?"));
1380
1381                         if (ok) {
1382                                 var query = "?op=pref-labels&method=colorreset&ids="+
1383                                         param_escape(labels.toString());
1384
1385                                 new Ajax.Request("backend.php", {
1386                                         parameters: query,
1387                                         onComplete: function(transport) {
1388                                                 updateLabelList();
1389                                         } });
1390                         }
1391
1392                 } else {
1393                         alert(__("No labels are selected."));
1394                 }
1395
1396         } catch (e) {
1397                 exception_error("labelColorReset", e);
1398         }
1399 }
1400
1401
1402 function inPreferences() {
1403         return true;
1404 }
1405
1406 function editProfiles() {
1407         try {
1408
1409                 if (dijit.byId("profileEditDlg"))
1410                         dijit.byId("profileEditDlg").destroyRecursive();
1411
1412                 var query = "backend.php?op=pref-prefs&method=editPrefProfiles";
1413
1414                 dialog = new dijit.Dialog({
1415                         id: "profileEditDlg",
1416                         title: __("Settings Profiles"),
1417                         style: "width: 600px",
1418                         getSelectedProfiles: function() {
1419                                 return getSelectedTableRowIds("prefFeedProfileList");
1420                         },
1421                         removeSelected: function() {
1422                                 var sel_rows = this.getSelectedProfiles();
1423
1424                                 if (sel_rows.length > 0) {
1425                                         var ok = confirm(__("Remove selected profiles? Active and default profiles will not be removed."));
1426
1427                                         if (ok) {
1428                                                 notify_progress("Removing selected profiles...", true);
1429
1430                                                 var query = "?op=rpc&method=remprofiles&ids="+
1431                                                         param_escape(sel_rows.toString());
1432
1433                                                 new Ajax.Request("backend.php", {
1434                                                         parameters: query,
1435                                                         onComplete: function(transport) {
1436                                                                 notify('');
1437                                                                 editProfiles();
1438                                                         } });
1439
1440                                         }
1441
1442                                 } else {
1443                                         alert(__("No profiles are selected."));
1444                                 }
1445                         },
1446                         activateProfile: function() {
1447                                 var sel_rows = this.getSelectedProfiles();
1448
1449                                 if (sel_rows.length == 1) {
1450
1451                                         var ok = confirm(__("Activate selected profile?"));
1452
1453                                         if (ok) {
1454                                                 notify_progress("Loading, please wait...");
1455
1456                                                 var query = "?op=rpc&method=setprofile&id="+
1457                                                         param_escape(sel_rows.toString());
1458
1459                                                 new Ajax.Request("backend.php", {
1460                                                         parameters: query,
1461                                                         onComplete: function(transport) {
1462                                                                 window.location.reload();
1463                                                         } });
1464                                         }
1465
1466                                 } else {
1467                                         alert(__("Please choose a profile to activate."));
1468                                 }
1469                         },
1470                         addProfile: function() {
1471                                 if (this.validate()) {
1472                                         notify_progress("Creating profile...", true);
1473
1474                                         var query = "?op=rpc&method=addprofile&title=" +
1475                                                 param_escape(dialog.attr('value').newprofile);
1476
1477                                         new Ajax.Request("backend.php", {
1478                                                 parameters: query,
1479                                                 onComplete: function(transport) {
1480                                                         notify('');
1481                                                         editProfiles();
1482                                                 } });
1483
1484                                 }
1485                         },
1486                         execute: function() {
1487                                 if (this.validate()) {
1488                                 }
1489                         },
1490                         href: query});
1491
1492                 dialog.show();
1493         } catch (e) {
1494                 exception_error("editProfiles", e);
1495         }
1496 }
1497
1498 function activatePrefProfile() {
1499
1500         var sel_rows = getSelectedFeedCats();
1501
1502         if (sel_rows.length == 1) {
1503
1504                 var ok = confirm(__("Activate selected profile?"));
1505
1506                 if (ok) {
1507                         notify_progress("Loading, please wait...");
1508
1509                         var query = "?op=rpc&method=setprofile&id="+
1510                                 param_escape(sel_rows.toString());
1511
1512                         new Ajax.Request("backend.php", {
1513                                 parameters: query,
1514                                 onComplete: function(transport) {
1515                                         window.location.reload();
1516                                 } });
1517                 }
1518
1519         } else {
1520                 alert(__("Please choose a profile to activate."));
1521         }
1522
1523         return false;
1524 }
1525
1526 function clearFeedAccessKeys() {
1527
1528         var ok = confirm(__("This will invalidate all previously generated feed URLs. Continue?"));
1529
1530         if (ok) {
1531                 notify_progress("Clearing URLs...");
1532
1533                 var query = "?op=pref-feeds&method=clearKeys";
1534
1535                 new Ajax.Request("backend.php", {
1536                         parameters: query,
1537                         onComplete: function(transport) {
1538                                 notify_info("Generated URLs cleared.");
1539                         } });
1540         }
1541
1542         return false;
1543 }
1544
1545 function clearArticleAccessKeys() {
1546
1547         var ok = confirm(__("This will invalidate all previously shared article URLs. Continue?"));
1548
1549         if (ok) {
1550                 notify_progress("Clearing URLs...");
1551
1552                 var query = "?op=rpc&method=clearArticleKeys";
1553
1554                 new Ajax.Request("backend.php", {
1555                         parameters: query,
1556                         onComplete: function(transport) {
1557                                 notify_info("Shared URLs cleared.");
1558                         } });
1559         }
1560
1561         return false;
1562 }
1563
1564 function resetFilterOrder() {
1565         try {
1566                 notify_progress("Loading, please wait...");
1567
1568                 new Ajax.Request("backend.php", {
1569                         parameters: "?op=pref-filters&method=filtersortreset",
1570                         onComplete: function(transport) {
1571                                 updateFilterList();
1572                         } });
1573
1574
1575         } catch (e) {
1576                 exception_error("resetFilterOrder");
1577         }
1578 }
1579
1580
1581 function resetFeedOrder() {
1582         try {
1583                 notify_progress("Loading, please wait...");
1584
1585                 new Ajax.Request("backend.php", {
1586                         parameters: "?op=pref-feeds&method=feedsortreset",
1587                         onComplete: function(transport) {
1588                                 updateFeedList();
1589                         } });
1590
1591
1592         } catch (e) {
1593                 exception_error("resetFeedOrder");
1594         }
1595 }
1596
1597 function resetCatOrder() {
1598         try {
1599                 notify_progress("Loading, please wait...");
1600
1601                 new Ajax.Request("backend.php", {
1602                         parameters: "?op=pref-feeds&method=catsortreset",
1603                         onComplete: function(transport) {
1604                                 updateFeedList();
1605                         } });
1606
1607
1608         } catch (e) {
1609                 exception_error("resetCatOrder");
1610         }
1611 }
1612
1613 function editCat(id, item, event) {
1614         try {
1615                 var new_name = prompt(__('Rename category to:'), item.name);
1616
1617                 if (new_name && new_name != item.name) {
1618
1619                         notify_progress("Loading, please wait...");
1620
1621                         new Ajax.Request("backend.php", {
1622                         parameters: {
1623                                 op: 'pref-feeds',
1624                                 method: 'renamecat',
1625                                 id: id,
1626                                 title: new_name,
1627                         },
1628                         onComplete: function(transport) {
1629                                 updateFeedList();
1630                         } });
1631                 }
1632
1633         } catch (e) {
1634                 exception_error("editCat", e);
1635         }
1636 }
1637
1638 function editLabel(id, event) {
1639         try {
1640                 var query = "backend.php?op=pref-labels&method=edit&id=" +
1641                         param_escape(id);
1642
1643                 if (dijit.byId("labelEditDlg"))
1644                         dijit.byId("labelEditDlg").destroyRecursive();
1645
1646                 dialog = new dijit.Dialog({
1647                         id: "labelEditDlg",
1648                         title: __("Label Editor"),
1649                         style: "width: 600px",
1650                         setLabelColor: function(id, fg, bg) {
1651
1652                                 var kind = '';
1653                                 var color = '';
1654
1655                                 if (fg && bg) {
1656                                         kind = 'both';
1657                                 } else if (fg) {
1658                                         kind = 'fg';
1659                                         color = fg;
1660                                 } else if (bg) {
1661                                         kind = 'bg';
1662                                         color = bg;
1663                                 }
1664
1665                                 var query = "?op=pref-labels&method=colorset&kind="+kind+
1666                                         "&ids=" + param_escape(id) + "&fg=" + param_escape(fg) +
1667                                         "&bg=" + param_escape(bg) + "&color=" + param_escape(color);
1668
1669                 //              console.log(query);
1670
1671                                 var e = $("LICID-" + id);
1672
1673                                 if (e) {
1674                                         if (fg) e.style.color = fg;
1675                                         if (bg) e.style.backgroundColor = bg;
1676                                 }
1677
1678                                 new Ajax.Request("backend.php", { parameters: query });
1679
1680                                 updateFilterList();
1681                         },
1682                         execute: function() {
1683                                 if (this.validate()) {
1684                                         var caption = this.attr('value').caption;
1685                                         var fg_color = this.attr('value').fg_color;
1686                                         var bg_color = this.attr('value').bg_color;
1687                                         var query = dojo.objectToQuery(this.attr('value'));
1688
1689                                         dijit.byId('labelTree').setNameById(id, caption);
1690                                         this.setLabelColor(id, fg_color, bg_color);
1691                                         this.hide();
1692
1693                                         new Ajax.Request("backend.php", {
1694                                                 parameters: query,
1695                                                 onComplete: function(transport) {
1696                                                         updateFilterList();
1697                                         } });
1698                                 }
1699                         },
1700                         href: query});
1701
1702                 dialog.show();
1703
1704         } catch (e) {
1705                 exception_error("editLabel", e);
1706         }
1707 }
1708
1709
1710 function customizeCSS() {
1711         try {
1712                 var query = "backend.php?op=pref-prefs&method=customizeCSS";
1713
1714                 if (dijit.byId("cssEditDlg"))
1715                         dijit.byId("cssEditDlg").destroyRecursive();
1716
1717                 dialog = new dijit.Dialog({
1718                         id: "cssEditDlg",
1719                         title: __("Customize stylesheet"),
1720                         style: "width: 600px",
1721                         execute: function() {
1722                                 notify_progress('Saving data...', true);
1723                                 new Ajax.Request("backend.php", {
1724                                         parameters: dojo.objectToQuery(this.attr('value')),
1725                                         onComplete: function(transport) {
1726                                                 notify('');
1727                                                 window.location.reload();
1728                                 } });
1729
1730                         },
1731                         href: query});
1732
1733                 dialog.show();
1734
1735         } catch (e) {
1736                 exception_error("customizeCSS", e);
1737         }
1738 }
1739
1740 function insertSSLserial(value) {
1741         try {
1742                 dijit.byId("SSL_CERT_SERIAL").attr('value', value);
1743         } catch (e) {
1744                 exception_error("insertSSLcerial", e);
1745         }
1746 }
1747
1748 function gotoExportOpml(filename, settings) {
1749         tmp = settings ? 1 : 0;
1750         document.location.href = "backend.php?op=opml&method=export&filename=" + filename + "&settings=" + tmp;
1751 }
1752
1753
1754 function batchSubscribe() {
1755         try {
1756                 var query = "backend.php?op=pref-feeds&method=batchSubscribe";
1757
1758                 // overlapping widgets
1759                 if (dijit.byId("batchSubDlg")) dijit.byId("batchSubDlg").destroyRecursive();
1760                 if (dijit.byId("feedAddDlg"))   dijit.byId("feedAddDlg").destroyRecursive();
1761
1762                 var dialog = new dijit.Dialog({
1763                         id: "batchSubDlg",
1764                         title: __("Batch subscribe"),
1765                         style: "width: 600px",
1766                         execute: function() {
1767                                 if (this.validate()) {
1768                                         console.log(dojo.objectToQuery(this.attr('value')));
1769
1770                                         notify_progress(__("Subscribing to feeds..."), true);
1771
1772                                         new Ajax.Request("backend.php", {
1773                                                 parameters: dojo.objectToQuery(this.attr('value')),
1774                                                 onComplete: function(transport) {
1775                                                         notify("");
1776                                                         updateFeedList();
1777                                                         dialog.hide();
1778                                                 } });
1779                                         }
1780                         },
1781                         href: query});
1782
1783                 dialog.show();
1784         } catch (e) {
1785                 exception_error("batchSubscribe", e);
1786         }
1787 }
1788
1789
1790 function toggleAdvancedPrefs() {
1791         try {
1792                 notify_progress("Loading, please wait...");
1793
1794                 new Ajax.Request("backend.php", {
1795                         parameters: "?op=pref-prefs&method=toggleadvanced",
1796                         onComplete: function(transport) {
1797                                 updatePrefsList();
1798                         } });
1799
1800         } catch (e) {
1801                 exception_error("toggleAdvancedPrefs", e);
1802         }
1803 }
1804
1805 function clearPluginData(name) {
1806         try {
1807                 if (confirm(__("Clear stored data for this plugin?"))) {
1808                         notify_progress("Loading, please wait...");
1809
1810                         new Ajax.Request("backend.php", {
1811                                 parameters: "?op=pref-prefs&method=clearplugindata&name=" + param_escape(name),
1812                                 onComplete: function(transport) {
1813                                         notify('');
1814                                         updatePrefsList();
1815                                 } });
1816                 }
1817         } catch (e) {
1818                 exception_error("clearPluginData", e);
1819         }
1820 }
1821
1822 function clearSqlLog() {
1823
1824         if (confirm(__("Clear all messages in the error log?"))) {
1825
1826                 notify_progress("Loading, please wait...");
1827                 var query = "?op=pref-system&method=clearLog";
1828
1829                 new Ajax.Request("backend.php", {
1830                         parameters: query,
1831                         onComplete: function(transport) {
1832                                 updateSystemList();
1833                         } });
1834
1835         }
1836 }
1837
1838