OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 */ var Page = cr.ui.pageManager.Page; | 6 /** @const */ var Page = cr.ui.pageManager.Page; |
7 /** @const */ var PageManager = cr.ui.pageManager.PageManager; | 7 /** @const */ var PageManager = cr.ui.pageManager.PageManager; |
8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
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 * @extends {cr.ui.pageManager.Page} | 13 * @extends {cr.ui.pageManager.Page} |
14 */ | 14 */ |
15 function SearchEngineManager() { | 15 function SearchEngineManager() { |
16 this.activeNavTab = null; | 16 this.activeNavTab = null; |
17 Page.call(this, 'searchEngines', | 17 Page.call( |
18 loadTimeData.getString('searchEngineManagerPageTabTitle'), | 18 this, 'searchEngines', |
19 'search-engine-manager-page'); | 19 loadTimeData.getString('searchEngineManagerPageTabTitle'), |
| 20 'search-engine-manager-page'); |
20 } | 21 } |
21 | 22 |
22 cr.addSingletonGetter(SearchEngineManager); | 23 cr.addSingletonGetter(SearchEngineManager); |
23 | 24 |
24 SearchEngineManager.prototype = { | 25 SearchEngineManager.prototype = { |
25 __proto__: Page.prototype, | 26 __proto__: Page.prototype, |
26 | 27 |
27 /** | 28 /** |
28 * List for default search engine options. | 29 * List for default search engine options. |
29 * @private | 30 * @private |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 /** | 74 /** |
74 * Updates the search engine list with the given entries. | 75 * Updates the search engine list with the given entries. |
75 * @private | 76 * @private |
76 * @param {!Array} defaultEngines List of possible default search engines. | 77 * @param {!Array} defaultEngines List of possible default search engines. |
77 * @param {!Array} otherEngines List of other search engines. | 78 * @param {!Array} otherEngines List of other search engines. |
78 * @param {!Array} keywords List of keywords from extensions. | 79 * @param {!Array} keywords List of keywords from extensions. |
79 */ | 80 */ |
80 updateSearchEngineList_: function(defaultEngines, otherEngines, keywords) { | 81 updateSearchEngineList_: function(defaultEngines, otherEngines, keywords) { |
81 this.defaultsList_.dataModel = new ArrayDataModel(defaultEngines); | 82 this.defaultsList_.dataModel = new ArrayDataModel(defaultEngines); |
82 | 83 |
83 otherEngines = otherEngines.map(function(x) { | 84 otherEngines = otherEngines |
84 return [x, x.name.toLocaleLowerCase()]; | 85 .map(function(x) { |
85 }).sort(function(a, b) { | 86 return [x, x.name.toLocaleLowerCase()]; |
86 return a[1].localeCompare(b[1]); | 87 }) |
87 }).map(function(x) { | 88 .sort(function(a, b) { |
88 return x[0]; | 89 return a[1].localeCompare(b[1]); |
89 }); | 90 }) |
| 91 .map(function(x) { |
| 92 return x[0]; |
| 93 }); |
90 | 94 |
91 var othersModel = new ArrayDataModel(otherEngines); | 95 var othersModel = new ArrayDataModel(otherEngines); |
92 // Add a "new engine" row. | 96 // Add a "new engine" row. |
93 othersModel.push({ | 97 othersModel.push({'modelIndex': '-1', 'canBeEdited': true}); |
94 'modelIndex': '-1', | |
95 'canBeEdited': true | |
96 }); | |
97 this.othersList_.dataModel = othersModel; | 98 this.othersList_.dataModel = othersModel; |
98 | 99 |
99 if (keywords.length > 0) { | 100 if (keywords.length > 0) { |
100 $('extension-keyword-div').hidden = false; | 101 $('extension-keyword-div').hidden = false; |
101 var extensionsModel = new ArrayDataModel(keywords); | 102 var extensionsModel = new ArrayDataModel(keywords); |
102 this.extensionList_.dataModel = extensionsModel; | 103 this.extensionList_.dataModel = extensionsModel; |
103 } else { | 104 } else { |
104 $('extension-keyword-div').hidden = true; | 105 $('extension-keyword-div').hidden = true; |
105 } | 106 } |
106 }, | 107 }, |
107 }; | 108 }; |
108 | 109 |
109 SearchEngineManager.updateSearchEngineList = function(defaultEngines, | 110 SearchEngineManager.updateSearchEngineList = function( |
110 otherEngines, | 111 defaultEngines, otherEngines, keywords) { |
111 keywords) { | 112 SearchEngineManager.getInstance().updateSearchEngineList_( |
112 SearchEngineManager.getInstance().updateSearchEngineList_(defaultEngines, | 113 defaultEngines, otherEngines, keywords); |
113 otherEngines, | |
114 keywords); | |
115 }; | 114 }; |
116 | 115 |
117 SearchEngineManager.validityCheckCallback = function(validity, modelIndex) { | 116 SearchEngineManager.validityCheckCallback = function(validity, modelIndex) { |
118 // Forward to all lists; those without a matching modelIndex will ignore it. | 117 // Forward to all lists; those without a matching modelIndex will ignore it. |
119 SearchEngineManager.getInstance().defaultsList_.validationComplete( | 118 SearchEngineManager.getInstance().defaultsList_.validationComplete( |
120 validity, modelIndex); | 119 validity, modelIndex); |
121 SearchEngineManager.getInstance().othersList_.validationComplete( | 120 SearchEngineManager.getInstance().othersList_.validationComplete( |
122 validity, modelIndex); | 121 validity, modelIndex); |
123 SearchEngineManager.getInstance().extensionList_.validationComplete( | 122 SearchEngineManager.getInstance().extensionList_.validationComplete( |
124 validity, modelIndex); | 123 validity, modelIndex); |
125 }; | 124 }; |
126 | 125 |
127 // Export | 126 // Export |
128 return { | 127 return {SearchEngineManager: SearchEngineManager}; |
129 SearchEngineManager: SearchEngineManager | |
130 }; | |
131 | 128 |
132 }); | 129 }); |
133 | |
OLD | NEW |