1 var init_params = new Array();
3 var hotkey_prefix = false;
4 var hotkey_prefix_pressed = false;
8 function notify_callback2(transport, sticky) {
9 notify_info(transport.responseText, sticky);
12 function updateFeedList(sort_key) {
14 var user_search = $("feed_search");
16 if (user_search) { search = user_search.value; }
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);
27 function updateInstanceList(sort_key) {
28 new Ajax.Request("backend.php", {
29 parameters: "?op=pref-instances&sort=" + param_escape(sort_key),
30 onComplete: function(transport) {
31 dijit.byId('instanceConfigTab').attr('content', transport.responseText);
32 selectTab("instanceConfig", true);
37 function updateUsersList(sort_key) {
39 var user_search = $("user_search");
41 if (user_search) { search = user_search.value; }
43 var query = "?op=pref-users&sort="
44 + param_escape(sort_key) +
45 "&search=" + param_escape(search);
47 new Ajax.Request("backend.php", {
49 onComplete: function(transport) {
50 dijit.byId('userConfigTab').attr('content', transport.responseText);
51 selectTab("userConfig", true)
56 exception_error("updateUsersList", e);
64 var login = prompt(__("Please enter login:"), "");
71 alert(__("Can't create user: no login specified."));
75 notify_progress("Adding user...");
77 var query = "?op=pref-users&method=add&login=" +
80 new Ajax.Request("backend.php", {
82 onComplete: function(transport) {
83 notify_callback2(transport);
88 exception_error("addUser", e);
92 function editUser(id, event) {
95 if (!event || !event.ctrlKey) {
97 notify_progress("Loading, please wait...");
99 selectTableRows('prefUserList', 'none');
100 selectTableRowById('UMRR-'+id, 'UMCHK-'+id, true);
102 var query = "?op=pref-users&method=edit&id=" +
105 new Ajax.Request("backend.php", {
107 onComplete: function(transport) {
108 infobox_callback2(transport);
109 document.forms['user_edit_form'].login.focus();
112 } else if (event.ctrlKey) {
113 var cb = $('UMCHK-' + id);
114 cb.checked = !cb.checked;
119 exception_error("editUser", e);
124 function editFilter(id) {
127 var query = "backend.php?op=pref-filters&method=edit&id=" + param_escape(id);
129 if (dijit.byId("feedEditDlg"))
130 dijit.byId("feedEditDlg").destroyRecursive();
132 if (dijit.byId("filterEditDlg"))
133 dijit.byId("filterEditDlg").destroyRecursive();
135 dialog = new dijit.Dialog({
137 title: __("Edit Filter"),
138 style: "width: 600px",
140 var query = "backend.php?" + dojo.formToQuery("filter_edit_form") + "&savemode=test";
142 if (dijit.byId("filterTestDlg"))
143 dijit.byId("filterTestDlg").destroyRecursive();
145 var test_dlg = new dijit.Dialog({
147 title: "Test Filter",
148 style: "width: 600px",
153 selectRules: function(select) {
154 $$("#filterDlg_Matches input[type=checkbox]").each(function(e) {
157 e.parentNode.addClassName("Selected");
159 e.parentNode.removeClassName("Selected");
162 selectActions: function(select) {
163 $$("#filterDlg_Actions input[type=checkbox]").each(function(e) {
167 e.parentNode.addClassName("Selected");
169 e.parentNode.removeClassName("Selected");
173 editRule: function(e) {
174 var li = e.parentNode;
175 var rule = li.getElementsByTagName("INPUT")[1].value;
176 addFilterRule(li, rule);
178 editAction: function(e) {
179 var li = e.parentNode;
180 var action = li.getElementsByTagName("INPUT")[1].value;
181 addFilterAction(li, action);
183 removeFilter: function() {
184 var msg = __("Remove filter?");
189 notify_progress("Removing filter...");
191 var id = this.attr('value').id;
193 var query = "?op=pref-filters&method=remove&ids="+
196 new Ajax.Request("backend.php", {
198 onComplete: function(transport) {
203 addAction: function() { addFilterAction(); },
204 addRule: function() { addFilterRule(); },
205 deleteAction: function() {
206 $$("#filterDlg_Actions li.[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) });
208 deleteRule: function() {
209 $$("#filterDlg_Matches li.[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) });
211 execute: function() {
212 if (this.validate()) {
214 notify_progress("Saving data...", true);
216 var query = dojo.formToQuery("filter_edit_form");
220 new Ajax.Request("backend.php", {
222 onComplete: function(transport) {
234 exception_error("editFilter", e);
238 function getSelectedLabels() {
239 var tree = dijit.byId("labelTree");
240 var items = tree.model.getCheckedItems();
243 items.each(function(item) {
244 rv.push(tree.model.store.getValue(item, 'bare_id'));
250 function getSelectedUsers() {
251 return getSelectedTableRowIds("prefUserList");
254 function getSelectedFeeds() {
255 var tree = dijit.byId("feedTree");
256 var items = tree.model.getCheckedItems();
259 items.each(function(item) {
260 if (item.id[0].match("FEED:"))
261 rv.push(tree.model.store.getValue(item, 'bare_id'));
267 function getSelectedFilters() {
268 var tree = dijit.byId("filterTree");
269 var items = tree.model.getCheckedItems();
272 items.each(function(item) {
273 rv.push(tree.model.store.getValue(item, 'bare_id'));
280 /* function getSelectedFeedCats() {
281 return getSelectedTableRowIds("prefFeedCatList");
284 function removeSelectedLabels() {
286 var sel_rows = getSelectedLabels();
288 if (sel_rows.length > 0) {
290 var ok = confirm(__("Remove selected labels?"));
293 notify_progress("Removing selected labels...");
295 var query = "?op=pref-labels&method=remove&ids="+
296 param_escape(sel_rows.toString());
298 new Ajax.Request("backend.php", {
300 onComplete: function(transport) {
306 alert(__("No labels are selected."));
312 function removeSelectedUsers() {
316 var sel_rows = getSelectedUsers();
318 if (sel_rows.length > 0) {
320 var ok = confirm(__("Remove selected users? Neither default admin nor your account will be removed."));
323 notify_progress("Removing selected users...");
325 var query = "?op=pref-users&method=remove&ids="+
326 param_escape(sel_rows.toString());
328 new Ajax.Request("backend.php", {
330 onComplete: function(transport) {
337 alert(__("No users are selected."));
341 exception_error("removeSelectedUsers", e);
347 function removeSelectedFilters() {
351 var sel_rows = getSelectedFilters();
353 if (sel_rows.length > 0) {
355 var ok = confirm(__("Remove selected filters?"));
358 notify_progress("Removing selected filters...");
360 var query = "?op=pref-filters&method=remove&ids="+
361 param_escape(sel_rows.toString());
363 new Ajax.Request("backend.php", {
365 onComplete: function(transport) {
370 alert(__("No filters are selected."));
374 exception_error("removeSelectedFilters", e);
381 function removeSelectedFeeds() {
385 var sel_rows = getSelectedFeeds();
387 if (sel_rows.length > 0) {
389 var ok = confirm(__("Unsubscribe from selected feeds?"));
393 notify_progress("Unsubscribing from selected feeds...", true);
395 var query = "?op=pref-feeds&method=remove&ids="+
396 param_escape(sel_rows.toString());
400 new Ajax.Request("backend.php", {
402 onComplete: function(transport) {
408 alert(__("No feeds are selected."));
412 exception_error("removeSelectedFeeds", e);
418 function clearSelectedFeeds() {
420 var sel_rows = getSelectedFeeds();
422 if (sel_rows.length > 1) {
423 alert(__("Please select only one feed."));
427 if (sel_rows.length > 0) {
429 var ok = confirm(__("Erase all non-starred articles in selected feed?"));
432 notify_progress("Clearing selected feed...");
433 clearFeedArticles(sel_rows[0]);
438 alert(__("No feeds are selected."));
445 function purgeSelectedFeeds() {
447 var sel_rows = getSelectedFeeds();
449 if (sel_rows.length > 0) {
451 var pr = prompt(__("How many days of articles to keep (0 - use default)?"), "0");
453 if (pr != undefined) {
454 notify_progress("Purging selected feed...");
456 var query = "?op=rpc&method=purge&ids="+
457 param_escape(sel_rows.toString()) + "&days=" + pr;
461 new Ajax.Request("prefs.php", {
463 onComplete: function(transport) {
470 alert(__("No feeds are selected."));
477 function userEditCancel() {
482 function userEditSave() {
486 var login = document.forms["user_edit_form"].login.value;
488 if (login.length == 0) {
489 alert(__("Login field cannot be blank."));
493 notify_progress("Saving user...");
497 var query = Form.serialize("user_edit_form");
499 new Ajax.Request("backend.php", {
501 onComplete: function(transport) {
506 exception_error("userEditSave", e);
514 function editSelectedUser() {
515 var rows = getSelectedUsers();
517 if (rows.length == 0) {
518 alert(__("No users are selected."));
522 if (rows.length > 1) {
523 alert(__("Please select only one user."));
532 function resetSelectedUserPass() {
536 var rows = getSelectedUsers();
538 if (rows.length == 0) {
539 alert(__("No users are selected."));
543 if (rows.length > 1) {
544 alert(__("Please select only one user."));
548 var ok = confirm(__("Reset password of selected user?"));
551 notify_progress("Resetting password for selected user...");
555 var query = "?op=pref-users&method=resetPass&id=" +
558 new Ajax.Request("backend.php", {
560 onComplete: function(transport) {
561 notify_info(transport.responseText);
567 exception_error("resetSelectedUserPass", e);
571 function selectedUserDetails() {
575 var rows = getSelectedUsers();
577 if (rows.length == 0) {
578 alert(__("No users are selected."));
582 if (rows.length > 1) {
583 alert(__("Please select only one user."));
587 notify_progress("Loading, please wait...");
591 var query = "?op=pref-users&method=userdetails&id=" + id;
593 new Ajax.Request("backend.php", {
595 onComplete: function(transport) {
596 infobox_callback2(transport);
599 exception_error("selectedUserDetails", e);
604 function editSelectedFilter() {
605 var rows = getSelectedFilters();
607 if (rows.length == 0) {
608 alert(__("No filters are selected."));
612 if (rows.length > 1) {
613 alert(__("Please select only one filter."));
623 function joinSelectedFilters() {
624 var rows = getSelectedFilters();
626 if (rows.length == 0) {
627 alert(__("No filters are selected."));
631 var ok = confirm(__("Combine selected filters?"));
634 notify_progress("Joining filters...");
636 var query = "?op=pref-filters&method=join&ids="+
637 param_escape(rows.toString());
641 new Ajax.Request("backend.php", {
643 onComplete: function(transport) {
649 function editSelectedFeed() {
650 var rows = getSelectedFeeds();
652 if (rows.length == 0) {
653 alert(__("No feeds are selected."));
657 if (rows.length > 1) {
658 return editSelectedFeeds();
663 editFeed(rows[0], {});
667 function editSelectedFeeds() {
670 var rows = getSelectedFeeds();
672 if (rows.length == 0) {
673 alert(__("No feeds are selected."));
677 notify_progress("Loading, please wait...");
679 var query = "backend.php?op=pref-feeds&method=editfeeds&ids=" +
680 param_escape(rows.toString());
684 if (dijit.byId("feedEditDlg"))
685 dijit.byId("feedEditDlg").destroyRecursive();
687 new Ajax.Request("backend.php", {
689 onComplete: function(transport) {
693 var dialog = new dijit.Dialog({
695 title: __("Edit Multiple Feeds"),
696 style: "width: 600px",
697 getChildByName: function (name) {
699 this.getChildren().each(
701 if (child.name == name) {
708 toggleField: function (checkbox, elem, label) {
709 this.getChildByName(elem).attr('disabled', !checkbox.checked);
712 if (checkbox.checked)
713 $(label).removeClassName('insensitive');
715 $(label).addClassName('insensitive');
718 execute: function() {
719 if (this.validate() && confirm(__("Save changes to selected feeds?"))) {
720 var query = dojo.objectToQuery(this.attr('value'));
722 /* Form.serialize ignores unchecked checkboxes */
724 if (!query.match("&rtl_content=") &&
725 this.getChildByName('rtl_content').attr('disabled') == false) {
726 query = query + "&rtl_content=false";
729 if (!query.match("&private=") &&
730 this.getChildByName('private').attr('disabled') == false) {
731 query = query + "&private=false";
735 if (!query.match("&cache_images=") &&
736 this.getChildByName('cache_images').attr('disabled') == false) {
737 query = query + "&cache_images=false";
741 if (!query.match("&include_in_digest=") &&
742 this.getChildByName('include_in_digest').attr('disabled') == false) {
743 query = query + "&include_in_digest=false";
746 if (!query.match("&always_display_enclosures=") &&
747 this.getChildByName('always_display_enclosures').attr('disabled') == false) {
748 query = query + "&always_display_enclosures=false";
751 if (!query.match("&mark_unread_on_update=") &&
752 this.getChildByName('mark_unread_on_update').attr('disabled') == false) {
753 query = query + "&mark_unread_on_update=false";
756 if (!query.match("&update_on_checksum_change=") &&
757 this.getChildByName('update_on_checksum_change').attr('disabled') == false) {
758 query = query + "&update_on_checksum_change=false";
763 notify_progress("Saving data...", true);
765 new Ajax.Request("backend.php", {
767 onComplete: function(transport) {
773 content: transport.responseText});
780 exception_error("editSelectedFeeds", e);
784 function piggie(enable) {
786 console.log("I LOVEDED IT!");
787 var piggie = $("piggie");
789 Element.show(piggie);
790 Position.Center(piggie);
796 function opmlImportComplete(iframe) {
798 if (!iframe.contentDocument.body.innerHTML) return false;
800 Element.show(iframe);
804 if (dijit.byId('opmlImportDlg'))
805 dijit.byId('opmlImportDlg').destroyRecursive();
807 var content = iframe.contentDocument.body.innerHTML;
809 dialog = new dijit.Dialog({
811 title: __("OPML Import"),
812 style: "width: 600px",
813 onCancel: function() {
818 execute: function() {
829 exception_error("opmlImportComplete", e);
833 function opmlImport() {
835 var opml_file = $("opml_file");
837 if (opml_file.value.length == 0) {
838 alert(__("Please choose an OPML file first."));
841 notify_progress("Importing, please wait...", true);
843 Element.show("upload_iframe");
849 function importData() {
851 var file = $("export_file");
853 if (file.value.length == 0) {
854 alert(__("Please choose the file first."));
857 notify_progress("Importing, please wait...", true);
859 Element.show("data_upload_iframe");
866 function updateFilterList() {
867 var user_search = $("filter_search");
869 if (user_search) { search = user_search.value; }
871 new Ajax.Request("backend.php", {
872 parameters: "?op=pref-filters&search=" + param_escape(search),
873 onComplete: function(transport) {
874 dijit.byId('filterConfigTab').attr('content', transport.responseText);
879 function updateLabelList() {
880 new Ajax.Request("backend.php", {
881 parameters: "?op=pref-labels",
882 onComplete: function(transport) {
883 dijit.byId('labelConfigTab').attr('content', transport.responseText);
888 function updatePrefsList() {
889 new Ajax.Request("backend.php", {
890 parameters: "?op=pref-prefs",
891 onComplete: function(transport) {
892 dijit.byId('genConfigTab').attr('content', transport.responseText);
897 function selectTab(id, noupdate, method) {
900 notify_progress("Loading, please wait...");
902 if (id == "feedConfig") {
904 } else if (id == "filterConfig") {
906 } else if (id == "labelConfig") {
908 } else if (id == "genConfig") {
910 } else if (id == "userConfig") {
914 var tab = dijit.byId(id + "Tab");
915 dijit.byId("pref-tabs").selectChild(tab);
920 exception_error("selectTab", e);
924 function init_second_stage() {
927 document.onkeydown = pref_hotkey_handler;
928 loading_set_progress(50);
931 dojo.addOnLoad(function() {
932 var tab = getURLParam('tab');
935 tab = dijit.byId(tab + "Tab");
936 if (tab) dijit.byId("pref-tabs").selectChild(tab);
939 var method = getURLParam('method');
941 if (method == 'editFeed') {
942 var param = getURLParam('methodparam');
944 window.setTimeout('editFeed(' + param + ')', 100);
948 setTimeout("hotkey_prefix_timeout()", 5*1000);
951 exception_error("init_second_stage", e);
958 dojo.registerModulePath("lib", "..");
959 dojo.registerModulePath("fox", "../../js/");
961 dojo.require("dijit.ColorPalette");
962 dojo.require("dijit.Dialog");
963 dojo.require("dijit.form.Button");
964 dojo.require("dijit.form.CheckBox");
965 dojo.require("dijit.form.DropDownButton");
966 dojo.require("dijit.form.FilteringSelect");
967 dojo.require("dijit.form.Form");
968 dojo.require("dijit.form.RadioButton");
969 dojo.require("dijit.form.Select");
970 dojo.require("dijit.form.SimpleTextarea");
971 dojo.require("dijit.form.TextBox");
972 dojo.require("dijit.form.ValidationTextBox");
973 dojo.require("dijit.InlineEditBox");
974 dojo.require("dijit.layout.AccordionContainer");
975 dojo.require("dijit.layout.BorderContainer");
976 dojo.require("dijit.layout.ContentPane");
977 dojo.require("dijit.layout.TabContainer");
978 dojo.require("dijit.Menu");
979 dojo.require("dijit.ProgressBar");
980 dojo.require("dijit.ProgressBar");
981 dojo.require("dijit.Toolbar");
982 dojo.require("dijit.Tree");
983 dojo.require("dijit.tree.dndSource");
984 dojo.require("dojo.data.ItemFileWriteStore");
986 dojo.require("lib.CheckBoxTree");
987 dojo.require("fox.PrefFeedTree");
988 dojo.require("fox.PrefFilterTree");
989 dojo.require("fox.PrefLabelTree");
993 dojo.addOnLoad(function() {
994 loading_set_progress(50);
996 new Ajax.Request("backend.php", {
997 parameters: {op: "rpc", method: "sanityCheck"},
998 onComplete: function(transport) {
999 backend_sanity_check_callback(transport);
1004 exception_error("init", e);
1008 function validatePrefsReset() {
1010 var ok = confirm(__("Reset to defaults?"));
1014 query = "?op=pref-prefs&method=resetconfig";
1017 new Ajax.Request("backend.php", {
1019 onComplete: function(transport) {
1020 var msg = transport.responseText;
1021 if (msg.match("PREFS_THEME_CHANGED")) {
1022 window.location.reload();
1032 exception_error("validatePrefsReset", e);
1040 function pref_hotkey_handler(e) {
1042 if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return;
1044 var keycode = false;
1045 var shift_key = false;
1047 var cmdline = $('cmdline');
1050 shift_key = e.shiftKey;
1056 keycode = window.event.keyCode;
1061 var keychar = String.fromCharCode(keycode);
1063 if (keycode == 27) { // escape
1064 if (Element.visible("hotkey_help_overlay")) {
1065 Element.hide("hotkey_help_overlay");
1067 hotkey_prefix = false;
1071 if (keycode == 16) return; // ignore lone shift
1072 if (keycode == 17) return; // ignore lone ctrl
1074 if ((keycode == 67 || keycode == 71) && !hotkey_prefix) {
1075 hotkey_prefix = keycode;
1077 var date = new Date();
1078 var ts = Math.round(date.getTime() / 1000);
1080 hotkey_prefix_pressed = ts;
1082 cmdline.innerHTML = keychar;
1083 Element.show(cmdline);
1085 console.log("KP: PREFIX=" + keycode + " CHAR=" + keychar);
1089 if (Element.visible("hotkey_help_overlay")) {
1090 Element.hide("hotkey_help_overlay");
1093 if (keycode == 13 || keycode == 27) {
1096 seq = seq + "" + keycode;
1099 /* Global hotkeys */
1101 Element.hide(cmdline);
1103 if (!hotkey_prefix) {
1105 if ((keycode == 191 || keychar == '?') && shift_key) { // ?
1110 if (keycode == 191 || keychar == '/') { // /
1111 var search_boxes = new Array("label_search",
1112 "feed_search", "filter_search", "user_search", "feed_browser_search");
1114 for (var i = 0; i < search_boxes.length; i++) {
1115 var elem = $(search_boxes[i]);
1117 $(search_boxes[i]).focus();
1126 if (hotkey_prefix == 67) { // c
1127 hotkey_prefix = false;
1129 if (keycode == 70) { // f
1134 if (keycode == 83) { // s
1139 if (keycode == 85) { // u
1143 if (keycode == 67) { // c
1148 if (keycode == 84 && shift_key) { // T
1157 if (hotkey_prefix == 71) { // g
1159 hotkey_prefix = false;
1161 if (keycode == 49 && $("genConfigTab")) { // 1
1162 selectTab("genConfig");
1166 if (keycode == 50 && $("feedConfigTab")) { // 2
1167 selectTab("feedConfig");
1171 if (keycode == 51 && $("filterConfigTab")) { // 4
1172 selectTab("filterConfig");
1176 if (keycode == 52 && $("labelConfigTab")) { // 5
1177 selectTab("labelConfig");
1181 if (keycode == 53 && $("userConfigTab")) { // 6
1182 selectTab("userConfig");
1186 if (keycode == 88) { // x
1193 if (seq.match("8073717369")) {
1201 if (hotkey_prefix) {
1202 console.log("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar);
1204 console.log("KP: CODE=" + keycode + " CHAR=" + keychar);
1208 exception_error("pref_hotkey_handler", e);
1212 function removeCategory(id, item) {
1215 var ok = confirm(__("Remove category %s? Any nested feeds would be placed into Uncategorized.").replace("%s", item.name));
1218 var query = "?op=pref-feeds&method=removeCat&ids="+
1221 notify_progress("Removing category...");
1223 new Ajax.Request("backend.php", {
1225 onComplete: function(transport) {
1232 exception_error("removeCategory", e);
1236 function createCategory() {
1238 var title = prompt(__("Category title:"));
1242 notify_progress("Creating category...");
1244 var query = "?op=pref-feeds&method=addCat&cat=" +
1245 param_escape(title);
1247 new Ajax.Request("backend.php", {
1249 onComplete: function(transport) {
1256 exception_error("createCategory", e);
1260 function showInactiveFeeds() {
1262 var query = "backend.php?op=dlg&method=inactiveFeeds";
1264 if (dijit.byId("inactiveFeedsDlg"))
1265 dijit.byId("inactiveFeedsDlg").destroyRecursive();
1267 dialog = new dijit.Dialog({
1268 id: "inactiveFeedsDlg",
1269 title: __("Feeds without recent updates"),
1270 style: "width: 600px",
1271 getSelectedFeeds: function() {
1272 return getSelectedTableRowIds("prefInactiveFeedList");
1274 removeSelected: function() {
1275 var sel_rows = this.getSelectedFeeds();
1277 console.log(sel_rows);
1279 if (sel_rows.length > 0) {
1280 var ok = confirm(__("Remove selected feeds?"));
1283 notify_progress("Removing selected feeds...", true);
1285 var query = "?op=pref-feeds&method=remove&ids="+
1286 param_escape(sel_rows.toString());
1288 new Ajax.Request("backend.php", {
1290 onComplete: function(transport) {
1298 alert(__("No feeds are selected."));
1301 execute: function() {
1302 if (this.validate()) {
1310 exception_error("showInactiveFeeds", e);
1315 function opmlRegenKey() {
1318 var ok = confirm(__("Replace current OPML publishing address with a new one?"));
1322 notify_progress("Trying to change address...", true);
1324 var query = "?op=rpc&method=regenOPMLKey";
1326 new Ajax.Request("backend.php", {
1328 onComplete: function(transport) {
1329 var reply = JSON.parse(transport.responseText);
1331 var new_link = reply.link;
1333 var e = $('pub_opml_url');
1337 e.innerHTML = new_link;
1339 new Effect.Highlight(e);
1344 notify_error("Could not change feed URL.");
1349 exception_error("opmlRegenKey", e);
1354 function feedActionChange() {
1356 var chooser = $("feedActionChooser");
1357 var opid = chooser[chooser.selectedIndex].value;
1359 chooser.selectedIndex = 0;
1362 exception_error("feedActionChange", e);
1366 function feedActionGo(op) {
1368 if (op == "facEdit") {
1370 var rows = getSelectedFeeds();
1372 if (rows.length > 1) {
1373 editSelectedFeeds();
1379 if (op == "facClear") {
1380 clearSelectedFeeds();
1383 if (op == "facPurge") {
1384 purgeSelectedFeeds();
1387 if (op == "facEditCats") {
1391 if (op == "facRescore") {
1392 rescoreSelectedFeeds();
1395 if (op == "facUnsubscribe") {
1396 removeSelectedFeeds();
1400 exception_error("feedActionGo", e);
1405 function clearFeedArticles(feed_id) {
1407 notify_progress("Clearing feed...");
1409 var query = "?op=pref-feeds&quiet=1&method=clear&id=" + feed_id;
1411 new Ajax.Request("backend.php", {
1413 onComplete: function(transport) {
1420 function rescoreSelectedFeeds() {
1422 var sel_rows = getSelectedFeeds();
1424 if (sel_rows.length > 0) {
1426 //var ok = confirm(__("Rescore last 100 articles in selected feeds?"));
1427 var ok = confirm(__("Rescore articles in selected feeds?"));
1430 notify_progress("Rescoring selected feeds...", true);
1432 var query = "?op=pref-feeds&method=rescore&quiet=1&ids="+
1433 param_escape(sel_rows.toString());
1435 new Ajax.Request("backend.php", {
1437 onComplete: function(transport) {
1438 notify_callback2(transport);
1443 alert(__("No feeds are selected."));
1449 function rescore_all_feeds() {
1450 var ok = confirm(__("Rescore all articles? This operation may take a lot of time."));
1453 notify_progress("Rescoring feeds...", true);
1455 var query = "?op=pref-feeds&method=rescoreAll&quiet=1";
1457 new Ajax.Request("backend.php", {
1459 onComplete: function(transport) {
1460 notify_callback2(transport);
1465 function labelColorReset() {
1467 var labels = getSelectedLabels();
1469 if (labels.length > 0) {
1470 var ok = confirm(__("Reset selected labels to default colors?"));
1473 var query = "?op=pref-labels&method=colorreset&ids="+
1474 param_escape(labels.toString());
1476 new Ajax.Request("backend.php", {
1478 onComplete: function(transport) {
1484 alert(__("No labels are selected."));
1488 exception_error("labelColorReset", e);
1493 function inPreferences() {
1497 function editProfiles() {
1500 if (dijit.byId("profileEditDlg"))
1501 dijit.byId("profileEditDlg").destroyRecursive();
1503 var query = "backend.php?op=dlg&method=editPrefProfiles";
1505 dialog = new dijit.Dialog({
1506 id: "profileEditDlg",
1507 title: __("Settings Profiles"),
1508 style: "width: 600px",
1509 getSelectedProfiles: function() {
1510 return getSelectedTableRowIds("prefFeedProfileList");
1512 removeSelected: function() {
1513 var sel_rows = this.getSelectedProfiles();
1515 if (sel_rows.length > 0) {
1516 var ok = confirm(__("Remove selected profiles? Active and default profiles will not be removed."));
1519 notify_progress("Removing selected profiles...", true);
1521 var query = "?op=rpc&method=remprofiles&ids="+
1522 param_escape(sel_rows.toString());
1524 new Ajax.Request("backend.php", {
1526 onComplete: function(transport) {
1534 alert(__("No profiles are selected."));
1537 activateProfile: function() {
1538 var sel_rows = this.getSelectedProfiles();
1540 if (sel_rows.length == 1) {
1542 var ok = confirm(__("Activate selected profile?"));
1545 notify_progress("Loading, please wait...");
1547 var query = "?op=rpc&method=setprofile&id="+
1548 param_escape(sel_rows.toString());
1550 new Ajax.Request("backend.php", {
1552 onComplete: function(transport) {
1553 window.location.reload();
1558 alert(__("Please choose a profile to activate."));
1561 addProfile: function() {
1562 if (this.validate()) {
1563 notify_progress("Creating profile...", true);
1565 var query = "?op=rpc&method=addprofile&title=" +
1566 param_escape(dialog.attr('value').newprofile);
1568 new Ajax.Request("backend.php", {
1570 onComplete: function(transport) {
1577 execute: function() {
1578 if (this.validate()) {
1585 exception_error("editProfiles", e);
1589 function activatePrefProfile() {
1591 var sel_rows = getSelectedFeedCats();
1593 if (sel_rows.length == 1) {
1595 var ok = confirm(__("Activate selected profile?"));
1598 notify_progress("Loading, please wait...");
1600 var query = "?op=rpc&method=setprofile&id="+
1601 param_escape(sel_rows.toString());
1603 new Ajax.Request("backend.php", {
1605 onComplete: function(transport) {
1606 window.location.reload();
1611 alert(__("Please choose a profile to activate."));
1617 function clearFeedAccessKeys() {
1619 var ok = confirm(__("This will invalidate all previously generated feed URLs. Continue?"));
1622 notify_progress("Clearing URLs...");
1624 var query = "?op=rpc&method=clearKeys";
1626 new Ajax.Request("backend.php", {
1628 onComplete: function(transport) {
1629 notify_info("Generated URLs cleared.");
1636 function clearArticleAccessKeys() {
1638 var ok = confirm(__("This will invalidate all previously shared article URLs. Continue?"));
1641 notify_progress("Clearing URLs...");
1643 var query = "?op=rpc&method=clearArticleKeys";
1645 new Ajax.Request("backend.php", {
1647 onComplete: function(transport) {
1648 notify_info("Shared URLs cleared.");
1654 function resetFeedOrder() {
1656 notify_progress("Loading, please wait...");
1658 new Ajax.Request("backend.php", {
1659 parameters: "?op=pref-feeds&method=feedsortreset",
1660 onComplete: function(transport) {
1666 exception_error("resetFeedOrder");
1670 function resetCatOrder() {
1672 notify_progress("Loading, please wait...");
1674 new Ajax.Request("backend.php", {
1675 parameters: "?op=pref-feeds&method=catsortreset",
1676 onComplete: function(transport) {
1682 exception_error("resetCatOrder");
1686 function toggleHiddenFeedCats() {
1688 notify_progress("Loading, please wait...");
1690 new Ajax.Request("backend.php", {
1691 parameters: "?op=pref-feeds&method=togglehiddenfeedcats",
1692 onComplete: function(transport) {
1697 exception_error("toggleHiddenFeedCats");
1701 function editCat(id, item, event) {
1703 var new_name = prompt(__('Rename category to:'), item.name);
1705 if (new_name && new_name != item.name) {
1707 notify_progress("Loading, please wait...");
1709 new Ajax.Request("backend.php", {
1712 method: 'renamecat',
1716 onComplete: function(transport) {
1722 exception_error("editCat", e);
1726 function editLabel(id, event) {
1728 var query = "backend.php?op=pref-labels&method=edit&id=" +
1731 if (dijit.byId("labelEditDlg"))
1732 dijit.byId("labelEditDlg").destroyRecursive();
1734 dialog = new dijit.Dialog({
1736 title: __("Label Editor"),
1737 style: "width: 600px",
1738 setLabelColor: function(id, fg, bg) {
1753 var query = "?op=pref-labels&method=colorset&kind="+kind+
1754 "&ids=" + param_escape(id) + "&fg=" + param_escape(fg) +
1755 "&bg=" + param_escape(bg) + "&color=" + param_escape(color);
1757 // console.log(query);
1759 var e = $("LICID-" + id);
1762 if (fg) e.style.color = fg;
1763 if (bg) e.style.backgroundColor = bg;
1766 new Ajax.Request("backend.php", { parameters: query });
1770 execute: function() {
1771 if (this.validate()) {
1772 var caption = this.attr('value').caption;
1773 var fg_color = this.attr('value').fg_color;
1774 var bg_color = this.attr('value').bg_color;
1775 var query = dojo.objectToQuery(this.attr('value'));
1777 dijit.byId('labelTree').setNameById(id, caption);
1778 this.setLabelColor(id, fg_color, bg_color);
1781 new Ajax.Request("backend.php", {
1783 onComplete: function(transport) {
1793 exception_error("editLabel", e);
1797 function clearTwitterCredentials() {
1799 var ok = confirm(__("This will clear your stored authentication information for Twitter. Continue?"));
1802 notify_progress("Clearing credentials...");
1804 var query = "?op=pref-feeds&method=remtwitterinfo";
1806 new Ajax.Request("backend.php", {
1808 onComplete: function(transport) {
1809 notify_info("Twitter credentials have been cleared.");
1815 exception_error("clearTwitterCredentials", e);
1819 function customizeCSS() {
1821 var query = "backend.php?op=dlg&method=customizeCSS";
1823 if (dijit.byId("cssEditDlg"))
1824 dijit.byId("cssEditDlg").destroyRecursive();
1826 dialog = new dijit.Dialog({
1828 title: __("Customize stylesheet"),
1829 style: "width: 600px",
1830 execute: function() {
1831 notify_progress('Saving data...', true);
1832 new Ajax.Request("backend.php", {
1833 parameters: dojo.objectToQuery(this.attr('value')),
1834 onComplete: function(transport) {
1836 window.location.reload();
1845 exception_error("customizeCSS", e);
1849 function insertSSLserial(value) {
1851 dijit.byId("SSL_CERT_SERIAL").attr('value', value);
1853 exception_error("insertSSLcerial", e);
1857 function getSelectedInstances() {
1858 return getSelectedTableRowIds("prefInstanceList");
1861 function addInstance() {
1863 var query = "backend.php?op=dlg&method=addInstance";
1865 if (dijit.byId("instanceAddDlg"))
1866 dijit.byId("instanceAddDlg").destroyRecursive();
1868 dialog = new dijit.Dialog({
1869 id: "instanceAddDlg",
1870 title: __("Link Instance"),
1871 style: "width: 600px",
1872 regenKey: function() {
1873 new Ajax.Request("backend.php", {
1874 parameters: "?op=rpc&method=genHash",
1875 onComplete: function(transport) {
1876 var reply = JSON.parse(transport.responseText);
1878 dijit.byId('instance_add_key').attr('value', reply.hash);
1882 execute: function() {
1883 if (this.validate()) {
1884 console.warn(dojo.objectToQuery(this.attr('value')));
1886 notify_progress('Saving data...', true);
1887 new Ajax.Request("backend.php", {
1888 parameters: dojo.objectToQuery(this.attr('value')),
1889 onComplete: function(transport) {
1892 updateInstanceList();
1902 exception_error("addInstance", e);
1906 function editInstance(id, event) {
1908 if (!event || !event.ctrlKey) {
1910 selectTableRows('prefInstanceList', 'none');
1911 selectTableRowById('LIRR-'+id, 'LICHK-'+id, true);
1913 var query = "backend.php?op=pref-instances&method=edit&id=" +
1916 if (dijit.byId("instanceEditDlg"))
1917 dijit.byId("instanceEditDlg").destroyRecursive();
1919 dialog = new dijit.Dialog({
1920 id: "instanceEditDlg",
1921 title: __("Edit Instance"),
1922 style: "width: 600px",
1923 regenKey: function() {
1924 new Ajax.Request("backend.php", {
1925 parameters: "?op=rpc&method=genHash",
1926 onComplete: function(transport) {
1927 var reply = JSON.parse(transport.responseText);
1929 dijit.byId('instance_edit_key').attr('value', reply.hash);
1933 execute: function() {
1934 if (this.validate()) {
1935 // console.warn(dojo.objectToQuery(this.attr('value')));
1937 notify_progress('Saving data...', true);
1938 new Ajax.Request("backend.php", {
1939 parameters: dojo.objectToQuery(this.attr('value')),
1940 onComplete: function(transport) {
1943 updateInstanceList();
1952 } else if (event.ctrlKey) {
1953 var cb = $('LICHK-' + id);
1954 cb.checked = !cb.checked;
1955 toggleSelectRow(cb);
1960 exception_error("editInstance", e);
1964 function removeSelectedInstances() {
1966 var sel_rows = getSelectedInstances();
1968 if (sel_rows.length > 0) {
1970 var ok = confirm(__("Remove selected instances?"));
1973 notify_progress("Removing selected instances...");
1975 var query = "?op=pref-instances&method=remove&ids="+
1976 param_escape(sel_rows.toString());
1978 new Ajax.Request("backend.php", {
1980 onComplete: function(transport) {
1982 updateInstanceList();
1987 alert(__("No instances are selected."));
1991 exception_error("removeInstance", e);
1995 function editSelectedInstance() {
1996 var rows = getSelectedInstances();
1998 if (rows.length == 0) {
1999 alert(__("No instances are selected."));
2003 if (rows.length > 1) {
2004 alert(__("Please select only one instance."));
2010 editInstance(rows[0]);
2013 function showHelp() {
2015 new Ajax.Request("backend.php", {
2016 parameters: "?op=backend&method=help&topic=prefs",
2017 onComplete: function(transport) {
2018 $("hotkey_help_overlay").innerHTML = transport.responseText;
2019 Effect.Appear("hotkey_help_overlay", {duration : 0.3});
2023 exception_error("showHelp", e);
2027 function exportData() {
2030 var query = "backend.php?op=dlg&method=exportData";
2032 if (dijit.byId("dataExportDlg"))
2033 dijit.byId("dataExportDlg").destroyRecursive();
2037 dialog = new dijit.Dialog({
2038 id: "dataExportDlg",
2039 title: __("Export Data"),
2040 style: "width: 600px",
2041 prepare: function() {
2043 notify_progress("Loading, please wait...");
2045 new Ajax.Request("backend.php", {
2046 parameters: "?op=rpc&method=exportrun&offset=" + exported,
2047 onComplete: function(transport) {
2049 var rv = JSON.parse(transport.responseText);
2051 if (rv && rv.exported != undefined) {
2052 if (rv.exported > 0) {
2054 exported += rv.exported;
2056 $("export_status_message").innerHTML =
2057 "<img src='images/indicator_tiny.gif'> " +
2058 "Exported %d articles, please wait...".replace("%d",
2061 setTimeout('dijit.byId("dataExportDlg").prepare()', 2000);
2065 $("export_status_message").innerHTML =
2066 __("Finished, exported %d articles. You can download the data <a class='visibleLink' href='%u'>here</a>.")
2067 .replace("%d", exported)
2068 .replace("%u", "backend.php?op=rpc&subop=exportget");
2075 $("export_status_message").innerHTML =
2076 "Error occured, could not export data.";
2079 exception_error("exportData", e, transport.responseText);
2087 execute: function() {
2088 if (this.validate()) {
2100 exception_error("exportData", e);
2104 function dataImportComplete(iframe) {
2106 if (!iframe.contentDocument.body.innerHTML) return false;
2108 Element.hide(iframe);
2112 if (dijit.byId('dataImportDlg'))
2113 dijit.byId('dataImportDlg').destroyRecursive();
2115 var content = iframe.contentDocument.body.innerHTML;
2117 dialog = new dijit.Dialog({
2118 id: "dataImportDlg",
2119 title: __("Data Import"),
2120 style: "width: 600px",
2121 onCancel: function() {
2129 exception_error("dataImportComplete", e);
2133 function gotoExportOpml(filename, settings) {
2134 tmp = settings ? 1 : 0;
2135 document.location.href = "backend.php?op=opml&method=export&filename=" + filename + "&settings=" + tmp;
2139 function batchSubscribe() {
2141 var query = "backend.php?op=dlg&method=batchSubscribe";
2143 if (dijit.byId("batchSubDlg"))
2144 dijit.byId("batchSubDlg").destroyRecursive();
2146 var dialog = new dijit.Dialog({
2148 title: __("Batch subscribe"),
2149 style: "width: 600px",
2150 execute: function() {
2151 if (this.validate()) {
2152 console.log(dojo.objectToQuery(this.attr('value')));
2154 notify_progress(__("Subscribing to feeds..."), true);
2156 new Ajax.Request("backend.php", {
2157 parameters: dojo.objectToQuery(this.attr('value')),
2158 onComplete: function(transport) {
2169 exception_error("batchSubscribe", e);
2173 function updateSelf() {
2175 var query = "backend.php?op=pref-prefs&method=updateSelf";
2177 if (dijit.byId("updateSelfDlg"))
2178 dijit.byId("updateSelfDlg").destroyRecursive();
2180 var dialog = new dijit.Dialog({
2181 id: "updateSelfDlg",
2182 title: __("Update Tiny Tiny RSS"),
2183 style: "width: 600px",
2185 performUpdate: function(step) {
2186 dijit.byId("self_update_start_btn").attr("disabled", true);
2187 dijit.byId("self_update_stop_btn").attr("disabled", true);
2189 notify_progress("Loading, please wait...", true);
2190 new Ajax.Request("backend.php", {
2191 parameters: "?op=pref-prefs&method=performUpdate&step=" + step +
2192 "¶ms=" + param_escape(JSON.stringify(dialog.attr("update-params"))),
2193 onComplete: function(transport) {
2195 rv = JSON.parse(transport.responseText);
2199 rv['log'].each(function(line) {
2200 $("self_update_log").innerHTML += "<li>" + line + "</li>";
2203 dialog.attr("update-params", rv['params']);
2206 window.setTimeout("dijit.byId('updateSelfDlg').performUpdate("+(step+1)+")", 500);
2208 dijit.byId("self_update_stop_btn").attr("disabled", false);
2212 console.log(transport.responseText);
2213 notify_error("Received invalid data from server.");
2216 dialog.attr("updated", true);
2218 exception_error("updateSelf/inner", e);
2223 if (dialog.attr("updated")) {
2224 window.location.reload();
2230 if (prompt(__("Live updating is considered experimental. Backup your tt-rss directory before continuing. Please type 'yes' to continue.")) == 'yes') {
2231 dialog.performUpdate(0);
2238 exception_error("batchSubscribe", e);
2242 function toggleAdvancedPrefs() {
2244 notify_progress("Loading, please wait...");
2246 new Ajax.Request("backend.php", {
2247 parameters: "?op=pref-prefs&method=toggleadvanced",
2248 onComplete: function(transport) {
2253 exception_error("toggleAdvancedPrefs", e);