OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 login.createScreen('OAuthEnrollmentScreen', 'oauth-enrollment', function() { | 5 login.createScreen('OAuthEnrollmentScreen', 'oauth-enrollment', function() { |
6 /** @const */ var STEP_SIGNIN = 'signin'; | 6 /** @const */ var STEP_SIGNIN = 'signin'; |
7 /** @const */ var STEP_WORKING = 'working'; | 7 /** @const */ var STEP_WORKING = 'working'; |
| 8 /** @const */ var STEP_ATTRIBUTE_PROMPT = 'attribute-prompt'; |
8 /** @const */ var STEP_ERROR = 'error'; | 9 /** @const */ var STEP_ERROR = 'error'; |
9 /** @const */ var STEP_SUCCESS = 'success'; | 10 /** @const */ var STEP_SUCCESS = 'success'; |
10 | 11 |
11 /** @const */ var HELP_TOPIC_ENROLLMENT = 4631259; | 12 /** @const */ var HELP_TOPIC_ENROLLMENT = 4631259; |
12 | 13 |
13 return { | 14 return { |
14 EXTERNAL_API: [ | 15 EXTERNAL_API: [ |
15 'showStep', | 16 'showStep', |
16 'showError', | 17 'showError', |
17 'doReload', | 18 'doReload', |
| 19 'showAttributePromptStep', |
18 ], | 20 ], |
19 | 21 |
20 /** | 22 /** |
21 * URL to load in the sign in frame. | 23 * URL to load in the sign in frame. |
22 */ | 24 */ |
23 signInUrl_: null, | 25 signInUrl_: null, |
24 | 26 |
25 /** | 27 /** |
26 * Gaia auth params for sign in frame. | 28 * Gaia auth params for sign in frame. |
27 */ | 29 */ |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 }.bind(this)); | 128 }.bind(this)); |
127 | 129 |
128 makeButton( | 130 makeButton( |
129 'oauth-enroll-done-button', | 131 'oauth-enroll-done-button', |
130 ['oauth-enroll-focus-on-success'], | 132 ['oauth-enroll-focus-on-success'], |
131 loadTimeData.getString('oauthEnrollDone'), | 133 loadTimeData.getString('oauthEnrollDone'), |
132 function() { | 134 function() { |
133 chrome.send('oauthEnrollClose', ['done']); | 135 chrome.send('oauthEnrollClose', ['done']); |
134 }); | 136 }); |
135 | 137 |
| 138 makeButton( |
| 139 'oauth-enroll-continue-button', |
| 140 ['oauth-enroll-focus-on-attribute-prompt'], |
| 141 loadTimeData.getString('oauthEnrollContinue'), |
| 142 function() { |
| 143 chrome.send('oauthEnrollAttributes', |
| 144 [$('oauth-enroll-asset-id').value, |
| 145 $('oauth-enroll-location').value]); |
| 146 }); |
| 147 |
136 return buttons; | 148 return buttons; |
137 }, | 149 }, |
138 | 150 |
139 /** | 151 /** |
140 * Event handler that is invoked just before the frame is shown. | 152 * Event handler that is invoked just before the frame is shown. |
141 * @param {Object} data Screen init payload, contains the signin frame | 153 * @param {Object} data Screen init payload, contains the signin frame |
142 * URL. | 154 * URL. |
143 */ | 155 */ |
144 onBeforeShow: function(data) { | 156 onBeforeShow: function(data) { |
145 this.signInParams_ = {}; | 157 this.signInParams_ = {}; |
146 this.signInParams_['gaiaUrl'] = data.gaiaUrl; | 158 this.signInParams_['gaiaUrl'] = data.gaiaUrl; |
147 this.signInParams_['needPassword'] = false; | 159 this.signInParams_['needPassword'] = false; |
148 this.signInUrl_ = data.signin_url; | 160 this.signInUrl_ = data.signin_url; |
149 var modes = ['manual', 'forced', 'recovery']; | 161 var modes = ['manual', 'forced', 'recovery']; |
150 for (var i = 0; i < modes.length; ++i) { | 162 for (var i = 0; i < modes.length; ++i) { |
151 this.classList.toggle('mode-' + modes[i], | 163 this.classList.toggle('mode-' + modes[i], |
152 data.enrollment_mode == modes[i]); | 164 data.enrollment_mode == modes[i]); |
153 } | 165 } |
154 this.managementDomain_ = data.management_domain; | 166 this.managementDomain_ = data.management_domain; |
155 this.isCancelDisabled = true; | 167 this.isCancelDisabled = true; |
156 this.doReload(); | 168 this.doReload(); |
157 this.learnMoreHelpTopicID_ = data.learn_more_help_topic_id; | 169 this.learnMoreHelpTopicID_ = data.learn_more_help_topic_id; |
158 this.updateLocalizedContent(); | 170 this.updateLocalizedContent(); |
159 this.showStep(STEP_SIGNIN); | 171 this.showStep(STEP_SIGNIN); |
160 }, | 172 }, |
161 | 173 |
162 /** | 174 /** |
| 175 * Shows attribute-prompt step with pre-filled asset ID and location. |
| 176 */ |
| 177 showAttributePromptStep: function(annotated_asset_id, annotated_location) { |
| 178 $('oauth-enroll-attribute-prompt-message').innerHTML = |
| 179 loadTimeData.getString('oauthEnrollAttributes'); |
| 180 |
| 181 $('oauth-enroll-asset-id').value = annotated_asset_id; |
| 182 $('oauth-enroll-location').value = annotated_location; |
| 183 |
| 184 this.showStep(STEP_ATTRIBUTE_PROMPT); |
| 185 }, |
| 186 |
| 187 /** |
163 * Cancels enrollment and drops the user back to the login screen. | 188 * Cancels enrollment and drops the user back to the login screen. |
164 */ | 189 */ |
165 cancel: function() { | 190 cancel: function() { |
166 if (this.isCancelDisabled) | 191 if (this.isCancelDisabled) |
167 return; | 192 return; |
168 this.isCancelDisabled = true; | 193 this.isCancelDisabled = true; |
169 chrome.send('oauthEnrollClose', ['cancel']); | 194 chrome.send('oauthEnrollClose', ['cancel']); |
170 }, | 195 }, |
171 | 196 |
172 /** | 197 /** |
| 198 * Returns whether |step| is the device attribute update error or not. |
| 199 */ |
| 200 isAttributeUpdateError: function(step) { |
| 201 return this.currentStep_ == STEP_ATTRIBUTE_PROMPT && step == STEP_ERROR; |
| 202 }, |
| 203 |
| 204 /** |
| 205 * Shows cancel or done button. |
| 206 */ |
| 207 hideCancelShowDone: function(hide) { |
| 208 $('oauth-enroll-cancel-button').hidden = hide; |
| 209 $('oauth-enroll-cancel-button').disabled = hide; |
| 210 |
| 211 $('oauth-enroll-done-button').hidden = !hide; |
| 212 $('oauth-enroll-done-button').disabled = !hide; |
| 213 }, |
| 214 |
| 215 /** |
173 * Switches between the different steps in the enrollment flow. | 216 * Switches between the different steps in the enrollment flow. |
174 * @param {string} step the steps to show, one of "signin", "working", | 217 * @param {string} step the steps to show, one of "signin", "working", |
175 * "error", "success". | 218 * "attribute-prompt", "error", "success". |
176 */ | 219 */ |
177 showStep: function(step) { | 220 showStep: function(step) { |
| 221 var focusStep = step; |
| 222 |
178 this.classList.toggle('oauth-enroll-state-' + this.currentStep_, false); | 223 this.classList.toggle('oauth-enroll-state-' + this.currentStep_, false); |
179 this.classList.toggle('oauth-enroll-state-' + step, true); | 224 this.classList.toggle('oauth-enroll-state-' + step, true); |
| 225 |
| 226 /** |
| 227 * In case of device attribute update error done button should be shown |
| 228 * instead of cancel button and focus on success, |
| 229 * because enrollment has completed |
| 230 */ |
| 231 if (this.isAttributeUpdateError(step)) { |
| 232 focusStep = STEP_SUCCESS; |
| 233 this.hideCancelShowDone(true); |
| 234 } else { |
| 235 if (step == STEP_ERROR) |
| 236 this.hideCancelShowDone(false); |
| 237 } |
| 238 |
180 var focusElements = | 239 var focusElements = |
181 this.querySelectorAll('.oauth-enroll-focus-on-' + step); | 240 this.querySelectorAll('.oauth-enroll-focus-on-' + focusStep); |
182 for (var i = 0; i < focusElements.length; ++i) { | 241 for (var i = 0; i < focusElements.length; ++i) { |
183 if (getComputedStyle(focusElements[i])['display'] != 'none') { | 242 if (getComputedStyle(focusElements[i])['display'] != 'none') { |
184 focusElements[i].focus(); | 243 focusElements[i].focus(); |
185 break; | 244 break; |
186 } | 245 } |
187 } | 246 } |
188 this.currentStep_ = step; | 247 this.currentStep_ = step; |
189 }, | 248 }, |
190 | 249 |
191 /** | 250 /** |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 * Opens the learn more help topic. | 343 * Opens the learn more help topic. |
285 */ | 344 */ |
286 launchLearnMoreHelp_: function() { | 345 launchLearnMoreHelp_: function() { |
287 if (this.learnMoreHelpTopicID_) { | 346 if (this.learnMoreHelpTopicID_) { |
288 chrome.send('launchHelpApp', [this.learnMoreHelpTopicID_]); | 347 chrome.send('launchHelpApp', [this.learnMoreHelpTopicID_]); |
289 } | 348 } |
290 } | 349 } |
291 }; | 350 }; |
292 }); | 351 }); |
293 | 352 |
OLD | NEW |