| 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_BUTTON: 5, | 16 INSPECT_LINK: 5, |
| 17 CONNECTION_ERROR: 6, | 17 CONNECTION_ERROR: 6, |
| 18 }; | 18 }; |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * A table that lists the devices and responds to changes in the given | 21 * A table that lists the devices and responds to changes in the given |
| 22 * DeviceCollection. Fires events for inspection requests from listed | 22 * DeviceCollection. Fires events for inspection requests from listed |
| 23 * devices. | 23 * devices. |
| 24 * @constructor | 24 * @constructor |
| 25 * @extends {HTMLTableElement} | 25 * @extends {HTMLTableElement} |
| 26 */ | 26 */ |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 */ | 68 */ |
| 69 handleChange_: function(event) { | 69 handleChange_: function(event) { |
| 70 this.updateRow_(this.devices_.item(event.index), event.index); | 70 this.updateRow_(this.devices_.item(event.index), event.index); |
| 71 }, | 71 }, |
| 72 | 72 |
| 73 /** | 73 /** |
| 74 * Fires a inspect pressed event for the row |index|. | 74 * Fires a inspect pressed event for the row |index|. |
| 75 * @private | 75 * @private |
| 76 * @param {number} index | 76 * @param {number} index |
| 77 */ | 77 */ |
| 78 handleInspectBtn_: function(index) { | 78 handleInspectClick_: function(index) { |
| 79 var event = new CustomEvent('inspectpressed', { | 79 var event = new CustomEvent('inspectpressed', { |
| 80 bubbles: true, | 80 bubbles: true, |
| 81 detail: { | 81 detail: { |
| 82 address: this.devices_.item(index).address, | 82 address: this.devices_.item(index).address, |
| 83 } | 83 } |
| 84 }); | 84 }); |
| 85 this.dispatchEvent(event); | 85 this.dispatchEvent(event); |
| 86 }, | 86 }, |
| 87 | 87 |
| 88 /** | 88 /** |
| (...skipping 18 matching lines...) Expand all Loading... |
| 107 * @param {?number} index | 107 * @param {?number} index |
| 108 */ | 108 */ |
| 109 insertRow_: function(device, index) { | 109 insertRow_: function(device, index) { |
| 110 var row = this.body_.insertRow(index); | 110 var row = this.body_.insertRow(index); |
| 111 row.id = device.address; | 111 row.id = device.address; |
| 112 | 112 |
| 113 for (var i = 0; i < this.headers_.length; i++) { | 113 for (var i = 0; i < this.headers_.length; i++) { |
| 114 row.insertCell(); | 114 row.insertCell(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 // Make two extra cells for the inspect button and connect errors. | 117 // Make two extra cells for the inspect link and connect errors. |
| 118 var inspectCell = row.insertCell(); | 118 var inspectCell = row.insertCell(); |
| 119 | 119 |
| 120 // TODO(crbug.com/663830): Replace connection error column with better | 120 // TODO(crbug.com/663830): Replace connection error column with better |
| 121 // notification system. | 121 // notification system. |
| 122 var connectErrorCell = row.insertCell(); | 122 var connectErrorCell = row.insertCell(); |
| 123 | 123 |
| 124 var inspectButton = document.createElement('button'); | 124 var inspectLink = document.createElement('a', 'action-link'); |
| 125 inspectCell.appendChild(inspectButton); | 125 inspectCell.appendChild(inspectLink); |
| 126 inspectButton.addEventListener('click', function() { | 126 inspectLink.addEventListener('click', function() { |
| 127 this.handleInspectBtn_(row.sectionRowIndex); | 127 this.handleInspectClick_(row.sectionRowIndex); |
| 128 }.bind(this)); | 128 }.bind(this)); |
| 129 | 129 |
| 130 this.updateRow_(device, row.sectionRowIndex); | 130 this.updateRow_(device, row.sectionRowIndex); |
| 131 }, | 131 }, |
| 132 | 132 |
| 133 /** | 133 /** |
| 134 * Deletes and recreates the table using the cached |devices_|. | 134 * Deletes and recreates the table using the cached |devices_|. |
| 135 * @private | 135 * @private |
| 136 */ | 136 */ |
| 137 redraw_: function() { | 137 redraw_: function() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 150 * @private | 150 * @private |
| 151 * @param {!interfaces.BluetoothDevice.DeviceInfo} device | 151 * @param {!interfaces.BluetoothDevice.DeviceInfo} device |
| 152 * @param {number} index | 152 * @param {number} index |
| 153 */ | 153 */ |
| 154 updateRow_: function(device, index) { | 154 updateRow_: function(device, index) { |
| 155 var row = this.body_.rows[index]; | 155 var row = this.body_.rows[index]; |
| 156 assert(row, 'Row ' + index + ' is not in the table.'); | 156 assert(row, 'Row ' + index + ' is not in the table.'); |
| 157 | 157 |
| 158 row.classList.toggle('removed', device.removed); | 158 row.classList.toggle('removed', device.removed); |
| 159 | 159 |
| 160 var inspectButton = row.cells[COLUMNS.INSPECT_BUTTON].children[0]; | 160 var inspectLink = row.cells[COLUMNS.INSPECT_LINK].children[0]; |
| 161 inspectButton.disabled = false; | 161 inspectLink.disabled = false; |
| 162 switch (device.connectionStatus) { | 162 switch (device.connectionStatus) { |
| 163 case device_collection.ConnectionStatus.DISCONNECTED: | 163 case device_collection.ConnectionStatus.DISCONNECTED: |
| 164 inspectButton.textContent = 'Inspect'; | 164 inspectLink.textContent = 'Inspect'; |
| 165 break; | 165 break; |
| 166 case device_collection.ConnectionStatus.CONNECTED: | 166 case device_collection.ConnectionStatus.CONNECTED: |
| 167 inspectButton.textContent = 'Forget'; | 167 inspectLink.textContent = 'Forget'; |
| 168 break; | 168 break; |
| 169 case device_collection.ConnectionStatus.CONNECTING: | 169 case device_collection.ConnectionStatus.CONNECTING: |
| 170 inspectButton.disabled = true; | 170 inspectLink.disabled = true; |
| 171 break; | 171 break; |
| 172 default: assert('case not handled'); | 172 default: assert('case not handled'); |
| 173 } | 173 } |
| 174 | 174 |
| 175 // TODO(crbug.com/663830): Replace connection error column with better | 175 // TODO(crbug.com/663830): Replace connection error column with better |
| 176 // notification system. | 176 // notification system. |
| 177 var connectErrorCell = row.cells[COLUMNS.CONNECTION_ERROR]; | 177 var connectErrorCell = row.cells[COLUMNS.CONNECTION_ERROR]; |
| 178 connectErrorCell.textContent = device.connectionMessage; | 178 connectErrorCell.textContent = device.connectionMessage; |
| 179 connectErrorCell.hidden = !device.connectionMessage; | 179 connectErrorCell.hidden = !device.connectionMessage; |
| 180 | 180 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 198 cell.textContent = obj == null ? 'Unknown' : obj; | 198 cell.textContent = obj == null ? 'Unknown' : obj; |
| 199 cell.dataset.label = header.textContent; | 199 cell.dataset.label = header.textContent; |
| 200 } | 200 } |
| 201 }, | 201 }, |
| 202 }; | 202 }; |
| 203 | 203 |
| 204 return { | 204 return { |
| 205 DeviceTable: DeviceTable, | 205 DeviceTable: DeviceTable, |
| 206 }; | 206 }; |
| 207 }); | 207 }); |
| OLD | NEW |