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

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

Issue 326933004: Example of usage of new features of context and screen. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 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.
4
5 /**
6 * @fileoverview controller pairing screen implementation.
7 */
8
9 login.createScreen('ControllerPairingScreen', 'controller-pairing', function() {
10 'use strict';
11
12 /** @const */ var CONTEXT_KEY_PAGE = 'page';
13 /** @const */ var CONTEXT_KEY_CONTROLS_DISABLED = 'controlsDisabled';
14 /** @const */ var CONTEXT_KEY_DEVICES = 'devices';
15 /** @const */ var CONTEXT_KEY_CONFIRMATION_CODE = 'code';
16 /** @const */ var CONTEXT_KEY_SELECTED_DEVICE = 'selectedDevice';
17 /** @const */ var CONTEXT_KEY_ACCOUNT_ID = "accountId";
18
19 /** @const */ var PAGE_DEVICES_DISCOVERY = 'devices-discovery';
20 /** @const */ var PAGE_DEVICE_SELECT = 'device-select';
21 /** @const */ var PAGE_DEVICE_NOT_FOUND = 'device-not-found';
22 /** @const */ var PAGE_ESTABLISHING_CONNECTION = 'establishing-connection';
23 /** @const */ var PAGE_ESTABLISHING_CONNECTION_ERROR =
24 'establishing-connection-error';
25 /** @const */ var PAGE_CODE_CONFIRMATION = 'code-confirmation';
26 /** @const */ var PAGE_HOST_UPDATE = 'host-update';
27 /** @const */ var PAGE_HOST_CONNECTION_LOST = 'host-connection-lost';
28 /** @const */ var PAGE_ENRLOLLMENT_INTRODUCTION = 'enrollment-introduction';
29 /** @const */ var PAGE_AUTHENTICATION = 'authentication';
30 /** @const */ var PAGE_HOST_ENROLLMENT = 'host-enrollment';
31 /** @const */ var PAGE_HOST_ENROLLMENT_ERROR = 'host-enrollment-error';
32 /** @const */ var PAGE_PAIRING_DONE = 'pairing-done';
33
34 return {
35 deviceSelectionChangedCallback_: null,
36
37 /** @override */
38 decorate: function() {
39 this.makeMagic();
40
41 this.observeContext(CONTEXT_KEY_PAGE, this.pageChanged_);
42 this.observeContext(CONTEXT_KEY_CONTROLS_DISABLED, this.disableControls_);
43
44 cr.ui.List.decorate(this.deviceList_);
45 this.deviceList_.selectionModel = new cr.ui.ListSingleSelectionModel();
46 },
47
48 pageChanged_: function(newPage, oldPage) {
49 this.deviceList_.hidden = this.chooseDeviceButton_.hidden =
50 (newPage != PAGE_DEVICE_SELECT);
51 this.throbber_.hidden = [PAGE_DEVICES_DISCOVERY,
52 PAGE_DEVICE_SELECT,
53 PAGE_ESTABLISHING_CONNECTION,
54 PAGE_HOST_UPDATE,
55 PAGE_HOST_CONNECTION_LOST,
56 PAGE_HOST_ENROLLMENT].indexOf(newPage) == -1;
57 this.confirmationCodeLabel_.hidden = this.acceptCodeButton_.hidden =
58 this.rejectCodeButton_.hidden = (newPage != PAGE_CODE_CONFIRMATION);
59
60 if (newPage == PAGE_DEVICE_SELECT) {
61 this.observeContext(CONTEXT_KEY_DEVICES, this.deviceListChanged_);
62 this.observeContext(CONTEXT_KEY_SELECTED_DEVICE,
63 this.updateDeviceSelection_);
64 this.deviceSelectionChangedCallback_ =
65 this.deviceSelectionChanged_.bind(this);
66 this.deviceList_.addEventListener('change',
67 this.deviceSelectionChangedCallback_);
68 this.deviceSelectionChanged_();
69 this.deviceListChanged_(this.context.get(CONTEXT_KEY_DEVICES));
70 setTimeout(this.deviceList_.redraw.bind(this.deviceList_), 0);
71 } else if (oldPage == PAGE_DEVICE_SELECT) {
72 this.unobserveContext(this.deviceListChanged_);
73 this.observeContext(this.updateDeviceSelection_);
74 this.deviceList_.removeEventListener('change',
75 this.deviceSelectionChangedCallback_);
76 this.deviceSelectionChangedCallback_ = null;
77 }
78
79 if (newPage == PAGE_CODE_CONFIRMATION) {
80 this.confirmationCodeLabel_.textContent =
81 this.context.get(CONTEXT_KEY_CONFIRMATION_CODE) + '?';
82 }
83
84 this.pageNameLabel_.textContent = '<<<< ' + newPage + ' >>>>';
85 this.setAttribute('page', newPage);
86 },
87
88 deviceListChanged_: function(deviceList) {
89 this.deviceList_.dataModel =
90 new cr.ui.ArrayDataModel(deviceList.split('\0'));
91 this.updateDeviceSelection_();
92 },
93
94 deviceSelectionChanged_: function() {
95 var item = this.deviceList_.selectedItem;
96 this.context.set(CONTEXT_KEY_SELECTED_DEVICE, item ? item : '');
97 this.commitContextChanges();
98 },
99
100 updateDeviceSelection_: function() {
101 var selectedDevice = this.context.get(CONTEXT_KEY_SELECTED_DEVICE, null);
102 if (selectedDevice === '')
103 selectedDevice = null;
104 this.deviceList_.selectedItem = selectedDevice;
105 },
106
107 disableControls_: function(disable) {
108 this.querySelectorAll('button').forEach(function(button) {
109 button.disabled = disable;
110 });
111 }
112 };
113 });
114
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698