OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 cr.define('help', function() { | 5 cr.define('help', function() { |
| 6 var Page = cr.ui.pageManager.Page; |
| 7 var PageManager = cr.ui.pageManager.PageManager; |
| 8 |
6 /** | 9 /** |
7 * Encapsulated handling of the channel change overlay. | 10 * Encapsulated handling of the channel change overlay. |
8 */ | 11 */ |
9 function ChannelChangePage() {} | 12 function ChannelChangePage() { |
| 13 Page.call(this, 'channel-change-page', '', 'channel-change-page'); |
| 14 } |
10 | 15 |
11 cr.addSingletonGetter(ChannelChangePage); | 16 cr.addSingletonGetter(ChannelChangePage); |
12 | 17 |
13 ChannelChangePage.prototype = { | 18 ChannelChangePage.prototype = { |
14 __proto__: help.HelpBasePage.prototype, | 19 __proto__: Page.prototype, |
15 | 20 |
16 /** | 21 /** |
17 * Name of the channel the device is currently on. | 22 * Name of the channel the device is currently on. |
18 * @private | 23 * @private |
19 */ | 24 */ |
20 currentChannel_: null, | 25 currentChannel_: null, |
21 | 26 |
22 /** | 27 /** |
23 * Name of the channel the device is supposed to be on. | 28 * Name of the channel the device is supposed to be on. |
24 * @private | 29 * @private |
(...skipping 14 matching lines...) Expand all Loading... |
39 | 44 |
40 /** | 45 /** |
41 * List of the possible ui states. | 46 * List of the possible ui states. |
42 * @private | 47 * @private |
43 */ | 48 */ |
44 uiClassTable_: ['selected-channel-requires-powerwash', | 49 uiClassTable_: ['selected-channel-requires-powerwash', |
45 'selected-channel-requires-delayed-update', | 50 'selected-channel-requires-delayed-update', |
46 'selected-channel-good', | 51 'selected-channel-good', |
47 'selected-channel-unstable'], | 52 'selected-channel-unstable'], |
48 | 53 |
49 /** | 54 /** override */ |
50 * Perform initial setup. | 55 initializePage: function() { |
51 */ | 56 Page.prototype.initializePage.call(this); |
52 initialize: function() { | 57 |
53 help.HelpBasePage.prototype.initialize.call(this, 'channel-change-page'); | 58 $('channel-change-page-cancel-button').onclick = |
| 59 PageManager.closeOverlay.bind(PageManager); |
54 | 60 |
55 var self = this; | 61 var self = this; |
56 | |
57 $('channel-change-page-cancel-button').onclick = function() { | |
58 help.HelpPage.cancelOverlay(); | |
59 }; | |
60 | |
61 var options = this.getAllChannelOptions_(); | 62 var options = this.getAllChannelOptions_(); |
62 for (var i = 0; i < options.length; i++) { | 63 for (var i = 0; i < options.length; i++) { |
63 var option = options[i]; | 64 var option = options[i]; |
64 option.onclick = function() { | 65 option.onclick = function() { |
65 self.updateUI_(this.value); | 66 self.updateUI_(this.value); |
66 }; | 67 }; |
67 } | 68 } |
68 | 69 |
69 $('channel-change-page-powerwash-button').onclick = function() { | 70 $('channel-change-page-powerwash-button').onclick = function() { |
70 self.setChannel_(self.getSelectedOption_(), true); | 71 self.setChannel_(self.getSelectedOption_(), true); |
71 help.HelpPage.cancelOverlay(); | 72 PageManager.closeOverlay(); |
72 }; | 73 }; |
73 | 74 |
74 $('channel-change-page-change-button').onclick = function() { | 75 $('channel-change-page-change-button').onclick = function() { |
75 self.setChannel_(self.getSelectedOption_(), false); | 76 self.setChannel_(self.getSelectedOption_(), false); |
76 help.HelpPage.cancelOverlay(); | 77 PageManager.closeOverlay(); |
77 }; | 78 }; |
78 }, | 79 }, |
79 | 80 |
80 onBeforeShow: function() { | 81 /** @override */ |
81 help.HelpBasePage.prototype.onBeforeShow.call(this); | 82 didShowPage: function() { |
82 if (this.targetChannel_ != null) | 83 if (this.targetChannel_ != null) |
83 this.selectOption_(this.targetChannel_); | 84 this.selectOption_(this.targetChannel_); |
84 else if (this.currentChannel_ != null) | 85 else if (this.currentChannel_ != null) |
85 this.selectOption_(this.currentChannel_); | 86 this.selectOption_(this.currentChannel_); |
86 var options = this.getAllChannelOptions_(); | 87 var options = this.getAllChannelOptions_(); |
87 for (var i = 0; i < options.length; i++) { | 88 for (var i = 0; i < options.length; i++) { |
88 var option = options[i]; | 89 var option = options[i]; |
89 if (option.checked) | 90 if (option.checked) |
90 option.focus(); | 91 option.focus(); |
91 } | 92 } |
92 }, | 93 }, |
93 | 94 |
94 /** | 95 /** |
95 * Returns the list of all radio buttons responsible for channel selection. | 96 * Returns the list of all radio buttons responsible for channel selection. |
96 * @return {Array.<HTMLInputElement>} Array of radio buttons | 97 * @return {Array.<HTMLInputElement>} Array of radio buttons |
97 * @private | 98 * @private |
98 */ | 99 */ |
99 getAllChannelOptions_: function() { | 100 getAllChannelOptions_: function() { |
100 return $('channel-change-page').querySelectorAll('input[type="radio"]'); | 101 return this.pageDiv.querySelectorAll('input[type="radio"]'); |
101 }, | 102 }, |
102 | 103 |
103 /** | 104 /** |
104 * Returns value of the selected option. | 105 * Returns value of the selected option. |
105 * @return {string} Selected channel name or null, if neither | 106 * @return {string} Selected channel name or null, if neither |
106 * option is selected. | 107 * option is selected. |
107 * @private | 108 * @private |
108 */ | 109 */ |
109 getSelectedOption_: function() { | 110 getSelectedOption_: function() { |
110 var options = this.getAllChannelOptions_(); | 111 var options = this.getAllChannelOptions_(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 // Warn user about unstable channel. | 162 // Warn user about unstable channel. |
162 newOverlayClass = 'selected-channel-unstable'; | 163 newOverlayClass = 'selected-channel-unstable'; |
163 } else { | 164 } else { |
164 // Switching to the less stable channel. | 165 // Switching to the less stable channel. |
165 newOverlayClass = 'selected-channel-good'; | 166 newOverlayClass = 'selected-channel-good'; |
166 } | 167 } |
167 } | 168 } |
168 | 169 |
169 // Switch to the new UI state. | 170 // Switch to the new UI state. |
170 for (var i = 0; i < this.uiClassTable_.length; i++) | 171 for (var i = 0; i < this.uiClassTable_.length; i++) |
171 $('channel-change-page').classList.remove(this.uiClassTable_[i]); | 172 this.pageDiv.classList.remove(this.uiClassTable_[i]); |
172 | 173 |
173 if (newOverlayClass) | 174 if (newOverlayClass) |
174 $('channel-change-page').classList.add(newOverlayClass); | 175 this.pageDiv.classList.add(newOverlayClass); |
175 }, | 176 }, |
176 | 177 |
177 /** | 178 /** |
178 * Sets the device target channel. | 179 * Sets the device target channel. |
179 * @param {string} channel The name of the target channel | 180 * @param {string} channel The name of the target channel |
180 * @param {boolean} isPowerwashAllowed True iff powerwash is allowed | 181 * @param {boolean} isPowerwashAllowed True iff powerwash is allowed |
181 * @private | 182 * @private |
182 */ | 183 */ |
183 setChannel_: function(channel, isPowerwashAllowed) { | 184 setChannel_: function(channel, isPowerwashAllowed) { |
184 this.targetChannel_ = channel; | 185 this.targetChannel_ = channel; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 255 |
255 ChannelChangePage.isPageReady = function() { | 256 ChannelChangePage.isPageReady = function() { |
256 return ChannelChangePage.getInstance().isPageReady_(); | 257 return ChannelChangePage.getInstance().isPageReady_(); |
257 }; | 258 }; |
258 | 259 |
259 // Export | 260 // Export |
260 return { | 261 return { |
261 ChannelChangePage: ChannelChangePage | 262 ChannelChangePage: ChannelChangePage |
262 }; | 263 }; |
263 }); | 264 }); |
OLD | NEW |