OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 cr.define('options', function() { | |
6 /** @const */ var OptionsPage = options.OptionsPage; | |
7 | |
8 /** | |
9 * Encapsulated handling of the Bluetooth options page. | |
10 * @constructor | |
11 */ | |
12 function BluetoothOptions() { | |
13 OptionsPage.call(this, | |
14 'bluetooth', | |
15 loadTimeData.getString('bluetoothOptionsPageTabTitle'), | |
16 'bluetooth-options'); | |
17 } | |
18 | |
19 cr.addSingletonGetter(BluetoothOptions); | |
20 | |
21 BluetoothOptions.prototype = { | |
22 __proto__: OptionsPage.prototype, | |
23 | |
24 /** | |
25 * The list of available (unpaired) bluetooth devices. | |
26 * @type {DeletableItemList} | |
27 * @private | |
28 */ | |
29 deviceList_: null, | |
30 | |
31 /** @inheritDoc */ | |
32 initializePage: function() { | |
33 OptionsPage.prototype.initializePage.call(this); | |
34 this.createDeviceList_(); | |
35 | |
36 $('bluetooth-add-device-cancel-button').onclick = function(event) { | |
37 chrome.send('stopBluetoothDeviceDiscovery'); | |
38 OptionsPage.closeOverlay(); | |
39 }; | |
40 | |
41 var self = this; | |
42 $('bluetooth-add-device-apply-button').onclick = function(event) { | |
43 var device = self.deviceList_.selectedItem; | |
44 var address = device.address; | |
45 chrome.send('stopBluetoothDeviceDiscovery'); | |
46 OptionsPage.closeOverlay(); | |
47 device.pairing = 'bluetoothStartConnecting'; | |
48 options.BluetoothPairing.showDialog(device); | |
49 chrome.send('updateBluetoothDevice', [address, 'connect']); | |
50 }; | |
51 | |
52 $('bluetooth-add-device-apply-button').onmousedown = function(event) { | |
53 // Prevent 'blur' event, which would reset the list selection, | |
54 // thereby disabling the apply button. | |
55 event.preventDefault(); | |
56 }; | |
57 | |
58 $('bluetooth-unpaired-devices-list').addEventListener('change', | |
59 function() { | |
60 var item = $('bluetooth-unpaired-devices-list').selectedItem; | |
61 var disabled = !item || item.paired || item.connected; | |
62 $('bluetooth-add-device-apply-button').disabled = disabled; | |
63 }); | |
64 }, | |
65 | |
66 /** | |
67 * Creates, decorates and initializes the bluetooth device list. | |
68 * @private | |
69 */ | |
70 createDeviceList_: function() { | |
71 this.deviceList_ = $('bluetooth-unpaired-devices-list'); | |
72 options.system.bluetooth.BluetoothDeviceList.decorate(this.deviceList_); | |
73 this.deviceList_.autoExpands = true; | |
74 } | |
75 }; | |
76 | |
77 /** | |
78 * Automatically start the device discovery process if the | |
79 * "Add device" dialog is visible. | |
80 */ | |
81 BluetoothOptions.updateDiscovery = function() { | |
82 var page = BluetoothOptions.getInstance(); | |
83 if (page && page.visible) | |
84 chrome.send('findBluetoothDevices'); | |
85 } | |
86 | |
87 // Export | |
88 return { | |
89 BluetoothOptions: BluetoothOptions | |
90 }; | |
91 }); | |
OLD | NEW |