| 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 chrome://bluetooth-internals/. | 6 * Javascript for DeviceTable UI, served from chrome://bluetooth-internals/. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 cr.define('device_table', function() { | 9 cr.define('device_table', function() { |
| 10 var COLUMNS = { | 10 var COLUMNS = { |
| 11 NAME: 0, | 11 NAME: 0, |
| 12 ADDRESS: 1, | 12 ADDRESS: 1, |
| 13 RSSI: 2, | 13 RSSI: 2, |
| 14 SERVICES: 3, | 14 SERVICES: 3, |
| 15 CONNECTION_STATE: 4, | 15 CONNECTION_STATE: 4, |
| 16 LINKS: 5, | 16 LINKS: 5, |
| 17 }; | 17 }; |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * A table that lists the devices and responds to changes in the given | 20 * A table that lists the devices and responds to changes in the given |
| 21 * DeviceCollection. Fires events for inspection requests from listed | 21 * DeviceCollection. Fires events for inspection requests from listed |
| 22 * devices. | 22 * devices. |
| 23 * @constructor | 23 * @constructor |
| 24 * @extends {HTMLTableElement} | 24 * @extends {HTMLTableElement} |
| 25 */ | 25 */ |
| 26 var DeviceTable = cr.ui.define(function() { | 26 var DeviceTable = cr.ui.define(function() { |
| 27 /** @private {?Array<device_collection.Device>} */ | 27 /** @private {?Array<device_collection.Device>} */ |
| 28 this.devices_ = null; | 28 this.devices_ = null; |
| 29 | 29 |
| 30 return document.importNode($('table-template').content.children[0], | 30 return document.importNode( |
| 31 true /* deep */); | 31 $('table-template').content.children[0], true /* deep */); |
| 32 }); | 32 }); |
| 33 | 33 |
| 34 DeviceTable.prototype = { | 34 DeviceTable.prototype = { |
| 35 __proto__: HTMLTableElement.prototype, | 35 __proto__: HTMLTableElement.prototype, |
| 36 | 36 |
| 37 /** | 37 /** |
| 38 * Decorates an element as a UI element class. Caches references to the | 38 * Decorates an element as a UI element class. Caches references to the |
| 39 * table body and headers. | 39 * table body and headers. |
| 40 */ | 40 */ |
| 41 decorate: function() { | 41 decorate: function() { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 * @param {!interfaces.BluetoothDevice.DeviceInfo} device | 133 * @param {!interfaces.BluetoothDevice.DeviceInfo} device |
| 134 * @param {?number} index | 134 * @param {?number} index |
| 135 * @private | 135 * @private |
| 136 */ | 136 */ |
| 137 insertRow_: function(device, index) { | 137 insertRow_: function(device, index) { |
| 138 var row = this.body_.insertRow(index); | 138 var row = this.body_.insertRow(index); |
| 139 row.id = device.address; | 139 row.id = device.address; |
| 140 | 140 |
| 141 for (var i = 0; i < this.headers_.length; i++) { | 141 for (var i = 0; i < this.headers_.length; i++) { |
| 142 // Skip the LINKS column. It has no data-field attribute. | 142 // Skip the LINKS column. It has no data-field attribute. |
| 143 if (i === COLUMNS.LINKS) continue; | 143 if (i === COLUMNS.LINKS) |
| 144 continue; |
| 144 row.insertCell(); | 145 row.insertCell(); |
| 145 } | 146 } |
| 146 | 147 |
| 147 // Make two extra cells for the inspect link and connect errors. | 148 // Make two extra cells for the inspect link and connect errors. |
| 148 var inspectCell = row.insertCell(); | 149 var inspectCell = row.insertCell(); |
| 149 | 150 |
| 150 var inspectLink = document.createElement('a', 'action-link'); | 151 var inspectLink = document.createElement('a', 'action-link'); |
| 151 inspectLink.textContent = 'Inspect'; | 152 inspectLink.textContent = 'Inspect'; |
| 152 inspectCell.appendChild(inspectLink); | 153 inspectCell.appendChild(inspectLink); |
| 153 inspectLink.addEventListener('click', function() { | 154 inspectLink.addEventListener('click', function() { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 var forgetLink = row.cells[COLUMNS.LINKS].children[1]; | 195 var forgetLink = row.cells[COLUMNS.LINKS].children[1]; |
| 195 | 196 |
| 196 if (this.inspectionMap_.has(device)) | 197 if (this.inspectionMap_.has(device)) |
| 197 forgetLink.disabled = !this.inspectionMap_.get(device); | 198 forgetLink.disabled = !this.inspectionMap_.get(device); |
| 198 else | 199 else |
| 199 forgetLink.disabled = true; | 200 forgetLink.disabled = true; |
| 200 | 201 |
| 201 // Update the properties based on the header field path. | 202 // Update the properties based on the header field path. |
| 202 for (var i = 0; i < this.headers_.length; i++) { | 203 for (var i = 0; i < this.headers_.length; i++) { |
| 203 // Skip the LINKS column. It has no data-field attribute. | 204 // Skip the LINKS column. It has no data-field attribute. |
| 204 if (i === COLUMNS.LINKS) continue; | 205 if (i === COLUMNS.LINKS) |
| 206 continue; |
| 205 | 207 |
| 206 var header = this.headers_[i]; | 208 var header = this.headers_[i]; |
| 207 var propName = header.dataset.field; | 209 var propName = header.dataset.field; |
| 208 | 210 |
| 209 var parts = propName.split('.'); | 211 var parts = propName.split('.'); |
| 210 var obj = device; | 212 var obj = device; |
| 211 while (obj != null && parts.length > 0) { | 213 while (obj != null && parts.length > 0) { |
| 212 var part = parts.shift(); | 214 var part = parts.shift(); |
| 213 obj = obj[part]; | 215 obj = obj[part]; |
| 214 } | 216 } |
| 215 | 217 |
| 216 if (propName == 'is_gatt_connected') { | 218 if (propName == 'is_gatt_connected') { |
| 217 obj = obj ? 'Connected' : 'Not Connected'; | 219 obj = obj ? 'Connected' : 'Not Connected'; |
| 218 } | 220 } |
| 219 | 221 |
| 220 var cell = row.cells[i]; | 222 var cell = row.cells[i]; |
| 221 cell.textContent = obj == null ? 'Unknown' : obj; | 223 cell.textContent = obj == null ? 'Unknown' : obj; |
| 222 cell.dataset.label = header.textContent; | 224 cell.dataset.label = header.textContent; |
| 223 } | 225 } |
| 224 }, | 226 }, |
| 225 }; | 227 }; |
| 226 | 228 |
| 227 return { | 229 return { |
| 228 DeviceTable: DeviceTable, | 230 DeviceTable: DeviceTable, |
| 229 }; | 231 }; |
| 230 }); | 232 }); |
| OLD | NEW |