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

Side by Side Diff: chrome/browser/resources/bluetooth_internals/device_table.js

Issue 2488093003: bluetooth: Componentize device list fixes (Closed)
Patch Set: Combine private and type Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 /** 5 /**
6 * Javascript for DeviceTable UI, served from 6 * Javascript for DeviceTable UI, served from chrome://bluetooth-internals/.
7 * chrome://bluetooth-internals/.
8 */ 7 */
9 8
10 cr.define('device_table', function() { 9 cr.define('device_table', function() {
11 var REMOVED_CSS = 'removed';
12
13 /** 10 /**
14 * A table that lists the devices and responds to changes in the given 11 * A table that lists the devices and responds to changes in the given
15 * DeviceCollection. 12 * DeviceCollection.
16 * @constructor 13 * @constructor
17 * @extends {HTMLTableElement} 14 * @extends {HTMLTableElement}
18 */ 15 */
19 var DeviceTable = cr.ui.define(function() { 16 var DeviceTable = cr.ui.define(function() {
20 // @type {Array<device_collection.Device>} 17 /** @private {?Array<device_collection.Device>} */
21 this.devices_ = null; 18 this.devices_ = null;
22 19
23 return document.importNode($('table-template').content.children[0], 20 return document.importNode($('table-template').content.children[0],
24 true /* deep */); 21 true /* deep */);
25 }); 22 });
26 23
27 DeviceTable.prototype = { 24 DeviceTable.prototype = {
28 __proto__: HTMLTableElement.prototype, 25 __proto__: HTMLTableElement.prototype,
29 26
30 /** 27 /**
31 * Decorates an element as a UI element class. Caches references to the 28 * Decorates an element as a UI element class. Caches references to the
32 * table body and headers. 29 * table body and headers.
33 */ 30 */
34 decorate: function() { 31 decorate: function() {
32 /** @private */
35 this.body_ = this.tBodies[0]; 33 this.body_ = this.tBodies[0];
34 /** @private */
36 this.headers_ = this.tHead.rows[0].cells; 35 this.headers_ = this.tHead.rows[0].cells;
37 }, 36 },
38 37
39 /** 38 /**
40 * Sets the tables device collection. 39 * Sets the tables device collection.
41 * @param {!device_collection.DeviceCollection} deviceCollection 40 * @param {!device_collection.DeviceCollection} deviceCollection
42 */ 41 */
43 setDevices: function(deviceCollection) { 42 setDevices: function(deviceCollection) {
44 assert(!this.devices_, 'Devices can only be set once.'); 43 assert(!this.devices_, 'Devices can only be set once.');
45 44
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 /** 109 /**
111 * Updates the row at |index| with the info from |device|. 110 * Updates the row at |index| with the info from |device|.
112 * @private 111 * @private
113 * @param {!device_collection.Device} device 112 * @param {!device_collection.Device} device
114 * @param {number} index 113 * @param {number} index
115 */ 114 */
116 updateRow_: function(device, index) { 115 updateRow_: function(device, index) {
117 assert(this.body_.rows[index], 'Row ' + index + ' is not in the table.'); 116 assert(this.body_.rows[index], 'Row ' + index + ' is not in the table.');
118 var row = this.body_.rows[index]; 117 var row = this.body_.rows[index];
119 118
120 if (device.removed) { 119 row.classList.toggle('removed', device.removed);
121 row.classList.add(REMOVED_CSS);
122 } else {
123 row.classList.remove(REMOVED_CSS);
124 }
125 120
126 // Update the properties based on the header field path. 121 // Update the properties based on the header field path.
127 for (var i = 0; i < this.headers_.length; i++) { 122 for (var i = 0; i < this.headers_.length; i++) {
128 var header = this.headers_[i]; 123 var header = this.headers_[i];
129 var propName = header.dataset.field; 124 var propName = header.dataset.field;
130 125
131 var parts = propName.split('.'); 126 var parts = propName.split('.');
132 var obj = device.info; 127 var obj = device.info;
133 while (obj != null && parts.length > 0) { 128 while (obj != null && parts.length > 0) {
134 var part = parts.shift(); 129 var part = parts.shift();
135 obj = obj[part]; 130 obj = obj[part];
136 } 131 }
137 132
138 var cell = row.cells[i]; 133 var cell = row.cells[i];
139 cell.textContent = obj || 'Unknown'; 134 cell.textContent = obj || 'Unknown';
140 cell.dataset.label = header.textContent; 135 cell.dataset.label = header.textContent;
141 } 136 }
142 }, 137 },
143 }; 138 };
144 139
145 return { 140 return {
146 DeviceTable: DeviceTable, 141 DeviceTable: DeviceTable,
147 }; 142 };
148 }); 143 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698