Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: chrome/browser/resources/options/handler_options_list.js

Issue 7033018: Handler settings page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Responded to comments Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 cr.define('options', function() {
6 const ArrayDataModel = cr.ui.ArrayDataModel;
7 const List = cr.ui.List;
8 const ListItem = cr.ui.ListItem;
9 const HandlerOptions = options.HandlerOptions;
10
11 const localStrings = new LocalStrings();
12
13 /**
14 * Creates a new protocol / content handler list item.
15 *
16 * Accepts values in the form
17 * { protocol: 'mailto',
18 * handlers: [
19 * ['http://www.thesite.com/%s', 'The title of the protocol'],
20 * ...,
21 * ],
22 * }
23 * @param {Object} entry A dictionary describing the handlers for a given
24 * 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.
25 * @constructor
26 * @extends {cr.ui.ListItem}
27 */
28 function HandlerListItem(entry) {
29 var el = cr.doc.createElement('div');
30 el.dataItem = entry;
31 el.__proto__ = HandlerListItem.prototype;
32 el.decorate();
33
34 return el;
35 }
36
37 HandlerListItem.prototype = {
38 __proto__: ListItem.prototype,
39
40 buildWidget_: function(data, delegate) {
41 // Protocol.
42 var protocolElement = document.createElement('div');
43 protocolElement.innerText = data.protocol;
44 protocolElement.className = 'handlers-type-column';
45 this.appendChild(protocolElement);
46
47 // Handler selection.
48 var handlerElement;
49 var selectElement;
50 if (data.handlers.length > 1) {
51 selectElement = document.createElement('select');
52 for (var i = 0; i < data.handlers.length; ++i) {
53 var optionElement = document.createElement('option');
54 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.
55 optionElement.selected = true;
56 }
57 optionElement.innerText = data.handlers[i][1];
58 optionElement.value = i;
59 selectElement.appendChild(optionElement);
60 }
Evan Stade 2011/05/20 22:01:28 insert newline
koz (OOO until 15th September) 2011/05/20 22:19:56 Done.
61 selectElement.addEventListener('change', function (e) {
62 var index = e.target.value;
63 delegate.setDefault([data.protocol].concat(data.handlers[index]));
64 });
65 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.
66 handlerElement.appendChild(selectElement);
67 } else {
68 handlerElement = document.createElement('div');
69 handlerElement.innerText = data.handlers[0][1];
70 }
71 handlerElement.className = 'handlers-site-column';
72 this.appendChild(handlerElement);
73
74 // Remove link.
75 var removeElement = document.createElement('div');
76 removeElement.innerText =
77 localStrings.getString('handlers_remove_link');
78 removeElement.addEventListener('click', function (e) {
79 var value = selectElement ? selectElement.value : 0;
80 delegate.removeHandler(value,
81 [data.protocol].concat(data.handlers[value]));
82 });
83 removeElement.className = 'handlers-remove-column handlers-remove-link';
84 this.appendChild(removeElement);
85 },
86
87 /** @inheritDoc */
88 decorate: function() {
89 ListItem.prototype.decorate.call(this);
90
91 var self = this;
92 var delegate = {
93 removeHandler: function(index, handler) {
94 chrome.send('removeHandler', [handler]);
95 },
96 setDefault: function(handler) {
97 chrome.send('setDefault', [handler]);
98 },
99 };
100
101 this.buildWidget_(this.dataItem, delegate);
102 },
103 };
104
105 /**
106 * Create a new passwords list.
107 * @constructor
108 * @extends {cr.ui.List}
109 */
110 var HandlersList = cr.ui.define('list');
111
112 HandlersList.prototype = {
113 __proto__: List.prototype,
114
115 /** @inheritDoc */
116 createItem: function(entry) {
117 return new HandlerListItem(entry);
118 },
119
120 /**
121 * The length of the list.
122 */
123 get length() {
124 return this.dataModel.length;
125 },
126
127 /**
128 * Set the protocol handlers displayed by this list.
129 * See HandlerListItem for an example of the format the list should take.
130 *
131 * @param {Object} list A list of protocols with their registered handlers.
132 */
133 setHandlers: function(list) {
134 this.dataModel = new ArrayDataModel(list);
135 },
136 };
137
138 return {
139 HandlerListItem: HandlerListItem,
140 HandlersList: HandlersList,
141 };
142 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698