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

Side by Side Diff: chrome/browser/resources/chromeos/emulator/bluetooth_settings.js

Issue 1999593002: Update chrome://device-emulator with newer Polymer guidelines (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: narrow mode drawer + webui safety Created 4 years, 7 months 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 * A bluetooth device. 6 * A bluetooth device.
7 * @constructor 7 * @constructor
8 */ 8 */
9 var BluetoothDevice = function() { 9 var BluetoothDevice = function() {
10 // The device's address (MAC format, must be unique). 10 // The device's address (MAC format, must be unique).
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // The text containing a PIN key or passkey for pairing. 47 // The text containing a PIN key or passkey for pairing.
48 this.pairingAuthToken = ''; 48 this.pairingAuthToken = '';
49 49
50 // The label of the selected pairing action option. 50 // The label of the selected pairing action option.
51 this.pairingAction = ''; 51 this.pairingAction = '';
52 }; 52 };
53 53
54 Polymer({ 54 Polymer({
55 is: 'bluetooth-settings', 55 is: 'bluetooth-settings',
56 56
57 behaviors: [Polymer.NeonAnimatableBehavior],
58
57 properties: { 59 properties: {
58 /** 60 /**
59 * The title to be displayed in a heading element for the element.
60 */
61 title: {type: String},
62
63 /**
64 * A set of bluetooth devices. 61 * A set of bluetooth devices.
65 * @type !Array<!BluetoothDevice> 62 * @type !Array<!BluetoothDevice>
66 */ 63 */
67 devices: {type: Array, value: function() { return []; }}, 64 devices: {type: Array, value: function() { return []; }},
68 65
69 /** 66 /**
70 * A set of predefined bluetooth devices. 67 * A set of predefined bluetooth devices.
71 * @type !Array<!Bluetooth> 68 * @type !Array<!Bluetooth>
72 */ 69 */
73 predefinedDevices: {type: Array, value: function() { return []; }}, 70 predefinedDevices: {type: Array, value: function() { return []; }},
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 */ 153 */
157 currentEditableObjectChanged: function(obj) { 154 currentEditableObjectChanged: function(obj) {
158 if (this.currentEditIndex >= 0) { 155 if (this.currentEditIndex >= 0) {
159 var prop = obj.path.split('.')[1]; 156 var prop = obj.path.split('.')[1];
160 this.set('devices.' + this.currentEditIndex.toString() + '.' + prop, 157 this.set('devices.' + this.currentEditIndex.toString() + '.' + prop,
161 obj.value); 158 obj.value);
162 } 159 }
163 }, 160 },
164 161
165 /** 162 /**
166 * Called when the device edit modal is opened. Re-validates necessary input 163 * Called when the device edit dialog is opened. Re-validates necessary input
167 * fields. 164 * fields.
168 */ 165 */
169 editDialogOpened: function() { 166 editDialogOpened: function() {
170 this.validateAddress(); 167 this.validateAddress();
171 this.validatePath(); 168 this.validatePath();
172 }, 169 },
173 170
174 handleAddressInput: function() { 171 handleAddressInput: function() {
175 this.autoFormatAddress(); 172 this.autoFormatAddress();
176 this.validateAddress(); 173 this.validateAddress();
177 }, 174 },
178 175
179 autoFormatAddress: function() { 176 autoFormatAddress: function() {
180 var input = this.$.deviceAddressInput; 177 var input = this.$.deviceAddressInput;
181 var regex = /([a-f0-9]{2})([a-f0-9]{2})/i; 178 var regex = /([a-f0-9]{2})([a-f0-9]{2})/i;
182 // Remove things that aren't hex characters from the string. 179 // Remove things that aren't hex characters from the string.
183 var val = input.value.replace(/[^a-f0-9]/ig, ''); 180 var val = input.value.replace(/[^a-f0-9]/ig, '');
184 181
185 // Insert a ':' in the middle of every four hex characters. 182 // Insert a ':' in the middle of every four hex characters.
186 while (regex.test(val)) 183 while (regex.test(val))
187 val = val.replace(regex, '$1:$2'); 184 val = val.replace(regex, '$1:$2');
188 185
189 input.value = val; 186 input.value = val;
190 }, 187 },
191 188
192 /** 189 /**
193 * Called on-input from an input element and on edit modal open. 190 * Called on-input from an input element and on edit dialog open.
194 * Validates whether or not the 191 * Validates whether or not the
195 * input's content matches a regular expression. If the input's value 192 * input's content matches a regular expression. If the input's value
196 * satisfies the regex, then make sure that the address is not already 193 * satisfies the regex, then make sure that the address is not already
197 * in use. 194 * in use.
198 */ 195 */
199 validateAddress: function() { 196 validateAddress: function() {
200 var input = this.$.deviceAddressInput; 197 var input = this.$.deviceAddressInput;
201 var val = input.value; 198 var val = input.value;
202 var exists = false; 199 var exists = false;
203 var addressRegex = RegExp('^([\\da-fA-F]{2}:){5}[\\da-fA-F]{2}$'); 200 var addressRegex = RegExp('^([\\da-fA-F]{2}:){5}[\\da-fA-F]{2}$');
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 newDevice.path = ''; 447 newDevice.path = '';
451 newDevice.address = ''; 448 newDevice.address = '';
452 newDevice.name += ' (Copy)'; 449 newDevice.name += ' (Copy)';
453 newDevice.alias += ' (Copy)'; 450 newDevice.alias += ' (Copy)';
454 newDevice.discoverable = false; 451 newDevice.discoverable = false;
455 newDevice.paired = false; 452 newDevice.paired = false;
456 this.push('devices', newDevice); 453 this.push('devices', newDevice);
457 }, 454 },
458 455
459 /** 456 /**
460 * Shows a modal dialog to edit the selected device's properties. 457 * Shows a dialog to edit the selected device's properties.
461 * @param {Event} event Contains event data. |event.model.index| is the index 458 * @param {Event} event Contains event data. |event.model.index| is the index
462 * of the item which the target is contained in. 459 * of the item which the target is contained in.
463 */ 460 */
464 showEditModal: function(event) { 461 showEditDialog: function(event) {
465 var index = event.model.index; 462 var index = event.model.index;
466 this.currentEditIndex = index; 463 this.currentEditIndex = index;
467 this.currentEditableObject = this.devices[index]; 464 this.currentEditableObject = this.devices[index];
468 this.$.editModal.toggle(); 465 this.$.editDialog.toggle();
469 }, 466 },
470 467
471 /** 468 /**
472 * A click handler for the delete button on bluetooth devices. 469 * A click handler for the delete button on bluetooth devices.
473 * @param {Event} event Contains event data. |event.model.index| is the index 470 * @param {Event} event Contains event data. |event.model.index| is the index
474 * of the item which the target is contained in. 471 * of the item which the target is contained in.
475 */ 472 */
476 deleteDevice: function(event) { 473 deleteDevice: function(event) {
477 var index = event.model.index; 474 var index = event.model.index;
478 var device = this.devices[index]; 475 var device = this.devices[index];
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 * @return {number} The value which |classText| represents. 515 * @return {number} The value which |classText| represents.
519 */ 516 */
520 getValueForDeviceClass: function(classText) { 517 getValueForDeviceClass: function(classText) {
521 for (var i = 0; i < this.deviceClassOptions.length; ++i) { 518 for (var i = 0; i < this.deviceClassOptions.length; ++i) {
522 if (this.deviceClassOptions[i].text == classText) 519 if (this.deviceClassOptions[i].text == classText)
523 return this.deviceClassOptions[i].value; 520 return this.deviceClassOptions[i].value;
524 } 521 }
525 return 0; 522 return 0;
526 }, 523 },
527 }); 524 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698