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