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
3 // found in the LICENSE file.
6 * @fileoverview controller pairing screen implementation.
9 login.createScreen('ControllerPairingScreen', 'controller-pairing', function() {
11 decorate: function() {
12 this.children[0].decorate(this);
17 Polymer('pairing-device-list', (function() {
18 /** @const */ var ICON_COLORS = ['#F0B9CB', '#F0ACC3', '#F098B6', '#F084A9',
19 '#F06D99', '#F05287', '#F0467F', '#F03473',
20 '#F01E65', '#F00051'];
22 /* Returns pseudo-random color depending of hash of the |name|. */
23 colorByName: function(name) {
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];
32 Polymer('controller-pairing-screen', (function() {
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';
41 /** @const */ var ACTION_ENROLL = 'enroll';
43 /** @const */ var PAGE_AUTHENTICATION = 'authentication';
50 'C.devices': 'deviceListChanged',
51 'C.page': 'pageChanged'
55 initialize: function() {
56 this.context.set(CONTEXT_KEY_CONTROLS_DISABLED, true);
57 this.commitContextChanges();
58 this.gaiaHost_ = new cr.login.GaiaAuthHost(this.$.gaiaFrame);
61 pageChanged: function(oldPage, newPage) {
62 if (newPage == PAGE_AUTHENTICATION) {
63 this.gaiaHost_.load(cr.login.GaiaAuthHost.AuthMode.DEFAULT,
65 this.onAuthCompleted_.bind(this));
69 deviceListChanged: function() {
70 this.selectedDevice = this.context.get(CONTEXT_KEY_SELECTED_DEVICE);
73 selectedDeviceChanged: function() {
74 this.context.set(CONTEXT_KEY_SELECTED_DEVICE,
75 this.selectedDevice ? this.selectedDevice : '');
76 this.commitContextChanges();
79 helpButtonClicked: function() {
80 console.error('Help is not implemented yet.');
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);