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

Unified Diff: new-options.js

Issue 29411555: Issue 5169 - Add whitelisted tab to the new options page (Closed)
Patch Set: Created April 21, 2017, 11:32 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
Index: new-options.js
===================================================================
--- a/new-options.js
+++ b/new-options.js
@@ -43,18 +43,25 @@
this.items = [];
}
- Collection.prototype._setEmpty = function(table, text)
+ Collection.prototype._setEmpty = function(table, texts)
{
- let placeholder = table.querySelector(".empty-placeholder");
- if (text && !placeholder)
+ let placeholders = table.querySelectorAll(".empty-placeholder");
+
+ if (texts && placeholders.length == 0)
{
- placeholder = document.createElement("li");
- placeholder.className = "empty-placeholder";
- placeholder.textContent = getMessage(text);
- table.appendChild(placeholder);
+ for (let i = 0; i < texts.length; i++)
Thomas Greiner 2017/05/09 13:42:56 Detail: You're not using the index so I'd recommen
saroyanm 2017/05/16 20:20:07 Well spotted, done.
+ {
+ let placeholder = document.createElement("li");
+ placeholder.className = "empty-placeholder";
+ placeholder.textContent = getMessage(texts[i]);
+ table.appendChild(placeholder);
+ }
}
- else if (placeholder)
- table.removeChild(placeholder);
+ else if (placeholders.length > 0)
+ {
+ for (let i = 0; i < placeholders.length; i++)
+ table.removeChild(placeholders[i]);
+ }
};
Collection.prototype._createElementQuery = function(item)
@@ -284,17 +291,17 @@
collections.langs = new Collection([
{
id: "blocking-languages-table",
- emptyText: "options_dialog_language_added_empty"
+ emptyText: ["options_dialog_language_added_empty"]
},
{
id: "blocking-languages-dialog-table",
- emptyText: "options_dialog_language_added_empty"
+ emptyText: ["options_dialog_language_added_empty"]
}
]);
collections.allLangs = new Collection([
{
id: "all-lang-table",
- emptyText: "options_dialog_language_other_empty",
+ emptyText: ["options_dialog_language_other_empty"],
searchable: true
}
]);
@@ -311,13 +318,13 @@
collections.whitelist = new Collection([
{
id: "whitelisting-table",
- emptyText: "options_whitelisted_empty"
+ emptyText: ["options_whitelist_empty_1", "options_whitelist_empty_2"]
}
]);
collections.customFilters = new Collection([
{
id: "custom-filters-table",
- emptyText: "options_customFilters_empty"
+ emptyText: ["options_customFilters_empty"]
}
]);
collections.filterLists = new Collection([
@@ -767,10 +774,57 @@
let placeholderValue = getMessage("options_dialog_language_find");
E("find-language").setAttribute("placeholder", placeholderValue);
E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false);
- E("whitelisting-textbox").addEventListener("keypress", (e) =>
+ let exampleValue = getMessage("options_whitelist_placeholder_example");
+ exampleValue += " www.example.com";
+ E("whitelisting-textbox").setAttribute("placeholder", exampleValue);
+ E("whitelisting-textbox").addEventListener("keyup", (e) =>
Thomas Greiner 2017/05/09 13:42:56 I'm not sure it's a good idea to validate the inpu
saroyanm 2017/05/16 20:20:06 It will, that's why I'm using keyUp instead.
saroyanm 2017/05/18 16:21:52 Fine for now because we are checking for only empt
{
+ let addWhitelistButton = E("whitelisting-add-button");
+ let validationElement = E("whitelisting-validation");
if (getKey(e) == "Enter")
- addWhitelistedDomain();
+ {
+ if (!E("whitelisting-add-button").hasAttribute("disabled"))
+ addWhitelistedDomain();
+ }
+ else
+ {
+ let validIpAddressRegex = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25"
saroyanm 2017/04/21 12:03:17 Regular expression to match Hostname and IP addres
Thomas Greiner 2017/05/09 13:42:56 Detail: Those are constants that we can simply com
Thomas Greiner 2017/05/09 13:42:56 I don't think we need to be that specific. Somethi
saroyanm 2017/05/16 20:20:07 I think this is not anymore relevant, while the va
+ + "[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$";
Thomas Greiner 2017/05/09 13:42:56 You need to escape the escape characters since you
+ let validHostnameRegex = "^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9]"
Thomas Greiner 2017/05/09 13:42:56 Same here. I don't think we need to be that specif
+ +")\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$";
+
+ let isDuplicate = false;
+ for (let i = 0; i < collections.whitelist.items.length; i++)
+ {
+ if (collections.whitelist.items[i].title == e.target.value)
+ isDuplicate = true;
Thomas Greiner 2017/05/09 13:42:56 Detail: Why do we need this variable? We could jus
+ }
+
+ if (isDuplicate)
+ {
+ addWhitelistButton.setAttribute("disabled", "");
saroyanm 2017/04/21 12:03:17 I think we should use checkValidity() method inste
Thomas Greiner 2017/05/09 13:42:56 Detail: Can't we just do `addWhitelistButton.disab
saroyanm 2017/05/16 20:20:06 done.
+ validationElement.textContent =
+ getMessage("options_whitelist_duplicate");
+ }
+ else if (new RegExp(validIpAddressRegex).test(e.target.value) ||
+ new RegExp(validHostnameRegex).test(e.target.value))
+ {
+ addWhitelistButton.removeAttribute("disabled");
+ validationElement.textContent = "";
+ }
+ else if (!e.target.value)
+ {
+ validationElement.textContent = "";
+ addWhitelistButton.setAttribute("disabled", "");
+ }
+ else
+ {
+ addWhitelistButton.setAttribute("disabled", "");
+ validationElement.textContent =
+ getMessage("options_whitelist_invalid");
+
+ }
+ }
}, false);
// Advanced tab
@@ -986,8 +1040,7 @@
}
domain.value = "";
- document.querySelector("#whitelisting .controls")
- .classList.remove("mode-edit");
+ E("whitelisting-add-button").setAttribute("disabled", "");
}
function editCustomFilters()
« new-options.html ('K') | « new-options.html ('k') | skin/new-options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld