Index: chrome/browser/resources/options/manage_profile_overlay.js |
diff --git a/chrome/browser/resources/options/manage_profile_overlay.js b/chrome/browser/resources/options/manage_profile_overlay.js |
index ae97f12f87c3da19e4da92d6a4f7db5d84bf5d01..0bc99b07af4ea181589acee8567100930722cd6a 100644 |
--- a/chrome/browser/resources/options/manage_profile_overlay.js |
+++ b/chrome/browser/resources/options/manage_profile_overlay.js |
@@ -108,34 +108,47 @@ cr.define('options', function() { |
}, |
/** |
- * Determine whether |name| is valid; i.e. not equal to any other profile |
- * name. |
+ * Get the localized string id of the error to display if |name| is not |
+ * valid. |
* @param {string} name The profile name to validate. |
- * @return true if the name is not equal to any other profile name. |
+ * @return {string} The localString of the error to display to the user, or |
+ * the empty string if there is no error. |
* @private |
*/ |
- isNameValid_: function(name) { |
+ getNameErrorLocalStringId_: function(name) { |
// if the name hasn't changed, assume it is valid. |
if (name == this.profileInfo_.name) |
- return true; |
+ return ''; |
- return this.profileNames_[name] == undefined; |
+ if (!name) |
+ return 'manageProfilesEmptyNameError'; |
+ |
+ if (this.profileNames_[name] != undefined) |
+ return 'manageProfilesDuplicateNameError'; |
+ |
+ return ''; |
}, |
/** |
- * Update the UI elements accordingly if the profile name is valid/invalid. |
- * @param {boolean} isValid True if the UI should be updated as if the name |
- * were valid. |
+ * Display the name error DOM elements, with |errorText| in the bubble. |
+ * @param {string} errorText The localized string id to display as an error. |
* @private |
*/ |
- setNameIsValid_: function(isValid) { |
- var dupeNameErrorEl = $('manage-profile-duplicate-name-error'); |
- if (isValid) |
- dupeNameErrorEl.classList.add('hiding'); |
- else |
- dupeNameErrorEl.classList.remove('hiding'); |
+ showNameError_: function(errorText) { |
+ var nameErrorEl = $('manage-profile-name-error'); |
+ nameErrorEl.classList.remove('hiding'); |
+ nameErrorEl.textContent = localStrings.getString(errorText); |
- $('manage-profile-ok').disabled = !isValid; |
+ $('manage-profile-ok').disabled = true; |
+ }, |
+ |
+ /** |
+ * Hide the name error DOM elements. |
+ * @private |
+ */ |
+ hideNameError_: function() { |
+ $('manage-profile-name-error').classList.add('hiding'); |
+ $('manage-profile-ok').disabled = false; |
}, |
/** |
@@ -144,7 +157,11 @@ cr.define('options', function() { |
* @private |
*/ |
onNameChanged_: function(event) { |
- this.setNameIsValid_(this.isNameValid_(event.target.value)); |
+ var errorId = this.getNameErrorLocalStringId_(event.target.value); |
+ if (errorId) |
+ this.showNameError_(errorId); |
+ else |
+ this.hideNameError_(); |
}, |
/** |
@@ -167,7 +184,7 @@ cr.define('options', function() { |
ManageProfileOverlay.setProfileInfo(profileInfo); |
$('manage-profile-overlay-manage').hidden = false; |
$('manage-profile-overlay-delete').hidden = true; |
- ManageProfileOverlay.getInstance().setNameIsValid_(true); |
+ ManageProfileOverlay.getInstance().hideNameError_(); |
// Intentionally don't show the URL in the location bar as we don't want |
// people trying to navigate here by hand. |