Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / chromeos / login / oobe_screen_network.js
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.
4
5 /**
6  * @fileoverview Oobe network screen implementation.
7  */
8
9 login.createScreen('NetworkScreen', 'connect', function() {
10   return {
11     EXTERNAL_API: [
12       'enableContinueButton',
13       'setInputMethod',
14       'setTimezone',
15       'showError'
16     ],
17
18     /**
19      * Dropdown element for networks selection.
20      */
21     dropdown_: null,
22
23     /** @override */
24     decorate: function() {
25       Oobe.setupSelect($('language-select'),
26                        loadTimeData.getValue('languageList'),
27                        'networkOnLanguageChanged');
28
29       Oobe.setupSelect($('keyboard-select'),
30                        loadTimeData.getValue('inputMethodsList'),
31                        'networkOnInputMethodChanged');
32
33       Oobe.setupSelect($('timezone-select'),
34                        loadTimeData.getValue('timezoneList'),
35                        'networkOnTimezoneChanged');
36
37       this.dropdown_ = $('networks-list');
38       cr.ui.DropDown.decorate(this.dropdown_);
39     },
40
41     onBeforeShow: function(data) {
42       cr.ui.DropDown.show('networks-list', true, -1);
43     },
44
45     onBeforeHide: function() {
46       cr.ui.DropDown.hide('networks-list');
47       this.enableContinueButton(false);
48     },
49
50     /**
51      * Header text of the screen.
52      * @type {string}
53      */
54     get header() {
55       return loadTimeData.getString('networkScreenTitle');
56     },
57
58     /**
59      * Buttons in oobe wizard's button strip.
60      * @type {array} Array of Buttons.
61      */
62     get buttons() {
63       var buttons = [];
64
65       var continueButton = this.ownerDocument.createElement('button');
66       continueButton.disabled = true;
67       continueButton.id = 'continue-button';
68       continueButton.textContent = loadTimeData.getString('continueButton');
69       continueButton.classList.add('preserve-disabled-state');
70       continueButton.addEventListener('click', function(e) {
71         chrome.send('networkOnExit');
72         e.stopPropagation();
73       });
74       buttons.push(continueButton);
75
76       return buttons;
77     },
78
79     /**
80      * Returns a control which should receive an initial focus.
81      */
82     get defaultControl() {
83       return $('language-select');
84     },
85
86     /**
87      * Enables/disables continue button.
88      * @param {boolean} enable Should the button be enabled?
89      */
90     enableContinueButton: function(enable) {
91       $('continue-button').disabled = !enable;
92     },
93
94     /**
95      * Sets the current input method.
96      * @param {string} inputMethodId The ID of the input method to select.
97      */
98     setInputMethod: function(inputMethodId) {
99       option = $('keyboard-select').querySelector(
100           'option[value="' + inputMethodId + '"]');
101       if (option)
102         option.selected = true;
103     },
104
105     /**
106      * Sets the current timezone.
107      * @param {string} timezoneId The timezone ID to select.
108      */
109     setTimezone: function(timezoneId) {
110       $('timezone-select').value = timezoneId;
111     },
112
113     /**
114      * Shows the network error message.
115      * @param {string} message Message to be shown.
116      */
117     showError: function(message) {
118       var error = document.createElement('div');
119       var messageDiv = document.createElement('div');
120       messageDiv.className = 'error-message-bubble';
121       messageDiv.textContent = message;
122       error.appendChild(messageDiv);
123       error.setAttribute('role', 'alert');
124
125       $('bubble').showContentForElement($('networks-list'),
126                                         cr.ui.Bubble.Attachment.BOTTOM,
127                                         error);
128     }
129   };
130 });
131