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

Side by Side Diff: chrome/browser/resources/settings/checkbox/checkbox.js

Issue 1310373008: Add cr_policy_indicator for settings controls (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@md_settings_compiled_resources_3
Patch Set: Feedback Created 5 years, 3 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 6 * @fileoverview
7 * `cr-settings-checkbox` is a checkbox that controls a supplied preference. 7 * `cr-settings-checkbox` is a checkbox that controls a supplied preference.
8 * 8 *
9 * Example: 9 * Example:
10 * <cr-settings-checkbox pref="{{prefs.settings.enableFoo}}" 10 * <cr-settings-checkbox pref="{{prefs.settings.enableFoo}}"
11 * label="Enable foo setting." subLabel="(bar also)"> 11 * label="Enable foo setting." subLabel="(bar also)">
12 * </cr-settings-checkbox> 12 * </cr-settings-checkbox>
13 * 13 *
14 * @element cr-settings-checkbox 14 * @element cr-settings-checkbox
15 */ 15 */
16 Polymer({ 16 Polymer({
17 is: 'cr-settings-checkbox', 17 is: 'cr-settings-checkbox',
18 18
19 properties: { 19 properties: {
20 /** 20 /**
21 * The boolean preference object to control. 21 * The boolean preference object to control.
22 * @type {?chrome.settingsPrivate.PrefObject} 22 * @type {?chrome.settingsPrivate.PrefObject}
23 */ 23 */
24 pref: { 24 pref: {
25 type: Object, 25 type: Object,
26 notify: true, 26 notify: true,
27 value: null 27 value: null,
28 }, 28 },
29 29
30 /** Whether the checkbox should represent the inverted value. */
30 inverted: { 31 inverted: {
31 type: Boolean, 32 type: Boolean,
32 value: false 33 value: false,
33 }, 34 },
34 35
36 /** Whether the checkbox is checked. */
35 checked: { 37 checked: {
36 type: Boolean, 38 type: Boolean,
37 value: false, 39 value: false,
38 observer: 'checkedChanged_' 40 observer: 'checkedChanged_',
39 }, 41 },
40 42
43 /** Disabled property for the element. */
44 disabled: {
45 type: Boolean,
46 value: false,
47 },
48
49 /** Checkbox label. */
41 label: { 50 label: {
42 type: String, 51 type: String,
43 value: '', 52 value: '',
44 }, 53 },
45 54
55 /** Additional sub-label for the checkbox. */
46 subLabel: { 56 subLabel: {
47 type: String, 57 type: String,
48 value: '', 58 value: '',
49 }, 59 },
50 }, 60 },
51 61
52 observers: [ 62 observers: [
53 'prefValueChanged_(pref.value)' 63 'prefValueChanged_(pref.value)'
54 ], 64 ],
55 65
56 /** @override */ 66 /** @override */
57 ready: function() { 67 ready: function() {
58 this.$.events.forward(this.$.checkbox, ['change']); 68 this.$.events.forward(this.$.checkbox, ['change']);
59 }, 69 },
60 70
61 /** @private */ 71 /**
72 * Polymer observer for pref.value
73 * @param {?chrome.settingsPrivate.PrefObject} prefValue
michaelpg 2015/09/16 18:58:52 the type of value is {*} -- pref is the PrefObject
stevenjb 2015/09/16 21:45:53 Ah, right, pref.value. Done.
74 * @private
75 */
62 prefValueChanged_: function(prefValue) { 76 prefValueChanged_: function(prefValue) {
63 // prefValue is initially undefined when Polymer initializes pref. 77 // prefValue is initially undefined when Polymer initializes pref.
64 if (prefValue !== undefined) { 78 if (prefValue !== undefined)
michaelpg 2015/09/16 18:58:52 should be able to remove this upon rebase
stevenjb 2015/09/16 21:45:53 Done.
65 this.checked = this.getNewValue_(prefValue); 79 this.checked = this.getNewValue_(prefValue);
66 }
67 }, 80 },
68 81
69 /** @private */ 82 /**
83 * Polymer observer for checked.
84 * @private
85 */
70 checkedChanged_: function() { 86 checkedChanged_: function() {
71 if (this.pref) { 87 this.set('pref.value', this.getNewValue_(this.checked));
72 this.set('pref.value', this.getNewValue_(this.checked));
73 }
74 }, 88 },
75 89
76 /** @private */ 90 /**
77 getNewValue_: function(val) { 91 * @param {*} value
78 return this.inverted ? !val : val; 92 * @return {boolean} The value as a boolean, inverted if |inverted| is true.
79 } 93 * @private
94 */
95 getNewValue_: function(value) {
96 return this.inverted ? !value : !!value;
97 },
98
99 /**
100 * @param {boolean} disabled
101 * @param {?chrome.settingsPrivate.PrefObject} pref
102 * @return {boolean} Whether the checkbox should be disabled.
103 * @private
104 */
105 checkboxDisabled_: function(disabled, pref) {
106 return disabled || (!!pref &&
107 pref.policyEnforcement ==
108 chrome.settingsPrivate.PolicyEnforcement.ENFORCED);
109 },
80 }); 110 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698