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 @@
'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_search_field',
'<(DEPTH)/ui/webui/resources/cr_elements/policy/compiled_resources2.gyp:cr_policy_indicator_behavior',
'../compiled_resources2.gyp:direction_delegate',
'../compiled_resources2.gyp:global_scroll_target_behavior',
'../prefs/compiled_resources2.gyp:prefs',
......
......@@ -87,6 +87,20 @@ Polymer({
this.$.drawer.closeDrawer();
}.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')) {
this.pageVisibility_ = {
people: false,
......
......@@ -7,7 +7,6 @@
'target_name': 'cr_policy_indicator_behavior',
'dependencies': [
'<(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'],
},
......
......@@ -6,6 +6,19 @@
* @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} */
var CrPolicyIndicatorType = {
DEVICE_POLICY: 'devicePolicy',
......@@ -57,35 +70,30 @@ var CrPolicyIndicatorBehavior = {
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 {string} name The name associated with the controllable. See
* @param {string} name The name associated with the indicator. See
* 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|.
*/
getPolicyIndicatorTooltip: function(type, name) {
getPolicyIndicatorTooltip: function(type, name, opt_matches) {
if (!CrPolicyStrings)
return ''; // Tooltips may not be defined, e.g. in OOBE.
switch (type) {
case CrPolicyIndicatorType.PRIMARY_USER:
return this.i18n_('controlledSettingShared', name);
return CrPolicyStrings.controlledSettingShared.replace('$1', name);
case CrPolicyIndicatorType.OWNER:
return this.i18n_('controlledSettingOwner', name);
return CrPolicyStrings.controlledSettingOwner.replace('$1', name);
case CrPolicyIndicatorType.USER_POLICY:
case CrPolicyIndicatorType.DEVICE_POLICY:
return this.i18n_('controlledSettingPolicy');
return CrPolicyStrings.controlledSettingPolicy;
case CrPolicyIndicatorType.RECOMMENDED:
// This case is not handled here since it requires knowledge of the
// value and recommended value associated with the controllable.
assertNotReached();
return opt_matches ?
CrPolicyStrings.controlledSettingRecommendedMatches :
CrPolicyStrings.controlledSettingRecommendedDiffers;
}
return '';
}
},
};
......@@ -75,18 +75,14 @@ Polymer({
* @private
*/
getTooltip_: function() {
if (this.indicatorType == CrPolicyIndicatorType.NONE)
return '';
if (this.indicatorType == CrPolicyIndicatorType.RECOMMENDED) {
if (!this.property)
return '';
var matches;
if (this.indicatorType == CrPolicyIndicatorType.RECOMMENDED &&
this.property) {
var value = this.property.Active;
if (value == undefined && this.property.Effective)
value = this.property[this.property.Effective];
if (value == this.recommended_)
return this.i18n_('controlledSettingRecommendedMatches');
return this.i18n_('controlledSettingRecommendedDiffers');
matches = value == this.recommended_;
}
return this.getPolicyIndicatorTooltip(this.indicatorType, '');
return this.getPolicyIndicatorTooltip(this.indicatorType, '', matches);
}
});
......@@ -37,11 +37,8 @@ Polymer({
* @private
*/
getTooltip_: function(type, pref) {
if (type == CrPolicyIndicatorType.RECOMMENDED) {
if (pref && pref.value == pref.recommendedValue)
return this.i18n_('controlledSettingRecommendedMatches');
return this.i18n_('controlledSettingRecommendedDiffers');
}
return this.getPolicyIndicatorTooltip(type, pref.controlledByName || '');
var matches = pref && pref.value == pref.recommendedValue;
return this.getPolicyIndicatorTooltip(
type, pref.controlledByName || '', matches);
}
});
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