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

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

Issue 2696903005: Move common cr-policy-indicator behavior into CrPolicyIndicatorBehavior (Closed)
Patch Set: remove behavior from Settings controls that have indicators Created 3 years, 10 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 */ 8 */
9 Polymer({ 9 Polymer({
10 is: 'cr-policy-pref-indicator', 10 is: 'cr-policy-pref-indicator',
11 11
12 behaviors: [CrPolicyIndicatorBehavior, CrPolicyPrefBehavior], 12 behaviors: [CrPolicyIndicatorBehavior],
13 13
14 properties: { 14 properties: {
15 /** 15 /**
16 * Optional preference object associated with the indicator. Initialized to 16 * Optional preference object associated with the indicator. Initialized to
17 * null so that computed functions will get called if this is never set. 17 * null so that computed functions will get called if this is never set.
18 * @type {!chrome.settingsPrivate.PrefObject|undefined} 18 * @type {!chrome.settingsPrivate.PrefObject|undefined}
19 */ 19 */
20 pref: Object, 20 pref: Object,
21 21
22 /** 22 /**
23 * Which indicator type to show (or NONE). 23 * Which indicator type to show (or NONE).
24 * @type {CrPolicyIndicatorType} 24 * @type {CrPolicyIndicatorType}
25 * @private 25 * @override
stevenjb (google-dont-use) 2017/02/22 01:01:10 Huh. Didn't realize we can do this. It's a little
michaelpg 2017/02/22 21:00:01 Sometimes it would be nice to have real inheritanc
26 */ 26 */
27 indicatorType_: { 27 indicatorType: {
28 type: String, 28 type: String,
29 value: CrPolicyIndicatorType.NONE, 29 value: CrPolicyIndicatorType.NONE,
30 computed: 'getIndicatorType(pref.controlledBy, pref.enforcement)', 30 computed: 'getIndicatorType_(pref.controlledBy, pref.enforcement)',
stevenjb (google-dont-use) 2017/02/22 01:01:10 maybe getIndicatorTypeForPref_?
michaelpg 2017/02/22 21:00:01 Done.
31 },
32
33 /** @override */
34 indicatorTooltip: {
35 type: String,
36 computed: 'getIndicatorTooltipForPref_(indicatorType, pref.*)',
31 }, 37 },
32 }, 38 },
33 39
34 /** 40 /**
35 * @param {CrPolicyIndicatorType} type 41 * @param {!chrome.settingsPrivate.ControlledBy|undefined} controlledBy
36 * @return {string} The tooltip text for |type|. 42 * @param {!chrome.settingsPrivate.Enforcement|undefined} enforcement
37 * @private 43 * @return {CrPolicyIndicatorType} The indicator type based on |controlledBy|
44 * and |enforcement|.
38 */ 45 */
39 getTooltip_: function(type) { 46 getIndicatorType_: function(controlledBy, enforcement) {
40 var matches = !!this.pref && this.pref.value == this.pref.recommendedValue; 47 if (enforcement == chrome.settingsPrivate.Enforcement.RECOMMENDED)
41 return this.getPolicyIndicatorTooltip( 48 return CrPolicyIndicatorType.RECOMMENDED;
42 type, this.pref.controlledByName || '', matches); 49 if (enforcement == chrome.settingsPrivate.Enforcement.ENFORCED) {
50 switch (controlledBy) {
51 case chrome.settingsPrivate.ControlledBy.PRIMARY_USER:
52 return CrPolicyIndicatorType.PRIMARY_USER;
53 case chrome.settingsPrivate.ControlledBy.OWNER:
54 return CrPolicyIndicatorType.OWNER;
55 case chrome.settingsPrivate.ControlledBy.USER_POLICY:
56 return CrPolicyIndicatorType.USER_POLICY;
57 case chrome.settingsPrivate.ControlledBy.DEVICE_POLICY:
58 return CrPolicyIndicatorType.DEVICE_POLICY;
59 }
60 }
61 return CrPolicyIndicatorType.NONE;
43 }, 62 },
44 63
45 /** 64 /**
46 * @return {boolean} Whether the policy indicator is on. Useful for testing. 65 * @param {CrPolicyIndicatorType} indicatorType
66 * @return {string} The tooltip text for |indicatorType|.
67 * @private
47 */ 68 */
48 isActive: function() { 69 getIndicatorTooltipForPref_: function(indicatorType) {
49 return this.isIndicatorVisible(this.indicatorType_); 70 var matches = this.pref && this.pref.value == this.pref.recommendedValue;
71 return this.getIndicatorTooltip(
72 indicatorType, this.pref.controlledByName || '', matches);
50 }, 73 },
51 }); 74 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698