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

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

Issue 7520037: [cros] Network dropdown button in WebUI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 9 years, 4 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 Oobe network screen implementation. 6 * @fileoverview Oobe network screen implementation.
7 */ 7 */
8 8
9 cr.define('oobe', function() { 9 cr.define('oobe', function() {
10 /** 10 /**
11 * Creates a new DropDown div.
12 * @constructor
13 * @extends {HTMLDivElement}
14 */
15 var DropDown = cr.ui.define('div');
16
17 DropDown.prototype = {
18 __proto__: HTMLDivElement.prototype,
19
20 /** @inheritDoc */
21 decorate: function() {
22 this.isShown = false;
23 this.appendChild(this.createTitle_());
24
25 // Create menu items container.
26 var container = document.createElement('div')
xiyuan 2011/08/06 00:16:34 nit: document -> this.ownerDocument
Nikita (slow) 2011/08/06 16:41:16 Done.
27 container.id = 'dropdownMenu';
28 container.classList.add('dropdown-container');
29 container.hidden = !this.isShown;
30 this.appendChild(container);
31 },
32
33 /**
34 * Sets title and icon.
35 * @param {string} title Text on dropdown.
36 * @param {string} icon Icon in dataURL format.
37 */
38 setTitle: function(title, icon) {
39 // TODO(nkostylev): Icon support for dropdown title.
40 $('dropdownTitle').innerText = title;
xiyuan 2011/08/06 00:16:34 nit: innerText -> textContent
Nikita (slow) 2011/08/06 16:41:16 Done.
41 },
42
43 /**
44 * Sets dropdown items.
45 * @param {Array} items Dropdown items array.
46 */
47 setItems: function(items) {
48 var container = $('dropdownMenu');
xiyuan 2011/08/06 00:16:34 nit: container = this.lastElementChild; And if we
Nikita (slow) 2011/08/06 16:41:16 Done.
49 container.innerHTML = '';
50 for (var i = 0; i < items.length; ++i) {
51 var item = items[i];
52 if ('sub' in item) {
53 // Workaround for submenus, add items on top level.
54 // TODO(altimofeev): support submenus.
55 for (var j = 0; j < item.sub.length; ++j)
56 this.createItem_(container, item.sub[j]);
57 continue;
58 }
59 this.createItem_(container, item);
60 }
61 },
62
63 /**
64 * Creates dropdown item element and adds into container.
65 * @param {HTMLElement} container Container where item is added.
66 * @param {!Object} item Item to be added.
67 * @private
68 */
69 createItem_ : function(container, item) {
70 var itemContentElement;
71 var className = 'dropdown-item';
72 if (item.id == -2) {
xiyuan 2011/08/06 00:16:34 nit: give -2 a constant name?
Nikita (slow) 2011/08/06 16:41:16 Done.
73 className = 'dropdown-divider';
74 itemContentElement = document.createElement('hr');
xiyuan 2011/08/06 00:16:34 nit: document -> this.ownerDocument
Nikita (slow) 2011/08/06 16:41:16 Done.
75 } else {
76 var span = document.createElement('span');
xiyuan 2011/08/06 00:16:34 ditto
Nikita (slow) 2011/08/06 16:41:16 Done.
77 if ('bold' in item && item.bold) {
78 var bold = document.createElement('b');
xiyuan 2011/08/06 00:16:34 nit: I would prefer to use CSS instead of create a
Nikita (slow) 2011/08/06 16:41:16 Done.
79 bold.textContent = item.label;
80 span.appendChild(bold);
81 } else {
82 span.textContent = item.label;
83 }
84 itemContentElement = span;
85 var image = document.createElement('img');
86 if (item.icon)
87 image.src = item.icon;
88 }
89
90 var itemElement = document.createElement('div');
xiyuan 2011/08/06 00:16:34 nit: document -> this.ownerDocument
Nikita (slow) 2011/08/06 16:41:16 Done.
91 itemElement.classList.add(className);
92 itemElement.appendChild(itemContentElement);
93 itemElement.iid = item.id;
94 itemElement.controller = this;
95 var enabled = 'enabled' in item && item.enabled;
96 if (!enabled)
97 itemElement.classList.add('disabled-item');
98
99 if (item.id > 0) {
100 var wrapperDiv = document.createElement('div');
xiyuan 2011/08/06 00:16:34 nit: document -> this.ownerDocument
Nikita (slow) 2011/08/06 16:41:16 Done.
101 wrapperDiv.classList.add('dropdown-item-container');
102 var imageDiv = document.createElement('div');
xiyuan 2011/08/06 00:16:34 nit: document -> this.ownerDocument
Nikita (slow) 2011/08/06 16:41:16 Done.
103 imageDiv.classList.add('dropdown-image');
104 imageDiv.appendChild(image);
105 wrapperDiv.appendChild(imageDiv);
106 wrapperDiv.appendChild(itemElement);
107 wrapperDiv.addEventListener('click', function f(e) {
108 var item = this.childNodes[1];
109 if (item.iid < -1 || item.classList.contains('disabled-item'))
110 return;
111 item.controller.isShown = !item.controller.isShown;
112 item.controller.childNodes[1].hidden = !item.controller.isShown;
xiyuan 2011/08/06 00:16:34 seems like we can make isShown a property. get is
Nikita (slow) 2011/08/06 16:41:16 Done.
113 if (item.iid >= 0)
114 chrome.send('networkItemChosen', [item.iid]);
115 });
116 itemElement = wrapperDiv;
117 }
118 container.appendChild(itemElement);
119 },
120
121 /**
122 * Creates dropdown title element.
123 * @type {HTMLElement}
124 * @private
125 */
126 createTitle_: function() {
127 var el = document.createElement('button');
xiyuan 2011/08/06 00:16:34 nit: document -> this.ownerDocument
Nikita (slow) 2011/08/06 16:41:16 Done.
128 el.id = 'dropdownTitle';
129 el.classList.add('dropdown-title');
130 el.iid = -1;
131 el.controller = this;
132 el.addEventListener('click', function f(e) {
133 this.controller.isShown = !this.controller.isShown;
134 this.controller.childNodes[1].hidden = !this.controller.isShown;
135 });
136 return el;
137 }
138 };
139
140 /**
11 * Creates a new oobe screen div. 141 * Creates a new oobe screen div.
12 * @constructor 142 * @constructor
13 * @extends {HTMLDivElement} 143 * @extends {HTMLDivElement}
14 */ 144 */
15 var NetworkScreen = cr.ui.define('div'); 145 var NetworkScreen = cr.ui.define('div');
16 146
17 /** 147 /**
18 * Registers with Oobe. 148 * Registers with Oobe.
19 */ 149 */
20 NetworkScreen.register = function() { 150 NetworkScreen.register = function() {
21 var screen = $('connect'); 151 var screen = $('connect');
22 NetworkScreen.decorate(screen); 152 NetworkScreen.decorate(screen);
23 Oobe.getInstance().registerScreen(screen); 153 Oobe.getInstance().registerScreen(screen);
24 }; 154 };
25 155
26 NetworkScreen.prototype = { 156 NetworkScreen.prototype = {
27 __proto__: HTMLDivElement.prototype, 157 __proto__: HTMLDivElement.prototype,
28 158
159 /**
160 * Dropdown element for networks selection.
161 */
162 dropdown_: null,
163
29 /** @inheritDoc */ 164 /** @inheritDoc */
30 decorate: function() { 165 decorate: function() {
31 Oobe.setupSelect($('language-select'), 166 Oobe.setupSelect($('language-select'),
32 templateData.languageList, 167 templateData.languageList,
33 'networkOnLanguageChanged'); 168 'networkOnLanguageChanged');
34 169
35 Oobe.setupSelect($('keyboard-select'), 170 Oobe.setupSelect($('keyboard-select'),
36 templateData.inputMethodsList, 171 templateData.inputMethodsList,
37 'networkOnInputMethodChanged'); 172 'networkOnInputMethodChanged');
38 }, 173
174 this.dropdown_ = $('networks-list');
175 DropDown.decorate(this.dropdown_);
176 },
177
178 /**
179 * Updates network list in dropdown.
180 * @param {Array} items Dropdown items array.
181 */
182 updateNetworks: function(data) {
183 this.dropdown_.setItems(data);
184 },
185
186 /**
187 * Updates dropdown title and icon.
188 * @param {string} title Text on dropdown.
189 * @param {string} icon Icon in dataURL format.
190 */
191 updateNetworkTitle: function(title, icon) {
192 this.dropdown_.setTitle(title, icon);
193 },
39 194
40 /** 195 /**
41 * Header text of the screen. 196 * Header text of the screen.
42 * @type {string} 197 * @type {string}
43 */ 198 */
44 get header() { 199 get header() {
45 return localStrings.getString('networkScreenTitle'); 200 return localStrings.getString('networkScreenTitle');
46 }, 201 },
47 202
48 /** 203 /**
49 * Buttons in oobe wizard's button strip. 204 * Buttons in oobe wizard's button strip.
50 * @type {array} Array of Buttons. 205 * @type {array} Array of Buttons.
51 */ 206 */
52 get buttons() { 207 get buttons() {
53 var buttons = []; 208 var buttons = [];
54 209
55 var continueButton = this.ownerDocument.createElement('button'); 210 var continueButton = this.ownerDocument.createElement('button');
56 continueButton.id = 'continue-button'; 211 continueButton.id = 'continue-button';
57 continueButton.textContent = localStrings.getString('continueButton'); 212 continueButton.textContent = localStrings.getString('continueButton');
58 continueButton.addEventListener('click', function(e) { 213 continueButton.addEventListener('click', function(e) {
59 chrome.send('networkOnExit', []); 214 chrome.send('networkOnExit', []);
60 }); 215 });
61 buttons.push(continueButton); 216 buttons.push(continueButton);
62 217
63 return buttons; 218 return buttons;
64 } 219 }
65 }; 220 };
66 221
222 NetworkScreen.updateNetworks = function(data) {
223 $('connect').updateNetworks(data);
224 };
225
226 NetworkScreen.updateNetworkTitle = function(title, icon) {
227 $('connect').updateNetworkTitle(title, icon);
228 };
229
67 return { 230 return {
68 NetworkScreen: NetworkScreen 231 NetworkScreen: NetworkScreen
69 }; 232 };
70 }); 233 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698