Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: ui/webui/resources/cr_elements/v1_0/policy/cr_policy_pref_indicator.js

Issue 1391433003: Extract policy indicator behavior (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue_521791_network_indicators_a
Patch Set: . Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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: {type: String, value: CrPolicyIndicatorType.NONE},
50 }, 38 },
51 39
52 observers: ['prefPolicyChanged_(pref.policySource, pref.policyEnforcement)'], 40 observers: ['prefPolicyChanged_(pref.policySource, pref.policyEnforcement)'],
Dan Beam 2015/10/15 04:31:01 it seems like indicatorType should just be compute
stevenjb 2015/10/15 22:56:22 Yes, better. Done.
53 41
54 /** 42 /**
55 * Polymer observer for pref. 43 * Polymer observer for pref.
56 * @param {chrome.settingsPrivate.PolicySource} source 44 * @param {chrome.settingsPrivate.PolicySource} source
57 * @param {chrome.settingsPrivate.PolicyEnforcement} enforcement 45 * @param {chrome.settingsPrivate.PolicyEnforcement} enforcement
58 * @private 46 * @private
59 */ 47 */
60 prefPolicyChanged_: function(source, enforcement) { 48 prefPolicyChanged_: function(source, enforcement) {
61 var type = CrPolicyIndicator.Type.NONE; 49 this.indicatorType = this.getIndicatorType(source, enforcement);
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 }, 50 },
79 51
80 /** 52 /**
81 * @param {CrPolicyIndicator.Type} type 53 * @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 54 * @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|. 55 * @return {string} The tooltip text for |type|.
128 * @private 56 * @private
129 */ 57 */
130 getTooltipText_: function(type, pref, controllingUser) { 58 getTooltip_: function(type, pref, controllingUser) {
59 if (type == CrPolicyIndicatorType.RECOMMENDED) {
60 if (pref && pref.value == pref.recommendedValue)
61 return this.i18n_('controlledSettingRecommendedMatches');
62 return this.i18n_('controlledSettingRecommendedDiffers');
63 }
131 var name = pref ? pref.policySourceName : controllingUser; 64 var name = pref ? pref.policySourceName : controllingUser;
132 65 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 } 66 }
150 }); 67 });
151 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698