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
3 // found in the LICENSE file.
5 cr.define('options', function() {
6 /** @const */ var OptionsPage = options.OptionsPage;
7 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel;
10 * Encapsulated handling of search engine management page.
13 function SearchEngineManager() {
14 this.activeNavTab = null;
15 OptionsPage.call(this, 'searchEngines',
16 loadTimeData.getString('searchEngineManagerPageTabTitle'),
17 'search-engine-manager-page');
20 cr.addSingletonGetter(SearchEngineManager);
22 SearchEngineManager.prototype = {
23 __proto__: OptionsPage.prototype,
26 * List for default search engine options.
32 * List for other search engine options.
38 * List for extension keywords.
44 initializePage: function() {
45 OptionsPage.prototype.initializePage.call(this);
47 this.defaultsList_ = $('default-search-engine-list');
48 this.setUpList_(this.defaultsList_);
50 this.othersList_ = $('other-search-engine-list');
51 this.setUpList_(this.othersList_);
53 this.extensionList_ = $('extension-keyword-list');
54 this.setUpList_(this.extensionList_);
56 $('search-engine-manager-confirm').onclick = function() {
57 OptionsPage.closeOverlay();
62 * Sets up the given list as a search engine list
63 * @param {List} list The list to set up.
66 setUpList_: function(list) {
67 options.search_engines.SearchEngineList.decorate(list);
68 list.autoExpands = true;
72 * Updates the search engine list with the given entries.
74 * @param {Array} defaultEngines List of possible default search engines.
75 * @param {Array} otherEngines List of other search engines.
76 * @param {Array} keywords List of keywords from extensions.
78 updateSearchEngineList_: function(defaultEngines, otherEngines, keywords) {
79 this.defaultsList_.dataModel = new ArrayDataModel(defaultEngines);
81 otherEngines = otherEngines.map(function(x) {
82 return [x, x.name.toLocaleLowerCase()];
83 }).sort(function(a, b) {
84 return a[1].localeCompare(b[1]);
89 var othersModel = new ArrayDataModel(otherEngines);
90 // Add a "new engine" row.
95 this.othersList_.dataModel = othersModel;
97 if (keywords.length > 0) {
98 $('extension-keyword-div').hidden = false;
99 var extensionsModel = new ArrayDataModel(keywords);
100 this.extensionList_.dataModel = extensionsModel;
102 $('extension-keyword-div').hidden = true;
107 SearchEngineManager.updateSearchEngineList = function(defaultEngines,
110 SearchEngineManager.getInstance().updateSearchEngineList_(defaultEngines,
115 SearchEngineManager.validityCheckCallback = function(validity, modelIndex) {
116 // Forward to all lists; those without a matching modelIndex will ignore it.
117 SearchEngineManager.getInstance().defaultsList_.validationComplete(
118 validity, modelIndex);
119 SearchEngineManager.getInstance().othersList_.validationComplete(
120 validity, modelIndex);
121 SearchEngineManager.getInstance().extensionList_.validationComplete(
122 validity, modelIndex);
127 SearchEngineManager: SearchEngineManager