| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * @fileoverview controller pairing screen implementation. | 6 * @fileoverview controller pairing screen implementation. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 login.createScreen('ControllerPairingScreen', 'controller-pairing', function() { | 9 login.createScreen('ControllerPairingScreen', 'controller-pairing', function() { |
| 10 return { | 10 return { |
| 11 decorate: function() { | 11 decorate: function() { |
| 12 this.children[0].decorate(this); | 12 this.children[0].decorate(this); |
| 13 } | 13 } |
| 14 }; | 14 }; |
| 15 }); | 15 }); |
| 16 | |
| 17 Polymer('pairing-device-list', (function() { | |
| 18 /** @const */ var ICON_COLORS = ['#F0B9CB', '#F0ACC3', '#F098B6', '#F084A9', | |
| 19 '#F06D99', '#F05287', '#F0467F', '#F03473', | |
| 20 '#F01E65', '#F00051']; | |
| 21 return { | |
| 22 /* Returns pseudo-random color depending of hash of the |name|. */ | |
| 23 colorByName: function(name) { | |
| 24 var hash = 0; | |
| 25 for (var i = 0; i < name.length; ++i) | |
| 26 hash = (name.charCodeAt(i) + 31 * hash) | 0; | |
| 27 return ICON_COLORS[hash % ICON_COLORS.length]; | |
| 28 } | |
| 29 }; | |
| 30 })()); | |
| 31 | |
| 32 Polymer('controller-pairing-screen', (function() { | |
| 33 'use strict'; | |
| 34 | |
| 35 // Keep these constants synced with corresponding constants defined in | |
| 36 // controller_pairing_screen_actor.{h,cc}. | |
| 37 /** @const */ var CONTEXT_KEY_CONTROLS_DISABLED = 'controlsDisabled'; | |
| 38 /** @const */ var CONTEXT_KEY_SELECTED_DEVICE = 'selectedDevice'; | |
| 39 /** @const */ var CONTEXT_KEY_ACCOUNT_ID = 'accountId'; | |
| 40 | |
| 41 /** @const */ var ACTION_ENROLL = 'enroll'; | |
| 42 | |
| 43 /** @const */ var PAGE_AUTHENTICATION = 'authentication'; | |
| 44 | |
| 45 return { | |
| 46 gaiaHost_: null, | |
| 47 selectedDevice: null, | |
| 48 | |
| 49 observe: { | |
| 50 'C.devices': 'deviceListChanged', | |
| 51 'C.page': 'pageChanged' | |
| 52 }, | |
| 53 | |
| 54 /** @override */ | |
| 55 initialize: function() { | |
| 56 this.context.set(CONTEXT_KEY_CONTROLS_DISABLED, true); | |
| 57 this.commitContextChanges(); | |
| 58 this.gaiaHost_ = new cr.login.GaiaAuthHost(this.$.gaiaFrame); | |
| 59 }, | |
| 60 | |
| 61 pageChanged: function(oldPage, newPage) { | |
| 62 if (newPage == PAGE_AUTHENTICATION) { | |
| 63 this.gaiaHost_.load(cr.login.GaiaAuthHost.AuthMode.DEFAULT, | |
| 64 {}, | |
| 65 this.onAuthCompleted_.bind(this)); | |
| 66 } | |
| 67 }, | |
| 68 | |
| 69 deviceListChanged: function() { | |
| 70 this.selectedDevice = this.context.get(CONTEXT_KEY_SELECTED_DEVICE); | |
| 71 }, | |
| 72 | |
| 73 selectedDeviceChanged: function() { | |
| 74 this.context.set(CONTEXT_KEY_SELECTED_DEVICE, | |
| 75 this.selectedDevice ? this.selectedDevice : ''); | |
| 76 this.commitContextChanges(); | |
| 77 }, | |
| 78 | |
| 79 helpButtonClicked: function() { | |
| 80 console.error('Help is not implemented yet.'); | |
| 81 }, | |
| 82 | |
| 83 onAuthCompleted_: function(credentials) { | |
| 84 this.context.set(CONTEXT_KEY_ACCOUNT_ID, credentials.email); | |
| 85 this.commitContextChanges(); | |
| 86 this.send(login.Screen.CALLBACK_USER_ACTED, ACTION_ENROLL); | |
| 87 } | |
| 88 }; | |
| 89 })()); | |
| 90 | |
| OLD | NEW |