| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 cr.define('options', function() { | |
| 6 const OptionsPage = options.OptionsPage; | |
| 7 | |
| 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 | |
| 10 // the browser. This means subsequent errors (like invalid password) are | |
| 11 // rendered in the captcha state, which is basically identical except we | |
| 12 // don't show the top error blurb "Error Signing in" or the "Create | |
| 13 // account" link. | |
| 14 var captchaChallengeActive_ = false; | |
| 15 | |
| 16 // True if the synced account uses a custom passphrase. | |
| 17 var usePassphrase_ = false; | |
| 18 | |
| 19 /** | |
| 20 * SyncSetupOverlay class | |
| 21 * Encapsulated handling of the 'Sync Setup' overlay page. | |
| 22 * @class | |
| 23 */ | |
| 24 function SyncSetupOverlay() { | |
| 25 OptionsPage.call(this, 'syncSetup', | |
| 26 templateData.syncSetupOverlayTitle, | |
| 27 'sync-setup-overlay'); | |
| 28 } | |
| 29 | |
| 30 cr.addSingletonGetter(SyncSetupOverlay); | |
| 31 | |
| 32 SyncSetupOverlay.prototype = { | |
| 33 __proto__: OptionsPage.prototype, | |
| 34 | |
| 35 /** | |
| 36 * Initializes the page. | |
| 37 */ | |
| 38 initializePage: function() { | |
| 39 OptionsPage.prototype.initializePage.call(this); | |
| 40 | |
| 41 var acct_text = $('gaia-account-text'); | |
| 42 var translated_text = acct_text.textContent; | |
| 43 var posGoogle = translated_text.indexOf('Google'); | |
| 44 if (posGoogle != -1) { | |
| 45 var ltr = templateData['textdirection'] == 'ltr'; | |
| 46 var googleIsAtEndOfSentence = posGoogle != 0; | |
| 47 if (googleIsAtEndOfSentence == ltr) { | |
| 48 // We're in ltr and in the translation the word 'Google' is AFTER the | |
| 49 // word 'Account' OR we're in rtl and 'Google' is BEFORE 'Account'. | |
| 50 var logo_td = $('gaia-logo'); | |
| 51 logo_td.parentNode.appendChild(logo_td); | |
| 52 } | |
| 53 acct_text.textContent = translated_text.replace('Google',''); | |
| 54 } | |
| 55 | |
| 56 var self = this; | |
| 57 $('gaia-login-form').onsubmit = function() { | |
| 58 self.sendCredentialsAndClose_(); | |
| 59 return false; | |
| 60 }; | |
| 61 $('choose-data-types-form').onsubmit = function() { | |
| 62 self.sendConfiguration_(); | |
| 63 return false; | |
| 64 }; | |
| 65 $('google-option').onchange = $('explicit-option').onchange = function() { | |
| 66 self.onRadioChange_(); | |
| 67 }; | |
| 68 $('choose-datatypes-cancel').onclick = $('sync-setup-cancel').onclick = | |
| 69 $('confirm-everything-cancel').onclick = function() { | |
| 70 self.closeOverlay_(); | |
| 71 }; | |
| 72 $('customize-link').onclick = function() { | |
| 73 self.showCustomizePage_(false); | |
| 74 }; | |
| 75 $('confirm-everything-ok').onclick = function() { | |
| 76 self.sendConfiguration_(); | |
| 77 }; | |
| 78 $('use-default-link').onclick = function() { | |
| 79 self.showSyncEverythingPage_(); | |
| 80 }; | |
| 81 $('cancel-no-button').onclick = function() { | |
| 82 self.hideCancelWarning_(); | |
| 83 return false; | |
| 84 }; | |
| 85 $('cancel-yes-button').onclick = function() { | |
| 86 chrome.send('PassphraseCancel', ['']); | |
| 87 return false; | |
| 88 }; | |
| 89 $('passphrase-form').onsubmit = $('passphrase-ok').onclick = function() { | |
| 90 self.sendPassphraseAndClose_(); | |
| 91 return false; | |
| 92 }; | |
| 93 $('passphrase-cancel').onclick = function() { | |
| 94 self.showCancelWarning_(); | |
| 95 return false; | |
| 96 }; | |
| 97 }, | |
| 98 | |
| 99 closeOverlay_: function() { | |
| 100 OptionsPage.closeOverlay(); | |
| 101 }, | |
| 102 | |
| 103 /** @inheritDoc */ | |
| 104 didShowPage: function() { | |
| 105 chrome.send('didShowPage'); | |
| 106 }, | |
| 107 | |
| 108 /** @inheritDoc */ | |
| 109 didClosePage: function() { | |
| 110 chrome.send('didClosePage'); | |
| 111 }, | |
| 112 | |
| 113 showCancelWarning_: function() { | |
| 114 $('cancel-warning-box').hidden = false; | |
| 115 $('passphrase-ok').disabled = true; | |
| 116 $('passphrase-cancel').disabled = true; | |
| 117 $('cancel-no-button').focus(); | |
| 118 }, | |
| 119 | |
| 120 sendPassphraseAndClose_: function() { | |
| 121 var f = $('passphrase-form'); | |
| 122 var result = JSON.stringify({"passphrase": f.passphrase.value}); | |
| 123 chrome.send("Passphrase", [result]); | |
| 124 }, | |
| 125 | |
| 126 getRadioCheckedValue_: function() { | |
| 127 var f = $('choose-data-types-form'); | |
| 128 for (var i = 0; i < f.option.length; ++i) { | |
| 129 if (f.option[i].checked) { | |
| 130 return f.option[i].value; | |
| 131 } | |
| 132 } | |
| 133 | |
| 134 return undefined; | |
| 135 }, | |
| 136 | |
| 137 onRadioChange_: function() { | |
| 138 var visible = this.getRadioCheckedValue_() == "explicit"; | |
| 139 $('sync-custom-passphrase').hidden = !visible; | |
| 140 }, | |
| 141 | |
| 142 checkAllDataTypeCheckboxes_: function() { | |
| 143 var checkboxes = document.getElementsByName("dataTypeCheckbox"); | |
| 144 for (var i = 0; i < checkboxes.length; i++) { | |
| 145 // Only check the visible ones (since there's no way to uncheck | |
| 146 // the invisible ones). | |
| 147 if (checkboxes[i].parentElement.className == "sync-item-show") { | |
| 148 checkboxes[i].checked = true; | |
| 149 } | |
| 150 } | |
| 151 }, | |
| 152 | |
| 153 setDataTypeCheckboxesEnabled_: function(enabled) { | |
| 154 var checkboxes = document.getElementsByName("dataTypeCheckbox"); | |
| 155 var labels = document.getElementsByName("dataTypeLabel"); | |
| 156 for (var i = 0; i < checkboxes.length; i++) { | |
| 157 checkboxes[i].disabled = !enabled; | |
| 158 if (checkboxes[i].disabled) { | |
| 159 labels[i].className = "sync-label-inactive"; | |
| 160 } else { | |
| 161 labels[i].className = "sync-label-active"; | |
| 162 } | |
| 163 } | |
| 164 }, | |
| 165 | |
| 166 setCheckboxesToKeepEverythingSynced_: function(value) { | |
| 167 this.setDataTypeCheckboxesEnabled_(!value); | |
| 168 if (value) | |
| 169 this.checkAllDataTypeCheckboxes_(); | |
| 170 }, | |
| 171 | |
| 172 // Returns true if at least one data type is enabled and no data types are | |
| 173 // checked. (If all data type checkboxes are disabled, it's because "keep | |
| 174 // everything synced" is checked.) | |
| 175 noDataTypesChecked_: function() { | |
| 176 var checkboxes = document.getElementsByName("dataTypeCheckbox"); | |
| 177 var atLeastOneChecked = false; | |
| 178 var atLeastOneEnabled = false; | |
| 179 for (var i = 0; i < checkboxes.length; i++) { | |
| 180 if (!checkboxes[i].disabled && | |
| 181 checkboxes[i].parentElement.className == "sync-item-show") { | |
| 182 atLeastOneEnabled = true; | |
| 183 if (checkboxes[i].checked) { | |
| 184 atLeastOneChecked = true; | |
| 185 } | |
| 186 } | |
| 187 } | |
| 188 | |
| 189 return atLeastOneEnabled && !atLeastOneChecked; | |
| 190 }, | |
| 191 | |
| 192 checkPassphraseMatch_: function() { | |
| 193 var emptyError = $('empty-error'); | |
| 194 var mismatchError = $('mismatch-error'); | |
| 195 emptyError.style.display = "none"; | |
| 196 mismatchError.style.display = "none"; | |
| 197 | |
| 198 var f = $('choose-data-types-form'); | |
| 199 if (this.getRadioCheckedValue_() != "explicit" || f.option[0].disabled) | |
| 200 return true; | |
| 201 | |
| 202 var customPassphrase = $('custom-passphrase'); | |
| 203 if (customPassphrase.value.length == 0) { | |
| 204 emptyError.style.display = "block"; | |
| 205 return false; | |
| 206 } | |
| 207 | |
| 208 var confirmPassphrase = $('confirm-passphrase'); | |
| 209 if (confirmPassphrase.value != customPassphrase.value) { | |
| 210 mismatchError.style.display = "block"; | |
| 211 return false; | |
| 212 } | |
| 213 | |
| 214 return true; | |
| 215 }, | |
| 216 | |
| 217 hideCancelWarning_: function() { | |
| 218 $('cancel-warning-box').hidden = true; | |
| 219 $('passphrase-ok').disabled = false; | |
| 220 $('passphrase-cancel').disabled = false; | |
| 221 }, | |
| 222 | |
| 223 sendConfiguration_: function() { | |
| 224 // Trying to submit, so hide previous errors. | |
| 225 $('aborted-text').className = "sync-error-hide"; | |
| 226 $('error-text').className = "sync-error-hide"; | |
| 227 | |
| 228 if (this.noDataTypesChecked_()) { | |
| 229 $('error-text').className = "sync-error-show"; | |
| 230 return; | |
| 231 } | |
| 232 | |
| 233 var f = $('choose-data-types-form'); | |
| 234 if (!this.checkPassphraseMatch_()) | |
| 235 return; | |
| 236 | |
| 237 var syncAll = | |
| 238 document.getElementById('sync-select-datatypes').selectedIndex == 0; | |
| 239 | |
| 240 // These values need to be kept in sync with where they are read in | |
| 241 // SyncSetupFlow::GetDataTypeChoiceData(). | |
| 242 var result = JSON.stringify({ | |
| 243 "keepEverythingSynced": syncAll, | |
| 244 "syncBookmarks": syncAll || $('bookmarks-checkbox').checked, | |
| 245 "syncPreferences": syncAll || $('preferences-checkbox').checked, | |
| 246 "syncThemes": syncAll || $('themes-checkbox').checked, | |
| 247 "syncPasswords": syncAll || $('passwords-checkbox').checked, | |
| 248 "syncAutofill": syncAll || $('autofill-checkbox').checked, | |
| 249 "syncExtensions": syncAll || $('extensions-checkbox').checked, | |
| 250 "syncTypedUrls": syncAll || $('typed-urls-checkbox').checked, | |
| 251 "syncApps": syncAll || $('apps-checkbox').checked, | |
| 252 "syncSessions": syncAll || $('sessions-checkbox').checked, | |
| 253 "usePassphrase": (this.getRadioCheckedValue_() == 'explicit'), | |
| 254 "passphrase": $('custom-passphrase').value | |
| 255 }); | |
| 256 chrome.send("Configure", [result]); | |
| 257 }, | |
| 258 | |
| 259 setChooseDataTypesCheckboxes_: function(args) { | |
| 260 // If this frame is on top, the focus should be on it, so pressing enter | |
| 261 // submits this form. | |
| 262 if (args.iframeToShow == 'configure') { | |
| 263 $('choose-datatypes-ok').focus(); | |
| 264 } | |
| 265 | |
| 266 var datatypeSelect = document.getElementById('sync-select-datatypes'); | |
| 267 datatypeSelect.selectedIndex = args.keepEverythingSynced ? 0 : 1; | |
| 268 | |
| 269 $('bookmarks-checkbox').checked = args.syncBookmarks; | |
| 270 $('preferences-checkbox').checked = args.syncPreferences; | |
| 271 $('themes-checkbox').checked = args.syncThemes; | |
| 272 | |
| 273 if (args.passwordsRegistered) { | |
| 274 $('passwords-checkbox').checked = args.syncPasswords; | |
| 275 $('passwords-item').className = "sync-item-show"; | |
| 276 } else { | |
| 277 $('passwords-item').className = "sync-item-hide"; | |
| 278 } | |
| 279 if (args.autofillRegistered) { | |
| 280 $('autofill-checkbox').checked = args.syncAutofill; | |
| 281 $('autofill-item').className = "sync-item-show"; | |
| 282 } else { | |
| 283 $('autofill-item').className = "sync-item-hide"; | |
| 284 } | |
| 285 if (args.extensionsRegistered) { | |
| 286 $('extensions-checkbox').checked = args.syncExtensions; | |
| 287 $('extensions-item').className = "sync-item-show"; | |
| 288 } else { | |
| 289 $('extensions-item').className = "sync-item-hide"; | |
| 290 } | |
| 291 if (args.typedUrlsRegistered) { | |
| 292 $('typedUrls-checkbox').checked = args.syncTypedUrls; | |
| 293 $('omnibox-item').className = "sync-item-show"; | |
| 294 } else { | |
| 295 $('omnibox-item').className = "sync-item-hide"; | |
| 296 } | |
| 297 if (args.appsRegistered) { | |
| 298 $('apps-checkbox').checked = args.syncApps; | |
| 299 $('apps-item').className = "sync-item-show"; | |
| 300 } else { | |
| 301 $('apps-item').className = "sync-item-hide"; | |
| 302 } | |
| 303 | |
| 304 this.setCheckboxesToKeepEverythingSynced_(args.keepEverythingSynced); | |
| 305 if (args.sessionsRegistered) { | |
| 306 $('sessions-checkbox').checked = args.syncSessions; | |
| 307 $('sessions-item').className = "sync-item-show"; | |
| 308 } else { | |
| 309 $('sessions-item').className = "sync-item-hide"; | |
| 310 } | |
| 311 }, | |
| 312 | |
| 313 setEncryptionCheckboxes_: function(args) { | |
| 314 if (args["usePassphrase"]) { | |
| 315 $('explicit-option').checked = true; | |
| 316 | |
| 317 // The passphrase, once set, cannot be unset, but we show a reset link. | |
| 318 $('explicit-option').disabled = true; | |
| 319 $('google-option').disabled = true; | |
| 320 $('sync-custom-passphrase').hidden = true; | |
| 321 } else { | |
| 322 $('google-option').checked = true; | |
| 323 } | |
| 324 }, | |
| 325 | |
| 326 setErrorState_: function(args) { | |
| 327 if (!args.was_aborted) | |
| 328 return; | |
| 329 | |
| 330 $('aborted-text').className = "sync-error-show"; | |
| 331 $('choose-datatypes-ok').disabled = true; | |
| 332 }, | |
| 333 | |
| 334 setCheckboxesAndErrors_: function(args) { | |
| 335 this.setChooseDataTypesCheckboxes_(args); | |
| 336 this.setEncryptionCheckboxes_(args); | |
| 337 this.setErrorState_(args); | |
| 338 }, | |
| 339 | |
| 340 // Called once, when this html/js is loaded. | |
| 341 showConfigure_: function(args) { | |
| 342 var datatypeSelect = document.getElementById('sync-select-datatypes'); | |
| 343 var self = this; | |
| 344 datatypeSelect.onchange = function() { | |
| 345 var syncAll = this.selectedIndex == 0; | |
| 346 self.setCheckboxesToKeepEverythingSynced_(syncAll); | |
| 347 }; | |
| 348 | |
| 349 $('sync-setup-configure').classList.remove('hidden'); | |
| 350 | |
| 351 if (args) { | |
| 352 this.setCheckboxesAndErrors_(args); | |
| 353 | |
| 354 // Whether to display the 'Sync everything' confirmation page or the | |
| 355 // customize data types page. | |
| 356 var showSyncEverythingPage = args['showSyncEverythingPage']; | |
| 357 var keepEverythingSynced = args['keepEverythingSynced']; | |
| 358 this.usePassphrase_ = args['usePassphrase']; | |
| 359 if (showSyncEverythingPage == false || | |
| 360 keepEverythingSynced == false || this.usePassphrase_) { | |
| 361 this.showCustomizePage_(keepEverythingSynced); | |
| 362 } else { | |
| 363 this.showSyncEverythingPage_(); | |
| 364 } | |
| 365 } | |
| 366 }, | |
| 367 | |
| 368 showSyncEverythingPage_: function() { | |
| 369 $('confirm-sync-preferences').hidden = false; | |
| 370 $('customize-sync-preferences').hidden = true; | |
| 371 | |
| 372 // Reset the selection to 'Sync everything'. | |
| 373 $('sync-select-datatypes').selectedIndex = 0; | |
| 374 | |
| 375 // The default state is to sync everything. | |
| 376 this.setCheckboxesToKeepEverythingSynced_(true); | |
| 377 | |
| 378 // If the account is not synced with a custom passphrase, reset the | |
| 379 // passphrase radio when switching to the 'Sync everything' page. | |
| 380 if (!this.usePassphrase_) { | |
| 381 $('google-option').checked = true; | |
| 382 $('sync-custom-passphrase').hidden = true; | |
| 383 } | |
| 384 | |
| 385 $('confirm-everything-ok').focus(); | |
| 386 }, | |
| 387 | |
| 388 showCustomizePage_: function(syncEverything) { | |
| 389 document.getElementById('confirm-sync-preferences').hidden = true; | |
| 390 document.getElementById('customize-sync-preferences').hidden = false; | |
| 391 | |
| 392 // If the user has selected the 'Customize' page on initial set up, it's | |
| 393 // likely he intends to change the data types. Select the | |
| 394 // 'Choose data types' option in this case. | |
| 395 var index = syncEverything ? 0 : 1; | |
| 396 document.getElementById('sync-select-datatypes').selectedIndex = index; | |
| 397 this.setDataTypeCheckboxesEnabled_(!syncEverything); | |
| 398 $('choose-datatypes-ok').focus(); | |
| 399 }, | |
| 400 | |
| 401 showSyncSetupPage_: function(page, args) { | |
| 402 if (page == 'settingUp') { | |
| 403 this.setThrobbersVisible_(true); | |
| 404 return; | |
| 405 } else { | |
| 406 this.setThrobbersVisible_(false); | |
| 407 } | |
| 408 | |
| 409 // Hide an existing visible overlay. | |
| 410 var overlay = $('sync-setup-overlay'); | |
| 411 for (var i = 0; i < overlay.children.length; i++) | |
| 412 overlay.children[i].classList.add('hidden'); | |
| 413 | |
| 414 if (page == 'login') | |
| 415 this.showGaiaLogin_(args); | |
| 416 else if (page == 'configure') | |
| 417 this.showConfigure_(args); | |
| 418 else if (page == 'passphrase') | |
| 419 this.showPassphrase_(args); | |
| 420 else if (page == 'done') | |
| 421 this.closeOverlay_(); | |
| 422 }, | |
| 423 | |
| 424 setThrobbersVisible_: function(visible) { | |
| 425 var throbbers = document.getElementsByClassName("throbber"); | |
| 426 for (var i = 0; i < throbbers.length; i++) | |
| 427 throbbers[i].style.visibility = visible ? "visible" : "hidden"; | |
| 428 }, | |
| 429 | |
| 430 showPassphrase_: function(args) { | |
| 431 $('sync-setup-passphrase').classList.remove('hidden'); | |
| 432 | |
| 433 $('passphrase-rejected-body').style.display = "none"; | |
| 434 $('normal-body').style.display = "none"; | |
| 435 $('incorrect-passphrase').style.display = "none"; | |
| 436 | |
| 437 if (args["passphrase_creation_rejected"]) { | |
| 438 $('passphrase-rejected-body').style.display = "block"; | |
| 439 } else { | |
| 440 $('normal-body').style.display = "block"; | |
| 441 } | |
| 442 | |
| 443 if (args["passphrase_setting_rejected"]) { | |
| 444 $('incorrect-passphrase').style.display = "block"; | |
| 445 } | |
| 446 | |
| 447 $('passphrase').focus(); | |
| 448 }, | |
| 449 | |
| 450 setElementDisplay_: function(id, display) { | |
| 451 var d = document.getElementById(id); | |
| 452 if (d) | |
| 453 d.style.display = display; | |
| 454 }, | |
| 455 | |
| 456 loginSetFocus_: function() { | |
| 457 var email = $('gaia-email'); | |
| 458 var passwd = $('gaia-passwd'); | |
| 459 if (email && (email.value == null || email.value == "")) { | |
| 460 email.focus(); | |
| 461 } else if (passwd) { | |
| 462 passwd.focus(); | |
| 463 } | |
| 464 }, | |
| 465 | |
| 466 showAccessCodeRequired_: function() { | |
| 467 this.setElementDisplay_("password-row", "none"); | |
| 468 this.setElementDisplay_("email-row", "none"); | |
| 469 $('create-account-cell').style.visibility = "hidden"; | |
| 470 | |
| 471 this.setElementDisplay_("access-code-label-row", "table-row"); | |
| 472 this.setElementDisplay_("access-code-input-row", "table-row"); | |
| 473 this.setElementDisplay_("access-code-help-row", "table-row"); | |
| 474 document.getElementById('access-code').disabled = false; | |
| 475 }, | |
| 476 | |
| 477 showCaptcha_: function(args) { | |
| 478 this.captchaChallengeActive_ = true; | |
| 479 | |
| 480 // The captcha takes up lots of space, so make room. | |
| 481 this.setElementDisplay_("top-blurb", "none"); | |
| 482 this.setElementDisplay_("top-blurb-error", "none"); | |
| 483 this.setElementDisplay_("create-account-div", "none"); | |
| 484 document.getElementById('create-account-cell').height = 0; | |
| 485 | |
| 486 // It's showtime for the captcha now. | |
| 487 this.setElementDisplay_("captcha-div", "block"); | |
| 488 document.getElementById('gaia-email').disabled = true; | |
| 489 document.getElementById('gaia-passwd').disabled = false; | |
| 490 document.getElementById('captcha-value').disabled = false; | |
| 491 document.getElementById('captcha-wrapper').style.backgroundImage = | |
| 492 url(args.captchaUrl); | |
| 493 }, | |
| 494 | |
| 495 showGaiaLogin_: function(args) { | |
| 496 $('sync-setup-login').classList.remove('hidden'); | |
| 497 | |
| 498 document.getElementById('gaia-email').disabled = false; | |
| 499 document.getElementById('gaia-passwd').disabled = false; | |
| 500 | |
| 501 var f = $('gaia-login-form'); | |
| 502 var email = $('gaia-email'); | |
| 503 var passwd = $('gaia-passwd'); | |
| 504 if (f) { | |
| 505 if (args.user != undefined) { | |
| 506 if (email.value != args.user) | |
| 507 passwd.value = ""; // Reset the password field | |
| 508 email.value = args.user; | |
| 509 } | |
| 510 | |
| 511 if (!args.editable_user) { | |
| 512 email.style.display = 'none'; | |
| 513 var span = document.getElementById('email-readonly'); | |
| 514 span.appendChild(document.createTextNode(email.value)); | |
| 515 span.style.display = 'inline'; | |
| 516 this.setElementDisplay_("create-account-div", "none"); | |
| 517 } | |
| 518 | |
| 519 f.accessCode.disabled = true; | |
| 520 } | |
| 521 | |
| 522 if (1 == args.error) { | |
| 523 var access_code = document.getElementById('access-code'); | |
| 524 if (access_code.value && access_code.value != "") { | |
| 525 this.setElementDisplay_("errormsg-0-access-code", 'block'); | |
| 526 this.showAccessCodeRequired_(); | |
| 527 } else { | |
| 528 this.setElementDisplay_("errormsg-1-password", 'table-row'); | |
| 529 } | |
| 530 this.setBlurbError_(args.error_message); | |
| 531 } else if (3 == args.error) { | |
| 532 this.setElementDisplay_("errormsg-0-connection", 'table-row'); | |
| 533 this.setBlurbError_(args.error_message); | |
| 534 } else if (4 == args.error) { | |
| 535 this.showCaptcha_(args); | |
| 536 } else if (8 == args.error) { | |
| 537 this.showAccessCodeRequired_(); | |
| 538 } else if (args.error_message) { | |
| 539 this.setBlurbError_(args.error_message); | |
| 540 } | |
| 541 | |
| 542 $('sign-in').disabled = false; | |
| 543 $('sign-in').value = templateData['signin']; | |
| 544 this.loginSetFocus_(); | |
| 545 }, | |
| 546 | |
| 547 resetErrorVisibility_: function() { | |
| 548 this.setElementDisplay_("errormsg-0-email", 'none'); | |
| 549 this.setElementDisplay_("errormsg-0-password", 'none'); | |
| 550 this.setElementDisplay_("errormsg-1-password", 'none'); | |
| 551 this.setElementDisplay_("errormsg-0-connection", 'none'); | |
| 552 this.setElementDisplay_("errormsg-0-access-code", 'none'); | |
| 553 }, | |
| 554 | |
| 555 setBlurbError_: function(error_message) { | |
| 556 if (this.captchaChallengeActive_) | |
| 557 return; // No blurb in captcha challenge mode. | |
| 558 | |
| 559 if (error_message) { | |
| 560 document.getElementById('error-signing-in').style.display = 'none'; | |
| 561 document.getElementById('error-custom').style.display = 'inline'; | |
| 562 document.getElementById('error-custom').textContent = error_message; | |
| 563 } else { | |
| 564 document.getElementById('error-signing-in').style.display = 'inline'; | |
| 565 document.getElementById('error-custom').style.display = 'none'; | |
| 566 } | |
| 567 | |
| 568 $('top-blurb-error').style.visibility = "visible"; | |
| 569 document.getElementById('gaia-email').disabled = false; | |
| 570 document.getElementById('gaia-passwd').disabled = false; | |
| 571 }, | |
| 572 | |
| 573 setErrorVisibility_: function() { | |
| 574 this.resetErrorVisibility_(); | |
| 575 var f = $('gaia-login-form'); | |
| 576 var email = $('gaia-email'); | |
| 577 var passwd = $('gaia-passwd'); | |
| 578 if (null == email.value || "" == email.value) { | |
| 579 this.setElementDisplay_("errormsg-0-email", 'table-row'); | |
| 580 this.setBlurbError_(); | |
| 581 return false; | |
| 582 } | |
| 583 if (null == passwd.value || "" == passwd.value) { | |
| 584 this.setElementDisplay_("errormsg-0-password", 'table-row'); | |
| 585 this.setBlurbError_(); | |
| 586 return false; | |
| 587 } | |
| 588 if (!f.accessCode.disabled && (null == f.accessCode.value || | |
| 589 "" == f.accessCode.value)) { | |
| 590 this.setElementDisplay_("errormsg-0-password", 'table-row'); | |
| 591 return false; | |
| 592 } | |
| 593 return true; | |
| 594 }, | |
| 595 | |
| 596 sendCredentialsAndClose_: function() { | |
| 597 if (!this.setErrorVisibility_()) { | |
| 598 return false; | |
| 599 } | |
| 600 | |
| 601 $('gaia-email').disabled = true; | |
| 602 $('gaia-passwd').disabled = true; | |
| 603 $('captcha-value').disabled = true; | |
| 604 $('access-code').disabled = true; | |
| 605 | |
| 606 $('logging-in-throbber').style.visibility = "visible"; | |
| 607 | |
| 608 var f = $('gaia-login-form'); | |
| 609 var email = $('gaia-email'); | |
| 610 var passwd = $('gaia-passwd'); | |
| 611 var result = JSON.stringify({"user" : email.value, | |
| 612 "pass" : passwd.value, | |
| 613 "captcha" : f.captchaValue.value, | |
| 614 "access_code" : f.accessCode.value}); | |
| 615 $('sign-in').disabled = true; | |
| 616 chrome.send("SubmitAuth", [result]); | |
| 617 }, | |
| 618 | |
| 619 showGaiaSuccessAndClose_: function() { | |
| 620 $('sign-in').value = localStrings.getString('loginSuccess'); | |
| 621 setTimeout(this.closeOverlay_, 1600); | |
| 622 }, | |
| 623 | |
| 624 showSuccessAndSettingUp_: function() { | |
| 625 $('sign-in').value = localStrings.getString('settingUp'); | |
| 626 }, | |
| 627 | |
| 628 /** @inheritDoc */ | |
| 629 shouldClose: function() { | |
| 630 if (!$('cancel-warning-box').hidden) { | |
| 631 chrome.send('PassphraseCancel', ['']); | |
| 632 return true; | |
| 633 } else if (!$('sync-setup-passphrase').classList.contains('hidden')) { | |
| 634 // The Passphrase page is showing, and the use has pressed escape. | |
| 635 // Activate the cancel logic in this case. | |
| 636 this.showCancelWarning_(); | |
| 637 return false; | |
| 638 } | |
| 639 | |
| 640 return true; | |
| 641 }, | |
| 642 }; | |
| 643 | |
| 644 SyncSetupOverlay.showSyncSetupPage = function(page, args) { | |
| 645 SyncSetupOverlay.getInstance().showSyncSetupPage_(page, args); | |
| 646 }; | |
| 647 | |
| 648 SyncSetupOverlay.showSuccessAndClose = function() { | |
| 649 SyncSetupOverlay.getInstance().showSuccessAndClose_(); | |
| 650 }; | |
| 651 | |
| 652 SyncSetupOverlay.showSuccessAndSettingUp = function() { | |
| 653 SyncSetupOverlay.getInstance().showSuccessAndSettingUp_(); | |
| 654 }; | |
| 655 | |
| 656 // Export | |
| 657 return { | |
| 658 SyncSetupOverlay: SyncSetupOverlay | |
| 659 }; | |
| 660 }); | |
| OLD | NEW |