Chromium Code Reviews| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 | 80 |
| 81 /** | 81 /** |
| 82 * Whether date and time are settable. Normally the date and time are forced | 82 * Whether date and time are settable. Normally the date and time are forced |
| 83 * by network time, so default to false to initially hide the button. | 83 * by network time, so default to false to initially hide the button. |
| 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 | |
| 91 /** | |
| 92 * Boolean flag indicatined whether per-user timezone option is enabled. | |
|
michaelpg
2017/05/30 22:21:23
"indicating"
Alexander Alekseev
2017/07/06 06:30:29
Done.
| |
| 93 * @private | |
| 94 */ | |
| 95 perUserTimezoneEnabled_: { | |
| 96 type: Boolean, | |
| 97 value: function() { | |
| 98 return loadTimeData.getBoolean('perUserTimezoneEnabled'); | |
| 99 }, | |
| 100 }, | |
| 90 }, | 101 }, |
| 91 | 102 |
| 103 // We need two separate observers, because prefs.settings.timezone.value is | |
| 104 // undefined when per-user timezone option is disabled, so we cannot combine | |
| 105 // all three inputs in a single observer. | |
| 92 observers: [ | 106 observers: [ |
| 93 'maybeGetTimeZoneList_(' + | 107 'maybeGetTimeZoneList_(' + |
| 108 'prefs.settings.timezone.value, timeZoneAutoDetect_)', | |
| 109 'maybeGetTimeZoneList_(' + | |
| 94 'prefs.cros.system.timezone.value, timeZoneAutoDetect_)', | 110 'prefs.cros.system.timezone.value, timeZoneAutoDetect_)', |
| 95 ], | 111 ], |
|
stevenjb
2017/05/30 16:47:18
This is much cleaner, thanks!
Alexander Alekseev
2017/07/06 06:30:29
Done.
| |
| 96 | 112 |
| 97 /** @override */ | 113 /** @override */ |
| 98 attached: function() { | 114 attached: function() { |
| 99 this.addWebUIListener( | 115 this.addWebUIListener( |
| 100 'time-zone-auto-detect-policy', | 116 'time-zone-auto-detect-policy', |
| 101 this.onTimeZoneAutoDetectPolicyChanged_.bind(this)); | 117 this.onTimeZoneAutoDetectPolicyChanged_.bind(this)); |
| 102 this.addWebUIListener( | 118 this.addWebUIListener( |
| 103 'can-set-date-time-changed', this.onCanSetDateTimeChanged_.bind(this)); | 119 'can-set-date-time-changed', this.onCanSetDateTimeChanged_.bind(this)); |
| 104 | 120 |
| 105 chrome.send('dateTimePageReady'); | 121 chrome.send('dateTimePageReady'); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 /** | 191 /** |
| 176 * Fetches the list of time zones if necessary. | 192 * Fetches the list of time zones if necessary. |
| 177 * @private | 193 * @private |
| 178 */ | 194 */ |
| 179 maybeGetTimeZoneList_: function() { | 195 maybeGetTimeZoneList_: function() { |
| 180 // Only fetch the list once. | 196 // Only fetch the list once. |
| 181 if (this.timeZoneList_.length > 1 || !CrSettingsPrefs.isInitialized) | 197 if (this.timeZoneList_.length > 1 || !CrSettingsPrefs.isInitialized) |
| 182 return; | 198 return; |
| 183 | 199 |
| 184 // If auto-detect is enabled, we only need the current time zone. | 200 // If auto-detect is enabled, we only need the current time zone. |
| 185 if (this.timeZoneAutoDetect_ && | 201 if (this.perUserTimezoneEnabled_) { |
|
michaelpg
2017/05/30 22:21:23
optional: use the "if" described in the comment.
Alexander Alekseev
2017/07/06 06:30:29
Done.
| |
| 186 this.getPref('cros.system.timezone').value == | 202 if (this.timeZoneAutoDetect_ && |
| 187 this.timeZoneList_[0].value) { | 203 this.getPref('settings.timezone').value == |
| 188 return; | 204 this.timeZoneList_[0].value) { |
| 205 return; | |
| 206 } | |
| 207 } else { | |
| 208 if (this.timeZoneAutoDetect_ && | |
| 209 this.getPref('cros.system.timezone').value == | |
| 210 this.timeZoneList_[0].value) { | |
| 211 return; | |
| 212 } | |
| 189 } | 213 } |
| 190 | 214 |
| 191 cr.sendWithPromise('getTimeZones').then(this.setTimeZoneList_.bind(this)); | 215 cr.sendWithPromise('getTimeZones').then(this.setTimeZoneList_.bind(this)); |
| 192 }, | 216 }, |
| 193 | 217 |
| 194 /** | 218 /** |
| 195 * Converts the C++ response into an array of menu options. | 219 * Converts the C++ response into an array of menu options. |
| 196 * @param {!Array<!Array<string>>} timeZones C++ time zones response. | 220 * @param {!Array<!Array<string>>} timeZones C++ time zones response. |
| 197 * @private | 221 * @private |
| 198 */ | 222 */ |
| 199 setTimeZoneList_: function(timeZones) { | 223 setTimeZoneList_: function(timeZones) { |
| 200 this.timeZoneList_ = timeZones.map(function(timeZonePair) { | 224 this.timeZoneList_ = timeZones.map(function(timeZonePair) { |
| 201 return { | 225 return { |
| 202 name: timeZonePair[1], | 226 name: timeZonePair[1], |
| 203 value: timeZonePair[0], | 227 value: timeZonePair[0], |
| 204 }; | 228 }; |
| 205 }); | 229 }); |
| 206 }, | 230 }, |
| 231 | |
| 232 /** | |
| 233 * Computes visibility of user timezone preference. | |
| 234 * @param prefUserTimezone Object pref.settings.timezone | |
| 235 * @param prefResolveValue Boolean | |
| 236 * prefs.settings.resolve_timezone_by_geolocation.value | |
| 237 * @private | |
| 238 */ | |
| 239 isUserTimeZoneSelectorHidden_: function(prefUserTimezone, prefResolveValue) { | |
| 240 return (prefUserTimezone && prefUserTimezone.controlledBy != null) || | |
| 241 (prefResolveValue == true); | |
| 242 }, | |
| 207 }); | 243 }); |
| OLD | NEW |