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.
5 Polymer('pairing-device-list', (function() {
6 /** @const */ var ICON_COLORS = ['#F0B9CB', '#F0ACC3', '#F098B6', '#F084A9',
7 '#F06D99', '#F05287', '#F0467F', '#F03473',
10 /* Returns pseudo-random color depending of hash of the |name|. */
11 colorByName: function(name) {
13 for (var i = 0; i < name.length; ++i)
14 hash = (name.charCodeAt(i) + 31 * hash) | 0;
15 return ICON_COLORS[hash % ICON_COLORS.length];
20 Polymer('controller-pairing-screen', (function() {
23 // Keep these constants synced with corresponding constants defined in
24 // controller_pairing_screen_actor.{h,cc}.
25 /** @const */ var CONTEXT_KEY_CONTROLS_DISABLED = 'controlsDisabled';
26 /** @const */ var CONTEXT_KEY_SELECTED_DEVICE = 'selectedDevice';
27 /** @const */ var CONTEXT_KEY_ACCOUNT_ID = 'accountId';
29 /** @const */ var ACTION_ENROLL = 'enroll';
31 /** @const */ var PAGE_AUTHENTICATION = 'authentication';
38 'C.devices': 'deviceListChanged',
39 'C.page': 'pageChanged'
43 initialize: function() {
44 this.context.set(CONTEXT_KEY_CONTROLS_DISABLED, true);
45 this.commitContextChanges();
46 this.gaiaHost_ = new cr.login.GaiaAuthHost(this.$.gaiaFrame);
49 pageChanged: function(oldPage, newPage) {
50 if (newPage == PAGE_AUTHENTICATION) {
51 this.gaiaHost_.load(cr.login.GaiaAuthHost.AuthMode.DEFAULT,
53 this.onAuthCompleted_.bind(this));
57 deviceListChanged: function() {
58 this.selectedDevice = this.context.get(CONTEXT_KEY_SELECTED_DEVICE);
61 selectedDeviceChanged: function() {
62 this.context.set(CONTEXT_KEY_SELECTED_DEVICE,
63 this.selectedDevice ? this.selectedDevice : '');
64 this.commitContextChanges();
67 helpButtonClicked: function() {
68 console.error('Help is not implemented yet.');
71 onAuthCompleted_: function(credentials) {
72 this.context.set(CONTEXT_KEY_ACCOUNT_ID, credentials.email);
73 this.commitContextChanges();
74 this.send(login.Screen.CALLBACK_USER_ACTED, ACTION_ENROLL);