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 { | |
11 decorate: function() { | |
12 this.children[0].decorate(this); | |
13 } | |
14 }; | |
15 }); | |
16 | |
17 Polymer('pairing-device-list', (function() { | |
18 /** @const */ var ICON_COLORS = ['#F0B9CB', '#F0ACC3', '#F098B6', '#F084A9', | |
Nikita (slow)
2014/10/13 17:23:40
Should use some of these:
https://www.google.com/d
| |
19 '#F06D99', '#F05287', '#F0467F', '#F03473', | |
20 '#F01E65', '#F00051']; | |
21 return { | |
22 disabled: false, | |
23 | |
24 /* Returns pseudo-random color depending of hash of the |name|. */ | |
25 colorByName: function(name) { | |
26 var hash = 0; | |
27 for (var i = 0; i < name.length; ++i) | |
28 hash = (name.charCodeAt(i) + 31 * hash) | 0; | |
29 return ICON_COLORS[hash % ICON_COLORS.length]; | |
30 } | |
31 }; | |
32 })()); | |
33 | |
34 Polymer('controller-pairing-page', { | |
35 type: 'solid', | |
36 }); | |
37 | |
38 Polymer('controller-pairing-screen', (function() { | |
10 'use strict'; | 39 'use strict'; |
11 | 40 |
12 // Keep these constants synced with corresponding constants defined in | 41 // Keep these constants synced with corresponding constants defined in |
13 // controller_pairing_screen_actor.{h,cc}. | 42 // controller_pairing_screen_actor.{h,cc}. |
14 /** @const */ var CONTEXT_KEY_PAGE = 'page'; | 43 /** @const */ var CONTEXT_KEY_PAGE = 'page'; |
15 /** @const */ var CONTEXT_KEY_CONTROLS_DISABLED = 'controlsDisabled'; | 44 /** @const */ var CONTEXT_KEY_CONTROLS_DISABLED = 'controlsDisabled'; |
16 /** @const */ var CONTEXT_KEY_DEVICES = 'devices'; | 45 /** @const */ var CONTEXT_KEY_DEVICES = 'devices'; |
17 /** @const */ var CONTEXT_KEY_CONFIRMATION_CODE = 'code'; | 46 /** @const */ var CONTEXT_KEY_CONFIRMATION_CODE = 'code'; |
18 /** @const */ var CONTEXT_KEY_SELECTED_DEVICE = 'selectedDevice'; | 47 /** @const */ var CONTEXT_KEY_SELECTED_DEVICE = 'selectedDevice'; |
19 /** @const */ var CONTEXT_KEY_ACCOUNT_ID = 'accountId'; | 48 /** @const */ var CONTEXT_KEY_ACCOUNT_ID = 'accountId'; |
(...skipping 25 matching lines...) Expand all Loading... | |
45 PAGE_CODE_CONFIRMATION, | 74 PAGE_CODE_CONFIRMATION, |
46 PAGE_HOST_UPDATE, | 75 PAGE_HOST_UPDATE, |
47 PAGE_HOST_CONNECTION_LOST, | 76 PAGE_HOST_CONNECTION_LOST, |
48 PAGE_ENROLLMENT_INTRODUCTION, | 77 PAGE_ENROLLMENT_INTRODUCTION, |
49 PAGE_AUTHENTICATION, | 78 PAGE_AUTHENTICATION, |
50 PAGE_HOST_ENROLLMENT, | 79 PAGE_HOST_ENROLLMENT, |
51 PAGE_HOST_ENROLLMENT_ERROR, | 80 PAGE_HOST_ENROLLMENT_ERROR, |
52 PAGE_PAIRING_DONE]; | 81 PAGE_PAIRING_DONE]; |
53 | 82 |
54 return { | 83 return { |
55 deviceSelectionChangedCallback_: null, | |
56 gaiaHost_: null, | 84 gaiaHost_: null, |
57 pages_: null, | 85 selectedDevice: null, |
86 | |
87 observe: { | |
dzhioev (left Google)
2014/10/10 13:53:01
https://www.polymer-project.org/docs/polymer/polym
| |
88 'C.devices': 'deviceListChanged', | |
89 'C.page': 'pageChanged' | |
90 }, | |
58 | 91 |
59 /** @override */ | 92 /** @override */ |
60 decorate: function() { | 93 initialize: function() { |
61 this.initialize(); | 94 this.context.set(CONTEXT_KEY_CONTROLS_DISABLED, true); |
62 | 95 this.commitContextChanges(); |
63 this.pages_ = {}; | 96 this.gaiaHost_ = new cr.login.GaiaAuthHost(this.$.gaiaFrame); |
64 PAGE_NAMES.forEach(function(pageName) { | |
65 var page = this.querySelector('.page-' + pageName); | |
66 if (page === null) | |
67 throw Error('Page "' + pageName + '" was not found.'); | |
68 page.hidden = true; | |
69 this.pages_[pageName] = page; | |
70 }, this); | |
71 | |
72 this.disableControls_(true); | |
73 | |
74 this.addContextObserver(CONTEXT_KEY_PAGE, this.pageChanged_); | |
75 this.addContextObserver(CONTEXT_KEY_CONTROLS_DISABLED, | |
76 this.disableControls_); | |
77 | |
78 cr.ui.List.decorate(this.deviceList_); | |
79 this.deviceList_.selectionModel = new cr.ui.ListSingleSelectionModel(); | |
80 | |
81 this.gaiaHost_ = new cr.login.GaiaAuthHost(this.gaiaFrame_); | |
82 | |
83 this.deviceSelectionChangedCallback_ = | |
84 this.deviceSelectionChanged_.bind(this); | |
85 }, | 97 }, |
86 | 98 |
87 pageChanged_: function(newPage, oldPage) { | 99 pageChanged: function(oldPage, newPage) { |
88 this.throbber_.hidden = [PAGE_DEVICES_DISCOVERY, | |
89 PAGE_DEVICE_SELECT, | |
90 PAGE_ESTABLISHING_CONNECTION, | |
91 PAGE_HOST_UPDATE, | |
92 PAGE_HOST_CONNECTION_LOST, | |
93 PAGE_HOST_ENROLLMENT].indexOf(newPage) == -1; | |
94 this.togglePage_(newPage); | |
95 if (newPage == PAGE_DEVICE_SELECT) { | |
96 this.addContextObserver(CONTEXT_KEY_DEVICES, this.setDeviceList_); | |
97 this.addContextObserver(CONTEXT_KEY_SELECTED_DEVICE, | |
98 this.setSelectedDevice_); | |
99 this.setDeviceList_(this.context.get(CONTEXT_KEY_DEVICES)); | |
100 this.deviceList_.addEventListener('change', | |
101 this.deviceSelectionChangedCallback_); | |
102 } else if (oldPage == PAGE_DEVICE_SELECT) { | |
103 this.removeContextObserver(this.setDeviceList_); | |
104 this.removeContextObserver(this.setSelectedDevice_); | |
105 this.deviceList_.removeEventListener('change', | |
106 this.deviceSelectionChangedCallback_); | |
107 } | |
108 | |
109 if (newPage == PAGE_CODE_CONFIRMATION) { | |
110 // TODO(dzhioev): replace with i18n pattern. | |
111 this.confirmationCodeLabel_.textContent = | |
112 this.context.get(CONTEXT_KEY_CONFIRMATION_CODE) + '?'; | |
113 } | |
114 | |
115 if (newPage == PAGE_AUTHENTICATION) { | 100 if (newPage == PAGE_AUTHENTICATION) { |
116 this.gaiaHost_.load(cr.login.GaiaAuthHost.AuthMode.DEFAULT, | 101 this.gaiaHost_.load(cr.login.GaiaAuthHost.AuthMode.DEFAULT, |
117 {}, | 102 {}, |
118 this.onAuthCompleted_.bind(this)); | 103 this.onAuthCompleted_.bind(this)); |
119 } | 104 } |
120 | |
121 if (newPage == PAGE_HOST_ENROLLMENT) { | |
122 this.domainNameLabel_.textContent = | |
123 this.context.get(CONTEXT_KEY_ENROLLMENT_DOMAIN); | |
124 } | |
125 | |
126 this.pageNameLabel_.textContent = '<<<< ' + newPage + ' >>>>'; | |
127 }, | 105 }, |
128 | 106 |
129 togglePage_: function(newPage) { | 107 deviceListChanged: function() { |
130 PAGE_NAMES.forEach(function(pageName) { | 108 this.selectedDevice = this.context.get(CONTEXT_KEY_SELECTED_DEVICE); |
131 this.pages_[pageName].hidden = (pageName !== newPage); | |
132 }, this); | |
133 }, | 109 }, |
134 | 110 |
135 setDeviceList_: function(deviceList) { | 111 selectedDeviceChanged: function() { |
dzhioev (left Google)
2014/10/10 13:53:01
https://www.polymer-project.org/docs/polymer/polym
| |
136 this.deviceList_.removeEventListener('change', | 112 this.context.set(CONTEXT_KEY_SELECTED_DEVICE, |
137 this.deviceSelectionChangedCallback_); | 113 this.selectedDevice ? this.selectedDevice : ''); |
138 | |
139 this.deviceList_.dataModel = new cr.ui.ArrayDataModel(deviceList); | |
140 this.setSelectedDevice_(this.context.get(CONTEXT_KEY_SELECTED_DEVICE)); | |
141 | |
142 this.deviceList_.addEventListener('change', | |
143 this.deviceSelectionChangedCallback_); | |
144 }, | |
145 | |
146 setSelectedDevice_: function(selectedDevice) { | |
147 this.deviceList_.selectedItem = selectedDevice; | |
148 }, | |
149 | |
150 deviceSelectionChanged_: function() { | |
151 var item = this.deviceList_.selectedItem; | |
152 this.context.set(CONTEXT_KEY_SELECTED_DEVICE, item ? item : ''); | |
153 this.commitContextChanges(); | 114 this.commitContextChanges(); |
154 }, | 115 }, |
155 | 116 |
156 disableControls_: function(disable) { | 117 helpButtonClicked: function() { |
157 this.querySelectorAll('button').forEach(function(button) { | 118 console.error('Help is not implemented yet.'); |
158 button.disabled = disable; | |
159 }); | |
160 this.context.set(CONTEXT_KEY_CONTROLS_DISABLED, disable); | |
161 this.commitContextChanges(); | |
162 }, | 119 }, |
163 | 120 |
164 onAuthCompleted_: function(credentials) { | 121 onAuthCompleted_: function(credentials) { |
165 this.context.set(CONTEXT_KEY_ACCOUNT_ID, credentials.email); | 122 this.context.set(CONTEXT_KEY_ACCOUNT_ID, credentials.email); |
166 this.commitContextChanges(); | 123 this.commitContextChanges(); |
167 this.send(login.Screen.CALLBACK_USER_ACTED, ACTION_ENROLL); | 124 this.send(login.Screen.CALLBACK_USER_ACTED, ACTION_ENROLL); |
168 } | 125 } |
169 }; | 126 }; |
170 }); | 127 })()); |
171 | 128 |
OLD | NEW |