OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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 | |
7 var OptionsPage = options.OptionsPage; | |
8 var RepeatingButton = cr.ui.RepeatingButton; | |
9 | |
10 ///////////////////////////////////////////////////////////////////////////// | |
11 // SystemOptions class: | |
12 | |
13 /** | |
14 * Encapsulated handling of ChromeOS system options page. | |
15 * @constructor | |
16 */ | |
17 | |
18 function SystemOptions() { | |
19 OptionsPage.call(this, 'system', templateData.systemPageTabTitle, | |
20 'systemPage'); | |
21 } | |
22 | |
23 cr.addSingletonGetter(SystemOptions); | |
24 | |
25 // Inherit SystemOptions from OptionsPage. | |
26 SystemOptions.prototype = { | |
27 __proto__: options.OptionsPage.prototype, | |
28 | |
29 /** | |
30 * Initializes SystemOptions page. | |
31 * Calls base class implementation to starts preference initialization. | |
32 */ | |
33 initializePage: function() { | |
34 OptionsPage.prototype.initializePage.call(this); | |
35 | |
36 // Disable time-related settings if we're not logged in as a real user. | |
37 if (AccountsOptions.loggedInAsGuest()) { | |
38 var timezone = $('timezone-select'); | |
39 if (timezone) | |
40 timezone.disabled = true; | |
41 var use_24hour_clock = $('use-24hour-clock'); | |
42 if (use_24hour_clock) | |
43 use_24hour_clock.disabled = true; | |
44 } | |
45 | |
46 options.system.bluetooth.BluetoothListElement.decorate( | |
47 $('bluetooth-device-list')); | |
48 | |
49 // TODO(kevers): Populate list of connected bluetooth devices. | |
50 // Set state of 'Enable bluetooth' checkbox. | |
51 $('bluetooth-find-devices').onclick = function(event) { | |
52 findBluetoothDevices_(); | |
53 }; | |
54 $('enable-bluetooth').onclick = function(event) { | |
55 chrome.send('bluetoothEnableChange', [Boolean(true)]); | |
56 }; | |
57 $('disable-bluetooth').onclick = function(event) { | |
58 chrome.send('bluetoothEnableChange', [Boolean(false)]); | |
59 }; | |
60 $('language-button').onclick = function(event) { | |
61 OptionsPage.navigateToPage('language'); | |
62 }; | |
63 $('modifier-keys-button').onclick = function(event) { | |
64 OptionsPage.navigateToPage('languageCustomizeModifierKeysOverlay'); | |
65 }; | |
66 $('accesibility-check').onchange = function(event) { | |
67 chrome.send('accessibilityChange', | |
68 [String($('accesibility-check').checked)]); | |
69 }; | |
70 initializeBrightnessButton_('brightness-decrease-button', | |
71 'decreaseScreenBrightness'); | |
72 initializeBrightnessButton_('brightness-increase-button', | |
73 'increaseScreenBrightness'); | |
74 } | |
75 }; | |
76 | |
77 /** | |
78 * Initializes a button for controlling screen brightness. | |
79 * @param {string} id Button ID. | |
80 * @param {string} callback Name of the callback function. | |
81 */ | |
82 function initializeBrightnessButton_(id, callback) { | |
83 var button = $(id); | |
84 cr.ui.decorate(button, RepeatingButton); | |
85 button.repeatInterval = 300; | |
86 button.addEventListener(RepeatingButton.Event.BUTTON_HELD, function(e) { | |
87 chrome.send(callback); | |
88 }); | |
89 } | |
90 | |
91 /** | |
92 * Scan for bluetooth devices. | |
93 * @private | |
94 */ | |
95 function findBluetoothDevices_() { | |
96 setVisibility_('bluetooth-scanning-label', true); | |
97 setVisibility_('bluetooth-scanning-icon', true); | |
98 | |
99 // Remove devices that are not currently connected. | |
100 var devices = $('bluetooth-device-list').childNodes; | |
101 for (var i = devices.length - 1; i >= 0; i--) { | |
102 var device = devices.item(i); | |
103 var data = device.data; | |
104 if (!data || data.status !== 'connected') | |
105 $('bluetooth-device-list').removeChild(device); | |
106 } | |
107 chrome.send('findBluetoothDevices'); | |
108 } | |
109 | |
110 /** | |
111 * Sets the visibility of an element. | |
112 * @param {string} id The id of the element. | |
113 * @param {boolean} visible True if the element should be made visible. | |
114 * @private | |
115 */ | |
116 function setVisibility_(id, visible) { | |
117 if (visible) | |
118 $(id).classList.remove("transparent"); | |
119 else | |
120 $(id).classList.add("transparent"); | |
121 } | |
122 | |
123 // | |
124 // Chrome callbacks | |
125 // | |
126 | |
127 /** | |
128 * Set the initial state of the accessibility checkbox. | |
129 */ | |
130 SystemOptions.SetAccessibilityCheckboxState = function(checked) { | |
131 $('accesibility-check').checked = checked; | |
132 }; | |
133 | |
134 /** | |
135 * Activate the bluetooth settings section on the System settings page. | |
136 */ | |
137 SystemOptions.showBluetoothSettings = function() { | |
138 $('bluetooth-devices').hidden = false; | |
139 }; | |
140 | |
141 /** | |
142 * Sets the state of the checkbox indicating if bluetooth is turned on. The | |
143 * state of the "Find devices" button and the list of discovered devices may | |
144 * also be affected by a change to the state. | |
145 * @param {boolean} checked Flag Indicating if Bluetooth is turned on. | |
146 */ | |
147 SystemOptions.setBluetoothState = function(checked) { | |
148 $('disable-bluetooth').hidden = !checked; | |
149 $('enable-bluetooth').hidden = checked; | |
150 $('bluetooth-finder-container').hidden = !checked; | |
151 $('no-bluetooth-devices-label').hidden = !checked; | |
152 if (!checked) { | |
153 setVisibility_('bluetooth-scanning-label', false); | |
154 setVisibility_('bluetooth-scanning-icon', false); | |
155 } | |
156 // Flush list of previously discovered devices if bluetooth is turned off. | |
157 if (!checked) { | |
158 var devices = $('bluetooth-device-list').childNodes; | |
159 for (var i = devices.length - 1; i >= 0; i--) { | |
160 var device = devices.item(i); | |
161 $('bluetooth-device-list').removeChild(device); | |
162 } | |
163 } | |
164 } | |
165 | |
166 /** | |
167 * Adds an element to the list of available bluetooth devices. If an element | |
168 * with a matching address is found, the existing element is updated. | |
169 * @param {{name: string, | |
170 * address: string, | |
171 * icon: string, | |
172 * paired: boolean, | |
173 * connected: boolean}} device | |
174 * Decription of the bluetooth device. | |
175 */ | |
176 SystemOptions.addBluetoothDevice = function(device) { | |
177 if ($('bluetooth-device-list').appendDevice(device)) | |
178 $('no-bluetooth-devices-label').hidden = true; | |
179 }; | |
180 | |
181 /** | |
182 * Hides the scanning label and icon that are used to indicate that a device | |
183 * search is in progress. | |
184 */ | |
185 SystemOptions.notifyBluetoothSearchComplete = function() { | |
186 setVisibility_('bluetooth-scanning-label', false); | |
187 setVisibility_('bluetooth-scanning-icon', false); | |
188 }; | |
189 | |
190 /** | |
191 * Displays the Touchpad Controls section when we detect a touchpad. | |
192 */ | |
193 SystemOptions.showTouchpadControls = function() { | |
194 $('touchpad-controls').hidden = false; | |
195 }; | |
196 | |
197 // Export | |
198 return { | |
199 SystemOptions: SystemOptions | |
200 }; | |
201 | |
202 }); | |
OLD | NEW |