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) { | |
548 var page = $(pageElementId); | |
549 var forEach = function (arr, fn) { | |
csilv
2011/06/03 01:34:54
style nit: eliminate space before opening parenthe
| |
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-display-default'), | |
csilv
2011/06/03 01:34:54
it doesn't look like 'reset-display-default' is ev
| |
561 function (elt) { elt.style.display = ''; }); | |
562 forEach(page.getElementsByClassName('reset-disabled'), | |
563 function (elt) { elt.disabled = true; }); | |
564 forEach(page.getElementsByClassName('reset-enabled'), | |
565 function (elt) { elt.disabled = false; }); | |
566 forEach(page.getElementsByClassName('reset-visibility-hidden'), | |
567 function (elt) { elt.style.visibility = 'hidden'; }); | |
553 }, | 568 }, |
554 | 569 |
555 showGaiaLogin_: function(args) { | 570 showGaiaLogin_: function(args) { |
571 this.resetPage_('sync-setup-login'); | |
556 $('sync-setup-login').hidden = false; | 572 $('sync-setup-login').hidden = false; |
557 | 573 |
558 document.getElementById('gaia-email').disabled = false; | |
559 document.getElementById('gaia-passwd').disabled = false; | |
560 | |
561 var f = $('gaia-login-form'); | 574 var f = $('gaia-login-form'); |
562 var email = $('gaia-email'); | 575 var email = $('gaia-email'); |
563 var passwd = $('gaia-passwd'); | 576 var passwd = $('gaia-passwd'); |
564 if (f) { | 577 if (f) { |
565 if (args.user != undefined) { | 578 if (args.user != undefined) { |
566 if (email.value != args.user) | 579 if (email.value != args.user) |
567 passwd.value = ""; // Reset the password field | 580 passwd.value = ""; // Reset the password field |
568 email.value = args.user; | 581 email.value = args.user; |
569 } | 582 } |
570 | 583 |
571 if (!args.editable_user) { | 584 if (!args.editable_user) { |
572 email.style.display = 'none'; | 585 email.style.display = 'none'; |
573 var span = document.getElementById('email-readonly'); | 586 var span = document.getElementById('email-readonly'); |
574 span.appendChild(document.createTextNode(email.value)); | 587 span.appendChild(document.createTextNode(email.value)); |
575 span.style.display = 'inline'; | 588 span.style.display = 'inline'; |
576 this.setElementDisplay_("create-account-div", "none"); | 589 $('create-account-div').hidden = true; |
577 } | 590 } |
578 | 591 |
579 f.accessCode.disabled = true; | 592 f.accessCode.disabled = true; |
580 } | 593 } |
581 | 594 |
582 if (1 == args.error) { | 595 if (1 == args.error) { |
583 var access_code = document.getElementById('access-code'); | 596 var access_code = document.getElementById('access-code'); |
584 if (access_code.value && access_code.value != "") { | 597 if (access_code.value && access_code.value != "") { |
585 this.setElementDisplay_("errormsg-0-access-code", 'block'); | 598 $('errormsg-0-access-code').hidden = false; |
586 this.showAccessCodeRequired_(); | 599 this.showAccessCodeRequired_(); |
587 } else { | 600 } else { |
588 this.setElementDisplay_("errormsg-1-password", 'table-row'); | 601 $('errormsg-1-password').hidden = false; |
589 } | 602 } |
590 this.setBlurbError_(args.error_message); | 603 this.setBlurbError_(args.error_message); |
591 } else if (3 == args.error) { | 604 } else if (3 == args.error) { |
592 this.setElementDisplay_("errormsg-0-connection", 'table-row'); | 605 $('errormsg-0-connection').hidden = false; |
593 this.setBlurbError_(args.error_message); | 606 this.setBlurbError_(args.error_message); |
594 } else if (4 == args.error) { | 607 } else if (4 == args.error) { |
595 this.showCaptcha_(args); | 608 this.showCaptcha_(args); |
596 } else if (8 == args.error) { | 609 } else if (8 == args.error) { |
597 this.showAccessCodeRequired_(); | 610 this.showAccessCodeRequired_(); |
598 } else if (args.error_message) { | 611 } else if (args.error_message) { |
599 this.setBlurbError_(args.error_message); | 612 this.setBlurbError_(args.error_message); |
600 } | 613 } |
601 | 614 |
602 $('sign-in').disabled = false; | 615 $('sign-in').disabled = false; |
603 $('sign-in').value = templateData['signin']; | 616 $('sign-in').value = templateData['signin']; |
604 this.loginSetFocus_(); | 617 this.loginSetFocus_(); |
605 }, | 618 }, |
606 | 619 |
607 resetErrorVisibility_: function() { | 620 resetErrorVisibility_: function() { |
608 this.setElementDisplay_("errormsg-0-email", 'none'); | 621 $("errormsg-0-email").hidden = true; |
609 this.setElementDisplay_("errormsg-0-password", 'none'); | 622 $("errormsg-0-password").hidden = true; |
610 this.setElementDisplay_("errormsg-1-password", 'none'); | 623 $("errormsg-1-password").hidden = true; |
611 this.setElementDisplay_("errormsg-0-connection", 'none'); | 624 $("errormsg-0-connection").hidden = true; |
612 this.setElementDisplay_("errormsg-0-access-code", 'none'); | 625 $("errormsg-0-access-code").hidden = true; |
613 }, | 626 }, |
614 | 627 |
615 setBlurbError_: function(error_message) { | 628 setBlurbError_: function(error_message) { |
616 if (this.captchaChallengeActive_) | 629 if (this.captchaChallengeActive_) |
617 return; // No blurb in captcha challenge mode. | 630 return; // No blurb in captcha challenge mode. |
618 | 631 |
619 if (error_message) { | 632 if (error_message) { |
620 document.getElementById('error-signing-in').style.display = 'none'; | 633 $('error-signing-in').hidden = true; |
621 document.getElementById('error-custom').style.display = 'inline'; | 634 $('error-custom').hidden = false; |
622 document.getElementById('error-custom').textContent = error_message; | 635 $('error-custom').textContent = error_message; |
623 } else { | 636 } else { |
624 document.getElementById('error-signing-in').style.display = 'inline'; | 637 $('error-signing-in').hidden = false; |
625 document.getElementById('error-custom').style.display = 'none'; | 638 $('error-custom').hidden = true; |
626 } | 639 } |
627 | 640 |
628 $('top-blurb-error').style.visibility = "visible"; | 641 $('top-blurb-error').style.visibility = "visible"; |
629 document.getElementById('gaia-email').disabled = false; | 642 $('gaia-email').disabled = false; |
630 document.getElementById('gaia-passwd').disabled = false; | 643 $('gaia-passwd').disabled = false; |
631 }, | 644 }, |
632 | 645 |
633 setErrorVisibility_: function() { | 646 setErrorVisibility_: function() { |
634 this.resetErrorVisibility_(); | 647 this.resetErrorVisibility_(); |
635 var f = $('gaia-login-form'); | 648 var f = $('gaia-login-form'); |
636 var email = $('gaia-email'); | 649 var email = $('gaia-email'); |
637 var passwd = $('gaia-passwd'); | 650 var passwd = $('gaia-passwd'); |
638 if (null == email.value || "" == email.value) { | 651 if (null == email.value || "" == email.value) { |
639 this.setElementDisplay_("errormsg-0-email", 'table-row'); | 652 $('errormsg-0-email').hidden = false; |
640 this.setBlurbError_(); | 653 this.setBlurbError_(); |
641 return false; | 654 return false; |
642 } | 655 } |
643 if (null == passwd.value || "" == passwd.value) { | 656 if (null == passwd.value || "" == passwd.value) { |
644 this.setElementDisplay_("errormsg-0-password", 'table-row'); | 657 $('errormsg-0-password').hidden = false; |
645 this.setBlurbError_(); | 658 this.setBlurbError_(); |
646 return false; | 659 return false; |
647 } | 660 } |
648 if (!f.accessCode.disabled && (null == f.accessCode.value || | 661 if (!f.accessCode.disabled && (null == f.accessCode.value || |
649 "" == f.accessCode.value)) { | 662 "" == f.accessCode.value)) { |
650 this.setElementDisplay_("errormsg-0-password", 'table-row'); | 663 $('errormsg-0-password').hidden = false; |
651 return false; | 664 return false; |
652 } | 665 } |
653 return true; | 666 return true; |
654 }, | 667 }, |
655 | 668 |
656 sendCredentialsAndClose_: function() { | 669 sendCredentialsAndClose_: function() { |
657 if (!this.setErrorVisibility_()) { | 670 if (!this.setErrorVisibility_()) { |
658 return false; | 671 return false; |
659 } | 672 } |
660 | 673 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
715 | 728 |
716 SyncSetupOverlay.showSuccessAndSettingUp = function() { | 729 SyncSetupOverlay.showSuccessAndSettingUp = function() { |
717 SyncSetupOverlay.getInstance().showSuccessAndSettingUp_(); | 730 SyncSetupOverlay.getInstance().showSuccessAndSettingUp_(); |
718 }; | 731 }; |
719 | 732 |
720 // Export | 733 // Export |
721 return { | 734 return { |
722 SyncSetupOverlay: SyncSetupOverlay | 735 SyncSetupOverlay: SyncSetupOverlay |
723 }; | 736 }; |
724 }); | 737 }); |
OLD | NEW |