Commit 7482287f authored by stevenjb's avatar stevenjb Committed by Commit bot

Eliminate loadTimeData dependency from cr_elements/policy

BUG=670767
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2624043002
Cr-Commit-Position: refs/heads/master@{#443100}
parent b0066bb3
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
'dependencies': [ 'dependencies': [
'<(DEPTH)/ui/webui/resources/cr_elements/cr_toolbar/compiled_resources2.gyp:cr_toolbar', '<(DEPTH)/ui/webui/resources/cr_elements/cr_toolbar/compiled_resources2.gyp:cr_toolbar',
'<(DEPTH)/ui/webui/resources/cr_elements/cr_toolbar/compiled_resources2.gyp:cr_toolbar_search_field', '<(DEPTH)/ui/webui/resources/cr_elements/cr_toolbar/compiled_resources2.gyp:cr_toolbar_search_field',
'<(DEPTH)/ui/webui/resources/cr_elements/policy/compiled_resources2.gyp:cr_policy_indicator_behavior',
'../compiled_resources2.gyp:direction_delegate', '../compiled_resources2.gyp:direction_delegate',
'../compiled_resources2.gyp:global_scroll_target_behavior', '../compiled_resources2.gyp:global_scroll_target_behavior',
'../prefs/compiled_resources2.gyp:prefs', '../prefs/compiled_resources2.gyp:prefs',
......
...@@ -87,6 +87,20 @@ Polymer({ ...@@ -87,6 +87,20 @@ Polymer({
this.$.drawer.closeDrawer(); this.$.drawer.closeDrawer();
}.bind(this)); }.bind(this));
CrPolicyStrings = {
controlledSettingPolicy:
loadTimeData.getString('controlledSettingPolicy'),
controlledSettingRecommendedMatches:
loadTimeData.getString('controlledSettingRecommendedMatches'),
controlledSettingRecommendedDiffers:
loadTimeData.getString('controlledSettingRecommendedDiffers'),
// <if expr="chromeos">
controlledSettingShared:
loadTimeData.getString('controlledSettingShared'),
controlledSettingOwner: loadTimeData.getString('controlledSettingOwner'),
// </if>
};
if (loadTimeData.getBoolean('isGuest')) { if (loadTimeData.getBoolean('isGuest')) {
this.pageVisibility_ = { this.pageVisibility_ = {
people: false, people: false,
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
'target_name': 'cr_policy_indicator_behavior', 'target_name': 'cr_policy_indicator_behavior',
'dependencies': [ 'dependencies': [
'<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:assert', '<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:assert',
'<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:load_time_data',
], ],
'includes': ['../../../../../third_party/closure_compiler/compile_js2.gypi'], 'includes': ['../../../../../third_party/closure_compiler/compile_js2.gypi'],
}, },
......
...@@ -6,6 +6,19 @@ ...@@ -6,6 +6,19 @@
* @fileoverview Behavior for policy controlled indicators. * @fileoverview Behavior for policy controlled indicators.
*/ */
/**
* Strings required for policy indicators. These must be set at runtime.
* Chrome OS only strings may be undefined.
* @type {{
* controlledSettingPolicy: string,
* controlledSettingRecommendedMatches: string,
* controlledSettingRecommendedDiffers: string,
* controlledSettingShared: (string|undefined),
* controlledSettingOwner: (string|undefined),
* }}
*/
var CrPolicyStrings;
/** @enum {string} */ /** @enum {string} */
var CrPolicyIndicatorType = { var CrPolicyIndicatorType = {
DEVICE_POLICY: 'devicePolicy', DEVICE_POLICY: 'devicePolicy',
...@@ -57,35 +70,30 @@ var CrPolicyIndicatorBehavior = { ...@@ -57,35 +70,30 @@ var CrPolicyIndicatorBehavior = {
return 'cr:' + icon; return 'cr:' + icon;
}, },
/**
* @param {string} id The id of the string to translate.
* @param {string=} opt_name An optional name argument.
* @return The translated string.
*/
i18n_: function(id, opt_name) {
return loadTimeData.getStringF(id, opt_name);
},
/** /**
* @param {CrPolicyIndicatorType} type * @param {CrPolicyIndicatorType} type
* @param {string} name The name associated with the controllable. See * @param {string} name The name associated with the indicator. See
* chrome.settingsPrivate.PrefObject.controlledByName * chrome.settingsPrivate.PrefObject.controlledByName
* @param {boolean=} opt_matches For RECOMMENDED only, whether the indicator
* value matches the recommended value.
* @return {string} The tooltip text for |type|. * @return {string} The tooltip text for |type|.
*/ */
getPolicyIndicatorTooltip: function(type, name) { getPolicyIndicatorTooltip: function(type, name, opt_matches) {
if (!CrPolicyStrings)
return ''; // Tooltips may not be defined, e.g. in OOBE.
switch (type) { switch (type) {
case CrPolicyIndicatorType.PRIMARY_USER: case CrPolicyIndicatorType.PRIMARY_USER:
return this.i18n_('controlledSettingShared', name); return CrPolicyStrings.controlledSettingShared.replace('$1', name);
case CrPolicyIndicatorType.OWNER: case CrPolicyIndicatorType.OWNER:
return this.i18n_('controlledSettingOwner', name); return CrPolicyStrings.controlledSettingOwner.replace('$1', name);
case CrPolicyIndicatorType.USER_POLICY: case CrPolicyIndicatorType.USER_POLICY:
case CrPolicyIndicatorType.DEVICE_POLICY: case CrPolicyIndicatorType.DEVICE_POLICY:
return this.i18n_('controlledSettingPolicy'); return CrPolicyStrings.controlledSettingPolicy;
case CrPolicyIndicatorType.RECOMMENDED: case CrPolicyIndicatorType.RECOMMENDED:
// This case is not handled here since it requires knowledge of the return opt_matches ?
// value and recommended value associated with the controllable. CrPolicyStrings.controlledSettingRecommendedMatches :
assertNotReached(); CrPolicyStrings.controlledSettingRecommendedDiffers;
} }
return ''; return '';
} },
}; };
...@@ -75,18 +75,14 @@ Polymer({ ...@@ -75,18 +75,14 @@ Polymer({
* @private * @private
*/ */
getTooltip_: function() { getTooltip_: function() {
if (this.indicatorType == CrPolicyIndicatorType.NONE) var matches;
return ''; if (this.indicatorType == CrPolicyIndicatorType.RECOMMENDED &&
if (this.indicatorType == CrPolicyIndicatorType.RECOMMENDED) { this.property) {
if (!this.property)
return '';
var value = this.property.Active; var value = this.property.Active;
if (value == undefined && this.property.Effective) if (value == undefined && this.property.Effective)
value = this.property[this.property.Effective]; value = this.property[this.property.Effective];
if (value == this.recommended_) matches = value == this.recommended_;
return this.i18n_('controlledSettingRecommendedMatches');
return this.i18n_('controlledSettingRecommendedDiffers');
} }
return this.getPolicyIndicatorTooltip(this.indicatorType, ''); return this.getPolicyIndicatorTooltip(this.indicatorType, '', matches);
} }
}); });
...@@ -37,11 +37,8 @@ Polymer({ ...@@ -37,11 +37,8 @@ Polymer({
* @private * @private
*/ */
getTooltip_: function(type, pref) { getTooltip_: function(type, pref) {
if (type == CrPolicyIndicatorType.RECOMMENDED) { var matches = pref && pref.value == pref.recommendedValue;
if (pref && pref.value == pref.recommendedValue) return this.getPolicyIndicatorTooltip(
return this.i18n_('controlledSettingRecommendedMatches'); type, pref.controlledByName || '', matches);
return this.i18n_('controlledSettingRecommendedDiffers');
}
return this.getPolicyIndicatorTooltip(type, pref.controlledByName || '');
} }
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment