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