| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('options', function() { | 5 cr.define('options', function() { |
| 6 var OptionsPage = options.OptionsPage; | 6 var OptionsPage = options.OptionsPage; |
| 7 var ArrayDataModel = cr.ui.ArrayDataModel; | 7 var ArrayDataModel = cr.ui.ArrayDataModel; |
| 8 | 8 |
| 9 const localStrings = new LocalStrings(); | 9 const localStrings = new LocalStrings(); |
| 10 | 10 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 * Set a dictionary of all profile names. These are used to prevent the | 101 * Set a dictionary of all profile names. These are used to prevent the |
| 102 * user from naming two profiles the same. | 102 * user from naming two profiles the same. |
| 103 * @param {Object} profileNames A dictionary of profile names. | 103 * @param {Object} profileNames A dictionary of profile names. |
| 104 * @private | 104 * @private |
| 105 */ | 105 */ |
| 106 receiveProfileNames_: function(profileNames) { | 106 receiveProfileNames_: function(profileNames) { |
| 107 this.profileNames_ = profileNames; | 107 this.profileNames_ = profileNames; |
| 108 }, | 108 }, |
| 109 | 109 |
| 110 /** | 110 /** |
| 111 * Determine whether |name| is valid; i.e. not equal to any other profile | 111 * Get the localized string id of the error to display if |name| is not |
| 112 * name. | 112 * valid. |
| 113 * @param {string} name The profile name to validate. | 113 * @param {string} name The profile name to validate. |
| 114 * @return true if the name is not equal to any other profile name. | 114 * @return {string} The localString of the error to display to the user, or |
| 115 * the empty string if there is no error. |
| 115 * @private | 116 * @private |
| 116 */ | 117 */ |
| 117 isNameValid_: function(name) { | 118 getNameErrorLocalStringId_: function(name) { |
| 118 // if the name hasn't changed, assume it is valid. | 119 // if the name hasn't changed, assume it is valid. |
| 119 if (name == this.profileInfo_.name) | 120 if (name == this.profileInfo_.name) |
| 120 return true; | 121 return ''; |
| 121 | 122 |
| 122 return this.profileNames_[name] == undefined; | 123 if (!name) |
| 124 return 'manageProfilesEmptyNameError'; |
| 125 |
| 126 if (this.profileNames_[name] != undefined) |
| 127 return 'manageProfilesDuplicateNameError'; |
| 128 |
| 129 return ''; |
| 123 }, | 130 }, |
| 124 | 131 |
| 125 /** | 132 /** |
| 126 * Update the UI elements accordingly if the profile name is valid/invalid. | 133 * Display the name error DOM elements, with |errorText| in the bubble. |
| 127 * @param {boolean} isValid True if the UI should be updated as if the name | 134 * @param {string} errorText The localized string id to display as an error. |
| 128 * were valid. | |
| 129 * @private | 135 * @private |
| 130 */ | 136 */ |
| 131 setNameIsValid_: function(isValid) { | 137 showNameError_: function(errorText) { |
| 132 var dupeNameErrorEl = $('manage-profile-duplicate-name-error'); | 138 var nameErrorEl = $('manage-profile-name-error'); |
| 133 if (isValid) | 139 nameErrorEl.classList.remove('hiding'); |
| 134 dupeNameErrorEl.classList.add('hiding'); | 140 nameErrorEl.textContent = localStrings.getString(errorText); |
| 135 else | |
| 136 dupeNameErrorEl.classList.remove('hiding'); | |
| 137 | 141 |
| 138 $('manage-profile-ok').disabled = !isValid; | 142 $('manage-profile-ok').disabled = true; |
| 139 }, | 143 }, |
| 140 | 144 |
| 141 /** | 145 /** |
| 146 * Hide the name error DOM elements. |
| 147 * @private |
| 148 */ |
| 149 hideNameError_: function() { |
| 150 $('manage-profile-name-error').classList.add('hiding'); |
| 151 $('manage-profile-ok').disabled = false; |
| 152 }, |
| 153 |
| 154 /** |
| 142 * oninput callback for <input> field. | 155 * oninput callback for <input> field. |
| 143 * @param event The event object | 156 * @param event The event object |
| 144 * @private | 157 * @private |
| 145 */ | 158 */ |
| 146 onNameChanged_: function(event) { | 159 onNameChanged_: function(event) { |
| 147 this.setNameIsValid_(this.isNameValid_(event.target.value)); | 160 var errorId = this.getNameErrorLocalStringId_(event.target.value); |
| 161 if (errorId) |
| 162 this.showNameError_(errorId); |
| 163 else |
| 164 this.hideNameError_(); |
| 148 }, | 165 }, |
| 149 | 166 |
| 150 /** | 167 /** |
| 151 * Called when the user clicks "OK". Saves the newly changed profile info. | 168 * Called when the user clicks "OK". Saves the newly changed profile info. |
| 152 * @private | 169 * @private |
| 153 */ | 170 */ |
| 154 submitManageChanges_: function() { | 171 submitManageChanges_: function() { |
| 155 var name = $('manage-profile-name').value; | 172 var name = $('manage-profile-name').value; |
| 156 var iconURL = $('manage-profile-icon-grid').selectedItem; | 173 var iconURL = $('manage-profile-icon-grid').selectedItem; |
| 157 chrome.send('setProfileNameAndIcon', | 174 chrome.send('setProfileNameAndIcon', |
| 158 [this.profileInfo_.filePath, name, iconURL]); | 175 [this.profileInfo_.filePath, name, iconURL]); |
| 159 }, | 176 }, |
| 160 | 177 |
| 161 /** | 178 /** |
| 162 * Display the "Manage Profile" dialog. | 179 * Display the "Manage Profile" dialog. |
| 163 * @param {Object} profileInfo The profile object of the profile to manage. | 180 * @param {Object} profileInfo The profile object of the profile to manage. |
| 164 * @private | 181 * @private |
| 165 */ | 182 */ |
| 166 showManageDialog_: function(profileInfo) { | 183 showManageDialog_: function(profileInfo) { |
| 167 ManageProfileOverlay.setProfileInfo(profileInfo); | 184 ManageProfileOverlay.setProfileInfo(profileInfo); |
| 168 $('manage-profile-overlay-manage').hidden = false; | 185 $('manage-profile-overlay-manage').hidden = false; |
| 169 $('manage-profile-overlay-delete').hidden = true; | 186 $('manage-profile-overlay-delete').hidden = true; |
| 170 ManageProfileOverlay.getInstance().setNameIsValid_(true); | 187 ManageProfileOverlay.getInstance().hideNameError_(); |
| 171 | 188 |
| 172 // Intentionally don't show the URL in the location bar as we don't want | 189 // Intentionally don't show the URL in the location bar as we don't want |
| 173 // people trying to navigate here by hand. | 190 // people trying to navigate here by hand. |
| 174 OptionsPage.showPageByName('manageProfile', false); | 191 OptionsPage.showPageByName('manageProfile', false); |
| 175 }, | 192 }, |
| 176 | 193 |
| 177 /** | 194 /** |
| 178 * Display the "Delete Profile" dialog. | 195 * Display the "Delete Profile" dialog. |
| 179 * @param {Object} profileInfo The profile object of the profile to delete. | 196 * @param {Object} profileInfo The profile object of the profile to delete. |
| 180 * @private | 197 * @private |
| (...skipping 22 matching lines...) Expand all Loading... |
| 203 ManageProfileOverlay[name] = function(value) { | 220 ManageProfileOverlay[name] = function(value) { |
| 204 ManageProfileOverlay.getInstance()[name + '_'](value); | 221 ManageProfileOverlay.getInstance()[name + '_'](value); |
| 205 }; | 222 }; |
| 206 }); | 223 }); |
| 207 | 224 |
| 208 // Export | 225 // Export |
| 209 return { | 226 return { |
| 210 ManageProfileOverlay: ManageProfileOverlay | 227 ManageProfileOverlay: ManageProfileOverlay |
| 211 }; | 228 }; |
| 212 }); | 229 }); |
| OLD | NEW |