OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * 'settings-date-time-page' is the settings page containing date and time | 7 * 'settings-date-time-page' is the settings page containing date and time |
8 * settings. | 8 * settings. |
9 */ | 9 */ |
10 | 10 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 * @private | 84 * @private |
85 */ | 85 */ |
86 canSetDateTime_: { | 86 canSetDateTime_: { |
87 type: Boolean, | 87 type: Boolean, |
88 value: false, | 88 value: false, |
89 }, | 89 }, |
90 }, | 90 }, |
91 | 91 |
92 observers: [ | 92 observers: [ |
93 'maybeGetTimeZoneList_(' + | 93 'maybeGetTimeZoneList_(' + |
94 'prefs.cros.system.timezone.value, timeZoneAutoDetect_)', | 94 'prefs.settings.timezone.value, timeZoneAutoDetect_)', |
| 95 'onPerUserTimezoneEnabledChanged_(' + |
| 96 'prefs.cros.flags.per_user_timezone_enabled.value)', |
95 ], | 97 ], |
96 | 98 |
| 99 // True if !prefs.cros.flags.per_user_timezone_enabled.value has been |
| 100 // acknowledged. |
| 101 nonPerUserTimezoneSeen_: false, |
| 102 |
97 /** @override */ | 103 /** @override */ |
98 attached: function() { | 104 attached: function() { |
99 this.addWebUIListener( | 105 this.addWebUIListener( |
100 'time-zone-auto-detect-policy', | 106 'time-zone-auto-detect-policy', |
101 this.onTimeZoneAutoDetectPolicyChanged_.bind(this)); | 107 this.onTimeZoneAutoDetectPolicyChanged_.bind(this)); |
102 this.addWebUIListener( | 108 this.addWebUIListener( |
103 'can-set-date-time-changed', this.onCanSetDateTimeChanged_.bind(this)); | 109 'can-set-date-time-changed', this.onCanSetDateTimeChanged_.bind(this)); |
104 | 110 |
105 chrome.send('dateTimePageReady'); | 111 chrome.send('dateTimePageReady'); |
106 this.maybeGetTimeZoneList_(); | 112 this.maybeGetTimeZoneList_(); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 /** | 181 /** |
176 * Fetches the list of time zones if necessary. | 182 * Fetches the list of time zones if necessary. |
177 * @private | 183 * @private |
178 */ | 184 */ |
179 maybeGetTimeZoneList_: function() { | 185 maybeGetTimeZoneList_: function() { |
180 // Only fetch the list once. | 186 // Only fetch the list once. |
181 if (this.timeZoneList_.length > 1 || !CrSettingsPrefs.isInitialized) | 187 if (this.timeZoneList_.length > 1 || !CrSettingsPrefs.isInitialized) |
182 return; | 188 return; |
183 | 189 |
184 // If auto-detect is enabled, we only need the current time zone. | 190 // If auto-detect is enabled, we only need the current time zone. |
185 if (this.timeZoneAutoDetect_ && | 191 var pref = this.getPref('cros.flags.per_user_timezone_enabled'); |
186 this.getPref('cros.system.timezone').value == | 192 if (pref && pref.value) { |
187 this.timeZoneList_[0].value) { | 193 if (this.timeZoneAutoDetect_ && |
188 return; | 194 this.getPref('settings.timezone').value == |
| 195 this.timeZoneList_[0].value) { |
| 196 return; |
| 197 } |
| 198 } else { |
| 199 if (this.timeZoneAutoDetect_ && |
| 200 this.getPref('cros.system.timezone').value == |
| 201 this.timeZoneList_[0].value) { |
| 202 return; |
| 203 } |
189 } | 204 } |
190 | 205 |
191 cr.sendWithPromise('getTimeZones').then(this.setTimeZoneList_.bind(this)); | 206 cr.sendWithPromise('getTimeZones').then(this.setTimeZoneList_.bind(this)); |
192 }, | 207 }, |
193 | 208 |
194 /** | 209 /** |
195 * Converts the C++ response into an array of menu options. | 210 * Converts the C++ response into an array of menu options. |
196 * @param {!Array<!Array<string>>} timeZones C++ time zones response. | 211 * @param {!Array<!Array<string>>} timeZones C++ time zones response. |
197 * @private | 212 * @private |
198 */ | 213 */ |
199 setTimeZoneList_: function(timeZones) { | 214 setTimeZoneList_: function(timeZones) { |
200 this.timeZoneList_ = timeZones.map(function(timeZonePair) { | 215 this.timeZoneList_ = timeZones.map(function(timeZonePair) { |
201 return { | 216 return { |
202 name: timeZonePair[1], | 217 name: timeZonePair[1], |
203 value: timeZonePair[0], | 218 value: timeZonePair[0], |
204 }; | 219 }; |
205 }); | 220 }); |
206 }, | 221 }, |
| 222 |
| 223 /** |
| 224 * Computes visibility of user timezone preference. |
| 225 * @param prefUserTimezone Object pref.settings.timezone |
| 226 * @param prefResolveValue Boolean |
| 227 * prefs.settings.resolve_timezone_by_geolocation.value |
| 228 * @private |
| 229 */ |
| 230 isUserTimeZoneSelectorHidden_: function(prefUserTimezone, prefResolveValue) { |
| 231 return (prefUserTimezone && prefUserTimezone.controlledBy != null) || |
| 232 (prefResolveValue == true); |
| 233 }, |
| 234 |
| 235 /** |
| 236 * Observer of this.prefs.cros.flags.per_user_timezone_enabled.value . |
| 237 * If it becomes disabled, adds legacy observer. |
| 238 * @private |
| 239 */ |
| 240 onPerUserTimezoneEnabledChanged_: function() { |
| 241 if (this.nonPerUserTimezoneSeen_) |
| 242 return; |
| 243 |
| 244 var pref = this.getPref('cros.flags.per_user_timezone_enabled'); |
| 245 if (!pref || !pref.value) { |
| 246 this.nonPerUserTimezoneSeen_ = true; |
| 247 // This is polymer private API, but we could probably remove this method |
| 248 // before switching to polymer 2.0 . |
| 249 this.get('_addComplexObserverEffect').call(this, |
| 250 'maybeGetTimeZoneList_(' + |
| 251 'prefs.cros.system.timezone.value, timeZoneAutoDetect_)'); |
| 252 } |
| 253 }, |
207 }); | 254 }); |
OLD | NEW |