1 // Copyright (c) 2012 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.
6 * @fileoverview Oobe network screen implementation.
9 login.createScreen('NetworkScreen', 'connect', function() {
10 var USER_ACTION_CONTINUE_BUTTON_CLICKED = 'continue';
11 var USER_ACTION_CONNECT_DEBUGGING_FEATURES_CLICKED =
12 'connect-debugging-features';
13 var CONTEXT_KEY_LOCALE = 'locale';
14 var CONTEXT_KEY_INPUT_METHOD = 'input-method';
15 var CONTEXT_KEY_TIMEZONE = 'timezone';
16 var CONTEXT_KEY_CONTINUE_BUTTON_ENABLED = 'continue-button-enabled';
24 * Dropdown element for networks selection.
29 decorate: function() {
32 Oobe.setupSelect($('language-select'),
33 loadTimeData.getValue('languageList'),
34 function(languageId) {
35 self.context.set(CONTEXT_KEY_LOCALE, languageId);
36 self.commitContextChanges();
38 Oobe.setupSelect($('keyboard-select'),
39 loadTimeData.getValue('inputMethodsList'),
40 function(inputMethodId) {
41 self.context.set(CONTEXT_KEY_INPUT_METHOD,
43 self.commitContextChanges();
45 Oobe.setupSelect($('timezone-select'),
46 loadTimeData.getValue('timezoneList'),
47 function(timezoneId) {
48 self.context.set(CONTEXT_KEY_TIMEZONE, timezoneId);
49 self.commitContextChanges();
52 this.dropdown_ = $('networks-list');
53 cr.ui.DropDown.decorate(this.dropdown_);
55 this.declareUserAction(
56 $('connect-debugging-features-link'),
57 { action_id: USER_ACTION_CONNECT_DEBUGGING_FEATURES_CLICKED,
60 this.declareUserAction(
61 $('connect-debugging-features-link'),
62 { action_id: USER_ACTION_CONNECT_DEBUGGING_FEATURES_CLICKED,
63 condition: function(event) { return event.keyCode == 32; },
67 this.context.addObserver(
68 CONTEXT_KEY_INPUT_METHOD,
69 function(inputMethodId) {
70 option = $('keyboard-select').querySelector(
71 'option[value="' + inputMethodId + '"]');
73 option.selected = true;
75 this.context.addObserver(CONTEXT_KEY_TIMEZONE, function(timezoneId) {
76 $('timezone-select').value = timezoneId;
78 this.context.addObserver(CONTEXT_KEY_CONTINUE_BUTTON_ENABLED,
80 $('continue-button').disabled = !enabled;
84 onBeforeShow: function(data) {
85 cr.ui.DropDown.show('networks-list', true, -1);
86 this.classList.toggle('connect-debugging-view',
87 data && 'isDeveloperMode' in data && data['isDeveloperMode']);
90 onBeforeHide: function() {
91 cr.ui.DropDown.hide('networks-list');
95 * Header text of the screen.
99 return loadTimeData.getString('networkScreenTitle');
103 * Buttons in oobe wizard's button strip.
104 * @type {array} Array of Buttons.
109 var continueButton = this.declareButton(
111 USER_ACTION_CONTINUE_BUTTON_CLICKED);
112 continueButton.disabled = !this.context.get(
113 CONTEXT_KEY_CONTINUE_BUTTON_ENABLED, false /* default */);
114 continueButton.textContent = loadTimeData.getString('continueButton');
115 continueButton.classList.add('preserve-disabled-state');
116 buttons.push(continueButton);
122 * Returns a control which should receive an initial focus.
124 get defaultControl() {
125 return $('language-select');
129 * Shows the network error message.
130 * @param {string} message Message to be shown.
132 showError: function(message) {
133 var error = document.createElement('div');
134 var messageDiv = document.createElement('div');
135 messageDiv.className = 'error-message-bubble';
136 messageDiv.textContent = message;
137 error.appendChild(messageDiv);
138 error.setAttribute('role', 'alert');
140 $('bubble').showContentForElement($('networks-list'),
141 cr.ui.Bubble.Attachment.BOTTOM,