Chromium Code Reviews| Index: chrome/browser/resources/options/handler_options_list.js |
| diff --git a/chrome/browser/resources/options/handler_options_list.js b/chrome/browser/resources/options/handler_options_list.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a8d51071409e821fc13767fea57fffaf26285129 |
| --- /dev/null |
| +++ b/chrome/browser/resources/options/handler_options_list.js |
| @@ -0,0 +1,142 @@ |
| +// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +cr.define('options', function() { |
| + const ArrayDataModel = cr.ui.ArrayDataModel; |
| + const List = cr.ui.List; |
| + const ListItem = cr.ui.ListItem; |
| + const HandlerOptions = options.HandlerOptions; |
| + |
| + const localStrings = new LocalStrings(); |
| + |
| + /** |
| + * Creates a new protocol / content handler list item. |
| + * |
| + * Accepts values in the form |
| + * { protocol: 'mailto', |
| + * handlers: [ |
| + * ['http://www.thesite.com/%s', 'The title of the protocol'], |
| + * ..., |
| + * ], |
| + * } |
| + * @param {Object} entry A dictionary describing the handlers for a given |
| + * protocol. |
|
Evan Stade
2011/05/20 22:01:28
indent protocol 4 spaces
koz (OOO until 15th September)
2011/05/20 22:19:56
Done.
|
| + * @constructor |
| + * @extends {cr.ui.ListItem} |
| + */ |
| + function HandlerListItem(entry) { |
| + var el = cr.doc.createElement('div'); |
| + el.dataItem = entry; |
| + el.__proto__ = HandlerListItem.prototype; |
| + el.decorate(); |
| + |
| + return el; |
| + } |
| + |
| + HandlerListItem.prototype = { |
| + __proto__: ListItem.prototype, |
| + |
| + buildWidget_: function(data, delegate) { |
| + // Protocol. |
| + var protocolElement = document.createElement('div'); |
| + protocolElement.innerText = data.protocol; |
| + protocolElement.className = 'handlers-type-column'; |
| + this.appendChild(protocolElement); |
| + |
| + // Handler selection. |
| + var handlerElement; |
| + var selectElement; |
| + if (data.handlers.length > 1) { |
| + selectElement = document.createElement('select'); |
| + for (var i = 0; i < data.handlers.length; ++i) { |
| + var optionElement = document.createElement('option'); |
| + if (i == data.default_handler) { |
|
Evan Stade
2011/05/20 22:01:28
optionElement.selected = i == data.default_handler
koz (OOO until 15th September)
2011/05/20 22:19:56
Done.
|
| + optionElement.selected = true; |
| + } |
| + optionElement.innerText = data.handlers[i][1]; |
| + optionElement.value = i; |
| + selectElement.appendChild(optionElement); |
| + } |
|
Evan Stade
2011/05/20 22:01:28
insert newline
koz (OOO until 15th September)
2011/05/20 22:19:56
Done.
|
| + selectElement.addEventListener('change', function (e) { |
| + var index = e.target.value; |
| + delegate.setDefault([data.protocol].concat(data.handlers[index])); |
| + }); |
| + handlerElement = document.createElement('div'); |
|
Evan Stade
2011/05/20 22:01:28
this line can be shared at handlerElement declarat
koz (OOO until 15th September)
2011/05/20 22:19:56
Done.
|
| + handlerElement.appendChild(selectElement); |
| + } else { |
| + handlerElement = document.createElement('div'); |
| + handlerElement.innerText = data.handlers[0][1]; |
| + } |
| + handlerElement.className = 'handlers-site-column'; |
| + this.appendChild(handlerElement); |
| + |
| + // Remove link. |
| + var removeElement = document.createElement('div'); |
| + removeElement.innerText = |
| + localStrings.getString('handlers_remove_link'); |
| + removeElement.addEventListener('click', function (e) { |
| + var value = selectElement ? selectElement.value : 0; |
| + delegate.removeHandler(value, |
| + [data.protocol].concat(data.handlers[value])); |
| + }); |
| + removeElement.className = 'handlers-remove-column handlers-remove-link'; |
| + this.appendChild(removeElement); |
| + }, |
| + |
| + /** @inheritDoc */ |
| + decorate: function() { |
| + ListItem.prototype.decorate.call(this); |
| + |
| + var self = this; |
| + var delegate = { |
| + removeHandler: function(index, handler) { |
| + chrome.send('removeHandler', [handler]); |
| + }, |
| + setDefault: function(handler) { |
| + chrome.send('setDefault', [handler]); |
| + }, |
| + }; |
| + |
| + this.buildWidget_(this.dataItem, delegate); |
| + }, |
| + }; |
| + |
| + /** |
| + * Create a new passwords list. |
| + * @constructor |
| + * @extends {cr.ui.List} |
| + */ |
| + var HandlersList = cr.ui.define('list'); |
| + |
| + HandlersList.prototype = { |
| + __proto__: List.prototype, |
| + |
| + /** @inheritDoc */ |
| + createItem: function(entry) { |
| + return new HandlerListItem(entry); |
| + }, |
| + |
| + /** |
| + * The length of the list. |
| + */ |
| + get length() { |
| + return this.dataModel.length; |
| + }, |
| + |
| + /** |
| + * Set the protocol handlers displayed by this list. |
| + * See HandlerListItem for an example of the format the list should take. |
| + * |
| + * @param {Object} list A list of protocols with their registered handlers. |
| + */ |
| + setHandlers: function(list) { |
| + this.dataModel = new ArrayDataModel(list); |
| + }, |
| + }; |
| + |
| + return { |
| + HandlerListItem: HandlerListItem, |
| + HandlersList: HandlersList, |
| + }; |
| +}); |