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 * Display the error bubble, with |errorText| in the bubble. |
112 * name. | 112 * @param {string} errorText The localized string id to display as an error. |
113 * @param {string} name The profile name to validate. | |
114 * @return true if the name is not equal to any other profile name. | |
115 * @private | 113 * @private |
116 */ | 114 */ |
117 isNameValid_: function(name) { | 115 showErrorBubble_: function(errorText) { |
118 // if the name hasn't changed, assume it is valid. | 116 var nameErrorEl = $('manage-profile-error-bubble'); |
119 if (name == this.profileInfo_.name) | 117 nameErrorEl.hidden = false; |
120 return true; | 118 nameErrorEl.textContent = localStrings.getString(errorText); |
121 | 119 |
122 return this.profileNames_[name] == undefined; | 120 $('manage-profile-ok').disabled = true; |
123 }, | 121 }, |
124 | 122 |
125 /** | 123 /** |
126 * Update the UI elements accordingly if the profile name is valid/invalid. | 124 * Hide the error bubble. |
127 * @param {boolean} isValid True if the UI should be updated as if the name | |
128 * were valid. | |
129 * @private | 125 * @private |
130 */ | 126 */ |
131 setNameIsValid_: function(isValid) { | 127 hideErrorBubble_: function() { |
132 var dupeNameErrorEl = $('manage-profile-duplicate-name-error'); | 128 $('manage-profile-error-bubble').hidden = true; |
133 if (isValid) | 129 $('manage-profile-ok').disabled = false; |
134 dupeNameErrorEl.classList.add('hiding'); | |
135 else | |
136 dupeNameErrorEl.classList.remove('hiding'); | |
137 | |
138 $('manage-profile-ok').disabled = !isValid; | |
139 }, | 130 }, |
140 | 131 |
141 /** | 132 /** |
142 * oninput callback for <input> field. | 133 * oninput callback for <input> field. |
143 * @param event The event object | 134 * @param event The event object |
144 * @private | 135 * @private |
145 */ | 136 */ |
146 onNameChanged_: function(event) { | 137 onNameChanged_: function(event) { |
147 this.setNameIsValid_(this.isNameValid_(event.target.value)); | 138 var newName = event.target.value; |
| 139 var oldName = this.profileInfo_.name; |
| 140 |
| 141 if (newName == oldName) { |
| 142 this.hideErrorBubble_(); |
| 143 } else if (this.profileNames_[newName] != undefined) { |
| 144 this.showErrorBubble_('manageProfilesDuplicateNameError'); |
| 145 } else { |
| 146 this.hideErrorBubble_(); |
| 147 |
| 148 var nameIsValid = $('manage-profile-name').validity.valid; |
| 149 $('manage-profile-ok').disabled = !nameIsValid; |
| 150 } |
148 }, | 151 }, |
149 | 152 |
150 /** | 153 /** |
151 * Called when the user clicks "OK". Saves the newly changed profile info. | 154 * Called when the user clicks "OK". Saves the newly changed profile info. |
152 * @private | 155 * @private |
153 */ | 156 */ |
154 submitManageChanges_: function() { | 157 submitManageChanges_: function() { |
155 var name = $('manage-profile-name').value; | 158 var name = $('manage-profile-name').value; |
156 var iconURL = $('manage-profile-icon-grid').selectedItem; | 159 var iconURL = $('manage-profile-icon-grid').selectedItem; |
157 chrome.send('setProfileNameAndIcon', | 160 chrome.send('setProfileNameAndIcon', |
158 [this.profileInfo_.filePath, name, iconURL]); | 161 [this.profileInfo_.filePath, name, iconURL]); |
159 }, | 162 }, |
160 | 163 |
161 /** | 164 /** |
162 * Display the "Manage Profile" dialog. | 165 * Display the "Manage Profile" dialog. |
163 * @param {Object} profileInfo The profile object of the profile to manage. | 166 * @param {Object} profileInfo The profile object of the profile to manage. |
164 * @private | 167 * @private |
165 */ | 168 */ |
166 showManageDialog_: function(profileInfo) { | 169 showManageDialog_: function(profileInfo) { |
167 ManageProfileOverlay.setProfileInfo(profileInfo); | 170 ManageProfileOverlay.setProfileInfo(profileInfo); |
168 $('manage-profile-overlay-manage').hidden = false; | 171 $('manage-profile-overlay-manage').hidden = false; |
169 $('manage-profile-overlay-delete').hidden = true; | 172 $('manage-profile-overlay-delete').hidden = true; |
170 ManageProfileOverlay.getInstance().setNameIsValid_(true); | 173 ManageProfileOverlay.getInstance().hideErrorBubble_(); |
171 | 174 |
172 // Intentionally don't show the URL in the location bar as we don't want | 175 // Intentionally don't show the URL in the location bar as we don't want |
173 // people trying to navigate here by hand. | 176 // people trying to navigate here by hand. |
174 OptionsPage.showPageByName('manageProfile', false); | 177 OptionsPage.showPageByName('manageProfile', false); |
175 }, | 178 }, |
176 | 179 |
177 /** | 180 /** |
178 * Display the "Delete Profile" dialog. | 181 * Display the "Delete Profile" dialog. |
179 * @param {Object} profileInfo The profile object of the profile to delete. | 182 * @param {Object} profileInfo The profile object of the profile to delete. |
180 * @private | 183 * @private |
(...skipping 22 matching lines...) Expand all Loading... |
203 ManageProfileOverlay[name] = function(value) { | 206 ManageProfileOverlay[name] = function(value) { |
204 ManageProfileOverlay.getInstance()[name + '_'](value); | 207 ManageProfileOverlay.getInstance()[name + '_'](value); |
205 }; | 208 }; |
206 }); | 209 }); |
207 | 210 |
208 // Export | 211 // Export |
209 return { | 212 return { |
210 ManageProfileOverlay: ManageProfileOverlay | 213 ManageProfileOverlay: ManageProfileOverlay |
211 }; | 214 }; |
212 }); | 215 }); |
OLD | NEW |