Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: chrome/browser/resources/chromeos/login/oobe_screen_controller_pairing.js

Issue 642313002: Implemented UI for the meetings controller out-of-box. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@merge_point
Patch Set: Empty line removed. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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',
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() {
10 'use strict'; 33 'use strict';
11 34
12 // Keep these constants synced with corresponding constants defined in 35 // Keep these constants synced with corresponding constants defined in
13 // controller_pairing_screen_actor.{h,cc}. 36 // controller_pairing_screen_actor.{h,cc}.
14 /** @const */ var CONTEXT_KEY_PAGE = 'page';
15 /** @const */ var CONTEXT_KEY_CONTROLS_DISABLED = 'controlsDisabled'; 37 /** @const */ var CONTEXT_KEY_CONTROLS_DISABLED = 'controlsDisabled';
16 /** @const */ var CONTEXT_KEY_DEVICES = 'devices';
17 /** @const */ var CONTEXT_KEY_CONFIRMATION_CODE = 'code';
18 /** @const */ var CONTEXT_KEY_SELECTED_DEVICE = 'selectedDevice'; 38 /** @const */ var CONTEXT_KEY_SELECTED_DEVICE = 'selectedDevice';
19 /** @const */ var CONTEXT_KEY_ACCOUNT_ID = 'accountId'; 39 /** @const */ var CONTEXT_KEY_ACCOUNT_ID = 'accountId';
20 /** @const */ var CONTEXT_KEY_ENROLLMENT_DOMAIN = 'enrollmentDomain';
21 40
22 /** @const */ var ACTION_ENROLL = 'enroll'; 41 /** @const */ var ACTION_ENROLL = 'enroll';
23 42
24 /** @const */ var PAGE_DEVICES_DISCOVERY = 'devices-discovery';
25 /** @const */ var PAGE_DEVICE_SELECT = 'device-select';
26 /** @const */ var PAGE_DEVICE_NOT_FOUND = 'device-not-found';
27 /** @const */ var PAGE_ESTABLISHING_CONNECTION = 'establishing-connection';
28 /** @const */ var PAGE_ESTABLISHING_CONNECTION_ERROR =
29 'establishing-connection-error';
30 /** @const */ var PAGE_CODE_CONFIRMATION = 'code-confirmation';
31 /** @const */ var PAGE_HOST_UPDATE = 'host-update';
32 /** @const */ var PAGE_HOST_CONNECTION_LOST = 'host-connection-lost';
33 /** @const */ var PAGE_ENROLLMENT_INTRODUCTION = 'enrollment-introduction';
34 /** @const */ var PAGE_AUTHENTICATION = 'authentication'; 43 /** @const */ var PAGE_AUTHENTICATION = 'authentication';
35 /** @const */ var PAGE_HOST_ENROLLMENT = 'host-enrollment';
36 /** @const */ var PAGE_HOST_ENROLLMENT_ERROR = 'host-enrollment-error';
37 /** @const */ var PAGE_PAIRING_DONE = 'pairing-done';
38
39 /** @const */ var PAGE_NAMES = [
40 PAGE_DEVICES_DISCOVERY,
41 PAGE_DEVICE_SELECT,
42 PAGE_DEVICE_NOT_FOUND,
43 PAGE_ESTABLISHING_CONNECTION,
44 PAGE_ESTABLISHING_CONNECTION_ERROR,
45 PAGE_CODE_CONFIRMATION,
46 PAGE_HOST_UPDATE,
47 PAGE_HOST_CONNECTION_LOST,
48 PAGE_ENROLLMENT_INTRODUCTION,
49 PAGE_AUTHENTICATION,
50 PAGE_HOST_ENROLLMENT,
51 PAGE_HOST_ENROLLMENT_ERROR,
52 PAGE_PAIRING_DONE];
53 44
54 return { 45 return {
55 deviceSelectionChangedCallback_: null,
56 gaiaHost_: null, 46 gaiaHost_: null,
57 pages_: null, 47 selectedDevice: null,
48
49 observe: {
50 'C.devices': 'deviceListChanged',
51 'C.page': 'pageChanged'
52 },
58 53
59 /** @override */ 54 /** @override */
60 decorate: function() { 55 initialize: function() {
61 this.initialize(); 56 this.context.set(CONTEXT_KEY_CONTROLS_DISABLED, true);
62 57 this.commitContextChanges();
63 this.pages_ = {}; 58 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 }, 59 },
86 60
87 pageChanged_: function(newPage, oldPage) { 61 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) { 62 if (newPage == PAGE_AUTHENTICATION) {
116 this.gaiaHost_.load(cr.login.GaiaAuthHost.AuthMode.DEFAULT, 63 this.gaiaHost_.load(cr.login.GaiaAuthHost.AuthMode.DEFAULT,
117 {}, 64 {},
118 this.onAuthCompleted_.bind(this)); 65 this.onAuthCompleted_.bind(this));
119 } 66 }
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 }, 67 },
128 68
129 togglePage_: function(newPage) { 69 deviceListChanged: function() {
130 PAGE_NAMES.forEach(function(pageName) { 70 this.selectedDevice = this.context.get(CONTEXT_KEY_SELECTED_DEVICE);
131 this.pages_[pageName].hidden = (pageName !== newPage);
132 }, this);
133 }, 71 },
134 72
135 setDeviceList_: function(deviceList) { 73 selectedDeviceChanged: function() {
136 this.deviceList_.removeEventListener('change', 74 this.context.set(CONTEXT_KEY_SELECTED_DEVICE,
137 this.deviceSelectionChangedCallback_); 75 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(); 76 this.commitContextChanges();
154 }, 77 },
155 78
156 disableControls_: function(disable) { 79 helpButtonClicked: function() {
157 this.querySelectorAll('button').forEach(function(button) { 80 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 }, 81 },
163 82
164 onAuthCompleted_: function(credentials) { 83 onAuthCompleted_: function(credentials) {
165 this.context.set(CONTEXT_KEY_ACCOUNT_ID, credentials.email); 84 this.context.set(CONTEXT_KEY_ACCOUNT_ID, credentials.email);
166 this.commitContextChanges(); 85 this.commitContextChanges();
167 this.send(login.Screen.CALLBACK_USER_ACTED, ACTION_ENROLL); 86 this.send(login.Screen.CALLBACK_USER_ACTED, ACTION_ENROLL);
168 } 87 }
169 }; 88 };
170 }); 89 })());
171 90
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698