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 DevicesPage and DevicesView, served from | 6 * Javascript for DevicesPage and DevicesView, served from |
7 * chrome://bluetooth-internals/. | 7 * chrome://bluetooth-internals/. |
8 */ | 8 */ |
9 | 9 |
10 cr.define('devices_page', function() { | 10 cr.define('devices_page', function() { |
11 /** @const */ var Page = cr.ui.pageManager.Page; | 11 /** @const */ var Page = cr.ui.pageManager.Page; |
12 | 12 |
13 /** | 13 /** |
| 14 * Enum of scan status for the devices page. |
| 15 * @enum {number} |
| 16 */ |
| 17 var ScanStatus = { |
| 18 OFF: 0, |
| 19 STARTING: 1, |
| 20 ON: 2, |
| 21 STOPPING: 3, |
| 22 }; |
| 23 |
| 24 |
| 25 /** |
14 * Page that contains a header and a DevicesView. | 26 * Page that contains a header and a DevicesView. |
15 * @constructor | 27 * @constructor |
16 * @extends {cr.ui.pageManager.Page} | 28 * @extends {cr.ui.pageManager.Page} |
17 */ | 29 */ |
18 function DevicesPage() { | 30 function DevicesPage() { |
19 Page.call(this, 'devices', 'Devices', 'devices'); | 31 Page.call(this, 'devices', 'Devices', 'devices'); |
20 | 32 |
21 this.deviceTable = new device_table.DeviceTable(); | 33 this.deviceTable = new device_table.DeviceTable(); |
22 this.pageDiv.appendChild(this.deviceTable); | 34 this.pageDiv.appendChild(this.deviceTable); |
| 35 this.scanBtn_ = this.pageDiv.querySelector('#scan-btn'); |
| 36 this.scanBtn_.addEventListener('click', function(event) { |
| 37 this.pageDiv.dispatchEvent(new CustomEvent('scanpressed')); |
| 38 }.bind(this)); |
23 } | 39 } |
24 | 40 |
25 DevicesPage.prototype = { | 41 DevicesPage.prototype = { |
26 __proto__: Page.prototype, | 42 __proto__: Page.prototype, |
27 | 43 |
28 /** | 44 /** |
29 * Sets the device collection for the page's device table. | 45 * Sets the device collection for the page's device table. |
30 * @param {!device_collection.DeviceCollection} devices | 46 * @param {!device_collection.DeviceCollection} devices |
31 */ | 47 */ |
32 setDevices: function(devices) { | 48 setDevices: function(devices) { |
33 this.deviceTable.setDevices(devices); | 49 this.deviceTable.setDevices(devices); |
| 50 }, |
| 51 |
| 52 setScanStatus: function(status) { |
| 53 switch (status) { |
| 54 case ScanStatus.OFF: |
| 55 this.scanBtn_.disabled = false; |
| 56 this.scanBtn_.textContent = 'Start Scan'; |
| 57 break; |
| 58 case ScanStatus.STARTING: |
| 59 this.scanBtn_.disabled = true; |
| 60 this.scanBtn_.textContent = 'Starting...'; |
| 61 break; |
| 62 case ScanStatus.ON: |
| 63 this.scanBtn_.disabled = false; |
| 64 this.scanBtn_.textContent = 'Stop Scan'; |
| 65 break; |
| 66 case ScanStatus.STOPPING: |
| 67 this.scanBtn_.disabled = true; |
| 68 this.scanBtn_.textContent = 'Stopping...'; |
| 69 break; |
| 70 } |
34 } | 71 } |
35 }; | 72 }; |
36 | 73 |
37 return { | 74 return { |
38 DevicesPage: DevicesPage | 75 DevicesPage: DevicesPage, |
| 76 ScanStatus: ScanStatus, |
39 }; | 77 }; |
40 }); | 78 }); |
OLD | NEW |