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

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: Better observer pattern for cr_policy_indicator 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 }, 27 },
28 28
29 /** Whether the checkbox should represent the inverted value. */
29 inverted: { 30 inverted: {
30 type: Boolean, 31 type: Boolean,
31 value: false 32 value: false,
32 }, 33 },
33 34
35 /** Whether the checkbox is checked. */
34 checked: { 36 checked: {
35 type: Boolean, 37 type: Boolean,
36 value: false, 38 value: false,
37 observer: 'checkedChanged_' 39 observer: 'checkedChanged_',
38 }, 40 },
39 41
42 /** Disabled property for the element. */
43 disabled: {
44 type: Boolean,
45 value: false,
46 },
47
48 /** Checkbox label. */
40 label: { 49 label: {
41 type: String, 50 type: String,
42 value: '', 51 value: '',
43 }, 52 },
44 53
54 /** Additional sub-label for the checkbox. */
45 subLabel: { 55 subLabel: {
46 type: String, 56 type: String,
47 value: '', 57 value: '',
48 }, 58 },
49 }, 59 },
50 60
51 observers: [ 61 observers: [
52 'prefValueChanged_(pref.value)' 62 'prefValueChanged_(pref.value)'
53 ], 63 ],
54 64
55 /** @override */ 65 /** @override */
56 ready: function() { 66 ready: function() {
57 this.$.events.forward(this.$.checkbox, ['change']); 67 this.$.events.forward(this.$.checkbox, ['change']);
58 }, 68 },
59 69
60 /** @private */ 70 /**
71 * Polymer observer for pref.value
michaelpg 2015/09/17 02:19:25 nit: append "."
stevenjb 2015/09/17 17:33:31 Done.
72 * @param {*} prefValue
73 * @private
74 */
61 prefValueChanged_: function(prefValue) { 75 prefValueChanged_: function(prefValue) {
62 this.checked = this.getNewValue_(prefValue); 76 this.checked = this.getNewValue_(prefValue);
63 }, 77 },
64 78
65 /** @private */ 79 /**
80 * Polymer observer for checked.
81 * @private
82 */
66 checkedChanged_: function() { 83 checkedChanged_: function() {
67 if (this.pref) { 84 this.set('pref.value', this.getNewValue_(this.checked));
68 this.set('pref.value', this.getNewValue_(this.checked));
69 }
70 }, 85 },
71 86
72 /** @private */ 87 /**
73 getNewValue_: function(val) { 88 * @param {*} value
74 return this.inverted ? !val : val; 89 * @return {boolean} The value as a boolean, inverted if |inverted| is true.
75 } 90 * @private
91 */
92 getNewValue_: function(value) {
93 return this.inverted ? !value : !!value;
94 },
95
96 /**
97 * @param {boolean} disabled
98 * @param {?chrome.settingsPrivate.PrefObject} pref
99 * @return {boolean} Whether the checkbox should be disabled.
100 * @private
101 */
102 checkboxDisabled_: function(disabled, pref) {
103 return disabled || (!!pref &&
michaelpg 2015/09/17 02:19:25 !!pref -> pref (no need to convert null to boolean
stevenjb 2015/09/17 17:33:31 Actually, closure will complain without the !!.
104 pref.policyEnforcement ==
105 chrome.settingsPrivate.PolicyEnforcement.ENFORCED);
106 },
76 }); 107 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698