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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..43a23891b392dfaed50637178ae30ba8aa85e5a1 |
| --- /dev/null |
| +++ b/ui/webui/resources/cr_elements/v1_0/policy/cr_policy_indicator.js |
| @@ -0,0 +1,102 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * @fileoverview |
| + * @element cr-policy-indicator |
| + */ |
| + |
| +/** @enum {string} */ |
| +var IndicatorType = { |
| + DEVICE_POLICY: 'devicePolicy', |
| + EXTENSION: 'extension', |
| + NONE: 'none', |
| + OWNER: 'owner', |
| + PRIMARY_USER: 'primary_user', |
| + RECOMMENDED: 'recommended', |
| + USER_POLICY: 'userPolicy', |
| +}; |
| + |
| +Polymer({ |
| + is: 'cr-policy-indicator', |
| + |
| + properties: { |
| + /** |
| + * The preference object to show an indicator for. |
| + * @type {?chrome.settingsPrivate.PrefObject} |
| + */ |
| + pref: {type: Object, value: null}, |
| + |
| + /** |
| + * Which indicator type to show (or NONE). |
| + * @type {IndicatorType} |
| + */ |
| + indicatorType: {type: String, value: IndicatorType.NONE}, |
| + }, |
| + |
| + observers: [ |
| + 'prefPolicyChanged_(pref.policySource)', |
| + 'prefPolicyChanged_(pref.policyEnforcement)' |
|
Dan Beam
2015/09/16 21:02:19
'prefPolicyChanged_(pref.policySource, pref.policy
stevenjb
2015/09/16 21:33:53
Done.
|
| + ], |
| + |
| + /** |
| + * Polymer observer for pref. |
| + * @private |
| + */ |
| + prefPolicyChanged_: function() { |
| + if (!this.pref) |
| + return; |
| + var source = this.pref.policySource; |
| + var enforcement = this.pref.policyEnforcement; |
| + var type = IndicatorType.NONE; |
| + if (enforcement == chrome.settingsPrivate.PolicyEnforcement.ENFORCED) { |
| + if (source == chrome.settingsPrivate.PolicySource.PRIMARY_USER) |
| + type = IndicatorType.PRIMARY_USER; |
| + else if (source == chrome.settingsPrivate.PolicySource.OWNER) |
| + type = IndicatorType.OWNER; |
| + else if (source == chrome.settingsPrivate.PolicySource.USER_POLICY) |
| + type = IndicatorType.USER_POLICY; |
| + else if (source == chrome.settingsPrivate.PolicySource.DEVICE_POLICY) |
| + type = IndicatorType.DEVICE_POLICY; |
| + else if (source == chrome.settingsPrivate.PolicySource.EXTENSION) |
| + type = IndicatorType.EXTENSION; |
| + } else if (enforcement == |
| + chrome.settingsPrivate.PolicyEnforcement.RECOMMENDED) { |
| + type = IndicatorType.RECOMMENDED; |
| + } |
| + this.indicatorType = type; |
| + }, |
| + |
| + /** |
| + * @param {IndicatorType} type |
| + * @return {boolean} True if the indicator should be shown. |
| + * @private |
| + */ |
| + isIndicatorVisible_: function(type) { return type != IndicatorType.NONE; }, |
| + |
| + /** |
| + * @param {IndicatorType} type |
| + * @return {string} The iron-icons icon name. |
| + * @private |
| + */ |
| + getIcon_: function(type) { |
| + switch (type) { |
| + case IndicatorType.NONE: |
| + return ''; |
| + case IndicatorType.PRIMARY_USER: |
| + return 'social:group'; |
| + case IndicatorType.OWNER: |
| + return 'social:person'; |
| + case IndicatorType.USER_POLICY: |
| + case IndicatorType.DEVICE_POLICY: |
| + return 'social:domain'; |
| + case IndicatorType.EXTENSION: |
| + return 'extension'; |
| + case IndicatorType.RECOMMENDED: |
| + return 'social:domain'; |
| + } |
| + assertNotReached(); |
| + return ''; |
| + } |
| +}); |