| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.search_engines', function() { | 5 cr.define('options.search_engines', function() { |
| 6 const InlineEditableItemList = options.InlineEditableItemList; | 6 const InlineEditableItemList = options.InlineEditableItemList; |
| 7 const InlineEditableItem = options.InlineEditableItem; | 7 const InlineEditableItem = options.InlineEditableItem; |
| 8 const ListSelectionController = cr.ui.ListSelectionController; | 8 const ListSelectionController = cr.ui.ListSelectionController; |
| 9 | 9 |
| 10 /** | 10 /** |
| 11 * Creates a new search engine list item. | 11 * Creates a new search engine list item. |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 | 147 |
| 148 if (this.isPlaceholder) { | 148 if (this.isPlaceholder) { |
| 149 this.nameField_.placeholder = | 149 this.nameField_.placeholder = |
| 150 localStrings.getString('searchEngineTableNamePlaceholder'); | 150 localStrings.getString('searchEngineTableNamePlaceholder'); |
| 151 this.keywordField_.placeholder = | 151 this.keywordField_.placeholder = |
| 152 localStrings.getString('searchEngineTableKeywordPlaceholder'); | 152 localStrings.getString('searchEngineTableKeywordPlaceholder'); |
| 153 this.urlField_.placeholder = | 153 this.urlField_.placeholder = |
| 154 localStrings.getString('searchEngineTableURLPlaceholder'); | 154 localStrings.getString('searchEngineTableURLPlaceholder'); |
| 155 } | 155 } |
| 156 | 156 |
| 157 var fields = [ this.nameField_, this.keywordField_, this.urlField_ ]; | 157 var fields = [this.nameField_, this.keywordField_, this.urlField_]; |
| 158 for (var i = 0; i < fields.length; i++) { | 158 for (var i = 0; i < fields.length; i++) { |
| 159 fields[i].oninput = this.startFieldValidation_.bind(this); | 159 fields[i].oninput = this.startFieldValidation_.bind(this); |
| 160 } | 160 } |
| 161 | 161 |
| 162 // Listen for edit events. | 162 // Listen for edit events. |
| 163 if (engine['canBeEdited']) { | 163 if (engine['canBeEdited']) { |
| 164 this.addEventListener('edit', this.onEditStarted_.bind(this)); | 164 this.addEventListener('edit', this.onEditStarted_.bind(this)); |
| 165 this.addEventListener('canceledit', this.onEditCancelled_.bind(this)); | 165 this.addEventListener('canceledit', this.onEditCancelled_.bind(this)); |
| 166 this.addEventListener('commitedit', this.onEditCommitted_.bind(this)); | 166 this.addEventListener('commitedit', this.onEditCommitted_.bind(this)); |
| 167 } else { | 167 } else { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 this.currentlyValid_ = !this.isPlaceholder; | 217 this.currentlyValid_ = !this.isPlaceholder; |
| 218 }, | 218 }, |
| 219 | 219 |
| 220 /** | 220 /** |
| 221 * Returns the input field values as an array suitable for passing to | 221 * Returns the input field values as an array suitable for passing to |
| 222 * chrome.send. The order of the array is important. | 222 * chrome.send. The order of the array is important. |
| 223 * @private | 223 * @private |
| 224 * @return {array} The current input field values. | 224 * @return {array} The current input field values. |
| 225 */ | 225 */ |
| 226 getInputFieldValues_: function() { | 226 getInputFieldValues_: function() { |
| 227 return [ this.nameField_.value, | 227 return [this.nameField_.value, |
| 228 this.keywordField_.value, | 228 this.keywordField_.value, |
| 229 this.urlField_.value ]; | 229 this.urlField_.value]; |
| 230 }, | 230 }, |
| 231 | 231 |
| 232 /** | 232 /** |
| 233 * Begins the process of asynchronously validing the input fields. | 233 * Begins the process of asynchronously validing the input fields. |
| 234 * @private | 234 * @private |
| 235 */ | 235 */ |
| 236 startFieldValidation_: function() { | 236 startFieldValidation_: function() { |
| 237 this.waitingForValidation_ = true; | 237 this.waitingForValidation_ = true; |
| 238 var args = this.getInputFieldValues_(); | 238 var args = this.getInputFieldValues_(); |
| 239 args.push(this.searchEngine_['modelIndex']); | 239 args.push(this.searchEngine_['modelIndex']); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 SearchEngineList.prototype = { | 279 SearchEngineList.prototype = { |
| 280 __proto__: InlineEditableItemList.prototype, | 280 __proto__: InlineEditableItemList.prototype, |
| 281 | 281 |
| 282 /** @inheritDoc */ | 282 /** @inheritDoc */ |
| 283 createItem: function(searchEngine) { | 283 createItem: function(searchEngine) { |
| 284 return new SearchEngineListItem(searchEngine); | 284 return new SearchEngineListItem(searchEngine); |
| 285 }, | 285 }, |
| 286 | 286 |
| 287 /** @inheritDoc */ | 287 /** @inheritDoc */ |
| 288 deleteItemAtIndex: function(index) { | 288 deleteItemAtIndex: function(index) { |
| 289 var modelIndex = this.dataModel.item(index)['modelIndex'] | 289 var modelIndex = this.dataModel.item(index)['modelIndex']; |
| 290 chrome.send('removeSearchEngine', [String(modelIndex)]); | 290 chrome.send('removeSearchEngine', [String(modelIndex)]); |
| 291 }, | 291 }, |
| 292 | 292 |
| 293 /** | 293 /** |
| 294 * Passes the results of an input validation check to the requesting row | 294 * Passes the results of an input validation check to the requesting row |
| 295 * if it's still being edited. | 295 * if it's still being edited. |
| 296 * @param {number} modelIndex The model index of the item that was checked. | 296 * @param {number} modelIndex The model index of the item that was checked. |
| 297 * @param {Object} validity A dictionary of validitation results. | 297 * @param {Object} validity A dictionary of validitation results. |
| 298 */ | 298 */ |
| 299 validationComplete: function(validity, modelIndex) { | 299 validationComplete: function(validity, modelIndex) { |
| 300 // If it's not still being edited, it no longer matters. | 300 // If it's not still being edited, it no longer matters. |
| 301 var currentSelection = this.selectedItem; | 301 var currentSelection = this.selectedItem; |
| 302 if (!currentSelection) | 302 if (!currentSelection) |
| 303 return; | 303 return; |
| 304 var listItem = this.getListItem(currentSelection); | 304 var listItem = this.getListItem(currentSelection); |
| 305 if (listItem.editing && currentSelection['modelIndex'] == modelIndex) | 305 if (listItem.editing && currentSelection['modelIndex'] == modelIndex) |
| 306 listItem.validationComplete(validity); | 306 listItem.validationComplete(validity); |
| 307 }, | 307 }, |
| 308 }; | 308 }; |
| 309 | 309 |
| 310 // Export | 310 // Export |
| 311 return { | 311 return { |
| 312 SearchEngineList: SearchEngineList | 312 SearchEngineList: SearchEngineList |
| 313 }; | 313 }; |
| 314 | 314 |
| 315 }); | 315 }); |
| 316 | 316 |
| OLD | NEW |