// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// TODO(sail): Refactor options_page and remove this include.
cr.define('sync_promo', function() {
/**
* SyncPromo class
* Subclass of options.SyncSetupOverlay that customizes the sync setup
* overlay for use in the new tab page.
* @class
*/
function SyncPromo() {
options.SyncSetupOverlay.call(this, 'syncSetup',
loadTimeData.getString('syncSetupOverlayTabTitle'),
'sync-setup-overlay');
}
// Replicating enum from chrome/common/extensions/extension_constants.h.
/** @const */ var actions = (function() {
var i = 0;
return {
VIEWED: i++,
LEARN_MORE_CLICKED: i++,
ACCOUNT_HELP_CLICKED: i++,
CREATE_ACCOUNT_CLICKED: i++,
SKIP_CLICKED: i++,
SIGN_IN_ATTEMPTED: i++,
SIGNED_IN_SUCCESSFULLY: i++,
ADVANCED_CLICKED: i++,
ENCRYPTION_HELP_CLICKED: i++,
CANCELLED_AFTER_SIGN_IN: i++,
CONFIRMED_AFTER_SIGN_IN: i++,
CLOSED_TAB: i++,
CLOSED_WINDOW: i++,
LEFT_DURING_THROBBER: i++,
};
}());
cr.addSingletonGetter(SyncPromo);
SyncPromo.prototype = {
__proto__: options.SyncSetupOverlay.prototype,
showOverlay_: function() {
$('sync-setup-overlay').hidden = false;
},
closeOverlay_: function() {
chrome.send('SyncPromo:Close');
},
// Initializes the page.
initializePage: function() {
options.SyncSetupOverlay.prototype.initializePage.call(this);
// Hide parts of the login UI and show the promo UI.
this.hideOuterLoginUI_();
$('promo-skip').hidden = false;
this.showSetupUI_();
chrome.send('SyncPromo:Initialize');
var self = this;
$('promo-skip-button').addEventListener('click', function() {
chrome.send('SyncPromo:UserSkipped');
self.closeOverlay_();
});
var learnMoreClickedAlready = false;
$('promo-learn-more').addEventListener('click', function() {
if (!learnMoreClickedAlready)
chrome.send('SyncPromo:UserFlowAction', [actions.LEARN_MORE_CLICKED]);
learnMoreClickedAlready = true;
});
$('promo-advanced').addEventListener('click', function() {
chrome.send('SyncPromo:ShowAdvancedSettings');
});
var accountHelpClickedAlready = false;
$('cannot-access-account-link').addEventListener('click', function() {
if (!accountHelpClickedAlready)
chrome.send('SyncPromo:UserFlowAction',
[actions.ACCOUNT_HELP_CLICKED]);
accountHelpClickedAlready = true;
});
var createAccountClickedAlready = false;
$('create-account-link').addEventListener('click', function() {
if (!createAccountClickedAlready)
chrome.send('SyncPromo:UserFlowAction',
[actions.CREATE_ACCOUNT_CLICKED]);
createAccountClickedAlready = true;
});
// We listen to the