Chromium Code Reviews| Index: ui/webui/resources/cr_elements/v1_0/policy/cr_policy_indicator.js |
| diff --git a/ui/webui/resources/cr_elements/v1_0/policy/cr_policy_indicator.js b/ui/webui/resources/cr_elements/v1_0/policy/cr_policy_indicator.js |
| index 486ff722035f4ef74d710a5acf7654fa4e94ca5d..5fa479e2f5b435b959be413d195ef958f70d4f2c 100644 |
| --- a/ui/webui/resources/cr_elements/v1_0/policy/cr_policy_indicator.js |
| +++ b/ui/webui/resources/cr_elements/v1_0/policy/cr_policy_indicator.js |
| @@ -3,10 +3,12 @@ |
| // found in the LICENSE file. |
| /** |
| - * @fileoverview |
| - * @element cr-policy-indicator |
| + * @fileoverview Polymer element for indicating policies that apply to an |
| + * element controlling a settings preference. |
| */ |
| +(function() { |
| + |
| /** @enum {string} */ |
| var IndicatorType = { |
| DEVICE_POLICY: 'devicePolicy', |
| @@ -18,6 +20,7 @@ var IndicatorType = { |
| USER_POLICY: 'userPolicy', |
| }; |
| +/** @element cr-policy-indicator */ |
| Polymer({ |
| is: 'cr-policy-indicator', |
| @@ -33,11 +36,17 @@ Polymer({ |
| * @type {IndicatorType} |
| */ |
| indicatorType: {type: String, value: IndicatorType.NONE}, |
| + |
| + /** |
| + * Polymer iron-meta instance for icon images |
| + * @type {Polymer.IronMeta} |
| + */ |
| + meta_: { |
| + value: Polymer.Base.create('iron-meta', {type: 'iconset'}) |
| + } |
| }, |
| - observers: [ |
| - 'prefPolicyChanged_(pref.policySource, pref.policyEnforcement)' |
| - ], |
| + observers: ['prefPolicyChanged_(pref.policySource, pref.policyEnforcement)'], |
| /** |
| * Polymer observer for pref. |
| @@ -63,6 +72,7 @@ Polymer({ |
| type = IndicatorType.RECOMMENDED; |
| } |
| this.indicatorType = type; |
| + this.updateIcon_(); |
| }, |
| /** |
| @@ -74,13 +84,11 @@ Polymer({ |
| /** |
| * @param {IndicatorType} type |
| - * @return {string} The iron-icons icon name. |
| + * @return {string|undefined} The iron-icons icon name for |type|. |
| * @private |
| */ |
| - getIcon_: function(type) { |
| + getIconForType_: function(type) { |
| switch (type) { |
| - case IndicatorType.NONE: |
| - return ''; |
| case IndicatorType.PRIMARY_USER: |
| return 'social:group'; |
| case IndicatorType.OWNER: |
| @@ -93,7 +101,59 @@ Polymer({ |
| case IndicatorType.RECOMMENDED: |
| return 'social:domain'; |
| } |
| - assertNotReached(); |
|
Dan Beam
2015/09/21 21:50:47
why did you remove this assertNotReached()?
stevenjb
2015/09/23 18:46:24
|type| could be undefined here. The assert didn't
|
| + return ''; |
| + }, |
| + |
| + /** |
| + * Creates or replaces the icon element for |indicatorType|. |
| + * @private |
| + */ |
| + updateIcon_: function() { |
| + var icon = this.getIconForType_(this.indicatorType); |
| + if (!icon) |
| + return; |
| + var parts = icon.split(':'); |
| + var iconName = parts.pop(); |
| + var iconsetName = parts.pop() || 'icons'; |
| + var iconset = |
| + /** @type {Polymer.IronIconsetSvg} */(this.meta_.byKey(iconsetName)); |
| + iconset.applyIcon(this.$.indicator, iconName); |
| + }, |
| + |
| + /** |
| + * @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 {IndicatorType} type The type of indicator. |
| + * @param {chrome.settingsPrivate.PrefObject} pref |
| + * @return {string} The tooltip text for |type|. |
| + * @private |
| + */ |
| + getTooltipText_: function(type, pref) { |
| + var name = pref.policySourceName || ''; |
| + switch (type) { |
| + case IndicatorType.PRIMARY_USER: |
| + return this.i18n_('controlledSettingShared', name); |
| + case IndicatorType.OWNER: |
| + return this.i18n_('controlledSettingOwner', name); |
| + case IndicatorType.USER_POLICY: |
| + case IndicatorType.DEVICE_POLICY: |
| + return this.i18n_('controlledSettingPolicy'); |
| + case IndicatorType.EXTENSION: |
| + return this.i18n_('controlledSettingExtension', name); |
| + case IndicatorType.RECOMMENDED: |
| + if (pref.value == pref.recommendedValue) |
| + return this.i18n_('controlledSettingRecommendedMatches'); |
| + else |
| + return this.i18n_('controlledSettingRecommendedDiffers'); |
| + } |
| return ''; |
| } |
| }); |
| +})(); |