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

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: move handle click 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 * Creates dropdown element.
7 * @param {!Element} root Root element, where dropdown is inserted to.
8 * @param {string} title Text on dropdown.
9 * @param {Array} items Initial array of dropdown items.
10 */
11 function DropDown(root, title, items) {
xiyuan 2011/07/29 21:39:33 we probably want to put this into a cr.define name
xiyuan 2011/07/29 21:39:33 It would be better to merge DropDown a HTMLDivElem
Nikita (slow) 2011/08/05 23:40:26 Done.
Nikita (slow) 2011/08/05 23:40:26 Done.
12 this.root_ = root;
13 this.container_ = document.createElement('div');
14 this.container_.classList.add('dropdown-container');
xiyuan 2011/07/29 21:39:33 this.container_ element seems not used.
Nikita (slow) 2011/08/05 23:40:26 Done.
15 this.isShown = false;
16
17 this.setTitle(title);
18 this.setItems(items);
19 }
20
21 DropDown.prototype = {
22 /**
23 * Sets title and icon.
24 * @param {string} title Text on dropdown.
25 * @param {string} icon Icon in dataURL format.
26 */
27 setTitle: function(title, icon) {
28 var titleHtml = title;
29 var image = document.createElement('img');
30 if (icon)
31 image.src = icon;
32 this.root_.insertBefore(
33 this.createDiv_('dropdown-title', image, titleHtml, -1, true),
34 this.root_.childNodes[0]);
35 if (this.root_.childNodes.length > 1)
36 this.root_.removeChild(this.root_.childNodes[1]);
xiyuan 2011/07/29 21:39:33 It seems a DropDown has two immediate child: title
Nikita (slow) 2011/08/05 23:40:26 Done.
37 },
38
39 /**
40 * Sets dropdown items.
41 * @param {Array} items Dropdown items array.
42 */
43 setItems: function(items) {
44 if (this.root_.childNodes.length > 1) {
45 this.root_.removeChild(this.root_.childNodes[1]);
xiyuan 2011/07/29 21:39:33 see above. Instead of creating the container every
Nikita (slow) 2011/08/05 23:40:26 Done.
46 }
47
48 var container = document.createElement('div')
49 container.classList.add('dropdown-container');
50
51 for (var i = 0; i < items.length; ++i) {
52 var item = items[i];
53 if ('sub' in item) {
54 // Workaround for submenus, add items on top level.
55 // TODO(altimofeev): support submenus.
56 // item = item.sub[0];
57 for (var j = 0; j < item.sub.length; ++j)
58 this.createItem_(container, item.sub[j]);
59
60 continue;
61 }
62 this.createItem_(container, item);
63 }
64
65 this.root_.appendChild(container);
66 container.style.display = this.isShown ? 'block' : 'none';
xiyuan 2011/07/29 21:39:33 suggest to use container.hidden instead of display
Nikita (slow) 2011/08/05 23:40:26 Done.
67 },
68
69 /**
70 * Creates dropdown element (div/button) for dropdown item / title.
71 * @param {string} className Element class.
72 * @param {HTMLElement} image Image element with icon.
73 * @param {string} innerHtml Inner contents of the element.
74 * @param {number} iid Internal ID of the element.
75 * @param {bool} enabled Whether element is enabled.
76 * @type {HTMLElement}
77 * @private
78 */
79 createDiv_: function(className, image, innerHtml, iid, enabled) {
80 var el = document.createElement(
81 className == 'dropdown-title' ? 'button' : 'div');
82 el.classList.add(className);
83 el.innerHTML = innerHtml;
xiyuan 2011/07/29 21:39:33 we probably should try to get rid of this use.
Nikita (slow) 2011/08/05 23:40:26 Done.
84 el.iid = iid;
85 el.link = this;
xiyuan 2011/07/29 21:39:33 nit: why DropDown is called "link"? Why not use pa
Nikita (slow) 2011/08/05 23:40:26 Done.
86 el.addEventListener('click', function f(e) {
87 if (this.iid < -1 || this.classList.contains('disabled-item'))
88 return;
89 this.link.isShown = !this.link.isShown;
xiyuan 2011/07/29 21:39:33 Do we really toggle isShown here?
Nikita (slow) 2011/08/05 23:40:26 Yes, menu is hidden on a click.
90 this.link.root_.childNodes[1].style.display =
xiyuan 2011/07/29 21:39:33 use hidden attribute.
Nikita (slow) 2011/08/05 23:40:26 Done.
91 this.link.isShown ? 'block' : 'none';
92 if (this.iid >= 0) {
93 chrome.send('networkItemChosen', [this.iid]);
94 }
95 });
96
97 if (!enabled)
98 el.classList.add('disabled-item');
99
100 // TODO(nkostylev): Icon support for title.
101 if (className != 'dropdown-title' && iid > 0) {
102 var wrapperDiv = document.createElement('div');
103 wrapperDiv.classList.add('dropdown-item-container');
104 var imageDiv = document.createElement('div');
105 imageDiv.classList.add('dropdown-image');
106 imageDiv.appendChild(image);
107 wrapperDiv.appendChild(imageDiv);
108 wrapperDiv.appendChild(el);
109 el = wrapperDiv;
110 }
111 return el;
112 },
113
114 /**
115 * Creates dropdown item element and adds into container.
116 * @param {HTMLElement} container Container where item is added.
117 * @param {!Object} item Item to be added.
118 * @private
119 */
120 createItem_ : function(container, item) {
121 var text = item.label;
122 if ('bold' in item && item.bold) {
123 text = '<b>' + text + "</b>";
124 }
125 var itemHtml = '<span>' + text + '</span>';
126
127 var className = 'dropdown-item';
128 // Separator.
129 if (item.id == -2) {
130 className = 'dropdown-divider';
131 itemHtml = "<hr>";
132 }
133
134 var image = document.createElement('img');
135 if (item.icon)
136 image.src = item.icon;
137 var enabled = 'enabled' in item && item.enabled;
138 container.appendChild(
139 this.createDiv_(className, image, itemHtml, item.id, enabled));
140 },
141 };
142
143 var dropdown = undefined;
xiyuan 2011/07/29 21:39:33 we should avoid using global vars. Let's put this
Nikita (slow) 2011/08/05 23:40:26 Done.
144
145 /**
6 * @fileoverview Oobe network screen implementation. 146 * @fileoverview Oobe network screen implementation.
7 */ 147 */
8 148
9 cr.define('oobe', function() { 149 cr.define('oobe', function() {
10 /** 150 /**
11 * Creates a new oobe screen div. 151 * Creates a new oobe screen div.
12 * @constructor 152 * @constructor
13 * @extends {HTMLDivElement} 153 * @extends {HTMLDivElement}
14 */ 154 */
15 var NetworkScreen = cr.ui.define('div'); 155 var NetworkScreen = cr.ui.define('div');
16 156
17 /** 157 /**
18 * Registers with Oobe. 158 * Registers with Oobe.
19 */ 159 */
20 NetworkScreen.register = function() { 160 NetworkScreen.register = function() {
21 var screen = $('connect'); 161 var screen = $('connect');
22 NetworkScreen.decorate(screen); 162 NetworkScreen.decorate(screen);
23 Oobe.getInstance().registerScreen(screen); 163 Oobe.getInstance().registerScreen(screen);
164
165 dropdown = new DropDown($('networks-list'), "empty", []);
24 }; 166 };
25 167
26 NetworkScreen.prototype = { 168 NetworkScreen.prototype = {
27 __proto__: HTMLDivElement.prototype, 169 __proto__: HTMLDivElement.prototype,
28 170
29 /** @inheritDoc */ 171 /** @inheritDoc */
30 decorate: function() { 172 decorate: function() {
31 Oobe.setupSelect($('language-select'), 173 Oobe.setupSelect($('language-select'),
32 templateData.languageList, 174 templateData.languageList,
33 'networkOnLanguageChanged'); 175 'networkOnLanguageChanged');
(...skipping 23 matching lines...) Expand all
57 continueButton.textContent = localStrings.getString('continueButton'); 199 continueButton.textContent = localStrings.getString('continueButton');
58 continueButton.addEventListener('click', function(e) { 200 continueButton.addEventListener('click', function(e) {
59 chrome.send('networkOnExit', []); 201 chrome.send('networkOnExit', []);
60 }); 202 });
61 buttons.push(continueButton); 203 buttons.push(continueButton);
62 204
63 return buttons; 205 return buttons;
64 } 206 }
65 }; 207 };
66 208
209 NetworkScreen.updateNetworks = function(data) {
210 dropdown.setItems(data[0].sub);
211 };
212
213 NetworkScreen.updateNetworkTitle = function(title, icon) {
214 dropdown.setTitle(title, icon);
215 };
216
67 return { 217 return {
68 NetworkScreen: NetworkScreen 218 NetworkScreen: NetworkScreen
69 }; 219 };
70 }); 220 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698