| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 /** | 5 /** |
| 6 * @fileoverview Locally managed user creation flow screen. | 6 * @fileoverview Locally managed user creation flow screen. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 login.createScreen('LocallyManagedUserCreationScreen', | 9 login.createScreen('LocallyManagedUserCreationScreen', |
| 10 'managed-user-creation-flow', function() { | 10 'managed-user-creation-flow', function() { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 __proto__: HTMLDivElement.prototype, | 26 __proto__: HTMLDivElement.prototype, |
| 27 | 27 |
| 28 /** @override */ | 28 /** @override */ |
| 29 decorate: function() { | 29 decorate: function() { |
| 30 // Mousedown has to be used instead of click to be able to prevent 'focus' | 30 // Mousedown has to be used instead of click to be able to prevent 'focus' |
| 31 // event later. | 31 // event later. |
| 32 this.addEventListener('mousedown', | 32 this.addEventListener('mousedown', |
| 33 this.handleMouseDown_.bind(this)); | 33 this.handleMouseDown_.bind(this)); |
| 34 var screen = $('managed-user-creation-flow'); | 34 var screen = $('managed-user-creation-flow'); |
| 35 var managerPod = this; | 35 var managerPod = this; |
| 36 this.passwordElement.addEventListener('keydown', function(e) { | 36 var hideManagerPasswordError = function(element) { |
| 37 managerPod.passwordErrorElement.hidden = true; | 37 managerPod.passwordErrorElement.hidden = true; |
| 38 }); | 38 }; |
| 39 this.passwordElement.addEventListener('keyup', function(e) { | 39 |
| 40 screen.updateNextButtonForManager_(); | 40 screen.configureTextInput( |
| 41 }); | 41 this.passwordElement, |
| 42 screen.updateNextButtonForManager_.bind(screen), |
| 43 screen.validIfNotEmpty_.bind(screen), |
| 44 function(element) { |
| 45 screen.getScreenButton('next').focus(); |
| 46 }, |
| 47 hideManagerPasswordError); |
| 42 }, | 48 }, |
| 43 | 49 |
| 44 /** | 50 /** |
| 45 * Updates UI elements from user data. | 51 * Updates UI elements from user data. |
| 46 */ | 52 */ |
| 47 update: function() { | 53 update: function() { |
| 48 this.imageElement.src = 'chrome://userimage/' + this.user.username + | 54 this.imageElement.src = 'chrome://userimage/' + this.user.username + |
| 49 '?id=' + ManagerPod.userImageSalt_[this.user.username]; | 55 '?id=' + ManagerPod.userImageSalt_[this.user.username]; |
| 50 | 56 |
| 51 this.nameElement.textContent = this.user.displayName; | 57 this.nameElement.textContent = this.user.displayName; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 this.managerList_ = new ManagerPodList(); | 227 this.managerList_ = new ManagerPodList(); |
| 222 $('managed-user-creation-flow-managers-pane'). | 228 $('managed-user-creation-flow-managers-pane'). |
| 223 appendChild(this.managerList_); | 229 appendChild(this.managerList_); |
| 224 | 230 |
| 225 var userNameField = $('managed-user-creation-flow-name'); | 231 var userNameField = $('managed-user-creation-flow-name'); |
| 226 var passwordField = $('managed-user-creation-flow-password'); | 232 var passwordField = $('managed-user-creation-flow-password'); |
| 227 var password2Field = $('managed-user-creation-flow-password-confirm'); | 233 var password2Field = $('managed-user-creation-flow-password-confirm'); |
| 228 | 234 |
| 229 var creationScreen = this; | 235 var creationScreen = this; |
| 230 | 236 |
| 231 userNameField.addEventListener('keydown', function(e) { | 237 var hideUserPasswordError = function(element) { |
| 232 if (e.keyIdentifier == 'Enter') { | 238 creationScreen.passwordErrorVisible = false; |
| 233 if (userNameField.value.length > 0) | 239 }; |
| 234 passwordField.focus(); | |
| 235 e.stopPropagation(); | |
| 236 return; | |
| 237 } | |
| 238 creationScreen.clearUserNameError_(); | |
| 239 }); | |
| 240 | 240 |
| 241 userNameField.addEventListener('keyup', function(e) { | 241 this.configureTextInput(userNameField, |
| 242 creationScreen.checkUserName_(); | 242 this.checkUserName_.bind(this), |
| 243 }); | 243 this.validIfNotEmpty_.bind(this), |
| 244 function(element) { |
| 245 passwordField.focus(); |
| 246 }, |
| 247 this.clearUserNameError_.bind(this)); |
| 244 | 248 |
| 245 passwordField.addEventListener('keydown', function(e) { | 249 this.configureTextInput(passwordField, |
| 246 creationScreen.passwordErrorVisible = false; | 250 this.updateNextButtonForUser_.bind(this), |
| 247 if (e.keyIdentifier == 'Enter') { | 251 this.validIfNotEmpty_.bind(this), |
| 248 if (passwordField.value.length > 0) { | 252 function(element) { |
| 249 password2Field.focus(); | 253 password2Field.focus(); |
| 250 creationScreen.updateNextButtonForUser_(); | 254 }, |
| 251 } | 255 hideUserPasswordError); |
| 252 e.stopPropagation(); | 256 this.configureTextInput(password2Field, |
| 253 } | 257 this.updateNextButtonForUser_.bind(this), |
| 254 }); | 258 this.validIfNotEmpty_.bind(this), |
| 255 | 259 function(element) { |
| 256 password2Field.addEventListener('keydown', function(e) { | 260 creationScreen.getScreenButton('next').focus(); |
| 257 creationScreen.passwordErrorVisible = false; | 261 }, |
| 258 if (e.keyIdentifier == 'Enter') { | 262 hideUserPasswordError); |
| 259 if (passwordField.value.length > 0) { | |
| 260 if (creationScreen.managerList_.selectedPod_) | |
| 261 creationScreen.managerList_.selectedPod_.focusInput(); | |
| 262 creationScreen.updateNextButtonForUser_(); | |
| 263 } | |
| 264 e.stopPropagation(); | |
| 265 } | |
| 266 }); | |
| 267 | |
| 268 password2Field.addEventListener('keyup', function(e) { | |
| 269 creationScreen.updateNextButtonForUser_(); | |
| 270 }); | |
| 271 | |
| 272 passwordField.addEventListener('keyup', function(e) { | |
| 273 creationScreen.updateNextButtonForUser_(); | |
| 274 }); | |
| 275 }, | 263 }, |
| 276 | 264 |
| 277 buttonIds: [], | 265 buttonIds: [], |
| 278 | 266 |
| 279 /** | 267 /** |
| 280 * Creates button for adding to controls. | 268 * Creates button for adding to controls. |
| 281 * @param {string} buttonId -- id for button, have to be unique within | 269 * @param {string} buttonId -- id for button, have to be unique within |
| 282 * screen. Actual id will be prefixed with screen name and appended with | 270 * screen. Actual id will be prefixed with screen name and appended with |
| 283 * '-button'. Use getScreenButton(buttonId) to find it later. | 271 * '-button'. Use getScreenButton(buttonId) to find it later. |
| 284 * @param {string} i18nPrefix -- screen prefix for i18n values. | 272 * @param {string} i18nPrefix -- screen prefix for i18n values. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 297 getString(i18nPrefix + capitalizedId + 'ButtonTitle'); | 285 getString(i18nPrefix + capitalizedId + 'ButtonTitle'); |
| 298 result.addEventListener('click', function(e) { | 286 result.addEventListener('click', function(e) { |
| 299 callback(buttonId); | 287 callback(buttonId); |
| 300 e.stopPropagation(); | 288 e.stopPropagation(); |
| 301 }); | 289 }); |
| 302 result.pages = pages; | 290 result.pages = pages; |
| 303 return result; | 291 return result; |
| 304 }, | 292 }, |
| 305 | 293 |
| 306 /** | 294 /** |
| 295 * Simple validator for |configureTextInput|. |
| 296 * Element is considered valid if it has any text. |
| 297 * @param {Element} element - element to be validated. |
| 298 * @return {boolean} - true, if element has any text. |
| 299 */ |
| 300 validIfNotEmpty_: function(element) { |
| 301 return (element.value.length > 0); |
| 302 }, |
| 303 |
| 304 /** |
| 305 * Configure text-input |element|. |
| 306 * @param {Element} element - element to be configured. |
| 307 * @param {function(element)} inputChangeListener - function that will be |
| 308 * called upon any button press/release. |
| 309 * @param {function(element)} validator - function that will be called when |
| 310 * Enter is pressed. If it returns |true| then advance to next element. |
| 311 * @param {function(element)} moveFocus - function that will determine next |
| 312 * element and move focus to it. |
| 313 * @param {function(element)} errorHider - function that is called upon |
| 314 * every button press, so that any associated error can be hidden. |
| 315 */ |
| 316 configureTextInput: function(element, |
| 317 inputChangeListener, |
| 318 validator, |
| 319 moveFocus, |
| 320 errorHider) { |
| 321 element.addEventListener('keydown', function(e) { |
| 322 if (e.keyIdentifier == 'Enter') { |
| 323 var dataValid = true; |
| 324 if (validator) |
| 325 dataValid = validator(element); |
| 326 if (!dataValid) { |
| 327 element.focus(); |
| 328 } else { |
| 329 if (moveFocus) |
| 330 moveFocus(element); |
| 331 } |
| 332 e.stopPropagation(); |
| 333 return; |
| 334 } |
| 335 if (errorHider) |
| 336 errorHider(element); |
| 337 if (inputChangeListener) |
| 338 inputChangeListener(element); |
| 339 }); |
| 340 element.addEventListener('keyup', function(e) { |
| 341 if (inputChangeListener) |
| 342 inputChangeListener(element); |
| 343 }); |
| 344 }, |
| 345 |
| 346 /** |
| 307 * Makes element from template. | 347 * Makes element from template. |
| 308 * @param {string} templateId -- template will be looked up within screen | 348 * @param {string} templateId -- template will be looked up within screen |
| 309 * by class with name "template-<templateId>". | 349 * by class with name "template-<templateId>". |
| 310 * @param {string} elementId -- id for result, uinque within screen. Actual | 350 * @param {string} elementId -- id for result, uinque within screen. Actual |
| 311 * id will be prefixed with screen name. Uer getScreenElement(id) to find | 351 * id will be prefixed with screen name. Uer getScreenElement(id) to find |
| 312 * it later. | 352 * it later. |
| 313 */ | 353 */ |
| 314 makeFromTemplate: function(templateId, elementId) { | 354 makeFromTemplate: function(templateId, elementId) { |
| 315 var templateClassName = 'template-' + templateId; | 355 var templateClassName = 'template-' + templateId; |
| 316 var templateNode = this.querySelector('.' + templateClassName); | 356 var templateNode = this.querySelector('.' + templateClassName); |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 * @private | 614 * @private |
| 575 */ | 615 */ |
| 576 setVisiblePage_: function(visiblePage) { | 616 setVisiblePage_: function(visiblePage) { |
| 577 this.disabled = false; | 617 this.disabled = false; |
| 578 this.updateText_(); | 618 this.updateText_(); |
| 579 var pageNames = ['intro', | 619 var pageNames = ['intro', |
| 580 'manager', | 620 'manager', |
| 581 'username', | 621 'username', |
| 582 'error', | 622 'error', |
| 583 'tutorial']; | 623 'tutorial']; |
| 624 var pageButtons = {'intro' : 'start', |
| 625 'error' : 'handleError', |
| 626 'tutorial' : 'finish'}; |
| 584 this.hideStatus_(); | 627 this.hideStatus_(); |
| 585 for (i in pageNames) { | 628 for (i in pageNames) { |
| 586 var pageName = pageNames[i]; | 629 var pageName = pageNames[i]; |
| 587 var page = $('managed-user-creation-flow-' + pageName); | 630 var page = $('managed-user-creation-flow-' + pageName); |
| 588 page.hidden = (pageName != visiblePage); | 631 page.hidden = (pageName != visiblePage); |
| 589 if (pageName == visiblePage) | 632 if (pageName == visiblePage) |
| 590 $('step-logo').hidden = page.classList.contains('step-no-logo'); | 633 $('step-logo').hidden = page.classList.contains('step-no-logo'); |
| 591 } | 634 } |
| 592 | 635 |
| 593 for (i in this.buttonIds) { | 636 for (i in this.buttonIds) { |
| 594 var button = this.getScreenButton(this.buttonIds[i]); | 637 var button = this.getScreenButton(this.buttonIds[i]); |
| 595 button.hidden = button.pages.indexOf(visiblePage) < 0; | 638 button.hidden = button.pages.indexOf(visiblePage) < 0; |
| 596 button.disabled = false; | 639 button.disabled = false; |
| 597 } | 640 } |
| 598 | 641 |
| 599 var pagesWithCancel = ['intro', 'manager', 'username', 'error']; | 642 var pagesWithCancel = ['intro', 'manager', 'username', 'error']; |
| 600 var cancelButton = $('cancel-add-user-button'); | 643 var cancelButton = $('cancel-add-user-button'); |
| 601 cancelButton.hidden = pagesWithCancel.indexOf(visiblePage) < 0; | 644 cancelButton.hidden = pagesWithCancel.indexOf(visiblePage) < 0; |
| 602 cancelButton.disabled = false; | 645 cancelButton.disabled = false; |
| 603 | 646 |
| 647 if (pageButtons[visiblePage]) |
| 648 this.getScreenButton(pageButtons[visiblePage]).focus(); |
| 649 |
| 604 this.currentPage_ = visiblePage; | 650 this.currentPage_ = visiblePage; |
| 605 }, | 651 }, |
| 606 | 652 |
| 607 setButtonDisabledStatus: function(buttonName, status) { | 653 setButtonDisabledStatus: function(buttonName, status) { |
| 608 var button = $('managed-user-creation-flow-' + buttonName + '-button'); | 654 var button = $('managed-user-creation-flow-' + buttonName + '-button'); |
| 609 button.disabled = status; | 655 button.disabled = status; |
| 610 }, | 656 }, |
| 611 | 657 |
| 612 finishButtonPressed_: function() { | 658 finishButtonPressed_: function() { |
| 613 chrome.send('finishLocalManagedUserCreation'); | 659 chrome.send('finishLocalManagedUserCreation'); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 this.setVisiblePage_('error'); | 826 this.setVisiblePage_('error'); |
| 781 }, | 827 }, |
| 782 | 828 |
| 783 showManagerPasswordError: function() { | 829 showManagerPasswordError: function() { |
| 784 this.disabled = false; | 830 this.disabled = false; |
| 785 this.showSelectedManagerPasswordError_(); | 831 this.showSelectedManagerPasswordError_(); |
| 786 } | 832 } |
| 787 }; | 833 }; |
| 788 }); | 834 }); |
| 789 | 835 |
| OLD | NEW |