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 if (this.timeZoneAutoDetect_) { |
186 this.getPref('cros.system.timezone').value == | 192 if (this.timeZoneList_[0].value == |
187 this.timeZoneList_[0].value) { | 193 (this.getPref('cros.flags.per_user_timezone_enabled').value ? |
188 return; | 194 this.getPref('settings.timezone').value : |
195 this.getPref('cros.system.timezone').value)) { | |
196 return; | |
197 } | |
189 } | 198 } |
190 | 199 |
191 cr.sendWithPromise('getTimeZones').then(this.setTimeZoneList_.bind(this)); | 200 cr.sendWithPromise('getTimeZones').then(this.setTimeZoneList_.bind(this)); |
192 }, | 201 }, |
193 | 202 |
194 /** | 203 /** |
195 * Converts the C++ response into an array of menu options. | 204 * Converts the C++ response into an array of menu options. |
196 * @param {!Array<!Array<string>>} timeZones C++ time zones response. | 205 * @param {!Array<!Array<string>>} timeZones C++ time zones response. |
197 * @private | 206 * @private |
198 */ | 207 */ |
199 setTimeZoneList_: function(timeZones) { | 208 setTimeZoneList_: function(timeZones) { |
200 this.timeZoneList_ = timeZones.map(function(timeZonePair) { | 209 this.timeZoneList_ = timeZones.map(function(timeZonePair) { |
201 return { | 210 return { |
202 name: timeZonePair[1], | 211 name: timeZonePair[1], |
203 value: timeZonePair[0], | 212 value: timeZonePair[0], |
204 }; | 213 }; |
205 }); | 214 }); |
206 }, | 215 }, |
216 | |
217 /** | |
218 * Computes visibility of user timezone preference. | |
219 * @param prefUserTimezone Object pref.settings.timezone | |
220 * @param prefResolveValue Boolean | |
221 * prefs.settings.resolve_timezone_by_geolocation.value | |
222 * @private | |
223 */ | |
224 isUserTimeZoneSelectorHidden_: function(prefUserTimezone, prefResolveValue) { | |
225 return (prefUserTimezone && prefUserTimezone.controlledBy != null) || | |
226 (prefResolveValue == true); | |
stevenjb
2017/07/10 19:10:53
nit: () not needed for ==
Alexander Alekseev
2017/07/14 03:32:47
Done.
| |
227 }, | |
228 | |
229 /** | |
230 * Observer of this.prefs.cros.flags.per_user_timezone_enabled.value . | |
231 * If it becomes disabled, adds legacy observer. | |
232 * @private | |
233 */ | |
234 onPerUserTimezoneEnabledChanged_: function() { | |
235 if (this.nonPerUserTimezoneSeen_) | |
236 return; | |
237 | |
238 if (!this.getPref('cros.flags.per_user_timezone_enabled').value) { | |
stevenjb
2017/07/10 19:10:53
invert and early exit
Alexander Alekseev
2017/07/14 03:32:47
Done.
| |
239 this.nonPerUserTimezoneSeen_ = true; | |
240 // This is polymer private API, but we could probably remove this method | |
241 // before switching to polymer 2.0 . | |
242 this['_addComplexObserverEffect'].call( | |
243 this, | |
244 'maybeGetTimeZoneList_(' + | |
245 'prefs.cros.system.timezone.value, timeZoneAutoDetect_)'); | |
246 } | |
247 }, | |
207 }); | 248 }); |
OLD | NEW |