OLD | NEW |
| (Empty) |
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. | |
4 | |
5 cr.define('options', function() { | |
6 /** @const */ var OptionsPage = options.OptionsPage; | |
7 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | |
8 | |
9 /** | |
10 * Encapsulated handling of search engine management page. | |
11 * @constructor | |
12 */ | |
13 function SearchEngineManager() { | |
14 this.activeNavTab = null; | |
15 OptionsPage.call(this, 'searchEngines', | |
16 loadTimeData.getString('searchEngineManagerPageTabTitle'), | |
17 'search-engine-manager-page'); | |
18 } | |
19 | |
20 cr.addSingletonGetter(SearchEngineManager); | |
21 | |
22 SearchEngineManager.prototype = { | |
23 __proto__: OptionsPage.prototype, | |
24 | |
25 /** | |
26 * List for default search engine options. | |
27 * @private | |
28 */ | |
29 defaultsList_: null, | |
30 | |
31 /** | |
32 * List for other search engine options. | |
33 * @private | |
34 */ | |
35 othersList_: null, | |
36 | |
37 /** | |
38 * List for extension keywords. | |
39 * @private | |
40 extensionList_ : null, | |
41 | |
42 /** inheritDoc */ | |
43 initializePage: function() { | |
44 OptionsPage.prototype.initializePage.call(this); | |
45 | |
46 this.defaultsList_ = $('default-search-engine-list'); | |
47 this.setUpList_(this.defaultsList_); | |
48 | |
49 this.othersList_ = $('other-search-engine-list'); | |
50 this.setUpList_(this.othersList_); | |
51 | |
52 this.extensionList_ = $('extension-keyword-list'); | |
53 this.setUpList_(this.extensionList_); | |
54 | |
55 $('search-engine-manager-confirm').onclick = function() { | |
56 OptionsPage.closeOverlay(); | |
57 }; | |
58 }, | |
59 | |
60 /** | |
61 * Sets up the given list as a search engine list | |
62 * @param {List} list The list to set up. | |
63 * @private | |
64 */ | |
65 setUpList_: function(list) { | |
66 options.search_engines.SearchEngineList.decorate(list); | |
67 list.autoExpands = true; | |
68 }, | |
69 | |
70 /** | |
71 * Updates the search engine list with the given entries. | |
72 * @private | |
73 * @param {Array} defaultEngines List of possible default search engines. | |
74 * @param {Array} otherEngines List of other search engines. | |
75 * @param {Array} keywords List of keywords from extensions. | |
76 */ | |
77 updateSearchEngineList_: function(defaultEngines, otherEngines, keywords) { | |
78 this.defaultsList_.dataModel = new ArrayDataModel(defaultEngines); | |
79 | |
80 otherEngines = otherEngines.map(function(x) { | |
81 return [x, x['name'].toLocaleLowerCase()]; | |
82 }).sort(function(a, b) { | |
83 return a[1].localeCompare(b[1]); | |
84 }).map(function(x) { | |
85 return x[0]; | |
86 }); | |
87 | |
88 var othersModel = new ArrayDataModel(otherEngines); | |
89 // Add a "new engine" row. | |
90 othersModel.push({ | |
91 'modelIndex': '-1', | |
92 'canBeEdited': true | |
93 }); | |
94 this.othersList_.dataModel = othersModel; | |
95 | |
96 if (keywords.length > 0) { | |
97 $('extension-keyword-div').hidden = false; | |
98 var extensionsModel = new ArrayDataModel(keywords); | |
99 this.extensionList_.dataModel = extensionsModel; | |
100 } else { | |
101 $('extension-keyword-div').hidden = true; | |
102 } | |
103 }, | |
104 }; | |
105 | |
106 SearchEngineManager.updateSearchEngineList = function(defaultEngines, | |
107 otherEngines, | |
108 keywords) { | |
109 SearchEngineManager.getInstance().updateSearchEngineList_(defaultEngines, | |
110 otherEngines, | |
111 keywords); | |
112 }; | |
113 | |
114 SearchEngineManager.validityCheckCallback = function(validity, modelIndex) { | |
115 // Forward to both lists; the one without a matching modelIndex will ignore | |
116 // it. | |
117 SearchEngineManager.getInstance().defaultsList_.validationComplete( | |
118 validity, modelIndex); | |
119 SearchEngineManager.getInstance().othersList_.validationComplete( | |
120 validity, modelIndex); | |
121 }; | |
122 | |
123 // Export | |
124 return { | |
125 SearchEngineManager: SearchEngineManager | |
126 }; | |
127 | |
128 }); | |
129 | |
OLD | NEW |