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-time | 7 * 'settings-date-time-page' is the settings page containing date and time |
8 * settings. | 8 * settings. |
9 * | |
10 * Example: | |
11 * | |
12 * <core-animated-pages> | |
13 * <settings-date-time-page prefs="{{prefs}}"> | |
14 * </settings-date-time-page> | |
15 * ... other pages ... | |
16 * </core-animated-pages> | |
17 */ | 9 */ |
| 10 |
| 11 cr.exportPath('settings'); |
| 12 |
| 13 /** |
| 14 * Possible values of the system time-zone auto-detection policy. Must stay in |
| 15 * sync with AutomaticTimezoneDetectionType in chrome_device_policy.proto. |
| 16 * @enum {number} |
| 17 * @const |
| 18 */ |
| 19 settings.AutomaticTimezoneDetectionPolicy = { |
| 20 USERS_DECIDE: 0, |
| 21 DISABLED: 1, |
| 22 IP_ONLY: 2, |
| 23 SEND_WIFI_ACCESS_POINTS: 3, |
| 24 }; |
| 25 |
18 Polymer({ | 26 Polymer({ |
19 is: 'settings-date-time-page', | 27 is: 'settings-date-time-page', |
20 | 28 |
| 29 behaviors: [PrefsBehavior], |
| 30 |
21 properties: { | 31 properties: { |
22 /** | 32 /** Preferences state. */ |
23 * Preferences state. | |
24 */ | |
25 prefs: { | 33 prefs: { |
26 type: Object, | 34 type: Object, |
27 notify: true | 35 notify: true, |
28 }, | 36 }, |
29 | 37 |
30 /** | 38 /** |
31 * Dictionary defining page visibility. | 39 * If the time zone is managed at the system level, the user cannot control |
32 * @type {!DateTimePageVisibility} | 40 * any time zone settings. |
| 41 * @private |
33 */ | 42 */ |
34 pageVisibility: Object, | 43 systemTimeZoneManaged_: { |
| 44 type: Boolean, |
| 45 value: function() { |
| 46 return loadTimeData.getBoolean('systemTimeZoneManaged'); |
| 47 }, |
| 48 }, |
| 49 |
| 50 /** |
| 51 * If the time zone auto-detection setting is managed at the system level, |
| 52 * the user cannot override the setting unless the policy is USERS_DECIDE. |
| 53 * @private |
| 54 */ |
| 55 systemTimeZoneDetectionManaged_: { |
| 56 type: Boolean, |
| 57 value: function() { |
| 58 return loadTimeData.getBoolean( |
| 59 'systemTimeZoneDetectionManaged'); |
| 60 }, |
| 61 }, |
| 62 |
| 63 /** |
| 64 * Value of the system time zone auto-detection policy, or null if system |
| 65 * time zone auto-detection is not managed. |
| 66 * @private {?settings.AutomaticTimezoneDetectionPolicy} |
| 67 */ |
| 68 systemTimeZoneDetectionPolicyValue_: { |
| 69 type: Number, |
| 70 value: function() { |
| 71 return loadTimeData.valueExists('systemTimeZoneDetectionPolicyValue') ? |
| 72 /** @type {settings.AutomaticTimezoneDetectionPolicy} */( |
| 73 loadTimeData.getInteger('systemTimeZoneDetectionPolicyValue')) : |
| 74 null; |
| 75 }, |
| 76 }, |
| 77 |
| 78 /** |
| 79 * Hides the time zone auto-detection feature when the |
| 80 * --disable-timezone-tracking-option flag is set. |
| 81 * @private |
| 82 */ |
| 83 hideTimeZoneDetection_: { |
| 84 type: Boolean, |
| 85 value: function() { |
| 86 return loadTimeData.valueExists('hideTimeZoneDetection') && |
| 87 loadTimeData.getBoolean('hideTimeZoneDetection'); |
| 88 }, |
| 89 readOnly: true, |
| 90 }, |
| 91 }, |
| 92 |
| 93 observers: [ |
| 94 // TODO(michaelpg): Implement a BrowserProxy to listen for policy changes. |
| 95 'updateTimeZoneDetectionCheckbox_(' + |
| 96 'prefs.settings.resolve_timezone_by_geolocation.value,' + |
| 97 'systemTimeZoneManaged_,' + |
| 98 'systemTimeZoneDetectionManaged_,' + |
| 99 'systemTimeZoneDetectionPolicyValue_)', |
| 100 ], |
| 101 |
| 102 /** |
| 103 * Processes all the time zone preferences and policy interactions in one |
| 104 * observer function instead of complicating the HTML with computed bindings. |
| 105 * @param {boolean} userPrefValue |
| 106 * @param {boolean} systemTimeZoneManaged |
| 107 * @param {boolean} systemTimeZoneDetectionManaged |
| 108 * @param {?settings.AutomaticTimezoneDetectionPolicy} |
| 109 * systemTimeZoneDetectionPolicyValue |
| 110 */ |
| 111 updateTimeZoneDetectionCheckbox_(userPrefValue, |
| 112 systemTimeZoneManaged, |
| 113 systemTimeZoneDetectionManaged, |
| 114 systemTimeZoneDetectionPolicyValue) { |
| 115 // Do nothing if the feature is disabled by a flag. |
| 116 if (this.hideTimeZoneDetection_) |
| 117 return; |
| 118 |
| 119 var checkbox = this.$.timeZoneDetectionCheckbox; |
| 120 |
| 121 // Time zone auto-detection is disabled when the time zone is managed. |
| 122 if (systemTimeZoneManaged) { |
| 123 checkbox.disabled = true; |
| 124 checkbox.checked = false; |
| 125 return; |
| 126 } |
| 127 |
| 128 // The time zone auto-detection policy may force-disable auto-detection. |
| 129 if (systemTimeZoneDetectionManaged && |
| 130 systemTimeZoneDetectionPolicyValue != |
| 131 settings.AutomaticTimezoneDetectionPolicy.USERS_DECIDE) { |
| 132 checkbox.disabled = true; |
| 133 checkbox.checked = |
| 134 systemTimeZoneDetectionPolicyValue != |
| 135 settings.AutomaticTimezoneDetectionPolicy.DISABLED; |
| 136 return; |
| 137 } |
| 138 |
| 139 // If there is no policy, or the policy is USERS_DECIDE, the pref is used. |
| 140 checkbox.disabled = false; |
| 141 checkbox.checked = userPrefValue; |
| 142 }, |
| 143 |
| 144 /** @param {!Event} e */ |
| 145 onTimeZoneDetectionCheckboxChange_: function(e) { |
| 146 this.setPrefValue( |
| 147 'settings.resolve_timezone_by_geolocation', e.target.checked); |
35 }, | 148 }, |
36 }); | 149 }); |
OLD | NEW |