OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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('options', function() { | 5 cr.define('options', function() { |
6 const OptionsPage = options.OptionsPage; | 6 const OptionsPage = options.OptionsPage; |
7 | 7 |
8 // Variable to track if a captcha challenge was issued. If this gets set to | 8 // Variable to track if a captcha challenge was issued. If this gets set to |
9 // true, it stays that way until we are told about successful login from | 9 // true, it stays that way until we are told about successful login from |
10 // the browser. This means subsequent errors (like invalid password) are | 10 // the browser. This means subsequent errors (like invalid password) are |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 } | 184 } |
185 } | 185 } |
186 } | 186 } |
187 | 187 |
188 return atLeastOneEnabled && !atLeastOneChecked; | 188 return atLeastOneEnabled && !atLeastOneChecked; |
189 }, | 189 }, |
190 | 190 |
191 checkPassphraseMatch_: function() { | 191 checkPassphraseMatch_: function() { |
192 var emptyError = $('empty-error'); | 192 var emptyError = $('empty-error'); |
193 var mismatchError = $('mismatch-error'); | 193 var mismatchError = $('mismatch-error'); |
194 emptyError.style.display = "none"; | 194 emptyError.hidden = true; |
195 mismatchError.style.display = "none"; | 195 mismatchError.hidden = true; |
196 | 196 |
197 var f = $('choose-data-types-form'); | 197 var f = $('choose-data-types-form'); |
198 if (this.getPassphraseRadioCheckedValue_() != "explicit" || | 198 if (this.getPassphraseRadioCheckedValue_() != "explicit" || |
199 f.option[0].disabled) | 199 f.option[0].disabled) |
200 return true; | 200 return true; |
201 | 201 |
202 var customPassphrase = $('custom-passphrase'); | 202 var customPassphrase = $('custom-passphrase'); |
203 if (customPassphrase.value.length == 0) { | 203 if (customPassphrase.value.length == 0) { |
204 emptyError.style.display = "block"; | 204 emptyError.hidden = false; |
205 return false; | 205 return false; |
206 } | 206 } |
207 | 207 |
208 var confirmPassphrase = $('confirm-passphrase'); | 208 var confirmPassphrase = $('confirm-passphrase'); |
209 if (confirmPassphrase.value != customPassphrase.value) { | 209 if (confirmPassphrase.value != customPassphrase.value) { |
210 mismatchError.style.display = "block"; | 210 mismatchError.hidden = false; |
211 return false; | 211 return false; |
212 } | 212 } |
213 | 213 |
214 return true; | 214 return true; |
215 }, | 215 }, |
216 | 216 |
217 sendConfiguration_: function() { | 217 sendConfiguration_: function() { |
218 // Trying to submit, so hide previous errors. | 218 // Trying to submit, so hide previous errors. |
219 $('aborted-text').className = "sync-error-hide"; | 219 $('aborted-text').className = "sync-error-hide"; |
220 $('error-text').className = "sync-error-hide"; | 220 $('error-text').className = "sync-error-hide"; |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
500 else | 500 else |
501 this.showOverlay_(); | 501 this.showOverlay_(); |
502 }, | 502 }, |
503 | 503 |
504 setThrobbersVisible_: function(visible) { | 504 setThrobbersVisible_: function(visible) { |
505 var throbbers = document.getElementsByClassName("throbber"); | 505 var throbbers = document.getElementsByClassName("throbber"); |
506 for (var i = 0; i < throbbers.length; i++) | 506 for (var i = 0; i < throbbers.length; i++) |
507 throbbers[i].style.visibility = visible ? "visible" : "hidden"; | 507 throbbers[i].style.visibility = visible ? "visible" : "hidden"; |
508 }, | 508 }, |
509 | 509 |
510 setElementDisplay_: function(id, display) { | |
511 var d = document.getElementById(id); | |
512 if (d) | |
513 d.style.display = display; | |
514 }, | |
515 | |
516 loginSetFocus_: function() { | 510 loginSetFocus_: function() { |
517 var email = $('gaia-email'); | 511 var email = $('gaia-email'); |
518 var passwd = $('gaia-passwd'); | 512 var passwd = $('gaia-passwd'); |
519 if (email && (email.value == null || email.value == "")) { | 513 if (email && (email.value == null || email.value == "")) { |
520 email.focus(); | 514 email.focus(); |
521 } else if (passwd) { | 515 } else if (passwd) { |
522 passwd.focus(); | 516 passwd.focus(); |
523 } | 517 } |
524 }, | 518 }, |
525 | 519 |
526 showAccessCodeRequired_: function() { | 520 showAccessCodeRequired_: function() { |
527 this.setElementDisplay_("password-row", "none"); | 521 $('password-row').hidden = true; |
528 this.setElementDisplay_("email-row", "none"); | 522 $('email-row').hidden = true; |
529 $('create-account-cell').style.visibility = "hidden"; | 523 $('create-account-cell').style.visibility = "hidden"; |
530 | 524 |
531 this.setElementDisplay_("access-code-label-row", "table-row"); | 525 $('access-code-label-row').hidden = false; |
532 this.setElementDisplay_("access-code-input-row", "table-row"); | 526 $('access-code-input-row').hidden = false; |
533 this.setElementDisplay_("access-code-help-row", "table-row"); | 527 $('access-code-help-row').hidden = false; |
534 document.getElementById('access-code').disabled = false; | 528 $('access-code').disabled = false; |
535 }, | 529 }, |
536 | 530 |
537 showCaptcha_: function(args) { | 531 showCaptcha_: function(args) { |
538 this.captchaChallengeActive_ = true; | 532 this.captchaChallengeActive_ = true; |
539 | 533 |
540 // The captcha takes up lots of space, so make room. | 534 // The captcha takes up lots of space, so make room. |
541 this.setElementDisplay_("top-blurb", "none"); | 535 $('top-blurb-error').hidden = true; |
542 this.setElementDisplay_("top-blurb-error", "none"); | 536 $('create-account-div').hidden = true; |
543 this.setElementDisplay_("create-account-div", "none"); | 537 $('create-account-cell').hidden = true; |
544 document.getElementById('create-account-cell').height = 0; | |
545 | 538 |
546 // It's showtime for the captcha now. | 539 // It's showtime for the captcha now. |
547 this.setElementDisplay_("captcha-div", "block"); | 540 $('captcha-div').hidden = false; |
548 document.getElementById('gaia-email').disabled = true; | 541 $('gaia-email').disabled = true; |
549 document.getElementById('gaia-passwd').disabled = false; | 542 $('gaia-passwd').disabled = false; |
550 document.getElementById('captcha-value').disabled = false; | 543 $('captcha-value').disabled = false; |
551 document.getElementById('captcha-wrapper').style.backgroundImage = | 544 $('captcha-wrapper').style.backgroundImage = url(args.captchaUrl); |
552 url(args.captchaUrl); | 545 }, |
546 | |
547 resetPage_: function(pageElementId) { | |
James Hawkins
2011/06/04 17:43:27
Add documentation for this method.
| |
548 var page = $(pageElementId); | |
549 var forEach = function(arr, fn) { | |
550 var length = arr.length; | |
551 for (var i = 0; i < length; i++) { | |
552 fn(arr[i]); | |
553 } | |
554 }; | |
555 | |
556 forEach(page.getElementsByClassName('reset-hidden'), | |
557 function(elt) { elt.hidden = true; }); | |
558 forEach(page.getElementsByClassName('reset-shown'), | |
559 function(elt) { elt.hidden = false; }); | |
560 forEach(page.getElementsByClassName('reset-disabled'), | |
561 function(elt) { elt.disabled = true; }); | |
562 forEach(page.getElementsByClassName('reset-enabled'), | |
563 function(elt) { elt.disabled = false; }); | |
564 forEach(page.getElementsByClassName('reset-visibility-hidden'), | |
565 function(elt) { elt.style.visibility = 'hidden'; }); | |
553 }, | 566 }, |
554 | 567 |
555 showGaiaLogin_: function(args) { | 568 showGaiaLogin_: function(args) { |
569 this.resetPage_('sync-setup-login'); | |
556 $('sync-setup-login').hidden = false; | 570 $('sync-setup-login').hidden = false; |
557 | 571 |
558 document.getElementById('gaia-email').disabled = false; | |
559 document.getElementById('gaia-passwd').disabled = false; | |
560 | |
561 var f = $('gaia-login-form'); | 572 var f = $('gaia-login-form'); |
562 var email = $('gaia-email'); | 573 var email = $('gaia-email'); |
563 var passwd = $('gaia-passwd'); | 574 var passwd = $('gaia-passwd'); |
564 if (f) { | 575 if (f) { |
565 if (args.user != undefined) { | 576 if (args.user != undefined) { |
566 if (email.value != args.user) | 577 if (email.value != args.user) |
567 passwd.value = ""; // Reset the password field | 578 passwd.value = ""; // Reset the password field |
568 email.value = args.user; | 579 email.value = args.user; |
569 } | 580 } |
570 | 581 |
571 if (!args.editable_user) { | 582 if (!args.editable_user) { |
572 email.style.display = 'none'; | 583 email.style.display = 'none'; |
573 var span = document.getElementById('email-readonly'); | 584 var span = document.getElementById('email-readonly'); |
574 span.appendChild(document.createTextNode(email.value)); | 585 span.appendChild(document.createTextNode(email.value)); |
575 span.style.display = 'inline'; | 586 span.style.display = 'inline'; |
576 this.setElementDisplay_("create-account-div", "none"); | 587 $('create-account-div').hidden = true; |
577 } | 588 } |
578 | 589 |
579 f.accessCode.disabled = true; | 590 f.accessCode.disabled = true; |
580 } | 591 } |
581 | 592 |
582 if (1 == args.error) { | 593 if (1 == args.error) { |
583 var access_code = document.getElementById('access-code'); | 594 var access_code = document.getElementById('access-code'); |
584 if (access_code.value && access_code.value != "") { | 595 if (access_code.value && access_code.value != "") { |
585 this.setElementDisplay_("errormsg-0-access-code", 'block'); | 596 $('errormsg-0-access-code').hidden = false; |
586 this.showAccessCodeRequired_(); | 597 this.showAccessCodeRequired_(); |
587 } else { | 598 } else { |
588 this.setElementDisplay_("errormsg-1-password", 'table-row'); | 599 $('errormsg-1-password').hidden = false; |
589 } | 600 } |
590 this.setBlurbError_(args.error_message); | 601 this.setBlurbError_(args.error_message); |
591 } else if (3 == args.error) { | 602 } else if (3 == args.error) { |
592 this.setElementDisplay_("errormsg-0-connection", 'table-row'); | 603 $('errormsg-0-connection').hidden = false; |
593 this.setBlurbError_(args.error_message); | 604 this.setBlurbError_(args.error_message); |
594 } else if (4 == args.error) { | 605 } else if (4 == args.error) { |
595 this.showCaptcha_(args); | 606 this.showCaptcha_(args); |
596 } else if (8 == args.error) { | 607 } else if (8 == args.error) { |
597 this.showAccessCodeRequired_(); | 608 this.showAccessCodeRequired_(); |
598 } else if (args.error_message) { | 609 } else if (args.error_message) { |
599 this.setBlurbError_(args.error_message); | 610 this.setBlurbError_(args.error_message); |
600 } | 611 } |
601 | 612 |
602 $('sign-in').disabled = false; | 613 $('sign-in').disabled = false; |
603 $('sign-in').value = templateData['signin']; | 614 $('sign-in').value = templateData['signin']; |
604 this.loginSetFocus_(); | 615 this.loginSetFocus_(); |
605 }, | 616 }, |
606 | 617 |
607 resetErrorVisibility_: function() { | 618 resetErrorVisibility_: function() { |
608 this.setElementDisplay_("errormsg-0-email", 'none'); | 619 $("errormsg-0-email").hidden = true; |
609 this.setElementDisplay_("errormsg-0-password", 'none'); | 620 $("errormsg-0-password").hidden = true; |
610 this.setElementDisplay_("errormsg-1-password", 'none'); | 621 $("errormsg-1-password").hidden = true; |
611 this.setElementDisplay_("errormsg-0-connection", 'none'); | 622 $("errormsg-0-connection").hidden = true; |
612 this.setElementDisplay_("errormsg-0-access-code", 'none'); | 623 $("errormsg-0-access-code").hidden = true; |
613 }, | 624 }, |
614 | 625 |
615 setBlurbError_: function(error_message) { | 626 setBlurbError_: function(error_message) { |
616 if (this.captchaChallengeActive_) | 627 if (this.captchaChallengeActive_) |
617 return; // No blurb in captcha challenge mode. | 628 return; // No blurb in captcha challenge mode. |
618 | 629 |
619 if (error_message) { | 630 if (error_message) { |
620 document.getElementById('error-signing-in').style.display = 'none'; | 631 $('error-signing-in').hidden = true; |
621 document.getElementById('error-custom').style.display = 'inline'; | 632 $('error-custom').hidden = false; |
622 document.getElementById('error-custom').textContent = error_message; | 633 $('error-custom').textContent = error_message; |
623 } else { | 634 } else { |
624 document.getElementById('error-signing-in').style.display = 'inline'; | 635 $('error-signing-in').hidden = false; |
625 document.getElementById('error-custom').style.display = 'none'; | 636 $('error-custom').hidden = true; |
626 } | 637 } |
627 | 638 |
628 $('top-blurb-error').style.visibility = "visible"; | 639 $('top-blurb-error').style.visibility = "visible"; |
629 document.getElementById('gaia-email').disabled = false; | 640 $('gaia-email').disabled = false; |
630 document.getElementById('gaia-passwd').disabled = false; | 641 $('gaia-passwd').disabled = false; |
631 }, | 642 }, |
632 | 643 |
633 setErrorVisibility_: function() { | 644 setErrorVisibility_: function() { |
634 this.resetErrorVisibility_(); | 645 this.resetErrorVisibility_(); |
635 var f = $('gaia-login-form'); | 646 var f = $('gaia-login-form'); |
636 var email = $('gaia-email'); | 647 var email = $('gaia-email'); |
637 var passwd = $('gaia-passwd'); | 648 var passwd = $('gaia-passwd'); |
638 if (null == email.value || "" == email.value) { | 649 if (null == email.value || "" == email.value) { |
639 this.setElementDisplay_("errormsg-0-email", 'table-row'); | 650 $('errormsg-0-email').hidden = false; |
640 this.setBlurbError_(); | 651 this.setBlurbError_(); |
641 return false; | 652 return false; |
642 } | 653 } |
643 if (null == passwd.value || "" == passwd.value) { | 654 if (null == passwd.value || "" == passwd.value) { |
644 this.setElementDisplay_("errormsg-0-password", 'table-row'); | 655 $('errormsg-0-password').hidden = false; |
645 this.setBlurbError_(); | 656 this.setBlurbError_(); |
646 return false; | 657 return false; |
647 } | 658 } |
648 if (!f.accessCode.disabled && (null == f.accessCode.value || | 659 if (!f.accessCode.disabled && (null == f.accessCode.value || |
649 "" == f.accessCode.value)) { | 660 "" == f.accessCode.value)) { |
650 this.setElementDisplay_("errormsg-0-password", 'table-row'); | 661 $('errormsg-0-password').hidden = false; |
651 return false; | 662 return false; |
652 } | 663 } |
653 return true; | 664 return true; |
654 }, | 665 }, |
655 | 666 |
656 sendCredentialsAndClose_: function() { | 667 sendCredentialsAndClose_: function() { |
657 if (!this.setErrorVisibility_()) { | 668 if (!this.setErrorVisibility_()) { |
658 return false; | 669 return false; |
659 } | 670 } |
660 | 671 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
715 | 726 |
716 SyncSetupOverlay.showSuccessAndSettingUp = function() { | 727 SyncSetupOverlay.showSuccessAndSettingUp = function() { |
717 SyncSetupOverlay.getInstance().showSuccessAndSettingUp_(); | 728 SyncSetupOverlay.getInstance().showSuccessAndSettingUp_(); |
718 }; | 729 }; |
719 | 730 |
720 // Export | 731 // Export |
721 return { | 732 return { |
722 SyncSetupOverlay: SyncSetupOverlay | 733 SyncSetupOverlay: SyncSetupOverlay |
723 }; | 734 }; |
724 }); | 735 }); |
OLD | NEW |