OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Polymer element for indicating policies that apply to an | 6 * @fileoverview Polymer element for indicating policies that apply to an |
7 * element controlling a settings preference. | 7 * element controlling a settings preference. |
| 8 * |
| 9 * @element cr-policy-pref-indicator |
8 */ | 10 */ |
9 | |
10 var CrPolicyIndicator = { | |
11 /** @enum {string} */ | |
12 Type: { | |
13 DEVICE_POLICY: 'devicePolicy', | |
14 EXTENSION: 'extension', | |
15 NONE: 'none', | |
16 OWNER: 'owner', | |
17 PRIMARY_USER: 'primary_user', | |
18 RECOMMENDED: 'recommended', | |
19 USER_POLICY: 'userPolicy', | |
20 }, | |
21 }; | |
22 | |
23 (function() { | |
24 | |
25 /** @element cr-policy-pref-indicator */ | |
26 Polymer({ | 11 Polymer({ |
27 is: 'cr-policy-pref-indicator', | 12 is: 'cr-policy-pref-indicator', |
28 | 13 |
| 14 behaviors: [CrPolicyIndicatorBehavior, CrPolicyPrefBehavior], |
| 15 |
29 properties: { | 16 properties: { |
30 /** | 17 /** |
31 * Optional preference object associated with the indicator. Initialized to | 18 * Optional preference object associated with the indicator. Initialized to |
32 * null so that computed functions will get called if this is never set. | 19 * null so that computed functions will get called if this is never set. |
33 * @type {?chrome.settingsPrivate.PrefObject} | 20 * @type {?chrome.settingsPrivate.PrefObject} |
34 */ | 21 */ |
35 pref: {type: Object, value: null}, | 22 pref: {type: Object, value: null}, |
36 | 23 |
37 /** | 24 /** |
38 * Optional email of the user controlling the setting when the setting does | 25 * Optional email of the user controlling the setting when the setting does |
39 * not correspond to a pref (Chrome OS only). Only used when pref is null. | 26 * not correspond to a pref (Chrome OS only). Only used when pref is null. |
40 * Initialized to '' so that computed functions will get called if this is | 27 * Initialized to '' so that computed functions will get called if this is |
41 * never set. | 28 * never set. TODO(stevenjb/michaelpg): Create a separate indicator for |
| 29 * non-pref (i.e. explicitly set) indicators (see languyage_detail_page). |
42 */ | 30 */ |
43 controllingUser: {type: String, value: ''}, | 31 controllingUser: {type: String, value: ''}, |
44 | 32 |
45 /** | 33 /** |
46 * Which indicator type to show (or NONE). | 34 * Which indicator type to show (or NONE). |
47 * @type {CrPolicyIndicator.Type} | 35 * @type {CrPolicyIndicatorType} |
48 */ | 36 */ |
49 indicatorType: {type: String, value: CrPolicyIndicator.Type.NONE}, | 37 indicatorType: { |
50 }, | 38 type: String, |
51 | 39 value: CrPolicyIndicatorType.NONE, |
52 observers: ['prefPolicyChanged_(pref.policySource, pref.policyEnforcement)'], | 40 computed: 'getIndicatorType(pref.policySource, pref.policyEnforcement)', |
53 | 41 }, |
54 /** | |
55 * Polymer observer for pref. | |
56 * @param {chrome.settingsPrivate.PolicySource} source | |
57 * @param {chrome.settingsPrivate.PolicyEnforcement} enforcement | |
58 * @private | |
59 */ | |
60 prefPolicyChanged_: function(source, enforcement) { | |
61 var type = CrPolicyIndicator.Type.NONE; | |
62 if (enforcement == chrome.settingsPrivate.PolicyEnforcement.ENFORCED) { | |
63 if (source == chrome.settingsPrivate.PolicySource.PRIMARY_USER) | |
64 type = CrPolicyIndicator.Type.PRIMARY_USER; | |
65 else if (source == chrome.settingsPrivate.PolicySource.OWNER) | |
66 type = CrPolicyIndicator.Type.OWNER; | |
67 else if (source == chrome.settingsPrivate.PolicySource.USER_POLICY) | |
68 type = CrPolicyIndicator.Type.USER_POLICY; | |
69 else if (source == chrome.settingsPrivate.PolicySource.DEVICE_POLICY) | |
70 type = CrPolicyIndicator.Type.DEVICE_POLICY; | |
71 else if (source == chrome.settingsPrivate.PolicySource.EXTENSION) | |
72 type = CrPolicyIndicator.Type.EXTENSION; | |
73 } else if (enforcement == | |
74 chrome.settingsPrivate.PolicyEnforcement.RECOMMENDED) { | |
75 type = CrPolicyIndicator.Type.RECOMMENDED; | |
76 } | |
77 this.indicatorType = type; | |
78 }, | 42 }, |
79 | 43 |
80 /** | 44 /** |
81 * @param {CrPolicyIndicator.Type} type | 45 * @param {CrPolicyIndicatorType} type |
82 * @return {boolean} True if the indicator should be shown. | |
83 * @private | |
84 */ | |
85 isIndicatorVisible_: function(type) { | |
86 return type != CrPolicyIndicator.Type.NONE; | |
87 }, | |
88 | |
89 /** | |
90 * @param {CrPolicyIndicator.Type} type | |
91 * @return {string} The iron-icons icon name. | |
92 * @private | |
93 */ | |
94 getIcon_: function(type) { | |
95 switch (type) { | |
96 case CrPolicyIndicator.Type.NONE: | |
97 return ''; | |
98 case CrPolicyIndicator.Type.PRIMARY_USER: | |
99 return 'social:group'; | |
100 case CrPolicyIndicator.Type.OWNER: | |
101 return 'social:person'; | |
102 case CrPolicyIndicator.Type.USER_POLICY: | |
103 case CrPolicyIndicator.Type.DEVICE_POLICY: | |
104 return 'social:domain'; | |
105 case CrPolicyIndicator.Type.EXTENSION: | |
106 return 'extension'; | |
107 case CrPolicyIndicator.Type.RECOMMENDED: | |
108 return 'social:domain'; | |
109 } | |
110 assertNotReached(); | |
111 }, | |
112 | |
113 /** | |
114 * @param {string} id The id of the string to translate. | |
115 * @param {string=} opt_name An optional name argument. | |
116 * @return The translated string. | |
117 */ | |
118 i18n_: function (id, opt_name) { | |
119 return loadTimeData.getStringF(id, opt_name); | |
120 }, | |
121 | |
122 /** | |
123 * @param {CrPolicyIndicator.Type} type The type of indicator. | |
124 * @param {?chrome.settingsPrivate.PrefObject} pref | 46 * @param {?chrome.settingsPrivate.PrefObject} pref |
125 * @param {string} controllingUser The user controlling the setting, if |pref| | |
126 * is null. | |
127 * @return {string} The tooltip text for |type|. | 47 * @return {string} The tooltip text for |type|. |
128 * @private | 48 * @private |
129 */ | 49 */ |
130 getTooltipText_: function(type, pref, controllingUser) { | 50 getTooltip_: function(type, pref, controllingUser) { |
| 51 if (type == CrPolicyIndicatorType.RECOMMENDED) { |
| 52 if (pref && pref.value == pref.recommendedValue) |
| 53 return this.i18n_('controlledSettingRecommendedMatches'); |
| 54 return this.i18n_('controlledSettingRecommendedDiffers'); |
| 55 } |
131 var name = pref ? pref.policySourceName : controllingUser; | 56 var name = pref ? pref.policySourceName : controllingUser; |
132 | 57 return this.getPolicyIndicatorTooltip(type, name); |
133 switch (type) { | |
134 case CrPolicyIndicator.Type.PRIMARY_USER: | |
135 return this.i18n_('controlledSettingShared', name); | |
136 case CrPolicyIndicator.Type.OWNER: | |
137 return this.i18n_('controlledSettingOwner', name); | |
138 case CrPolicyIndicator.Type.USER_POLICY: | |
139 case CrPolicyIndicator.Type.DEVICE_POLICY: | |
140 return this.i18n_('controlledSettingPolicy'); | |
141 case CrPolicyIndicator.Type.EXTENSION: | |
142 return this.i18n_('controlledSettingExtension', name); | |
143 case CrPolicyIndicator.Type.RECOMMENDED: | |
144 if (pref && pref.value == pref.recommendedValue) | |
145 return this.i18n_('controlledSettingRecommendedMatches'); | |
146 return this.i18n_('controlledSettingRecommendedDiffers'); | |
147 } | |
148 return ''; | |
149 } | 58 } |
150 }); | 59 }); |
151 })(); | |
OLD | NEW |