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

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: Removed errant /* */ 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.
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 function makeDiv(text) {
Evan Stade 2011/05/19 17:08:42 I don't think there's much point to this function.
koz (OOO until 15th September) 2011/05/19 21:07:52 Done.
38 var result = document.createElement('div');
39 if (text) {
Evan Stade 2011/05/19 17:08:42 no curlies
koz (OOO until 15th September) 2011/05/19 21:07:52 Done.
40 result.innerText = text;
41 }
42 return result;
43 }
44
45 HandlerListItem.prototype = {
46 __proto__: ListItem.prototype,
47
48 buildWidget_: function(data, delegate) {
49 // Protocol.
50 var protocolElement = makeDiv(data.protocol);
51 protocolElement.classList.add('handlers-type-column');
52 this.appendChild(protocolElement);
53
54 // Handler selection.
55 var handlerElement;
56 var selectElement;
57 if (data.handlers.length > 1) {
58 selectElement = document.createElement('select');
59 for (var i in data.handlers) {
Evan Stade 2011/05/19 17:08:42 don't use for...in for lists
koz (OOO until 15th September) 2011/05/19 21:07:52 Done.
60 var optionElement = document.createElement('option');
61 if (i == data.default_handler) {
62 optionElement.selected = true;
63 }
64 optionElement.innerText = data.handlers[i][1];
65 optionElement.value = i;
66 selectElement.appendChild(optionElement);
67 }
68 selectElement.addEventListener('change', function (e) {
69 var index = e.target.value;
70 delegate.setDefault([data.protocol].concat(data.handlers[index]));
71 });
72 handlerElement = makeDiv();
73 handlerElement.appendChild(selectElement);
74 } else {
75 handlerElement = makeDiv(data.handlers[0][1]);
76 }
77 handlerElement.classList.add('handlers-site-column');
Evan Stade 2011/05/19 17:08:42 handlerElement.classname = 'handlers-site-column';
koz (OOO until 15th September) 2011/05/19 21:07:52 Done.
78 this.appendChild(handlerElement);
79
80 // Remove link.
81 var removeElement =
82 makeDiv(localStrings.getString('handlers_remove_link'));
Evan Stade 2011/05/19 17:08:42 2 more spaces indent
koz (OOO until 15th September) 2011/05/19 21:07:52 Done.
83 removeElement.addEventListener('click', function (e) {
84 var value = selectElement ? selectElement.value : 0;
85 delegate.removeHandler(value,
86 [data.protocol].concat(data.handlers[value]));
87 });
88 removeElement.classList.add('handlers-remove-column');
Evan Stade 2011/05/19 17:08:42 removeElement.className = 'handlers-remove-column
koz (OOO until 15th September) 2011/05/19 21:07:52 Done.
89 removeElement.classList.add('handlers-remove-link');
90 this.appendChild(removeElement);
91 },
92
93 /** @inheritDoc */
94 decorate: function() {
95 ListItem.prototype.decorate.call(this);
96
97 var self = this;
98 var delegate = {
99 removeHandler: function(index, handler) {
100 HandlerOptions.removeHandler(index, handler);
101 },
102 setDefault: function(handler) {
103 HandlerOptions.setDefault(handler);
104 },
105 };
106
107 this.buildWidget_(this.dataItem, delegate);
108 },
109 };
110
111 /**
112 * Create a new passwords list.
113 * @constructor
114 * @extends {cr.ui.List}
115 */
116 var HandlersList = cr.ui.define('list');
117
118 HandlersList.prototype = {
119 __proto__: List.prototype,
120
121 /** @inheritDoc */
122 createItem: function(entry) {
123 return new HandlerListItem(entry);
124 },
125
126 /**
127 * The length of the list.
128 */
129 get length() {
130 return this.dataModel.length;
131 },
132
133 setHandlers: function(list) {
Evan Stade 2011/05/19 17:08:42 function comment
koz (OOO until 15th September) 2011/05/19 21:07:52 Done.
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