| 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 INSPECT_LINK: 5, | 16 INSPECT_LINK: 5, |
| 17 CONNECTION_ERROR: 6, | |
| 18 }; | 17 }; |
| 19 | 18 |
| 20 /** | 19 /** |
| 21 * 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 |
| 22 * DeviceCollection. Fires events for inspection requests from listed | 21 * DeviceCollection. Fires events for inspection requests from listed |
| 23 * devices. | 22 * devices. |
| 24 * @constructor | 23 * @constructor |
| 25 * @extends {HTMLTableElement} | 24 * @extends {HTMLTableElement} |
| 26 */ | 25 */ |
| 27 var DeviceTable = cr.ui.define(function() { | 26 var DeviceTable = cr.ui.define(function() { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 var row = this.body_.insertRow(index); | 109 var row = this.body_.insertRow(index); |
| 111 row.id = device.address; | 110 row.id = device.address; |
| 112 | 111 |
| 113 for (var i = 0; i < this.headers_.length; i++) { | 112 for (var i = 0; i < this.headers_.length; i++) { |
| 114 row.insertCell(); | 113 row.insertCell(); |
| 115 } | 114 } |
| 116 | 115 |
| 117 // Make two extra cells for the inspect link and connect errors. | 116 // Make two extra cells for the inspect link and connect errors. |
| 118 var inspectCell = row.insertCell(); | 117 var inspectCell = row.insertCell(); |
| 119 | 118 |
| 120 // TODO(crbug.com/663830): Replace connection error column with better | |
| 121 // notification system. | |
| 122 var connectErrorCell = row.insertCell(); | |
| 123 | |
| 124 var inspectLink = document.createElement('a', 'action-link'); | 119 var inspectLink = document.createElement('a', 'action-link'); |
| 125 inspectCell.appendChild(inspectLink); | 120 inspectCell.appendChild(inspectLink); |
| 126 inspectLink.addEventListener('click', function() { | 121 inspectLink.addEventListener('click', function() { |
| 127 this.handleInspectClick_(row.sectionRowIndex); | 122 this.handleInspectClick_(row.sectionRowIndex); |
| 128 }.bind(this)); | 123 }.bind(this)); |
| 129 | 124 |
| 130 this.updateRow_(device, row.sectionRowIndex); | 125 this.updateRow_(device, row.sectionRowIndex); |
| 131 }, | 126 }, |
| 132 | 127 |
| 133 /** | 128 /** |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 break; | 160 break; |
| 166 case device_collection.ConnectionStatus.CONNECTED: | 161 case device_collection.ConnectionStatus.CONNECTED: |
| 167 inspectLink.textContent = 'Forget'; | 162 inspectLink.textContent = 'Forget'; |
| 168 break; | 163 break; |
| 169 case device_collection.ConnectionStatus.CONNECTING: | 164 case device_collection.ConnectionStatus.CONNECTING: |
| 170 inspectLink.disabled = true; | 165 inspectLink.disabled = true; |
| 171 break; | 166 break; |
| 172 default: assert('case not handled'); | 167 default: assert('case not handled'); |
| 173 } | 168 } |
| 174 | 169 |
| 175 // TODO(crbug.com/663830): Replace connection error column with better | |
| 176 // notification system. | |
| 177 var connectErrorCell = row.cells[COLUMNS.CONNECTION_ERROR]; | |
| 178 connectErrorCell.textContent = device.connectionMessage; | |
| 179 connectErrorCell.hidden = !device.connectionMessage; | |
| 180 | |
| 181 // Update the properties based on the header field path. | 170 // Update the properties based on the header field path. |
| 182 for (var i = 0; i < this.headers_.length; i++) { | 171 for (var i = 0; i < this.headers_.length; i++) { |
| 183 var header = this.headers_[i]; | 172 var header = this.headers_[i]; |
| 184 var propName = header.dataset.field; | 173 var propName = header.dataset.field; |
| 185 | 174 |
| 186 var parts = propName.split('.'); | 175 var parts = propName.split('.'); |
| 187 var obj = device; | 176 var obj = device; |
| 188 while (obj != null && parts.length > 0) { | 177 while (obj != null && parts.length > 0) { |
| 189 var part = parts.shift(); | 178 var part = parts.shift(); |
| 190 obj = obj[part]; | 179 obj = obj[part]; |
| 191 } | 180 } |
| 192 | 181 |
| 193 if (propName == 'is_gatt_connected') { | 182 if (propName == 'is_gatt_connected') { |
| 194 obj = obj ? 'Connected' : 'Not Connected'; | 183 obj = obj ? 'Connected' : 'Not Connected'; |
| 195 } | 184 } |
| 196 | 185 |
| 197 var cell = row.cells[i]; | 186 var cell = row.cells[i]; |
| 198 cell.textContent = obj == null ? 'Unknown' : obj; | 187 cell.textContent = obj == null ? 'Unknown' : obj; |
| 199 cell.dataset.label = header.textContent; | 188 cell.dataset.label = header.textContent; |
| 200 } | 189 } |
| 201 }, | 190 }, |
| 202 }; | 191 }; |
| 203 | 192 |
| 204 return { | 193 return { |
| 205 DeviceTable: DeviceTable, | 194 DeviceTable: DeviceTable, |
| 206 }; | 195 }; |
| 207 }); | 196 }); |
| OLD | NEW |