| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 * Authenticator object that wraps GAIA webview. | 23 * Authenticator object that wraps GAIA webview. |
| 22 */ | 24 */ |
| 23 authenticator_: null, | 25 authenticator_: null, |
| 24 | 26 |
| 25 /** | 27 /** |
| 26 * The current step. This is the last value passed to showStep(). | 28 * The current step. This is the last value passed to showStep(). |
| 27 */ | 29 */ |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 } | 142 } |
| 141 | 143 |
| 142 makeButton( | 144 makeButton( |
| 143 'oauth-enroll-done-button', | 145 'oauth-enroll-done-button', |
| 144 ['oauth-enroll-focus-on-success'], | 146 ['oauth-enroll-focus-on-success'], |
| 145 loadTimeData.getString('oauthEnrollDone'), | 147 loadTimeData.getString('oauthEnrollDone'), |
| 146 function() { | 148 function() { |
| 147 chrome.send('oauthEnrollClose', ['done']); | 149 chrome.send('oauthEnrollClose', ['done']); |
| 148 }); | 150 }); |
| 149 | 151 |
| 152 makeButton( |
| 153 'oauth-enroll-continue-button', |
| 154 ['oauth-enroll-focus-on-attribute-prompt'], |
| 155 loadTimeData.getString('oauthEnrollContinue'), |
| 156 function() { |
| 157 chrome.send('oauthEnrollAttributes', |
| 158 [$('oauth-enroll-asset-id').value, |
| 159 $('oauth-enroll-location').value]); |
| 160 }); |
| 161 |
| 150 return buttons; | 162 return buttons; |
| 151 }, | 163 }, |
| 152 | 164 |
| 153 /** | 165 /** |
| 154 * Event handler that is invoked just before the frame is shown. | 166 * Event handler that is invoked just before the frame is shown. |
| 155 * @param {Object} data Screen init payload, contains the signin frame | 167 * @param {Object} data Screen init payload, contains the signin frame |
| 156 * URL. | 168 * URL. |
| 157 */ | 169 */ |
| 158 onBeforeShow: function(data) { | 170 onBeforeShow: function(data) { |
| 159 var gaiaParams = {}; | 171 var gaiaParams = {}; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 172 var modes = ['manual', 'forced', 'recovery']; | 184 var modes = ['manual', 'forced', 'recovery']; |
| 173 for (var i = 0; i < modes.length; ++i) { | 185 for (var i = 0; i < modes.length; ++i) { |
| 174 this.classList.toggle('mode-' + modes[i], | 186 this.classList.toggle('mode-' + modes[i], |
| 175 data.enrollment_mode == modes[i]); | 187 data.enrollment_mode == modes[i]); |
| 176 } | 188 } |
| 177 this.isCancelDisabled = true; | 189 this.isCancelDisabled = true; |
| 178 this.showStep(STEP_SIGNIN); | 190 this.showStep(STEP_SIGNIN); |
| 179 }, | 191 }, |
| 180 | 192 |
| 181 /** | 193 /** |
| 194 * Shows attribute-prompt step with pre-filled asset ID and |
| 195 * location. |
| 196 */ |
| 197 showAttributePromptStep: function(annotated_asset_id, annotated_location) { |
| 198 /** |
| 199 * innerHTML is used instead of textContent, |
| 200 * because oauthEnrollAttributes contains text formatting (bold, italic). |
| 201 */ |
| 202 $('oauth-enroll-attribute-prompt-message').innerHTML = |
| 203 loadTimeData.getString('oauthEnrollAttributes'); |
| 204 |
| 205 $('oauth-enroll-asset-id').value = annotated_asset_id; |
| 206 $('oauth-enroll-location').value = annotated_location; |
| 207 |
| 208 this.showStep(STEP_ATTRIBUTE_PROMPT); |
| 209 }, |
| 210 |
| 211 /** |
| 182 * Cancels enrollment and drops the user back to the login screen. | 212 * Cancels enrollment and drops the user back to the login screen. |
| 183 */ | 213 */ |
| 184 cancel: function() { | 214 cancel: function() { |
| 185 if (this.isCancelDisabled) | 215 if (this.isCancelDisabled) |
| 186 return; | 216 return; |
| 187 this.isCancelDisabled = true; | 217 this.isCancelDisabled = true; |
| 188 chrome.send('oauthEnrollClose', ['cancel']); | 218 chrome.send('oauthEnrollClose', ['cancel']); |
| 189 }, | 219 }, |
| 190 | 220 |
| 191 /** | 221 /** |
| 222 * Returns whether |step| is the device attribute update error or |
| 223 * not. |
| 224 */ |
| 225 isAttributeUpdateError: function(step) { |
| 226 return this.currentStep_ == STEP_ATTRIBUTE_PROMPT && step == STEP_ERROR; |
| 227 }, |
| 228 |
| 229 /** |
| 230 * Shows cancel or done button. |
| 231 */ |
| 232 hideCancelShowDone: function(hide) { |
| 233 $('oauth-enroll-cancel-button').hidden = hide; |
| 234 $('oauth-enroll-cancel-button').disabled = hide; |
| 235 |
| 236 $('oauth-enroll-done-button').hidden = !hide; |
| 237 $('oauth-enroll-done-button').disabled = !hide; |
| 238 }, |
| 239 |
| 240 /** |
| 192 * Switches between the different steps in the enrollment flow. | 241 * Switches between the different steps in the enrollment flow. |
| 193 * @param {string} step the steps to show, one of "signin", "working", | 242 * @param {string} step the steps to show, one of "signin", "working", |
| 194 * "error", "success". | 243 * "attribute-prompt", "error", "success". |
| 195 */ | 244 */ |
| 196 showStep: function(step) { | 245 showStep: function(step) { |
| 246 var focusStep = step; |
| 247 |
| 197 this.classList.toggle('oauth-enroll-state-' + this.currentStep_, false); | 248 this.classList.toggle('oauth-enroll-state-' + this.currentStep_, false); |
| 198 this.classList.toggle('oauth-enroll-state-' + step, true); | 249 this.classList.toggle('oauth-enroll-state-' + step, true); |
| 250 |
| 251 /** |
| 252 * In case of device attribute update error done button should be shown |
| 253 * instead of cancel button and focus on success, |
| 254 * because enrollment has completed |
| 255 */ |
| 256 if (this.isAttributeUpdateError(step)) { |
| 257 focusStep = STEP_SUCCESS; |
| 258 this.hideCancelShowDone(true); |
| 259 } else { |
| 260 if (step == STEP_ERROR) |
| 261 this.hideCancelShowDone(false); |
| 262 } |
| 263 |
| 199 var focusElements = | 264 var focusElements = |
| 200 this.querySelectorAll('.oauth-enroll-focus-on-' + step); | 265 this.querySelectorAll('.oauth-enroll-focus-on-' + focusStep); |
| 201 for (var i = 0; i < focusElements.length; ++i) { | 266 for (var i = 0; i < focusElements.length; ++i) { |
| 202 if (getComputedStyle(focusElements[i])['display'] != 'none') { | 267 if (getComputedStyle(focusElements[i])['display'] != 'none') { |
| 203 focusElements[i].focus(); | 268 focusElements[i].focus(); |
| 204 break; | 269 break; |
| 205 } | 270 } |
| 206 } | 271 } |
| 207 this.currentStep_ = step; | 272 this.currentStep_ = step; |
| 208 }, | 273 }, |
| 209 | 274 |
| 210 /** | 275 /** |
| (...skipping 15 matching lines...) Expand all Loading... |
| 226 * Retries the enrollment process after an error occurred in a previous | 291 * Retries the enrollment process after an error occurred in a previous |
| 227 * attempt. This goes to the C++ side through |chrome| first to clean up the | 292 * attempt. This goes to the C++ side through |chrome| first to clean up the |
| 228 * profile, so that the next attempt is performed with a clean state. | 293 * profile, so that the next attempt is performed with a clean state. |
| 229 */ | 294 */ |
| 230 doRetry_: function() { | 295 doRetry_: function() { |
| 231 chrome.send('oauthEnrollRetry'); | 296 chrome.send('oauthEnrollRetry'); |
| 232 } | 297 } |
| 233 }; | 298 }; |
| 234 }); | 299 }); |
| 235 | 300 |
| OLD | NEW |