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 properties: { |
| 28 /** |
| 29 * Object containing title and text of the introduction card. |
| 30 * @type {!{ title: string, text: string }|undefined} |
| 31 */ |
| 32 introduction: { |
| 33 type: Object, |
| 34 reflectToAttribute: false, |
| 35 readOnly: true, |
| 36 notify: false |
| 37 } |
| 38 }, |
| 39 |
| 40 /** @override */ |
| 41 ready: function() { |
| 42 // TODO(fhorschig): i18n! Replace sample text with reviewed message. |
| 43 this._setIntroduction({ |
| 44 title: 'Managed account policies', |
| 45 text: |
| 46 'Your device and your user account are managed which means that ' + |
| 47 'some of your settings are fixed by your administrator.\n' + |
| 48 'The cards below explain how the administrator\'s choices may ' + |
| 49 'impact your privacy or security.' |
| 50 }); |
| 51 |
| 52 // Set this element as receiver of calls to the Page. |
| 53 policy.Page = this; |
| 54 |
| 55 // Notify the browser that the page has loaded, causing it to send the |
| 56 // list of all known policies, the current policy values and the cloud |
| 57 // policy status. |
| 58 chrome.send('initialized'); |
| 59 }, |
| 60 |
| 61 /** |
| 62 * Looks for the existing PolicyGroup matching the |tag| and triggers adding |
| 63 * the policy to it. |
| 64 * @private |
| 65 * @param {string} name Name of the policy. |
| 66 * @param {string} tag Name of the policy's tag. |
| 67 */ |
| 68 addNameToTagGroup_: function(name, tag) { |
| 69 for (var pos = 0; pos < this.$.groups.children.length; ++pos) |
| 70 if (this.$.groups.children[pos].riskTag == tag) |
| 71 this.$.groups.children[pos].addPolicy(name); |
| 72 }, |
| 73 |
| 74 /** |
| 75 * Removes DOM Elements and empties list of known tags. |
| 76 * @private |
| 77 */ |
| 78 clearGroups_: function() { |
| 79 while (this.$.groups.firstChild) |
| 80 this.$.groups.removeChild(this.$.groups.firstChild); |
| 81 }, |
| 82 |
| 83 /** |
| 84 * Creates PolicyGroup and inserts it to list of known tags. |
| 85 * @param {string} tag Name of the tag (included in i18n strings). |
| 86 * @private |
| 87 */ |
| 88 createTagGroup_: function(tag) { |
| 89 this.$.groups.appendChild(new PolicyGroup(tag)); |
| 90 }, |
| 91 |
| 92 /** |
| 93 * Receives a list of known tags and creates an empty policy list for each. |
| 94 * @param {!Array<string>} tags List of tags. |
| 95 */ |
| 96 setPolicyGroups: function(tags) { |
| 97 this.clearGroups_(); |
| 98 tags.forEach(this.createTagGroup_.bind(this)); |
| 99 }, |
| 100 |
| 101 /** |
| 102 * Creates UI elements for tagged policies within the passed |names| object. |
| 103 * @param {!{chromePolicyNames: !Object<!Array<string>>}} namesWithTags |
| 104 */ |
| 105 setPolicyNames: function(namesWithTags) { |
| 106 for (var name in namesWithTags.chromePolicyNames) { |
| 107 namesWithTags.chromePolicyNames[name].forEach( |
| 108 this.addNameToTagGroup_.bind(this, name)); |
| 109 } |
| 110 }, |
| 111 |
| 112 /** |
| 113 * Receives a list of current values that it hands down to children. |
| 114 * @param {!{chromePolicies: !Object<string>}} values Current policies. |
| 115 */ |
| 116 setPolicyValues: function(values) { |
| 117 // TODO(fhorschig): Update or notify tag groups. |
| 118 }, |
| 119 |
| 120 /** |
| 121 * Receives an object with meta data about the currently set policies. |
| 122 * @param {!Object} status Dictionary containing meta data about set policies. |
| 123 */ |
| 124 setStatus: function(status) { |
| 125 // TODO(fhorschig): Update |this.$.introduction| with status information. |
| 126 // text according to policy status. |
| 127 } |
| 128 }); |
OLD | NEW |