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

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: 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
Mattias Nissler (ping if slow) 2011/08/09 13:20:40 I guess all this stuff should go into some object
simo 2011/08/10 14:28:19 Okay, I wasn't sure what the policy on this was be
5 localStrings = new LocalStrings();
6 /**
7 * This variable structure is here to document the structure that the template
8 * expects to correctly populate the page.
9 */
10 var policyDataformat = {
11 'policies': [
12 {
13 'level': 'managed',
14 'name': 'AllowXYZ',
15 'set': true,
16 'source_type': 'Device',
17 'status': 'ok',
18 'value': 'Allow',
19 },
20 ]
21 }
22
23 /**
24 * Takes the |policyData| input argument which represents data about the
25 * policies supported by the device/client and populates the html jstemplate
26 * with that data. It expects an object structure like the above.
27 * @param {Object} policyData Detailed info about policies
28 */
29 function renderTemplate(policyData) {
30 // This is the javascript code that processes the template:
31 var input = new JsEvalContext(policyData);
32 var output = document.getElementById('policiesTemplate');
33 jstProcess(input, output);
34 }
35
36 /**
37 * Asks the C++ PolicyUIHandler to get details about policies. The
38 * PolicyDOMHandler should reply to returnPolicyData() (below).
39 */
40 function requestPolicyData() {
41 chrome.send('requestPolicyData', []);
42 }
43
44 /**
45 * Called by the C++ PolicyUIHandler when it has the requested policy data.
46 */
47 function returnPolicyData(policyData) {
48 renderTemplate(policyData);
49 }
50
51 /**
52 * Determines whether a policy should be visible or not.
53 * @param {policy} policy information in the format given by above the
54 * PolicyDataFormat
55 */
56 function shouldDisplayPolicy(policy) {
57 return $('toggle-unsent-policies').checked || policy.set;
58 }
59
60 /**
61 * Returns true if the given policy was actually set and false otherwise (i.e. it
62 * is just one of the policies supported by the client but isn't set to a value).
63 *
64 * @policy {policy} information in the format given by above PolicyDataFormat
65 */
66 function isPolicySet(policy) {
67 return policy.set;
68 }
69
70 /**
71 * Initializes the page and loads the list of policies.
72 */
73 function load() {
74 i18nTemplate.process(document, templateData);
75 requestPolicyData();
76
77 // Set HTML event handlers.
78 $('toggle-unsent-policies').onchange = function (event) {
79 var table_rows = document.getElementsByClassName('policy-unset');
80 for (var i = 0; i < table_rows.length; ++i) {
81 if ($('toggle-unsent-policies').checked)
82 table_rows[i].style.display = 'table-row';
83 else
84 table_rows[i].style.display = 'none';
85 }
86
87 // Filter table again in case a search was active.
88 filterTable(search_term);
89 };
90
91 $('search-field').onsearch = function(event) {
92 filterTable(this.value);
93 };
94
95 $('search-field').placeholder = localStrings.getString('filterPoliciesText');
96 }
97
98 // The current search text for filtering the policy table.
99 var search_term = '';
100
101 /**
102 * Filters the table of policies by name.
103 * @param {term} The search string
104 */
105 function filterTable (term) {
106 search_term = term.toLowerCase();
107 var table = document.getElementById('policy-table');
108 var show_unsent = $('toggle-unsent-policies').checked;
109 for (var r = 1; r < table.rows.length; ++r) {
110 var row = table.rows[r];
111
112 // Don't change visibility of policies that aren't set if the checkbox
113 // isn't checked.
114 if (!show_unsent && row.className == 'policy-unset')
115 continue;
116
117 var name_cell = row.getElementsByClassName('policy-name')[0];
118 var cell_contents = name_cell.innerHTML.replace(/<[^>]+>/g,"");
119 if (cell_contents.toLowerCase().indexOf(search_term) >= 0)
120 row.style.display = 'table-row';
121 else
122 row.style.display = 'none';
123 }
124 }
125
126 // Get data and have it displayed upon loading.
127 document.addEventListener('DOMContentLoaded', load);
128
Mattias Nissler (ping if slow) 2011/08/09 13:20:40 remove trailing whitespace.
129
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698