| Index: chrome/browser/resources/bluetooth_internals/device_table.js
|
| diff --git a/chrome/browser/resources/bluetooth_internals/device_table.js b/chrome/browser/resources/bluetooth_internals/device_table.js
|
| index be9e4b0ebcea62c9ce6e8a529f8d4b915756de8a..b177864f880e01cf243630fd38b11f2516f332e5 100644
|
| --- a/chrome/browser/resources/bluetooth_internals/device_table.js
|
| +++ b/chrome/browser/resources/bluetooth_internals/device_table.js
|
| @@ -13,7 +13,7 @@ cr.define('device_table', function() {
|
| RSSI: 2,
|
| SERVICES: 3,
|
| CONNECTION_STATE: 4,
|
| - INSPECT_LINK: 5,
|
| + LINKS: 5,
|
| };
|
|
|
| /**
|
| @@ -43,6 +43,8 @@ cr.define('device_table', function() {
|
| this.body_ = this.tBodies[0];
|
| /** @private */
|
| this.headers_ = this.tHead.rows[0].cells;
|
| + /** @private {!Map<!interfaces.BluetoothDevice.DeviceInfo, boolean>} */
|
| + this.inspectionMap_ = new Map();
|
| },
|
|
|
| /**
|
| @@ -61,18 +63,45 @@ cr.define('device_table', function() {
|
| },
|
|
|
| /**
|
| - * Updates table row on change event of the device collection.
|
| + * Updates the inspect status of the row matching the given |deviceInfo|.
|
| + * If |isInspecting| is true, the forget link is enabled otherwise it's
|
| + * disabled.
|
| + * @param {!interfaces.BluetoothDevice.DeviceInfo} deviceInfo
|
| + * @param {boolean} isInspecting
|
| + */
|
| + setInspecting: function(deviceInfo, isInspecting) {
|
| + this.inspectionMap_.set(deviceInfo, isInspecting);
|
| + this.updateRow_(deviceInfo, this.devices_.indexOf(deviceInfo));
|
| + },
|
| +
|
| + /**
|
| + * Fires a forget pressed event for the row |index|.
|
| + * @param {number} index
|
| * @private
|
| + */
|
| + handleForgetClick_: function(index) {
|
| + var event = new CustomEvent('forgetpressed', {
|
| + bubbles: true,
|
| + detail: {
|
| + address: this.devices_.item(index).address,
|
| + }
|
| + });
|
| + this.dispatchEvent(event);
|
| + },
|
| +
|
| + /**
|
| + * Updates table row on change event of the device collection.
|
| * @param {!Event} event
|
| + * @private
|
| */
|
| handleChange_: function(event) {
|
| this.updateRow_(this.devices_.item(event.index), event.index);
|
| },
|
|
|
| /**
|
| - * Fires a inspect pressed event for the row |index|.
|
| - * @private
|
| + * Fires an inspect pressed event for the row |index|.
|
| * @param {number} index
|
| + * @private
|
| */
|
| handleInspectClick_: function(index) {
|
| var event = new CustomEvent('inspectpressed', {
|
| @@ -86,8 +115,8 @@ cr.define('device_table', function() {
|
|
|
| /**
|
| * Updates table row on splice event of the device collection.
|
| - * @private
|
| * @param {!Event} event
|
| + * @private
|
| */
|
| handleSplice_: function(event) {
|
| event.removed.forEach(function() {
|
| @@ -101,15 +130,17 @@ cr.define('device_table', function() {
|
|
|
| /**
|
| * Inserts a new row at |index| and updates it with info from |device|.
|
| - * @private
|
| * @param {!interfaces.BluetoothDevice.DeviceInfo} device
|
| * @param {?number} index
|
| + * @private
|
| */
|
| insertRow_: function(device, index) {
|
| var row = this.body_.insertRow(index);
|
| row.id = device.address;
|
|
|
| for (var i = 0; i < this.headers_.length; i++) {
|
| + // Skip the LINKS column. It has no data-field attribute.
|
| + if (i === COLUMNS.LINKS) continue;
|
| row.insertCell();
|
| }
|
|
|
| @@ -117,11 +148,19 @@ cr.define('device_table', function() {
|
| var inspectCell = row.insertCell();
|
|
|
| var inspectLink = document.createElement('a', 'action-link');
|
| + inspectLink.textContent = 'Inspect';
|
| inspectCell.appendChild(inspectLink);
|
| inspectLink.addEventListener('click', function() {
|
| this.handleInspectClick_(row.sectionRowIndex);
|
| }.bind(this));
|
|
|
| + var forgetLink = document.createElement('a', 'action-link');
|
| + forgetLink.textContent = 'Forget';
|
| + inspectCell.appendChild(forgetLink);
|
| + forgetLink.addEventListener('click', function() {
|
| + this.handleForgetClick_(row.sectionRowIndex);
|
| + }.bind(this));
|
| +
|
| this.updateRow_(device, row.sectionRowIndex);
|
| },
|
|
|
| @@ -142,9 +181,9 @@ cr.define('device_table', function() {
|
|
|
| /**
|
| * Updates the row at |index| with the info from |device|.
|
| - * @private
|
| * @param {!interfaces.BluetoothDevice.DeviceInfo} device
|
| * @param {number} index
|
| + * @private
|
| */
|
| updateRow_: function(device, index) {
|
| var row = this.body_.rows[index];
|
| @@ -152,23 +191,18 @@ cr.define('device_table', function() {
|
|
|
| row.classList.toggle('removed', device.removed);
|
|
|
| - var inspectLink = row.cells[COLUMNS.INSPECT_LINK].children[0];
|
| - inspectLink.disabled = false;
|
| - switch (device.connectionStatus) {
|
| - case device_collection.ConnectionStatus.DISCONNECTED:
|
| - inspectLink.textContent = 'Inspect';
|
| - break;
|
| - case device_collection.ConnectionStatus.CONNECTED:
|
| - inspectLink.textContent = 'Forget';
|
| - break;
|
| - case device_collection.ConnectionStatus.CONNECTING:
|
| - inspectLink.disabled = true;
|
| - break;
|
| - default: assert('case not handled');
|
| - }
|
| + var forgetLink = row.cells[COLUMNS.LINKS].children[1];
|
| +
|
| + if (this.inspectionMap_.has(device))
|
| + forgetLink.disabled = !this.inspectionMap_.get(device);
|
| + else
|
| + forgetLink.disabled = true;
|
|
|
| // Update the properties based on the header field path.
|
| for (var i = 0; i < this.headers_.length; i++) {
|
| + // Skip the LINKS column. It has no data-field attribute.
|
| + if (i === COLUMNS.LINKS) continue;
|
| +
|
| var header = this.headers_[i];
|
| var propName = header.dataset.field;
|
|
|
|
|