Chromium Code Reviews| 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), |
|
Nikita (slow)
2013/06/03 15:55:43
nit: Please fix parameter alignment for all calls
Denis Kuznetsov (DE-MUC)
2013/06/03 16:33:04
Done.
| |
| 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) { | |
|
Nikita (slow)
2013/06/03 15:55:43
private, should end with _
Denis Kuznetsov (DE-MUC)
2013/06/03 16:33:04
Done.
| |
| 301 return (element.value.length > 0); | |
| 302 }, | |
| 303 | |
| 304 /** | |
| 305 * Configure text-input |element| | |
|
Nikita (slow)
2013/06/03 15:55:43
nit: dot is missing.
Denis Kuznetsov (DE-MUC)
2013/06/03 16:33:04
Done.
| |
| 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 | |
| 317 configureTextInput: function(element, | |
|
Nikita (slow)
2013/06/03 15:55:43
private, should end with _
Denis Kuznetsov (DE-MUC)
2013/06/03 16:33:04
At some point it will be moved to parent class.
| |
| 318 inputChangeListener, | |
|
Nikita (slow)
2013/06/03 15:55:43
nit: Please fix alignment.
Denis Kuznetsov (DE-MUC)
2013/06/03 16:33:04
Done.
| |
| 319 validator, | |
| 320 moveFocus, | |
| 321 errorHider) { | |
| 322 element.addEventListener('keydown', function(e) { | |
| 323 if (e.keyIdentifier == 'Enter') { | |
| 324 var dataValid = true; | |
| 325 if (validator) | |
| 326 dataValid = validator(element); | |
| 327 if (!dataValid) { | |
| 328 element.focus(); | |
| 329 } else { | |
| 330 if (moveFocus) | |
| 331 moveFocus(element); | |
| 332 } | |
| 333 e.stopPropagation(); | |
| 334 return; | |
| 335 } | |
| 336 if (errorHider) | |
| 337 errorHider(element); | |
| 338 if (inputChangeListener) | |
| 339 inputChangeListener(element); | |
| 340 }); | |
| 341 element.addEventListener('keyup', function(e) { | |
| 342 if (inputChangeListener) | |
| 343 inputChangeListener(element); | |
| 344 }); | |
| 345 }, | |
| 346 | |
| 347 /** | |
| 307 * Makes element from template. | 348 * Makes element from template. |
| 308 * @param {string} templateId -- template will be looked up within screen | 349 * @param {string} templateId -- template will be looked up within screen |
| 309 * by class with name "template-<templateId>". | 350 * by class with name "template-<templateId>". |
| 310 * @param {string} elementId -- id for result, uinque within screen. Actual | 351 * @param {string} elementId -- id for result, uinque within screen. Actual |
| 311 * id will be prefixed with screen name. Uer getScreenElement(id) to find | 352 * id will be prefixed with screen name. Uer getScreenElement(id) to find |
| 312 * it later. | 353 * it later. |
| 313 */ | 354 */ |
| 314 makeFromTemplate: function(templateId, elementId) { | 355 makeFromTemplate: function(templateId, elementId) { |
| 315 var templateClassName = 'template-' + templateId; | 356 var templateClassName = 'template-' + templateId; |
| 316 var templateNode = this.querySelector('.' + templateClassName); | 357 var templateNode = this.querySelector('.' + templateClassName); |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 574 * @private | 615 * @private |
| 575 */ | 616 */ |
| 576 setVisiblePage_: function(visiblePage) { | 617 setVisiblePage_: function(visiblePage) { |
| 577 this.disabled = false; | 618 this.disabled = false; |
| 578 this.updateText_(); | 619 this.updateText_(); |
| 579 var pageNames = ['intro', | 620 var pageNames = ['intro', |
| 580 'manager', | 621 'manager', |
| 581 'username', | 622 'username', |
| 582 'error', | 623 'error', |
| 583 'tutorial']; | 624 'tutorial']; |
| 625 var pageButtons = {'intro' : 'start', | |
| 626 'error' : 'handleError', | |
| 627 'tutorial' : 'finish'}; | |
| 584 this.hideStatus_(); | 628 this.hideStatus_(); |
| 585 for (i in pageNames) { | 629 for (i in pageNames) { |
| 586 var pageName = pageNames[i]; | 630 var pageName = pageNames[i]; |
| 587 var page = $('managed-user-creation-flow-' + pageName); | 631 var page = $('managed-user-creation-flow-' + pageName); |
| 588 page.hidden = (pageName != visiblePage); | 632 page.hidden = (pageName != visiblePage); |
| 589 if (pageName == visiblePage) | 633 if (pageName == visiblePage) |
| 590 $('step-logo').hidden = page.classList.contains('step-no-logo'); | 634 $('step-logo').hidden = page.classList.contains('step-no-logo'); |
| 591 } | 635 } |
| 592 | 636 |
| 593 for (i in this.buttonIds) { | 637 for (i in this.buttonIds) { |
| 594 var button = this.getScreenButton(this.buttonIds[i]); | 638 var button = this.getScreenButton(this.buttonIds[i]); |
| 595 button.hidden = button.pages.indexOf(visiblePage) < 0; | 639 button.hidden = button.pages.indexOf(visiblePage) < 0; |
| 596 button.disabled = false; | 640 button.disabled = false; |
| 597 } | 641 } |
| 598 | 642 |
| 599 var pagesWithCancel = ['intro', 'manager', 'username', 'error']; | 643 var pagesWithCancel = ['intro', 'manager', 'username', 'error']; |
| 600 var cancelButton = $('cancel-add-user-button'); | 644 var cancelButton = $('cancel-add-user-button'); |
| 601 cancelButton.hidden = pagesWithCancel.indexOf(visiblePage) < 0; | 645 cancelButton.hidden = pagesWithCancel.indexOf(visiblePage) < 0; |
| 602 cancelButton.disabled = false; | 646 cancelButton.disabled = false; |
| 603 | 647 |
| 648 if (pageButtons[visiblePage]) | |
| 649 this.getScreenButton(pageButtons[visiblePage]).focus(); | |
| 650 | |
| 604 this.currentPage_ = visiblePage; | 651 this.currentPage_ = visiblePage; |
| 605 }, | 652 }, |
| 606 | 653 |
| 607 setButtonDisabledStatus: function(buttonName, status) { | 654 setButtonDisabledStatus: function(buttonName, status) { |
| 608 var button = $('managed-user-creation-flow-' + buttonName + '-button'); | 655 var button = $('managed-user-creation-flow-' + buttonName + '-button'); |
| 609 button.disabled = status; | 656 button.disabled = status; |
| 610 }, | 657 }, |
| 611 | 658 |
| 612 finishButtonPressed_: function() { | 659 finishButtonPressed_: function() { |
| 613 chrome.send('finishLocalManagedUserCreation'); | 660 chrome.send('finishLocalManagedUserCreation'); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 780 this.setVisiblePage_('error'); | 827 this.setVisiblePage_('error'); |
| 781 }, | 828 }, |
| 782 | 829 |
| 783 showManagerPasswordError: function() { | 830 showManagerPasswordError: function() { |
| 784 this.disabled = false; | 831 this.disabled = false; |
| 785 this.showSelectedManagerPasswordError_(); | 832 this.showSelectedManagerPasswordError_(); |
| 786 } | 833 } |
| 787 }; | 834 }; |
| 788 }); | 835 }); |
| 789 | 836 |
| OLD | NEW |