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 Page
= cr
.ui
.pageManager
.Page
;
7 /** @const */ var PageManager
= cr
.ui
.pageManager
.PageManager
;
8 /** @const */ var ArrayDataModel
= cr
.ui
.ArrayDataModel
;
11 * Encapsulated handling of search engine management page.
13 * @extends {cr.ui.pageManager.Page}
15 function SearchEngineManager() {
16 this.activeNavTab
= null;
17 Page
.call(this, 'searchEngines',
18 loadTimeData
.getString('searchEngineManagerPageTabTitle'),
19 'search-engine-manager-page');
22 cr
.addSingletonGetter(SearchEngineManager
);
24 SearchEngineManager
.prototype = {
25 __proto__
: Page
.prototype,
28 * List for default search engine options.
34 * List for other search engine options.
40 * List for extension keywords.
46 initializePage: function() {
47 Page
.prototype.initializePage
.call(this);
49 this.defaultsList_
= $('default-search-engine-list');
50 this.setUpList_(this.defaultsList_
);
52 this.othersList_
= $('other-search-engine-list');
53 this.setUpList_(this.othersList_
);
55 this.extensionList_
= $('extension-keyword-list');
56 this.setUpList_(this.extensionList_
);
58 $('search-engine-manager-confirm').onclick = function() {
59 PageManager
.closeOverlay();
64 * Sets up the given list as a search engine list
65 * @param {HTMLElement} list The list to set up.
68 setUpList_: function(list
) {
69 options
.search_engines
.SearchEngineList
.decorate(list
);
70 list
.autoExpands
= true;
74 * Updates the search engine list with the given entries.
76 * @param {!Array} defaultEngines List of possible default search engines.
77 * @param {!Array} otherEngines List of other search engines.
78 * @param {!Array} keywords List of keywords from extensions.
80 updateSearchEngineList_: function(defaultEngines
, otherEngines
, keywords
) {
81 this.defaultsList_
.dataModel
= new ArrayDataModel(defaultEngines
);
83 otherEngines
= otherEngines
.map(function(x
) {
84 return [x
, x
.name
.toLocaleLowerCase()];
85 }).sort(function(a
, b
) {
86 return a
[1].localeCompare(b
[1]);
91 var othersModel
= new ArrayDataModel(otherEngines
);
92 // Add a "new engine" row.
97 this.othersList_
.dataModel
= othersModel
;
99 if (keywords
.length
> 0) {
100 $('extension-keyword-div').hidden
= false;
101 var extensionsModel
= new ArrayDataModel(keywords
);
102 this.extensionList_
.dataModel
= extensionsModel
;
104 $('extension-keyword-div').hidden
= true;
109 SearchEngineManager
.updateSearchEngineList = function(defaultEngines
,
112 SearchEngineManager
.getInstance().updateSearchEngineList_(defaultEngines
,
117 SearchEngineManager
.validityCheckCallback = function(validity
, modelIndex
) {
118 // Forward to all lists; those without a matching modelIndex will ignore it.
119 SearchEngineManager
.getInstance().defaultsList_
.validationComplete(
120 validity
, modelIndex
);
121 SearchEngineManager
.getInstance().othersList_
.validationComplete(
122 validity
, modelIndex
);
123 SearchEngineManager
.getInstance().extensionList_
.validationComplete(
124 validity
, modelIndex
);
129 SearchEngineManager
: SearchEngineManager