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

Side by Side Diff: chrome/browser/resources/policy.js

Issue 7585036: First CL for the about:policy page. This only implements the policy section of the page. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Please ignore previous patch. Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 var localStrings = new LocalStrings();
6
7 /**
8 * This variable structure is here to document the structure that the template
9 * expects to correctly populate the page.
10 */
11 var policyDataformat = {
12 'policies': [
13 {
14 'level': 'managed',
15 'name': 'AllowXYZ',
16 'set': true,
17 'sourceType': 'Device',
18 'status': 'ok',
19 'value': true,
20 },
21 ],
22 'anyPoliciesSet': true
23 };
24
25 cr.define('cr.ui', function() {
arv (Not doing code reviews) 2011/08/16 19:14:44 This should not be part of cr.ui. cr.ui is meant f
simo 2011/08/17 10:22:09 Okay, I have put it into 'policies' now. Is that o
26
27 function Policy() {
28 }
29
30 cr.addSingletonGetter(Policy);
31
32 Policy.prototype = {
33
34 /**
35 * True if none of the received policies are actually set, false otherwise.
36 * @type {boolean}
37 */
38 noActivePolicies_: false,
39
40 /**
41 * The current search term for filtering of the policy table.
42 * @type {string}
arv (Not doing code reviews) 2011/08/16 19:14:44 @private
simo 2011/08/17 10:22:09 Done.
43 */
44 searchTerm_: '',
45
46 /**
47 * Takes the |policyData| input argument which represents data about the
48 * policies supported by the device/client and populates the html jstemplate
49 * with that data. It expects an object structure like the above.
50 * @param {Object} policyData Detailed info about policies
51 */
52 renderTemplate: function(policyData) {
53 this.noActivePolicies_ = !policyData.anyPoliciesSet;
54
55 // This is the javascript code that processes the template:
56 var input = new JsEvalContext(policyData);
57 var output = $('policiesTemplate');
58 jstProcess(input, output);
59 },
60
61 /**
62 * Filters the table of policies by name.
63 * @param {string} term The search string
64 */
65 filterTable: function(term) {
66 this.searchTerm_ = term.toLowerCase();
67 var table = $('policy-table');
68 var showUnsent = $('toggle-unsent-policies').checked;
69 for (var r = 1; r < table.rows.length; r++) {
70 var row = table.rows[r];
71
72 // Don't change visibility of policies that aren't set if the checkbox
73 // isn't checked.
74 if (!showUnsent && row.className == 'policy-unset')
75 continue;
76
77 var nameCell = row.querySelector('.policy-name');
78 var cellContents = nameCell.textContent;
79 if (cellContents.toLowerCase().indexOf(this.searchTerm_) >= 0)
80 row.style.display = 'table-row';
81 else
82 row.style.display = 'none';
83 }
84 },
85
86 /**
87 * Updates the visibility of the policies depending on the state of the
88 * 'toggle-unsent-policies' checkbox.
89 */
90 updatePolicyVisibility: function() {
91 if ($('toggle-unsent-policies').checked)
92 $('policies').style.visibility = 'visible';
93 else if (this.noActivePolicies_)
94 $('policies').style.visibility = 'hidden';
95
96 var tableRows = document.getElementsByClassName('policy-unset');
97 for (var i = 0; i < tableRows.length; i++) {
98 if ($('toggle-unsent-policies').checked)
99 tableRows[i].style.visibility = 'visible';
100 else
101 tableRows[i].style.visibility = 'hidden';
102 }
103
104 // Filter table again in case a search was active.
105 this.filterTable(this.searchTerm_);
106 }
107 };
108
109 /**
110 * Asks the C++ PolicyUIHandler to get details about policies. The
111 * PolicyDOMHandler should reply to returnPolicyData() (below).
112 */
113 Policy.requestPolicyData = function() {
114 chrome.send('requestPolicyData');
115 };
116
117 /**
118 * Called by the C++ PolicyUIHandler when it has the requested policy data.
119 */
120 Policy.returnPolicyData = function(policyData) {
121 Policy.getInstance().renderTemplate(policyData);
122 };
123
124 /**
125 * Determines whether a policy should be visible or not.
126 * @param {policy} policy information in the format given by above the
127 * PolicyDataFormat
128 */
129 Policy.shouldDisplayPolicy = function(policy) {
130 return $('toggle-unsent-policies').checked || policy.set;
131 };
132
133 /**
134 * Initializes the page and loads the list of policies.
135 */
136 Policy.initialize = function() {
137 i18nTemplate.process(document, templateData);
138 Policy.requestPolicyData();
139
140 // Set HTML event handlers.
141 $('toggle-unsent-policies').onchange = function(event) {
142 Policy.getInstance().updatePolicyVisibility();
143 };
144
145 $('search-field').onsearch = function(event) {
146 Policy.getInstance().filterTable(this.value);
147 };
148
149 $('search-field').placeholder =
150 localStrings.getString('filterPoliciesText');
151 };
152
153 // Export
154 return {
155 Policy: Policy
156 };
157 });
158
159 var Policy = cr.ui.Policy;
160
161 // Get data and have it displayed upon loading.
162 document.addEventListener('DOMContentLoaded', cr.ui.Policy.initialize);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698