OLD | NEW |
---|---|
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 /** @type {?Array<device_collection.Device>} |
18 * @private | |
Dan Beam
2016/11/11 06:32:31
nit: you can combine this into
/** @private {?Arr
mbrunson
2016/11/11 20:43:09
Done.
| |
19 */ | |
21 this.devices_ = null; | 20 this.devices_ = null; |
22 | 21 |
23 return document.importNode($('table-template').content.children[0], | 22 return document.importNode($('table-template').content.children[0], |
24 true /* deep */); | 23 true /* deep */); |
25 }); | 24 }); |
26 | 25 |
27 DeviceTable.prototype = { | 26 DeviceTable.prototype = { |
28 __proto__: HTMLTableElement.prototype, | 27 __proto__: HTMLTableElement.prototype, |
29 | 28 |
30 /** | 29 /** |
31 * Decorates an element as a UI element class. Caches references to the | 30 * Decorates an element as a UI element class. Caches references to the |
32 * table body and headers. | 31 * table body and headers. |
33 */ | 32 */ |
34 decorate: function() { | 33 decorate: function() { |
34 /** @private */ | |
35 this.body_ = this.tBodies[0]; | 35 this.body_ = this.tBodies[0]; |
36 /** @private */ | |
36 this.headers_ = this.tHead.rows[0].cells; | 37 this.headers_ = this.tHead.rows[0].cells; |
37 }, | 38 }, |
38 | 39 |
39 /** | 40 /** |
40 * Sets the tables device collection. | 41 * Sets the tables device collection. |
41 * @param {!device_collection.DeviceCollection} deviceCollection | 42 * @param {!device_collection.DeviceCollection} deviceCollection |
42 */ | 43 */ |
43 setDevices: function(deviceCollection) { | 44 setDevices: function(deviceCollection) { |
44 assert(!this.devices_, 'Devices can only be set once.'); | 45 assert(!this.devices_, 'Devices can only be set once.'); |
45 | 46 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 /** | 111 /** |
111 * Updates the row at |index| with the info from |device|. | 112 * Updates the row at |index| with the info from |device|. |
112 * @private | 113 * @private |
113 * @param {!device_collection.Device} device | 114 * @param {!device_collection.Device} device |
114 * @param {number} index | 115 * @param {number} index |
115 */ | 116 */ |
116 updateRow_: function(device, index) { | 117 updateRow_: function(device, index) { |
117 assert(this.body_.rows[index], 'Row ' + index + ' is not in the table.'); | 118 assert(this.body_.rows[index], 'Row ' + index + ' is not in the table.'); |
118 var row = this.body_.rows[index]; | 119 var row = this.body_.rows[index]; |
119 | 120 |
120 if (device.removed) { | 121 row.classList.toggle('removed', device.removed); |
121 row.classList.add(REMOVED_CSS); | |
122 } else { | |
123 row.classList.remove(REMOVED_CSS); | |
124 } | |
125 | 122 |
126 // Update the properties based on the header field path. | 123 // Update the properties based on the header field path. |
127 for (var i = 0; i < this.headers_.length; i++) { | 124 for (var i = 0; i < this.headers_.length; i++) { |
128 var header = this.headers_[i]; | 125 var header = this.headers_[i]; |
129 var propName = header.dataset.field; | 126 var propName = header.dataset.field; |
130 | 127 |
131 var parts = propName.split('.'); | 128 var parts = propName.split('.'); |
132 var obj = device.info; | 129 var obj = device.info; |
133 while (obj != null && parts.length > 0) { | 130 while (obj != null && parts.length > 0) { |
134 var part = parts.shift(); | 131 var part = parts.shift(); |
135 obj = obj[part]; | 132 obj = obj[part]; |
136 } | 133 } |
137 | 134 |
138 var cell = row.cells[i]; | 135 var cell = row.cells[i]; |
139 cell.textContent = obj || 'Unknown'; | 136 cell.textContent = obj || 'Unknown'; |
140 cell.dataset.label = header.textContent; | 137 cell.dataset.label = header.textContent; |
141 } | 138 } |
142 }, | 139 }, |
143 }; | 140 }; |
144 | 141 |
145 return { | 142 return { |
146 DeviceTable: DeviceTable, | 143 DeviceTable: DeviceTable, |
147 }; | 144 }; |
148 }); | 145 }); |
OLD | NEW |