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('new_tab', function() { | 5 cr.define('new_tab', function() { |
6 /** | 6 /** |
7 * NewTabSyncPromo class | 7 * NewTabSyncPromo class |
8 * Subclass of options.SyncSetupOverlay that customizes the sync setup | 8 * Subclass of options.SyncSetupOverlay that customizes the sync setup |
9 * overlay for use in the new tab page. | 9 * overlay for use in the new tab page. |
10 * @class | 10 * @class |
11 */ | 11 */ |
12 function NewTabSyncPromo() { | 12 function NewTabSyncPromo() { |
13 options.SyncSetupOverlay.call(this, 'syncSetup', | 13 options.SyncSetupOverlay.call(this, 'syncSetup', |
14 templateData.syncSetupOverlayTitle, | 14 templateData.syncSetupOverlayTitle, |
15 'sync-setup-overlay'); | 15 'sync-setup-overlay'); |
16 } | 16 } |
17 | 17 |
18 cr.addSingletonGetter(NewTabSyncPromo); | 18 cr.addSingletonGetter(NewTabSyncPromo); |
19 | 19 |
20 NewTabSyncPromo.prototype = { | 20 NewTabSyncPromo.prototype = { |
21 __proto__: options.SyncSetupOverlay.prototype, | 21 __proto__: options.SyncSetupOverlay.prototype, |
22 | 22 |
23 // Variable to track if the promo is expanded or collapsed. | 23 // Variable to track if the promo is expanded or collapsed. |
24 isSyncPromoExpanded_: false, | 24 isSyncPromoExpanded_: false, |
25 | 25 |
| 26 // Variable to track if the login name should be clickable. |
| 27 isLoginNameClickable_ : false, |
| 28 |
| 29 // Variable to track if the user is signed into sync. |
| 30 isUserSignedIntoSync_ : false, |
| 31 |
| 32 // Override SyncSetupOverlay::showOverlay_ to expand the sync promo when the |
| 33 // overlay is shown. |
26 showOverlay_: function() { | 34 showOverlay_: function() { |
27 this.expandSyncPromo_(true); | 35 this.isSyncPromoExpanded_ = true; |
| 36 $('sync-promo-login-status').hidden = true; |
| 37 $('sync-setup-overlay').hidden = false; |
| 38 $('sync-promo').classList.remove('collapsed'); |
| 39 layoutSections(); |
| 40 }, |
| 41 |
| 42 // Override SyncSetupOverlay::closeOverlay_ to collapse the sync promo when |
| 43 // the overlay is closed. |
| 44 closeOverlay_: function() { |
| 45 options.SyncSetupOverlay.prototype.closeOverlay_.call(this); |
| 46 this.isSyncPromoExpanded_ = false; |
| 47 $('sync-promo-login-status').hidden = false; |
| 48 $('sync-setup-overlay').hidden = true; |
| 49 $('sync-promo').classList.add('collapsed'); |
| 50 layoutSections(); |
| 51 |
| 52 // If the overlay is being closed because the user pressed cancelled |
| 53 // then we need to ensure that chrome knows about it. |
| 54 chrome.send('CollapseSyncPromo'); |
28 }, | 55 }, |
29 | 56 |
30 // Initializes the page. | 57 // Initializes the page. |
31 initializePage: function() { | 58 initializePage: function() { |
32 options.SyncSetupOverlay.prototype.initializePage.call(this); | 59 options.SyncSetupOverlay.prototype.initializePage.call(this); |
33 var self = this; | 60 var self = this; |
34 $('sync-promo-toggle-button').onclick = function() { | 61 $('sync-promo-toggle-button').onclick = function() { |
35 self.onTogglePromo(); | 62 self.onTogglePromo(); |
36 } | 63 } |
| 64 $('sync-promo-login-status-cell').onclick = function() { |
| 65 self.onLoginNameClicked(); |
| 66 } |
37 chrome.send('InitializeSyncPromo'); | 67 chrome.send('InitializeSyncPromo'); |
38 }, | 68 }, |
39 | 69 |
40 // Handler for the toggle button to show or hide the sync promo. | 70 // Handler for the toggle button to show or hide the sync promo. |
41 onTogglePromo: function() { | 71 onTogglePromo: function() { |
42 if (this.isSyncPromoExpanded_) { | 72 if (this.isSyncPromoExpanded_) { |
43 this.expandSyncPromo_(false); | |
44 chrome.send('CollapseSyncPromo'); | 73 chrome.send('CollapseSyncPromo'); |
| 74 this.closeOverlay_(); |
45 } else { | 75 } else { |
46 chrome.send('ExpandSyncPromo'); | 76 chrome.send('ExpandSyncPromo'); |
47 } | 77 } |
48 }, | 78 }, |
49 | 79 |
50 // Shows or hides the sync promo. | 80 // Called when the user clicks the login name on the top right of the sync |
51 expandSyncPromo_: function(shouldExpand) { | 81 // promo. If the user isn't signed in then we just expand the sync promo. |
52 this.isSyncPromoExpanded_ = shouldExpand; | 82 // If the user is signed in then we ask Chrome to show the profile menu. |
53 if (shouldExpand) { | 83 onLoginNameClicked: function() { |
54 $('sync-promo-login-status').hidden = true; | 84 if (!this.isLoginNameClickable_) |
55 $('sync-setup-overlay').hidden = false; | 85 return; |
56 $('sync-promo').classList.remove('collapsed'); | 86 |
| 87 if (this.isUserSignedIntoSync_) |
| 88 chrome.send('ShowProfileMenu'); |
| 89 else |
| 90 this.onTogglePromo(); |
| 91 }, |
| 92 |
| 93 // Updates the sync login status. If the user is not logged in then it |
| 94 // shows the sync promo toggle button. |
| 95 updateLogin_: function(login_status_msg, icon_url, is_signed_in, |
| 96 is_clickable) { |
| 97 $('sync-promo-login-status-msg').textContent = login_status_msg; |
| 98 this.isUserSignedIntoSync_ = is_signed_in; |
| 99 $('sync-promo-toggle').hidden = is_signed_in; |
| 100 |
| 101 if (icon_url == "") { |
| 102 $('login-status-avatar-icon').hidden = true; |
57 } else { | 103 } else { |
58 $('sync-promo-login-status').hidden = false; | 104 $('login-status-avatar-icon').hidden = false; |
59 $('sync-setup-overlay').hidden = true; | 105 $('login-status-avatar-icon').src = icon_url; |
60 $('sync-promo').classList.add('collapsed'); | |
61 } | 106 } |
| 107 |
| 108 this.isLoginNameClickable_ = is_clickable; |
| 109 if (is_clickable) |
| 110 $('sync-promo-login-status-cell').style.cursor = "pointer"; |
| 111 else |
| 112 $('sync-promo-login-status-cell').style.cursor = "default"; |
| 113 |
62 layoutSections(); | 114 layoutSections(); |
63 }, | 115 }, |
64 | 116 |
65 // Sets the sync login name. If there's no login name then makes the | |
66 // 'not connected' UI visible and shows the sync promo toggle button. | |
67 updateLogin_: function(user_name) { | |
68 if (user_name) { | |
69 $('sync-promo-toggle').hidden = true; | |
70 $('sync-promo-user-name').textContent = user_name; | |
71 $('sync-promo-not-connected').hidden = true; | |
72 } else { | |
73 $('sync-promo-toggle').hidden = false; | |
74 $('sync-promo-user-name').hidden = true; | |
75 $('sync-promo-not-connected').hidden = false; | |
76 } | |
77 layoutSections(); | |
78 }, | |
79 | |
80 // Shows the sync promo. | 117 // Shows the sync promo. |
81 showSyncPromo_: function() { | 118 showSyncPromo_: function() { |
82 $('sync-promo').hidden = false; | 119 $('sync-promo').hidden = false; |
83 }, | 120 }, |
84 }; | 121 }; |
85 | 122 |
86 NewTabSyncPromo.showErrorUI = function() { | 123 NewTabSyncPromo.showErrorUI = function() { |
87 NewTabSyncPromo.getInstance().showErrorUI_(); | 124 NewTabSyncPromo.getInstance().showErrorUI_(); |
88 }; | 125 }; |
89 | 126 |
(...skipping 18 matching lines...) Expand all Loading... |
108 }; | 145 }; |
109 | 146 |
110 NewTabSyncPromo.initialize = function() { | 147 NewTabSyncPromo.initialize = function() { |
111 NewTabSyncPromo.getInstance().initializePage(); | 148 NewTabSyncPromo.getInstance().initializePage(); |
112 } | 149 } |
113 | 150 |
114 NewTabSyncPromo.showSyncPromo = function() { | 151 NewTabSyncPromo.showSyncPromo = function() { |
115 NewTabSyncPromo.getInstance().showSyncPromo_(); | 152 NewTabSyncPromo.getInstance().showSyncPromo_(); |
116 } | 153 } |
117 | 154 |
118 NewTabSyncPromo.updateLogin = function(user_name) { | 155 NewTabSyncPromo.updateLogin = function(user_name, icon_url, is_signed_in, |
119 NewTabSyncPromo.getInstance().updateLogin_(user_name); | 156 is_clickable) { |
| 157 NewTabSyncPromo.getInstance().updateLogin_( |
| 158 user_name, icon_url, is_signed_in, is_clickable); |
120 } | 159 } |
121 | 160 |
122 // Export | 161 // Export |
123 return { | 162 return { |
124 NewTabSyncPromo : NewTabSyncPromo | 163 NewTabSyncPromo : NewTabSyncPromo |
125 }; | 164 }; |
126 }); | 165 }); |
127 | 166 |
128 var OptionsPage = options.OptionsPage; | 167 var OptionsPage = options.OptionsPage; |
129 var SyncSetupOverlay = new_tab.NewTabSyncPromo; | 168 var SyncSetupOverlay = new_tab.NewTabSyncPromo; |
130 window.addEventListener('DOMContentLoaded', new_tab.NewTabSyncPromo.initialize); | 169 window.addEventListener('DOMContentLoaded', new_tab.NewTabSyncPromo.initialize); |
OLD | NEW |