OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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.search_engines', function() { | 5 cr.define('options.search_engines', function() { |
6 const InlineEditableItemList = options.InlineEditableItemList; | 6 const InlineEditableItemList = options.InlineEditableItemList; |
7 const InlineEditableItem = options.InlineEditableItem; | 7 const InlineEditableItem = options.InlineEditableItem; |
8 const ListInlineHeaderSelectionController = | 8 const ListSelectionController = cr.ui.ListSelectionController; |
9 options.ListInlineHeaderSelectionController; | |
10 | 9 |
11 /** | 10 /** |
12 * Creates a new search engine list item. | 11 * Creates a new search engine list item. |
13 * @param {Object} searchEnigne The search engine this represents. | 12 * @param {Object} searchEnigne The search engine this represents. |
14 * @constructor | 13 * @constructor |
15 * @extends {cr.ui.ListItem} | 14 * @extends {cr.ui.ListItem} |
16 */ | 15 */ |
17 function SearchEngineListItem(searchEngine) { | 16 function SearchEngineListItem(searchEngine) { |
18 var el = cr.doc.createElement('div'); | 17 var el = cr.doc.createElement('div'); |
19 el.searchEngine_ = searchEngine; | 18 el.searchEngine_ = searchEngine; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 | 82 |
84 if (engine['modelIndex'] == '-1') { | 83 if (engine['modelIndex'] == '-1') { |
85 this.isPlaceholder_ = true; | 84 this.isPlaceholder_ = true; |
86 engine['name'] = ''; | 85 engine['name'] = ''; |
87 engine['keyword'] = ''; | 86 engine['keyword'] = ''; |
88 engine['url'] = ''; | 87 engine['url'] = ''; |
89 } | 88 } |
90 | 89 |
91 this.currentlyValid_ = !this.isPlaceholder_; | 90 this.currentlyValid_ = !this.isPlaceholder_; |
92 | 91 |
93 if (engine['heading']) { | 92 if (engine['default']) |
94 this.classList.add('heading'); | |
95 this.editable = false; | |
96 } else if (engine['default']) { | |
97 this.classList.add('default'); | 93 this.classList.add('default'); |
98 } | |
99 | 94 |
100 this.deletable = engine['canBeRemoved']; | 95 this.deletable = engine['canBeRemoved']; |
101 | 96 |
102 var nameText = engine['name']; | |
103 var keywordText = engine['keyword']; | |
104 var urlText = engine['url']; | |
105 if (engine['heading']) { | |
106 nameText = engine['heading']; | |
107 keywordText = localStrings.getString('searchEngineTableKeywordHeader'); | |
108 urlText = localStrings.getString('searchEngineTableURLHeader'); | |
109 } | |
110 | |
111 // Construct the name column. | 97 // Construct the name column. |
112 var nameColEl = this.ownerDocument.createElement('div'); | 98 var nameColEl = this.ownerDocument.createElement('div'); |
113 nameColEl.className = 'name-column'; | 99 nameColEl.className = 'name-column'; |
114 this.contentElement.appendChild(nameColEl); | 100 this.contentElement.appendChild(nameColEl); |
115 | 101 |
116 // For non-heading rows, start with a favicon. | 102 // Add the favicon. |
117 if (!engine['heading']) { | 103 var faviconDivEl = this.ownerDocument.createElement('div'); |
118 var faviconDivEl = this.ownerDocument.createElement('div'); | 104 faviconDivEl.className = 'favicon'; |
119 faviconDivEl.className = 'favicon'; | 105 var imgEl = this.ownerDocument.createElement('img'); |
120 var imgEl = this.ownerDocument.createElement('img'); | 106 imgEl.src = 'chrome://favicon/iconurl/' + engine['iconURL']; |
121 imgEl.src = 'chrome://favicon/iconurl/' + engine['iconURL']; | 107 faviconDivEl.appendChild(imgEl); |
122 faviconDivEl.appendChild(imgEl); | 108 nameColEl.appendChild(faviconDivEl); |
123 nameColEl.appendChild(faviconDivEl); | |
124 } | |
125 | 109 |
126 var nameEl = this.createEditableTextCell(nameText, this.isPlaceholder_); | 110 var nameEl = this.createEditableTextCell(engine['name'], |
| 111 this.isPlaceholder_); |
127 nameColEl.appendChild(nameEl); | 112 nameColEl.appendChild(nameEl); |
128 | 113 |
129 // Then the keyword column. | 114 // Then the keyword column. |
130 var keywordEl = this.createEditableTextCell(keywordText, | 115 var keywordEl = this.createEditableTextCell(engine['keyword'], |
131 this.isPlaceholder_); | 116 this.isPlaceholder_); |
132 keywordEl.className = 'keyword-column'; | 117 keywordEl.className = 'keyword-column'; |
133 this.contentElement.appendChild(keywordEl); | 118 this.contentElement.appendChild(keywordEl); |
134 | 119 |
135 // And the URL column. | 120 // And the URL column. |
136 var urlEl = this.createEditableTextCell(urlText, this.isPlaceholder_); | 121 var urlEl = this.createEditableTextCell(engine['url'], |
| 122 this.isPlaceholder_); |
137 var urlWithButtonEl = this.ownerDocument.createElement('div'); | 123 var urlWithButtonEl = this.ownerDocument.createElement('div'); |
138 urlWithButtonEl.appendChild(urlEl); | 124 urlWithButtonEl.appendChild(urlEl); |
139 urlWithButtonEl.className = 'url-column'; | 125 urlWithButtonEl.className = 'url-column'; |
140 this.contentElement.appendChild(urlWithButtonEl); | 126 this.contentElement.appendChild(urlWithButtonEl); |
141 // Add the Make Default button. Temporary until drag-and-drop re-ordering | 127 // Add the Make Default button. Temporary until drag-and-drop re-ordering |
142 // is implemented. When this is removed, remove the extra div above. | 128 // is implemented. When this is removed, remove the extra div above. |
143 if (engine['canBeDefault']) { | 129 if (engine['canBeDefault']) { |
144 var makeDefaultButtonEl = this.ownerDocument.createElement('button'); | 130 var makeDefaultButtonEl = this.ownerDocument.createElement('button'); |
| 131 makeDefaultButtonEl.className = "raw-button"; |
145 makeDefaultButtonEl.textContent = | 132 makeDefaultButtonEl.textContent = |
146 templateData.makeDefaultSearchEngineButton; | 133 templateData.makeDefaultSearchEngineButton; |
147 makeDefaultButtonEl.onclick = function(e) { | 134 makeDefaultButtonEl.onclick = function(e) { |
148 chrome.send('managerSetDefaultSearchEngine', [engine['modelIndex']]); | 135 chrome.send('managerSetDefaultSearchEngine', [engine['modelIndex']]); |
149 }; | 136 }; |
150 // Don't select the row when clicking the button. | 137 // Don't select the row when clicking the button. |
151 makeDefaultButtonEl.onmousedown = function(e) { | 138 makeDefaultButtonEl.onmousedown = function(e) { |
152 e.stopPropagation(); | 139 e.stopPropagation(); |
153 }; | 140 }; |
154 urlWithButtonEl.appendChild(makeDefaultButtonEl); | 141 urlWithButtonEl.appendChild(makeDefaultButtonEl); |
155 } | 142 } |
156 | 143 |
157 // Do final adjustment to the input fields. | 144 // Do final adjustment to the input fields. |
158 if (!engine['heading']) { | 145 this.nameField_ = nameEl.querySelector('input'); |
159 this.nameField_ = nameEl.querySelector('input'); | 146 this.keywordField_ = keywordEl.querySelector('input'); |
160 this.keywordField_ = keywordEl.querySelector('input'); | 147 this.urlField_ = urlEl.querySelector('input'); |
161 this.urlField_ = urlEl.querySelector('input'); | |
162 | 148 |
163 if (engine['urlLocked']) | 149 if (engine['urlLocked']) |
164 this.urlField_.disabled = true; | 150 this.urlField_.disabled = true; |
165 | 151 |
166 if (this.isPlaceholder_) { | 152 if (this.isPlaceholder_) { |
167 this.nameField_.placeholder = | 153 this.nameField_.placeholder = |
168 localStrings.getString('searchEngineTableNamePlaceholder'); | 154 localStrings.getString('searchEngineTableNamePlaceholder'); |
169 this.keywordField_.placeholder = | 155 this.keywordField_.placeholder = |
170 localStrings.getString('searchEngineTableKeywordPlaceholder'); | 156 localStrings.getString('searchEngineTableKeywordPlaceholder'); |
171 this.urlField_.placeholder = | 157 this.urlField_.placeholder = |
172 localStrings.getString('searchEngineTableURLPlaceholder'); | 158 localStrings.getString('searchEngineTableURLPlaceholder'); |
173 } | 159 } |
174 | 160 |
175 var fields = [ this.nameField_, this.keywordField_, this.urlField_ ]; | 161 var fields = [ this.nameField_, this.keywordField_, this.urlField_ ]; |
176 for (var i = 0; i < fields.length; i++) { | 162 for (var i = 0; i < fields.length; i++) { |
177 fields[i].oninput = this.startFieldValidation_.bind(this); | 163 fields[i].oninput = this.startFieldValidation_.bind(this); |
178 } | |
179 } | 164 } |
180 | 165 |
181 // Listen for edit events. | 166 // Listen for edit events. |
182 this.addEventListener('edit', this.onEditStarted_.bind(this)); | 167 this.addEventListener('edit', this.onEditStarted_.bind(this)); |
183 this.addEventListener('canceledit', this.onEditCancelled_.bind(this)); | 168 this.addEventListener('canceledit', this.onEditCancelled_.bind(this)); |
184 this.addEventListener('commitedit', this.onEditCommitted_.bind(this)); | 169 this.addEventListener('commitedit', this.onEditCommitted_.bind(this)); |
185 }, | 170 }, |
186 | 171 |
187 /** @inheritDoc */ | 172 /** @inheritDoc */ |
188 get currentInputIsValid() { | 173 get currentInputIsValid() { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 | 281 |
297 SearchEngineList.prototype = { | 282 SearchEngineList.prototype = { |
298 __proto__: InlineEditableItemList.prototype, | 283 __proto__: InlineEditableItemList.prototype, |
299 | 284 |
300 /** @inheritDoc */ | 285 /** @inheritDoc */ |
301 createItem: function(searchEngine) { | 286 createItem: function(searchEngine) { |
302 return new SearchEngineListItem(searchEngine); | 287 return new SearchEngineListItem(searchEngine); |
303 }, | 288 }, |
304 | 289 |
305 /** @inheritDoc */ | 290 /** @inheritDoc */ |
306 createSelectionController: function(sm) { | |
307 return new ListInlineHeaderSelectionController(sm, this); | |
308 }, | |
309 | |
310 /** @inheritDoc */ | |
311 deleteItemAtIndex: function(index) { | 291 deleteItemAtIndex: function(index) { |
312 var modelIndex = this.dataModel.item(index)['modelIndex'] | 292 var modelIndex = this.dataModel.item(index)['modelIndex'] |
313 chrome.send('removeSearchEngine', [String(modelIndex)]); | 293 chrome.send('removeSearchEngine', [String(modelIndex)]); |
314 }, | 294 }, |
315 | 295 |
316 /** | 296 /** |
317 * Returns true if the given item is selectable. | |
318 * @param {number} index The index to check. | |
319 */ | |
320 canSelectIndex: function(index) { | |
321 return !this.dataModel.item(index).hasOwnProperty('heading'); | |
322 }, | |
323 | |
324 /** | |
325 * Passes the results of an input validation check to the requesting row | 297 * Passes the results of an input validation check to the requesting row |
326 * if it's still being edited. | 298 * if it's still being edited. |
327 * @param {number} modelIndex The model index of the item that was checked. | 299 * @param {number} modelIndex The model index of the item that was checked. |
328 * @param {Object} validity A dictionary of validitation results. | 300 * @param {Object} validity A dictionary of validitation results. |
329 */ | 301 */ |
330 validationComplete: function(validity, modelIndex) { | 302 validationComplete: function(validity, modelIndex) { |
331 // If it's not still being edited, it no longer matters. | 303 // If it's not still being edited, it no longer matters. |
332 var currentSelection = this.selectedItem; | 304 var currentSelection = this.selectedItem; |
| 305 if (!currentSelection) |
| 306 return; |
333 var listItem = this.getListItem(currentSelection); | 307 var listItem = this.getListItem(currentSelection); |
334 if (listItem.editing && currentSelection['modelIndex'] == modelIndex) | 308 if (listItem.editing && currentSelection['modelIndex'] == modelIndex) |
335 listItem.validationComplete(validity); | 309 listItem.validationComplete(validity); |
336 }, | 310 }, |
337 }; | 311 }; |
338 | 312 |
339 // Export | 313 // Export |
340 return { | 314 return { |
341 SearchEngineList: SearchEngineList | 315 SearchEngineList: SearchEngineList |
342 }; | 316 }; |
343 | 317 |
344 }); | 318 }); |
345 | 319 |
OLD | NEW |