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..7a0f77afb8cfd9a2ea4cb9d6b58c84961de48ce8 |
--- /dev/null |
+++ b/ui/webui/resources/cr_elements/v1_0/policy/cr_policy_indicator.js |
@@ -0,0 +1,100 @@ |
+// 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: 'primary', |
+ 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: Object, value: IndicatorType.NONE}, |
+ }, |
+ |
+ observers: ['prefPropertyChanged_(pref.*)'], |
+ |
+ /** |
+ * Polymer observer for pref. |
+ * @private |
+ */ |
+ prefPropertyChanged_: function(pref) { |
+ if (!pref) |
+ return; |
+ if (pref.path != 'pref.policySource' && |
+ pref.path != 'pref.policyEnforcement') { |
+ return; |
Dan Beam
2015/08/28 00:20:22
nit: combine ifs
stevenjb
2015/08/28 23:18:08
Done.
|
+ } |
+ 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; |
Dan Beam
2015/08/28 00:20:22
why PRIMARY vs PRIMARY_USER?
stevenjb
2015/08/28 23:18:08
Done.
|
+ else if (source == chrome.settingsPrivate.PolicySource.OWNER) |
+ type = IndicatorType.OWNER; |
+ else if (source == chrome.settingsPrivate.PolicySource.USER) |
+ type = IndicatorType.USER_POLICY; |
Dan Beam
2015/08/28 00:20:22
why USER vs USER_POLICY?
stevenjb
2015/08/28 23:18:08
Yeah, I should fix that in the idl. Done.
|
+ else if (source == chrome.settingsPrivate.PolicySource.DEVICE) |
+ type = IndicatorType.DEVICE_POLICY; |
Dan Beam
2015/08/28 00:20:22
why DEVICE vs DEVICE_POLICY?
stevenjb
2015/08/28 23:18:08
Done.
|
+ 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 |
+ */ |
+ showIndicator_: function(type) { return type != IndicatorType.NONE; }, |
Dan Beam
2015/08/28 00:20:22
this sounds like a method to show an indicator, no
stevenjb
2015/08/28 23:18:08
Done.
|
+ |
+ /** |
+ * @param {IndicatorType} type |
+ * @return {string} The iron-icons icon name. |
+ * @private |
+ */ |
+ getIcon_: function(type) { |
+ switch (type) { |
+ case IndicatorType.PRIMARY: |
+ 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'; |
+ } |
Dan Beam
2015/08/28 00:20:22
should there be an assertNotReached() here?
stevenjb
2015/08/28 23:18:08
Done (hadn't seen that in our JS before).
|
+ return ''; |
+ } |
+}); |