]> git.wh0rd.org - tt-rss.git/blobdiff - js/prefs.js
add plugin storage table to schema; add ability to clear plugin data
[tt-rss.git] / js / prefs.js
index 1fbbc55a58c8654a87d218e6a9dd0075fe145c60..7ee88ab56a137b11e535c5ccad2ebfd03ea7b2ce 100644 (file)
@@ -24,15 +24,6 @@ function updateFeedList(sort_key) {
                } });
 }
 
-function updateInstanceList(sort_key) {
-       new Ajax.Request("backend.php", {
-               parameters: "?op=pref-instances&sort=" + param_escape(sort_key),
-               onComplete: function(transport) {
-                       dijit.byId('instanceConfigTab').attr('content', transport.responseText);
-                       selectTab("instanceConfig", true);
-                       notify("");
-               } });
-}
 
 function updateUsersList(sort_key) {
        try {
@@ -92,13 +83,8 @@ function addUser() {
 function editUser(id, event) {
 
        try {
-               if (!event || !event.ctrlKey) {
-
                notify_progress("Loading, please wait...");
 
-               selectTableRows('prefUserList', 'none');
-               selectTableRowById('UMRR-'+id, 'UMCHK-'+id, true);
-
                var query = "?op=pref-users&method=edit&id=" +
                        param_escape(id);
 
@@ -109,12 +95,6 @@ function editUser(id, event) {
                                        document.forms['user_edit_form'].login.focus();
                                } });
 
-               } else if (event.ctrlKey) {
-                       var cb = $('UMCHK-' + id);
-                       cb.checked = !cb.checked;
-                       toggleSelectRow(cb);
-               }
-
        } catch (e) {
                exception_error("editUser", e);
        }
@@ -136,6 +116,40 @@ function editFilter(id) {
                        id: "filterEditDlg",
                        title: __("Edit Filter"),
                        style: "width: 600px",
+                       test: function() {
+                               var query = "backend.php?" + dojo.formToQuery("filter_edit_form") + "&savemode=test";
+
+                               if (dijit.byId("filterTestDlg"))
+                                       dijit.byId("filterTestDlg").destroyRecursive();
+
+                               var test_dlg = new dijit.Dialog({
+                                       id: "filterTestDlg",
+                                       title: "Test Filter",
+                                       style: "width: 600px",
+                                       href: query});
+
+                               test_dlg.show();
+                       },
+                       selectRules: function(select) {
+                               $$("#filterDlg_Matches input[type=checkbox]").each(function(e) {
+                                       e.checked = select;
+                                       if (select)
+                                               e.parentNode.addClassName("Selected");
+                                       else
+                                               e.parentNode.removeClassName("Selected");
+                               });
+                       },
+                       selectActions: function(select) {
+                               $$("#filterDlg_Actions input[type=checkbox]").each(function(e) {
+                                       e.checked = select;
+
+                                       if (select)
+                                               e.parentNode.addClassName("Selected");
+                                       else
+                                               e.parentNode.removeClassName("Selected");
+
+                               });
+                       },
                        editRule: function(e) {
                                var li = e.parentNode;
                                var rule = li.getElementsByTagName("INPUT")[1].value;
@@ -230,6 +244,19 @@ function getSelectedFeeds() {
        return rv;
 }
 
+function getSelectedCategories() {
+       var tree = dijit.byId("feedTree");
+       var items = tree.model.getCheckedItems();
+       var rv = [];
+
+       items.each(function(item) {
+               if (item.id[0].match("CAT:"))
+                       rv.push(tree.model.store.getValue(item, 'bare_id'));
+       });
+
+       return rv;
+}
+
 function getSelectedFilters() {
        var tree = dijit.byId("filterTree");
        var items = tree.model.getCheckedItems();
@@ -243,10 +270,6 @@ function getSelectedFilters() {
 
 }
 
-/* function getSelectedFeedCats() {
-       return getSelectedTableRowIds("prefFeedCatList");
-} */
-
 function removeSelectedLabels() {
 
        var sel_rows = getSelectedLabels();
@@ -812,22 +835,6 @@ function opmlImport() {
        }
 }
 
-function importData() {
-
-       var file = $("export_file");
-
-       if (file.value.length == 0) {
-               alert(__("Please choose the file first."));
-               return false;
-       } else {
-               notify_progress("Importing, please wait...", true);
-
-               Element.show("data_upload_iframe");
-
-               return true;
-       }
-}
-
 
 function updateFilterList() {
        var user_search = $("filter_search");
@@ -1199,6 +1206,34 @@ function removeCategory(id, item) {
        }
 }
 
+function removeSelectedCategories() {
+
+       var sel_rows = getSelectedCategories();
+
+       if (sel_rows.length > 0) {
+
+               var ok = confirm(__("Remove selected categories?"));
+
+               if (ok) {
+                       notify_progress("Removing selected categories...");
+
+                       var query = "?op=pref-feeds&method=removeCat&ids="+
+                               param_escape(sel_rows.toString());
+
+                       new Ajax.Request("backend.php", {
+                               parameters: query,
+                               onComplete: function(transport) {
+                                               updateFeedList();
+                                       } });
+
+               }
+       } else {
+               alert(__("No categories are selected."));
+       }
+
+       return false;
+}
+
 function createCategory() {
        try {
                var title = prompt(__("Category title:"));
@@ -1225,7 +1260,7 @@ function createCategory() {
 
 function showInactiveFeeds() {
        try {
-               var query = "backend.php?op=dlg&method=inactiveFeeds";
+               var query = "backend.php?op=pref-feeds&method=inactiveFeeds";
 
                if (dijit.byId("inactiveFeedsDlg"))
                        dijit.byId("inactiveFeedsDlg").destroyRecursive();
@@ -1820,162 +1855,6 @@ function insertSSLserial(value) {
        }
 }
 
-function getSelectedInstances() {
-       return getSelectedTableRowIds("prefInstanceList");
-}
-
-function addInstance() {
-       try {
-               var query = "backend.php?op=dlg&method=addInstance";
-
-               if (dijit.byId("instanceAddDlg"))
-                       dijit.byId("instanceAddDlg").destroyRecursive();
-
-               dialog = new dijit.Dialog({
-                       id: "instanceAddDlg",
-                       title: __("Link Instance"),
-                       style: "width: 600px",
-                       regenKey: function() {
-                               new Ajax.Request("backend.php", {
-                                       parameters: "?op=rpc&method=genHash",
-                                       onComplete: function(transport) {
-                                               var reply = JSON.parse(transport.responseText);
-                                               if (reply)
-                                                       dijit.byId('instance_add_key').attr('value', reply.hash);
-
-                                       } });
-                       },
-                       execute: function() {
-                               if (this.validate()) {
-                                       console.warn(dojo.objectToQuery(this.attr('value')));
-
-                                       notify_progress('Saving data...', true);
-                                       new Ajax.Request("backend.php", {
-                                               parameters: dojo.objectToQuery(this.attr('value')),
-                                               onComplete: function(transport) {
-                                                       dialog.hide();
-                                                       notify('');
-                                                       updateInstanceList();
-                                       } });
-                               }
-                       },
-                       href: query,
-               });
-
-               dialog.show();
-
-       } catch (e) {
-               exception_error("addInstance", e);
-       }
-}
-
-function editInstance(id, event) {
-       try {
-               if (!event || !event.ctrlKey) {
-
-               selectTableRows('prefInstanceList', 'none');
-               selectTableRowById('LIRR-'+id, 'LICHK-'+id, true);
-
-               var query = "backend.php?op=pref-instances&method=edit&id=" +
-                       param_escape(id);
-
-               if (dijit.byId("instanceEditDlg"))
-                       dijit.byId("instanceEditDlg").destroyRecursive();
-
-               dialog = new dijit.Dialog({
-                       id: "instanceEditDlg",
-                       title: __("Edit Instance"),
-                       style: "width: 600px",
-                       regenKey: function() {
-                               new Ajax.Request("backend.php", {
-                                       parameters: "?op=rpc&method=genHash",
-                                       onComplete: function(transport) {
-                                               var reply = JSON.parse(transport.responseText);
-                                               if (reply)
-                                                       dijit.byId('instance_edit_key').attr('value', reply.hash);
-
-                                       } });
-                       },
-                       execute: function() {
-                               if (this.validate()) {
-//                                     console.warn(dojo.objectToQuery(this.attr('value')));
-
-                                       notify_progress('Saving data...', true);
-                                       new Ajax.Request("backend.php", {
-                                               parameters: dojo.objectToQuery(this.attr('value')),
-                                               onComplete: function(transport) {
-                                                       dialog.hide();
-                                                       notify('');
-                                                       updateInstanceList();
-                                       } });
-                               }
-                       },
-                       href: query,
-               });
-
-               dialog.show();
-
-               } else if (event.ctrlKey) {
-                       var cb = $('LICHK-' + id);
-                       cb.checked = !cb.checked;
-                       toggleSelectRow(cb);
-               }
-
-
-       } catch (e) {
-               exception_error("editInstance", e);
-       }
-}
-
-function removeSelectedInstances() {
-       try {
-               var sel_rows = getSelectedInstances();
-
-               if (sel_rows.length > 0) {
-
-                       var ok = confirm(__("Remove selected instances?"));
-
-                       if (ok) {
-                               notify_progress("Removing selected instances...");
-
-                               var query = "?op=pref-instances&method=remove&ids="+
-                                       param_escape(sel_rows.toString());
-
-                               new Ajax.Request("backend.php", {
-                                       parameters: query,
-                                       onComplete: function(transport) {
-                                               notify('');
-                                               updateInstanceList();
-                                       } });
-                       }
-
-               } else {
-                       alert(__("No instances are selected."));
-               }
-
-       } catch (e) {
-               exception_error("removeInstance", e);
-       }
-}
-
-function editSelectedInstance() {
-       var rows = getSelectedInstances();
-
-       if (rows.length == 0) {
-               alert(__("No instances are selected."));
-               return;
-       }
-
-       if (rows.length > 1) {
-               alert(__("Please select only one instance."));
-               return;
-       }
-
-       notify("");
-
-       editInstance(rows[0]);
-}
-
 function showHelp() {
        try {
                new Ajax.Request("backend.php", {
@@ -1990,112 +1869,6 @@ function showHelp() {
        }
 }
 
-function exportData() {
-       try {
-
-               var query = "backend.php?op=dlg&method=exportData";
-
-               if (dijit.byId("dataExportDlg"))
-                       dijit.byId("dataExportDlg").destroyRecursive();
-
-               var exported = 0;
-
-               dialog = new dijit.Dialog({
-                       id: "dataExportDlg",
-                       title: __("Export Data"),
-                       style: "width: 600px",
-                       prepare: function() {
-
-                               notify_progress("Loading, please wait...");
-
-                               new Ajax.Request("backend.php", {
-                                       parameters: "?op=rpc&method=exportrun&offset=" + exported,
-                                       onComplete: function(transport) {
-                                               try {
-                                                       var rv = JSON.parse(transport.responseText);
-
-                                                       if (rv && rv.exported != undefined) {
-                                                               if (rv.exported > 0) {
-
-                                                                       exported += rv.exported;
-
-                                                                       $("export_status_message").innerHTML =
-                                                                               "<img src='images/indicator_tiny.gif'> " +
-                                                                               "Exported %d articles, please wait...".replace("%d",
-                                                                                       exported);
-
-                                                                       setTimeout('dijit.byId("dataExportDlg").prepare()', 2000);
-
-                                                               } else {
-
-                                                                       $("export_status_message").innerHTML =
-                                                                               __("Finished, exported %d articles. You can download the data <a class='visibleLink' href='%u'>here</a>.")
-                                                                               .replace("%d", exported)
-                                                                               .replace("%u", "backend.php?op=rpc&subop=exportget");
-
-                                                                       exported = 0;
-
-                                                               }
-
-                                                       } else {
-                                                               $("export_status_message").innerHTML =
-                                                                       "Error occured, could not export data.";
-                                                       }
-                                               } catch (e) {
-                                                       exception_error("exportData", e, transport.responseText);
-                                               }
-
-                                               notify('');
-
-                                       } });
-
-                       },
-                       execute: function() {
-                               if (this.validate()) {
-
-
-
-                               }
-                       },
-                       href: query});
-
-               dialog.show();
-
-
-       } catch (e) {
-               exception_error("exportData", e);
-       }
-}
-
-function dataImportComplete(iframe) {
-       try {
-               if (!iframe.contentDocument.body.innerHTML) return false;
-
-               Element.hide(iframe);
-
-               notify('');
-
-               if (dijit.byId('dataImportDlg'))
-                       dijit.byId('dataImportDlg').destroyRecursive();
-
-               var content = iframe.contentDocument.body.innerHTML;
-
-               dialog = new dijit.Dialog({
-                       id: "dataImportDlg",
-                       title: __("Data Import"),
-                       style: "width: 600px",
-                       onCancel: function() {
-
-                       },
-                       content: content});
-
-               dialog.show();
-
-       } catch (e) {
-               exception_error("dataImportComplete", e);
-       }
-}
-
 function gotoExportOpml(filename, settings) {
        tmp = settings ? 1 : 0;
        document.location.href = "backend.php?op=opml&method=export&filename=" + filename + "&settings=" + tmp;
@@ -2106,8 +1879,9 @@ function batchSubscribe() {
        try {
                var query = "backend.php?op=dlg&method=batchSubscribe";
 
-               if (dijit.byId("batchSubDlg"))
-                       dijit.byId("batchSubDlg").destroyRecursive();
+               // overlapping widgets
+               if (dijit.byId("batchSubDlg")) dijit.byId("batchSubDlg").destroyRecursive();
+               if (dijit.byId("feedAddDlg"))   dijit.byId("feedAddDlg").destroyRecursive();
 
                var dialog = new dijit.Dialog({
                        id: "batchSubDlg",
@@ -2136,74 +1910,6 @@ function batchSubscribe() {
        }
 }
 
-function updateSelf() {
-       try {
-               var query = "backend.php?op=pref-prefs&method=updateSelf";
-
-               if (dijit.byId("updateSelfDlg"))
-                       dijit.byId("updateSelfDlg").destroyRecursive();
-
-               var dialog = new dijit.Dialog({
-                       id: "updateSelfDlg",
-                       title: __("Update Tiny Tiny RSS"),
-                       style: "width: 600px",
-                       closable: false,
-                       performUpdate: function(step) {
-                               dijit.byId("self_update_start_btn").attr("disabled", true);
-                               dijit.byId("self_update_stop_btn").attr("disabled", true);
-
-                               notify_progress("Loading, please wait...", true);
-                               new Ajax.Request("backend.php", {
-                               parameters: "?op=pref-prefs&method=performUpdate&step=" + step +
-                                       "&params=" + param_escape(JSON.stringify(dialog.attr("update-params"))),
-                               onComplete: function(transport) {
-                                       try {
-                                               rv = JSON.parse(transport.responseText);
-                                               if (rv) {
-                                                       notify('');
-
-                                                       rv['log'].each(function(line) {
-                                                               $("self_update_log").innerHTML += "<li>" + line + "</li>";
-                                                       });
-
-                                                       dialog.attr("update-params", rv['params']);
-
-                                                       if (!rv['stop']) {
-                                                               window.setTimeout("dijit.byId('updateSelfDlg').performUpdate("+(step+1)+")", 500);
-                                                       } else {
-                                                               dijit.byId("self_update_stop_btn").attr("disabled", false);
-                                                       }
-
-                                               } else {
-                                                       console.log(transport.responseText);
-                                                       notify_error("Received invalid data from server.");
-                                               }
-
-                                               dialog.attr("updated", true);
-                                       } catch (e) {
-                                               exception_error("updateSelf/inner", e);
-                                       }
-                               } });
-                       },
-                       close: function() {
-                               if (dialog.attr("updated")) {
-                                       window.location.reload();
-                               } else {
-                                       dialog.hide();
-                               }
-                       },
-                       start: function() {
-                               if (prompt(__("Live updating is considered experimental. Backup your tt-rss directory before continuing. Please type 'yes' to continue.")) == 'yes') {
-                                       dialog.performUpdate(0);
-                               }
-                       },
-                       href: query});
-
-               dialog.show();
-       } catch (e) {
-               exception_error("batchSubscribe", e);
-       }
-}
 
 function toggleAdvancedPrefs() {
        try {
@@ -2219,3 +1925,20 @@ function toggleAdvancedPrefs() {
                exception_error("toggleAdvancedPrefs", e);
        }
 }
+
+function clearPluginData(name) {
+       try {
+               if (confirm(__("Clear stored data for this plugin?"))) {
+                       notify_progress("Loading, please wait...");
+
+                       new Ajax.Request("backend.php", {
+                               parameters: "?op=pref-prefs&method=clearplugindata&name=" + param_escape(name),
+                               onComplete: function(transport) {
+                                       notify('');
+                                       updatePrefsList();
+                               } });
+               }
+       } catch (e) {
+               exception_error("clearPluginData", e);
+       }
+}