| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 const OptionsPage = options.OptionsPage; | 6 const OptionsPage = options.OptionsPage; |
| 7 const ArrayDataModel = cr.ui.ArrayDataModel; | 7 const ArrayDataModel = cr.ui.ArrayDataModel; |
| 8 const ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; | 8 const ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; |
| 9 | 9 |
| 10 /** | 10 /** |
| 11 * Encapsulated handling of search engine management page. | 11 * Encapsulated handling of search engine management page. |
| 12 * @constructor | 12 * @constructor |
| 13 */ | 13 */ |
| 14 function SearchEngineManager() { | 14 function SearchEngineManager() { |
| 15 this.activeNavTab = null; | 15 this.activeNavTab = null; |
| 16 OptionsPage.call(this, 'searchEngines', | 16 OptionsPage.call(this, 'searchEngines', |
| 17 templateData.searchEngineManagerPage, | 17 templateData.searchEngineManagerPage, |
| 18 'searchEngineManagerPage'); | 18 'searchEngineManagerPage'); |
| 19 } | 19 } |
| 20 | 20 |
| 21 cr.addSingletonGetter(SearchEngineManager); | 21 cr.addSingletonGetter(SearchEngineManager); |
| 22 | 22 |
| 23 SearchEngineManager.prototype = { | 23 SearchEngineManager.prototype = { |
| 24 __proto__: OptionsPage.prototype, | 24 __proto__: OptionsPage.prototype, |
| 25 list_: null, | |
| 26 | 25 |
| 26 /** |
| 27 * List for default search engine options |
| 28 * @type {boolean} |
| 29 * @private |
| 30 */ |
| 31 defaultsList_: null, |
| 32 |
| 33 /** |
| 34 * List for other search engine options |
| 35 * @type {boolean} |
| 36 * @private |
| 37 */ |
| 38 othersList_: null, |
| 39 |
| 40 /** inheritDoc */ |
| 27 initializePage: function() { | 41 initializePage: function() { |
| 28 OptionsPage.prototype.initializePage.call(this); | 42 OptionsPage.prototype.initializePage.call(this); |
| 29 | 43 |
| 30 this.list_ = $('searchEngineList') | 44 this.defaultsList_ = $('defaultSearchEngineList'); |
| 31 options.search_engines.SearchEngineList.decorate(this.list_); | 45 this.setUpList_(this.defaultsList_); |
| 32 var selectionModel = new ListSingleSelectionModel; | 46 |
| 33 this.list_.selectionModel = selectionModel; | 47 this.othersList_ = $('otherSearchEngineList'); |
| 34 this.list_.autoExpands = true; | 48 this.setUpList_(this.othersList_); |
| 49 }, |
| 50 |
| 51 /** |
| 52 * Sets up the given list as a search engine list |
| 53 * @param {List} list The list to set up. |
| 54 * @private |
| 55 */ |
| 56 setUpList_: function(list) { |
| 57 options.search_engines.SearchEngineList.decorate(list); |
| 58 list.selectionModel = new ListSingleSelectionModel; |
| 59 list.autoExpands = true; |
| 35 }, | 60 }, |
| 36 | 61 |
| 37 /** | 62 /** |
| 38 * Updates the search engine list with the given entries. | 63 * Updates the search engine list with the given entries. |
| 39 * @private | 64 * @private |
| 40 * @param {Array} engineList List of available search engines. | 65 * @param {Array} defaultEngines List of possible default search engines. |
| 66 * @param {Array} otherEngines List of other search engines. |
| 41 */ | 67 */ |
| 42 updateSearchEngineList_: function(engineList) { | 68 updateSearchEngineList_: function(defaultEngines, otherEngines) { |
| 43 var model = new ArrayDataModel(engineList); | 69 this.defaultsList_.dataModel = new ArrayDataModel(defaultEngines); |
| 44 model.push({ | 70 var othersModel = new ArrayDataModel(otherEngines); |
| 71 // Add a "new engine" row. |
| 72 othersModel.push({ |
| 45 'modelIndex': '-1' | 73 'modelIndex': '-1' |
| 46 }); | 74 }); |
| 47 this.list_.dataModel = model; | 75 this.othersList_.dataModel = othersModel; |
| 48 }, | 76 }, |
| 49 }; | 77 }; |
| 50 | 78 |
| 51 SearchEngineManager.updateSearchEngineList = function(engineList) { | 79 SearchEngineManager.updateSearchEngineList = function(defaultEngines, |
| 52 SearchEngineManager.getInstance().updateSearchEngineList_(engineList); | 80 otherEngines) { |
| 81 SearchEngineManager.getInstance().updateSearchEngineList_(defaultEngines, |
| 82 otherEngines); |
| 53 }; | 83 }; |
| 54 | 84 |
| 55 SearchEngineManager.validityCheckCallback = function(validity, modelIndex) { | 85 SearchEngineManager.validityCheckCallback = function(validity, modelIndex) { |
| 56 SearchEngineManager.getInstance().list_.validationComplete(validity, | 86 // Forward to both lists; the one without a matching modelIndex will ignore |
| 57 modelIndex); | 87 // it. |
| 88 SearchEngineManager.getInstance().defaultsList_.validationComplete( |
| 89 validity, modelIndex); |
| 90 SearchEngineManager.getInstance().othersList_.validationComplete( |
| 91 validity, modelIndex); |
| 58 }; | 92 }; |
| 59 | 93 |
| 60 // Export | 94 // Export |
| 61 return { | 95 return { |
| 62 SearchEngineManager: SearchEngineManager | 96 SearchEngineManager: SearchEngineManager |
| 63 }; | 97 }; |
| 64 | 98 |
| 65 }); | 99 }); |
| 66 | 100 |
| OLD | NEW |