BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / resources / options / search_engine_manager.js
blobce31ef6918163782cd2125798876f2c1a896a934
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;
10   /**
11    * Encapsulated handling of search engine management page.
12    * @constructor
13    * @extends {cr.ui.pageManager.Page}
14    */
15   function SearchEngineManager() {
16     this.activeNavTab = null;
17     Page.call(this, 'searchEngines',
18               loadTimeData.getString('searchEngineManagerPageTabTitle'),
19               'search-engine-manager-page');
20   }
22   cr.addSingletonGetter(SearchEngineManager);
24   SearchEngineManager.prototype = {
25     __proto__: Page.prototype,
27     /**
28      * List for default search engine options.
29      * @private
30      */
31     defaultsList_: null,
33     /**
34      * List for other search engine options.
35      * @private
36      */
37     othersList_: null,
39     /**
40      * List for extension keywords.
41      * @private
42      */
43     extensionList_: null,
45     /** @override */
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();
60       };
61     },
63     /**
64      * Sets up the given list as a search engine list
65      * @param {HTMLElement} list The list to set up.
66      * @private
67      */
68     setUpList_: function(list) {
69       options.search_engines.SearchEngineList.decorate(list);
70       list.autoExpands = true;
71     },
73     /**
74      * Updates the search engine list with the given entries.
75      * @private
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.
79      */
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]);
87       }).map(function(x) {
88         return x[0];
89       });
91       var othersModel = new ArrayDataModel(otherEngines);
92       // Add a "new engine" row.
93       othersModel.push({
94         'modelIndex': '-1',
95         'canBeEdited': true
96       });
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;
103       } else {
104         $('extension-keyword-div').hidden = true;
105       }
106     },
107   };
109   SearchEngineManager.updateSearchEngineList = function(defaultEngines,
110                                                         otherEngines,
111                                                         keywords) {
112     SearchEngineManager.getInstance().updateSearchEngineList_(defaultEngines,
113                                                               otherEngines,
114                                                               keywords);
115   };
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);
125   };
127   // Export
128   return {
129     SearchEngineManager: SearchEngineManager
130   };