Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: options.js

Issue 29338005: Issue 3761 - Don't clear user input when filter validation failed (Closed)
Patch Set: Created March 9, 2016, 8:14 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « messageResponder.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: options.js
===================================================================
--- a/options.js
+++ b/options.js
@@ -517,6 +517,17 @@
return null;
}
+ function sendMessageHandleErrors(message, onSuccess)
+ {
+ ext.backgroundPage.sendMessage(message, function(errors)
+ {
+ if (errors.length > 0)
+ alert(errors.join("\n"));
+ else if (onSuccess)
+ onSuccess();
+ });
+ }
+
function onClick(e)
{
var context = document.querySelector(".show-context-menu");
@@ -577,12 +588,15 @@
openDialog(element.getAttribute("data-dialog"));
break;
case "save-custom-filters":
- ext.backgroundPage.sendMessage(
+ sendMessageHandleErrors(
{
type: "filters.importRaw",
text: E("custom-filters-raw").value
+ },
+ function()
+ {
+ E("custom-filters").classList.remove("mode-edit");
});
- E("custom-filters").classList.remove("mode-edit");
break;
case "switch-tab":
document.body.setAttribute("data-tab",
@@ -682,12 +696,15 @@
function addCustomFilters()
{
var filterText = filterTextbox.value;
- ext.backgroundPage.sendMessage(
+ sendMessageHandleErrors(
{
type: "filters.add",
text: filterText
+ },
+ function()
+ {
+ filterTextbox.value = "";
});
- filterTextbox.value = "";
}
E("custom-filters-add").addEventListener("submit", function(e)
{
@@ -807,7 +824,7 @@
var domain = E("whitelisting-textbox");
if (domain.value)
{
- ext.backgroundPage.sendMessage(
+ sendMessageHandleErrors(
{
type: "filters.add",
text: "@@||" + domain.value.toLowerCase() + "^$document"
@@ -993,10 +1010,6 @@
dialog.querySelector(".url").textContent = subscription.url;
openDialog("predefined");
}
- else if (message.action == "error")
- {
- alert(message.args.join("\n"));
- }
break;
case "filters.listen":
onFilterMessage(message.action, message.args[0]);
« no previous file with comments | « messageResponder.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld