Chromium Code Reviews| 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 | |
| 7 * 'policy-ui' is the main MD element, combining the UI and models. | |
| 8 * | |
| 9 * Example: | |
| 10 * | |
| 11 * <policy-ui></policy-ui> | |
| 12 * | |
| 13 * @group Chrome Policy Elements | |
| 14 * @element policy-ui | |
| 15 */ | |
| 16 Polymer({ | |
| 17 is: 'policy-ui', | |
| 18 | |
| 19 /** @override */ | |
| 20 created: function() { | |
| 21 this.tagGroups = []; | |
|
stevenjb
2015/10/07 17:09:33
declare tagGroups as a typed property or variable
fhorschig
2015/10/08 09:35:46
Done.
| |
| 22 }, | |
| 23 | |
| 24 /** @override */ | |
| 25 ready: function() { | |
| 26 // TODO(fhorschig): i18n! Replace sample text with reviewed message. | |
| 27 this.introduction = { | |
|
stevenjb
2015/10/07 17:09:33
Declare and type introduction
fhorschig
2015/10/08 09:35:46
Done.
| |
| 28 title: 'Managed account policies', | |
| 29 text: | |
| 30 'Your device and your user account are managed which means that ' + | |
| 31 'some of your settings are fixed by your administrator.\n' + | |
| 32 'The cards below explain how the administrator\'s choices may ' + | |
| 33 'impact your privacy or security.' | |
| 34 }; | |
| 35 | |
| 36 // Set this element as receiver of calls to the Page. | |
| 37 policy.Page = this; | |
| 38 | |
| 39 // Notify the browser that the page has loaded, causing it to send the | |
| 40 // list of all known policies, the current policy values and the cloud | |
| 41 // policy status. | |
| 42 chrome.send('initialized'); | |
|
stevenjb
2015/10/07 17:09:32
Prefer a more specifically named identifier, e.g.
fhorschig
2015/10/08 09:35:45
We are using the same signal for capturing if chro
stevenjb
2015/10/08 17:12:39
I see, OK.
| |
| 43 }, | |
| 44 | |
| 45 /** | |
| 46 * Looks for the existing PolicyGroup matching the |tag| and triggers adding | |
| 47 * the policy to it. | |
| 48 * @private | |
| 49 * @param {string} name Name of the policy. | |
| 50 * @param {string} tag Name of the policy's tag. | |
| 51 */ | |
| 52 addNameToTagGroup_: function(name, tag) { | |
| 53 var pos = 0; | |
| 54 while (pos < this.tagGroups.length && | |
| 55 this.tagGroups[pos].name != tag) | |
| 56 ++pos; | |
|
stevenjb
2015/10/07 17:09:32
Use {} when the condition or statement is more tha
fhorschig
2015/10/08 09:35:46
Done. Thanks, didn't know this rule.
| |
| 57 this.tagGroups[pos].element.addPolicy(name); | |
| 58 }, | |
| 59 | |
| 60 /** | |
| 61 * Removes DOM Elements and empties list of known tags. | |
| 62 * @private | |
| 63 */ | |
| 64 clearGroups_: function() { | |
| 65 this.tagGroups = []; | |
| 66 while (this.$.groups.firstChild) | |
| 67 this.$.groups.removeChild(this.$.groups.firstChild); | |
|
stevenjb
2015/10/07 17:09:32
2 spaces here, not 4.
fhorschig
2015/10/08 09:35:46
Done.
| |
| 68 }, | |
| 69 | |
| 70 /** | |
| 71 * Creates PolicyGroup and inserts it to list of known tags. | |
| 72 * @private | |
|
stevenjb
2015/10/07 17:09:32
@private last
fhorschig
2015/10/08 09:35:46
Done.
| |
| 73 * @param {string} tag Name of the tag (included in i18n strings). | |
| 74 */ | |
| 75 createTagGroup_: function(tag) { | |
| 76 var domNode = new PolicyGroup(loadTimeData.getString(tag)); | |
| 77 this.tagGroups.push({ | |
| 78 name: tag, | |
| 79 element: domNode | |
| 80 }); | |
| 81 this.$.groups.appendChild(domNode); | |
| 82 }, | |
| 83 | |
| 84 /** | |
| 85 * Receives an list of known tags and creates an empty policy list for each. | |
|
stevenjb
2015/10/07 17:09:32
a list
fhorschig
2015/10/08 09:35:46
Done.
| |
| 86 * @param {Array} tags List of tags. | |
|
stevenjb
2015/10/07 17:09:32
{!Array<string>} (Always use ! or ? before Object
fhorschig
2015/10/08 09:35:46
Done.
| |
| 87 */ | |
| 88 setPolicyGroups: function(tags) { | |
| 89 this.clearGroups_(); | |
| 90 tags.forEach(this.createTagGroup_.bind(this)); | |
| 91 }, | |
| 92 | |
| 93 /** | |
| 94 * Creates UI elements for tagged policies within the passed |names| object. | |
| 95 * @param {{chromePolicyNames: Object<string, Array<string>>}} namesWithTags | |
|
stevenjb
2015/10/07 17:09:32
!Object<!Array<string>> (keys are always strings
fhorschig
2015/10/08 09:35:46
Done.
| |
| 96 */ | |
| 97 setPolicyNames: function(namesWithTags) { | |
| 98 for (var name in namesWithTags.chromePolicyNames) | |
| 99 namesWithTags.chromePolicyNames[name].forEach( | |
| 100 this.addNameToTagGroup_.bind(this, name)); | |
|
stevenjb
2015/10/07 17:09:33
{}
fhorschig
2015/10/08 09:35:46
Done.
| |
| 101 }, | |
| 102 | |
| 103 /** | |
| 104 * Receives a list of current values that it hands down to children. | |
| 105 * @param {Object} values Dictionary containing the current policy values. | |
|
stevenjb
2015/10/07 17:09:33
{!Object} or {?Object}
fhorschig
2015/10/08 09:35:46
Done.
| |
| 106 */ | |
| 107 setPolicyValues: function(values) { | |
| 108 // TODO(fhorschig): Update or notify |this.tagGroups|. | |
| 109 }, | |
| 110 | |
| 111 /** | |
| 112 * Receives an object with meta data about the currently set policies. | |
| 113 * @param {Object} status Dictionary containing meta data about set policies. | |
|
stevenjb
2015/10/07 17:09:33
! or ?
fhorschig
2015/10/08 09:35:46
Done.
| |
| 114 */ | |
| 115 setStatus: function(status) { | |
| 116 // TODO(fhorschig): Update |this.$.introduction| with status information. | |
| 117 // text according to policy status. | |
| 118 } | |
| 119 }); | |
| 120 | |
| 121 // Define a global entry point that will be set when the page is initialized. | |
| 122 cr.define('policy', function() { | |
|
stevenjb
2015/10/07 17:09:33
Can we put this above the Polymer object so that i
fhorschig
2015/10/08 09:35:45
Done.
| |
| 123 return { Page: null }; | |
| 124 }); | |
| OLD | NEW |