Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Side by Side Diff: chrome/browser/resources/options/chromeos/bluetooth_list_element.js

Issue 8539022: Bluetooth UI update. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Style fixes. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 cr.define('options.system.bluetooth', function() { 5 cr.define('options.system.bluetooth', function() {
6 /** 6 /**
7 * Bluetooth settings constants. 7 * Bluetooth settings constants.
8 */ 8 */
9 function Constants() {} 9 function Constants() {}
10 10
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 this.appendChild(new BluetoothItem(devices[i])); 76 this.appendChild(new BluetoothItem(devices[i]));
77 } 77 }
78 }, 78 },
79 79
80 /** 80 /**
81 * Adds a bluetooth device to the list of available devices. A check is 81 * Adds a bluetooth device to the list of available devices. A check is
82 * made to see if the device is already in the list, in which case the 82 * made to see if the device is already in the list, in which case the
83 * existing device is updated. 83 * existing device is updated.
84 * @param {Object.<string,string>} device Description of the bluetooth 84 * @param {Object.<string,string>} device Description of the bluetooth
85 * device. 85 * device.
86 * @return {boolean} True if the devies was successfully added or updated.
86 */ 87 */
87 appendDevice: function(device) { 88 appendDevice: function(device) {
88 if (!this.isSupported_(device)) 89 if (!this.isSupported_(device))
89 return; 90 return false;
90 var item = new BluetoothItem(device); 91 var item = new BluetoothItem(device);
91 var existing = this.findDevice(device.address); 92 var existing = this.findDevice(device.address);
92 if (existing) { 93 if (existing)
93 this.replaceChild(item, existing); 94 this.replaceChild(item, existing);
94 return; 95 else
95 } 96 this.appendChild(item);
96 this.appendChild(item); 97 return true;
97 }, 98 },
98 99
99 /** 100 /**
100 * Scans the list of elements corresponding to discovered Bluetooth 101 * Scans the list of elements corresponding to discovered Bluetooth
101 * devices for one with a matching address. 102 * devices for one with a matching address.
102 * @param {string} address The address of the device. 103 * @param {string} address The address of the device.
103 * @return {Element|undefined} Element corresponding to the device address 104 * @return {Element|undefined} Element corresponding to the device address
104 * or undefined if no corresponding element is found. 105 * or undefined if no corresponding element is found.
105 */ 106 */
106 findDevice: function(address) { 107 findDevice: function(address) {
(...skipping 28 matching lines...) Expand all
135 * icon: Constants.DEVICE_TYPE, 136 * icon: Constants.DEVICE_TYPE,
136 * paired: boolean, 137 * paired: boolean,
137 * connected: boolean, 138 * connected: boolean,
138 * pairing: string|undefined, 139 * pairing: string|undefined,
139 * passkey: number|undefined, 140 * passkey: number|undefined,
140 * entered: number|undefined}} device 141 * entered: number|undefined}} device
141 * Decription of the bluetooth device. 142 * Decription of the bluetooth device.
142 * @constructor 143 * @constructor
143 */ 144 */
144 function BluetoothItem(device) { 145 function BluetoothItem(device) {
145 var el = cr.doc.createElement('div'); 146 var el = $('bluetooth-item-template').cloneNode(true);
147 el.__proto__ = BluetoothItem.prototype;
148 el.removeAttribute('id');
149 el.hidden = false;
146 el.data = {}; 150 el.data = {};
147 for (var key in device) 151 for (var key in device)
148 el.data[key] = device[key]; 152 el.data[key] = device[key];
149 BluetoothItem.decorate(el); 153 el.decorate();
150 return el; 154 return el;
151 } 155 }
152 156
153 /**
154 * Decorates an element as a bluetooth item.
155 * @param {!HTMLElement} el The element to decorate.
156 */
157 BluetoothItem.decorate = function(el) {
158 el.__proto__ = BluetoothItem.prototype;
159 el.decorate();
160 };
161
162 BluetoothItem.prototype = { 157 BluetoothItem.prototype = {
163 __proto__: HTMLDivElement.prototype, 158 __proto__: HTMLDivElement.prototype,
164 159
165 /** @inheritDoc */ 160 /** @inheritDoc */
166 decorate: function() { 161 decorate: function() {
167 this.className = 'bluetooth-item'; 162 this.className = 'bluetooth-item';
168 this.connected = this.data.connected; 163 this.connected = this.data.connected;
169 // Though strictly speaking, a connected device will also be paired, 164 // Though strictly speaking, a connected device will also be paired,
170 // we are interested in tracking paired devices that are not connected. 165 // we are interested in tracking paired devices that are not connected.
171 this.paired = this.data.paired && !this.data.connected; 166 this.paired = this.data.paired && !this.data.connected;
172 this.connecting = !!this.data.pairing; 167 this.connecting = !!this.data.pairing;
173 this.addIcon_();
174 this.addLabels_(); 168 this.addLabels_();
175 this.addButtons_(); 169 this.addButtons_();
176 }, 170 },
177 171
178 /** 172 /**
179 * Adds an icon corresponding to the device category. 173 * Retrieves the descendent element with the matching class name.
174 * @param {string} className The class name for the target element.
175 * @return {Element|undefined} Returns the matching element if
176 * found and unique.
180 * @private 177 * @private
181 */ 178 */
182 addIcon_: function() { 179 getNodeByClass_:function(className) {
183 var iconElement = this.ownerDocument.createElement('div'); 180 var elements = this.getElementsByClassName(className);
184 iconElement.className = 'bluetooth-' + this.data.icon; 181 if (elements && elements.length == 1)
185 iconElement.classList.add('bluetooth-icon'); 182 return elements[0];
186 this.appendChild(iconElement); 183 },
184
185 /**
186 * Sets the text content for an element.
187 * @param {string} className The class name of the target element.
188 * @param {string} label Text content for the element.
189 * @private
190 */
191 setLabel_: function(className, label) {
192 var el = this.getNodeByClass_(className);
193 el.textContent = label;
187 }, 194 },
188 195
189 /** 196 /**
190 * Adds an element containing the display name, status and device pairing 197 * Adds an element containing the display name, status and device pairing
191 * instructions. 198 * instructions.
192 * @private 199 * @private
193 */ 200 */
194 addLabels_: function() { 201 addLabels_: function() {
195 var textDiv = this.ownerDocument.createElement('div'); 202 this.setLabel_('network-name-label', this.data.name);
196 textDiv.className = 'bluetooth-item-text'; 203 var status;
197 var nameEl = this.ownerDocument.createElement('div'); 204 if (this.data.connected)
198 nameEl.className = 'network-name-label'; 205 status = Constants.DEVICE_STATUS.CONNECTED;
199 nameEl.textContent = this.data.name; 206 else if (this.data.pairing)
200 textDiv.appendChild(nameEl); 207 status = Constants.DEVICE_STATUS.CONNECTING;
201 this.appendChild(textDiv); 208 if (status) {
202 this.setDeviceStatus_(textDiv); 209 var statusMessage = templateData[status];
203 if (this.data.pairing) { 210 if (statusMessage)
204 this.addPairingInstructions_(textDiv); 211 this.setLabel_('network-status-label', statusMessage);
212 if (this.connecting) {
213 var spinner = this.getNodeByClass_('inline-spinner');
214 if (spinner)
flackr 2011/11/11 22:55:38 Ditto here.
kevers 2011/11/14 17:51:17 Done.
215 spinner.hidden = false;
216 }
205 } 217 }
218 if (this.data.pairing)
219 this.addPairingInstructions_();
206 }, 220 },
207 221
208 /** 222 /**
209 * Adds a label showing the status of the device.
210 * @param {!Element} textDiv Target element for inserting the status label.
211 * @private
212 */
213 setDeviceStatus_: function(textDiv) {
214 var status;
215 if (this.data.connected)
216 status = Constants.DEVICE_STATUS.CONNECTED;
217 else if (this.data.paired)
218 status = Constants.DEVICE_STATUS.PAIRED;
219 else if (this.data.pairing)
220 status = Constants.DEVICE_STATUS.CONNECTING;
221 else
222 status = Constants.DEVICE_STATUS.NOT_PAIRED;
223 var statusMessage = templateData[status];
224 if (statusMessage) {
225 var statusEl = this.ownerDocument.createElement('div');
226 statusEl.className = 'network-status-label';
227 statusEl.textContent = statusMessage;
228 if (this.connecting) {
229 var throbber = this.ownerDocument.createElement('div');
230 throbber.className = 'throbber';
231 statusEl.appendChild(throbber);
232 }
233 textDiv.appendChild(statusEl);
234 }
235 },
236
237 /**
238 * Adds instructions on how to complete the pairing process. 223 * Adds instructions on how to complete the pairing process.
239 * @param {!Element} textDiv Target element for inserting the instructions. 224 * @param {!Element} textDiv Target element for inserting the instructions.
240 * @private 225 * @private
241 */ 226 */
242 addPairingInstructions_: function(textDiv) { 227 addPairingInstructions_: function() {
243 var instructionsEl = this.ownerDocument.createElement('div'); 228 var instructionsEl = this.getNodeByClass_('bluetooth-instructions');
244 instructionsEl.className = 'bluetooth-instructions';
245 var message = templateData[this.data.pairing]; 229 var message = templateData[this.data.pairing];
246 var array = this.formatInstructions_(message); 230 var array = this.formatInstructions_(message);
247 for (var i = 0; i < array.length; i++) { 231 for (var i = 0; i < array.length; i++) {
248 instructionsEl.appendChild(array[i]); 232 instructionsEl.appendChild(array[i]);
249 } 233 }
250 if (this.data.pairing == Constants.PAIRING.ENTER_PASSKEY) { 234 if (this.data.pairing == Constants.PAIRING.ENTER_PASSKEY) {
251 var input = this.ownerDocument.createElement('input'); 235 var input = this.ownerDocument.createElement('input');
252 input.type = 'text'; 236 input.type = 'text';
253 input.className = 'bluetooth-passkey-field'; 237 input.className = 'bluetooth-passkey-field';
254 instructionsEl.appendChild(input); 238 instructionsEl.appendChild(input);
255 } 239 }
256 textDiv.appendChild(instructionsEl);
257 }, 240 },
258 241
259 /** 242 /**
260 * Formats the pairing instruction, which may contain labels for 243 * Formats the pairing instruction, which may contain labels for
261 * substitution. The label '%1' is replaced with the passkey, and '%2' 244 * substitution. The label '%1' is replaced with the passkey, and '%2'
262 * is replaced with the name of the bluetooth device. Formatting of the 245 * is replaced with the name of the bluetooth device. Formatting of the
263 * passkey depends on the type of validation. 246 * passkey depends on the type of validation.
264 * @param {string} instructions The source instructions to format. 247 * @param {string} instructions The source instructions to format.
265 * @return {Array.<Element>} Array of formatted elements. 248 * @return {Array.<Element>} Array of formatted elements.
266 */ 249 */
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 if (opt_style) 312 if (opt_style)
330 el.className = opt_style; 313 el.className = opt_style;
331 return el; 314 return el;
332 }, 315 },
333 316
334 /** 317 /**
335 * Adds buttons for updating the connectivity of a device. 318 * Adds buttons for updating the connectivity of a device.
336 * @private. 319 * @private.
337 */ 320 */
338 addButtons_: function() { 321 addButtons_: function() {
339 var buttonsDiv = this.ownerDocument.createElement('div'); 322 var buttonsDiv = this.getNodeByClass_('bluetooth-button-group');
340 buttonsDiv.className = 'bluetooth-button-group';
341 var buttonLabelKey = null; 323 var buttonLabelKey = null;
342 var callbackType = null; 324 var callbackType = null;
343 if (this.connected) { 325 if (this.connected) {
344 buttonLabelKey = 'bluetoothDisconnectDevice'; 326 buttonLabelKey = 'bluetoothDisconnectDevice';
345 callbackType = 'disconnect'; 327 callbackType = 'disconnect';
346 } else if (this.paired) { 328 } else if (this.paired) {
347 buttonLabelKey = 'bluetoothForgetDevice'; 329 buttonLabelKey = 'bluetoothForgetDevice';
348 callbackType = 'disconnect'; 330 callbackType = 'disconnect';
349 } else if (this.connecting) { 331 } else if (this.connecting) {
350 buttonLabelKey = 'bluetoothCancel'; 332 buttonLabelKey = 'bluetoothCancel';
(...skipping 28 matching lines...) Expand all
379 361
380 cr.defineProperty(BluetoothItem, 'paired', cr.PropertyKind.BOOL_ATTR); 362 cr.defineProperty(BluetoothItem, 'paired', cr.PropertyKind.BOOL_ATTR);
381 363
382 cr.defineProperty(BluetoothItem, 'connecting', cr.PropertyKind.BOOL_ATTR); 364 cr.defineProperty(BluetoothItem, 'connecting', cr.PropertyKind.BOOL_ATTR);
383 365
384 return { 366 return {
385 Constants: Constants, 367 Constants: Constants,
386 BluetoothListElement: BluetoothListElement 368 BluetoothListElement: BluetoothListElement
387 }; 369 };
388 }); 370 });
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/resources/options/chromeos/system_options.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698