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();
48 pageChanged: function(oldPage
, newPage
) {
49 if (newPage
== PAGE_AUTHENTICATION
) {
50 this.gaiaHost_
.load(cr
.login
.GaiaAuthHost
.AuthMode
.DEFAULT
,
52 this.onAuthCompleted_
.bind(this));
56 deviceListChanged: function() {
57 this.selectedDevice
= this.context
.get(CONTEXT_KEY_SELECTED_DEVICE
);
60 selectedDeviceChanged: function() {
61 this.context
.set(CONTEXT_KEY_SELECTED_DEVICE
,
62 this.selectedDevice
? this.selectedDevice
: '');
63 this.commitContextChanges();
66 helpButtonClicked: function() {
67 console
.error('Help is not implemented yet.');
70 onAuthCompleted_: function(credentials
) {
71 this.context
.set(CONTEXT_KEY_ACCOUNT_ID
, credentials
.email
);
72 this.commitContextChanges();
73 this.send(login
.Screen
.CALLBACK_USER_ACTED
, ACTION_ENROLL
);