OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 /** | |
6 * @fileoverview Polymer element for indicating policies that apply to an | |
7 * element controlling a settings preference. | |
8 */ | |
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-indicator */ | |
26 Polymer({ | |
27 is: 'cr-policy-indicator', | |
28 | |
29 properties: { | |
30 /** | |
31 * Optional preference object associated with the indicator. Initialized to | |
32 * null so that computed functions will get called if this is never set. | |
33 * @type {?chrome.settingsPrivate.PrefObject} | |
34 */ | |
35 pref: {type: Object, value: null}, | |
36 | |
37 /** | |
38 * 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. | |
40 * Initialized to '' so that computed functions will get called if this is | |
41 * never set. | |
42 */ | |
43 controllingUser: {type: String, value: ''}, | |
44 | |
45 /** | |
46 * Which indicator type to show (or NONE). | |
47 * @type {CrPolicyIndicator.Type} | |
48 */ | |
49 indicatorType: {type: String, value: CrPolicyIndicator.Type.NONE}, | |
50 }, | |
51 | |
52 observers: ['prefPolicyChanged_(pref.policySource, pref.policyEnforcement)'], | |
53 | |
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 }, | |
79 | |
80 /** | |
81 * @param {CrPolicyIndicator.Type} 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 | |
125 * @param {string} controllingUser The user controlling the setting, if |pref| | |
126 * is null. | |
127 * @return {string} The tooltip text for |type|. | |
128 * @private | |
129 */ | |
130 getTooltipText_: function(type, pref, controllingUser) { | |
131 var name = pref ? pref.policySourceName : controllingUser; | |
132 | |
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 } | |
150 }); | |
151 })(); | |
OLD | NEW |