Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: chrome/browser/resources/settings/date_time_page/date_time_page.js

Issue 2393703005: MD Settings: Date and Time page, part 1/3 (Closed)
Patch Set: . Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/settings/date_time_page/date_time_page.js
diff --git a/chrome/browser/resources/settings/date_time_page/date_time_page.js b/chrome/browser/resources/settings/date_time_page/date_time_page.js
index d933992762b99f4c8f4aea52b31cecc661dcb7ea..75ad8ebb65530d44657a896b73af1d28a4126305 100644
--- a/chrome/browser/resources/settings/date_time_page/date_time_page.js
+++ b/chrome/browser/resources/settings/date_time_page/date_time_page.js
@@ -4,33 +4,146 @@
/**
* @fileoverview
- * 'settings-date-time-page' is the settings page containing date-time
+ * 'settings-date-time-page' is the settings page containing date and time
* settings.
- *
- * Example:
- *
- * <core-animated-pages>
- * <settings-date-time-page prefs="{{prefs}}">
- * </settings-date-time-page>
- * ... other pages ...
- * </core-animated-pages>
*/
+
+cr.exportPath('settings');
+
+/**
+ * Possible values of the system time-zone auto-detection policy. Must stay in
+ * sync with AutomaticTimezoneDetectionType in chrome_device_policy.proto.
+ * @enum {number}
+ * @const
+ */
+settings.AutomaticTimezoneDetectionPolicy = {
+ USERS_DECIDE: 0,
+ DISABLED: 1,
+ IP_ONLY: 2,
+ SEND_WIFI_ACCESS_POINTS: 3,
+};
+
Polymer({
is: 'settings-date-time-page',
+ behaviors: [PrefsBehavior],
+
properties: {
- /**
- * Preferences state.
- */
+ /** Preferences state. */
prefs: {
type: Object,
- notify: true
+ notify: true,
+ },
+
+ /**
+ * If the time zone is managed at the system level, the user cannot control
+ * any time zone settings.
+ * @private
+ */
+ systemTimeZoneManaged_: {
+ type: Boolean,
+ value: function() {
+ return loadTimeData.getBoolean('systemTimeZoneManaged');
+ },
+ },
+
+ /**
+ * If the time zone auto-detection setting is managed at the system level,
+ * the user cannot override the setting unless the policy is USERS_DECIDE.
+ * @private
+ */
+ systemTimeZoneDetectionManaged_: {
+ type: Boolean,
+ value: function() {
+ return loadTimeData.getBoolean(
+ 'systemTimeZoneDetectionManaged');
+ },
+ },
+
+ /**
+ * Value of the system time zone auto-detection policy, or null if system
+ * time zone auto-detection is not managed.
+ * @private {?settings.AutomaticTimezoneDetectionPolicy}
+ */
+ systemTimeZoneDetectionPolicyValue_: {
+ type: Number,
+ value: function() {
+ return loadTimeData.valueExists('systemTimeZoneDetectionPolicyValue') ?
+ /** @type {settings.AutomaticTimezoneDetectionPolicy} */(
+ loadTimeData.getInteger('systemTimeZoneDetectionPolicyValue')) :
+ null;
+ },
},
/**
- * Dictionary defining page visibility.
- * @type {!DateTimePageVisibility}
+ * Hides the time zone auto-detection feature when the
+ * --disable-timezone-tracking-option flag is set.
+ * @private
*/
- pageVisibility: Object,
+ hideTimeZoneDetection_: {
+ type: Boolean,
+ value: function() {
+ return loadTimeData.valueExists('hideTimeZoneDetection') &&
+ loadTimeData.getBoolean('hideTimeZoneDetection');
+ },
+ readOnly: true,
+ },
+ },
+
+ observers: [
+ // TODO(michaelpg): Implement a BrowserProxy to listen for policy changes.
+ 'updateTimeZoneDetectionCheckbox_(' +
+ 'prefs.settings.resolve_timezone_by_geolocation.value,' +
+ 'systemTimeZoneManaged_,' +
+ 'systemTimeZoneDetectionManaged_,' +
+ 'systemTimeZoneDetectionPolicyValue_)',
+ ],
+
+ /**
+ * Processes all the time zone preferences and policy interactions in one
+ * observer function instead of complicating the HTML with computed bindings.
+ * @param {boolean} userPrefValue
+ * @param {boolean} systemTimeZoneManaged
+ * @param {boolean} systemTimeZoneDetectionManaged
+ * @param {?settings.AutomaticTimezoneDetectionPolicy}
+ * systemTimeZoneDetectionPolicyValue
+ */
+ updateTimeZoneDetectionCheckbox_(userPrefValue,
+ systemTimeZoneManaged,
+ systemTimeZoneDetectionManaged,
+ systemTimeZoneDetectionPolicyValue) {
+ // Do nothing if the feature is disabled by a flag.
+ if (this.hideTimeZoneDetection_)
+ return;
+
+ var checkbox = this.$.timeZoneDetectionCheckbox;
+
+ // Time zone auto-detection is disabled when the time zone is managed.
+ if (systemTimeZoneManaged) {
+ checkbox.disabled = true;
+ checkbox.checked = false;
+ return;
+ }
+
+ // The time zone auto-detection policy may force-disable auto-detection.
+ if (systemTimeZoneDetectionManaged &&
+ systemTimeZoneDetectionPolicyValue !=
+ settings.AutomaticTimezoneDetectionPolicy.USERS_DECIDE) {
+ checkbox.disabled = true;
+ checkbox.checked =
+ systemTimeZoneDetectionPolicyValue !=
+ settings.AutomaticTimezoneDetectionPolicy.DISABLED;
+ return;
+ }
+
+ // If there is no policy, or the policy is USERS_DECIDE, the pref is used.
+ checkbox.disabled = false;
+ checkbox.checked = userPrefValue;
+ },
+
+ /** @param {!Event} e */
+ onTimeZoneDetectionCheckboxChange_: function(e) {
+ this.setPrefValue(
+ 'settings.resolve_timezone_by_geolocation', e.target.checked);
},
});

Powered by Google App Engine
This is Rietveld 408576698