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

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

Issue 7828042: Implemented status section functionality for about:policy. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 3 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var localStrings = new LocalStrings(); 5 //var localStrings = new LocalStrings();
6 6
7 /** 7 /**
8 * This variable structure is here to document the structure that the template 8 * This variable structure is here to document the structure that the template
9 * expects to correctly populate the page. 9 * expects to correctly populate the page.
10 */ 10 */
11 var policyDataformat = { 11 var policyDataformat = {
12 'policies': [ 12 'policies': [
13 { 13 {
14 'level': 'managed', 14 'level': 'managed',
15 'name': 'AllowXYZ', 15 'name': 'AllowXYZ',
16 'set': true, 16 'set': true,
17 'sourceType': 'Device', 17 'sourceType': 'Device',
18 'status': 'ok', 18 'status': 'ok',
19 'value': true, 19 'value': true
20 }, 20 }
21 ], 21 ],
22 'anyPoliciesSet': true 22 'anyPoliciesSet': true,
23 'status': {
24 'deviceFetchInterval': '8min',
25 'deviceId': 'D2AC39A2-3C8FC-E2C0-E45D2DC3782C',
26 'deviceLastFetchTime': '9:50 PM',
27 'devicePolicyDomain': 'google.com',
28 'deviceStatusMessage': 'OK',
29 'displayStatusSection': true,
30 'user': 'simo@google.com',
31 'userFetchInterval': '8min',
32 'userId': 'D2AC39A2-3C8FC-E2C0-E45D2DC3782C',
33 'userLastFetchTime': '9:50 PM',
34 'userStatusMessage': 'OK'
35 }
23 }; 36 };
24 37
25 cr.define('policies', function() { 38 cr.define('policies', function() {
26 39
27 function Policy() { 40 function Policy() {
28 } 41 }
29 42
30 cr.addSingletonGetter(Policy); 43 cr.addSingletonGetter(Policy);
31 44
32 Policy.prototype = { 45 Policy.prototype = {
33 46
34 /** 47 /**
35 * True if none of the received policies are actually set, false otherwise. 48 * True if none of the received policies are actually set, false otherwise.
36 * @type {boolean} 49 * @type {boolean}
37 */ 50 */
38 noActivePolicies_: false, 51 noActivePolicies_: false,
39 52
40 /** 53 /**
54 * True if the status section is being displayed, false otherwise.
55 * @type {boolean}
56 */
57 displayStatusSection_: false,
58
59 /**
41 * The current search term for filtering of the policy table. 60 * The current search term for filtering of the policy table.
42 * @type {string} 61 * @type {string}
43 * @private 62 * @private
44 */ 63 */
45 searchTerm_: '', 64 searchTerm_: '',
46 65
47 /** 66 /**
48 * Takes the |policyData| input argument which represents data about the 67 * The interval with which the last policy fetch times should be updated in
49 * policies supported by the device/client and populates the html jstemplate 68 * ms.
50 * with that data. It expects an object structure like the above. 69 * @type {number}
70 */
71 fetchTimeRefreshInterval_: 60000,
72
73 /**
74 * Takes the |policyData| argument and populates the page with this data. It
75 * expects an object structure like the above.
51 * @param {Object} policyData Detailed info about policies 76 * @param {Object} policyData Detailed info about policies
52 */ 77 */
53 renderTemplate: function(policyData) { 78 renderTemplate: function(data) {
54 this.noActivePolicies_ = !policyData.anyPoliciesSet; 79 this.noActivePolicies_ = !data.anyPoliciesSet;
80 this.displayStatusSection_ = data.status.displayStatusSection;
55 81
56 // This is the javascript code that processes the template: 82 // This is the javascript code that processes the template:
57 var input = new JsEvalContext(policyData); 83 var input = new JsEvalContext(data);
58 var output = $('policiesTemplate'); 84 var output = $('dataTemplate');
59 jstProcess(input, output); 85 jstProcess(input, output);
86 this.setToggleEventHandlers_();
60 }, 87 },
61 88
62 /** 89 /**
63 * Filters the table of policies by name. 90 * Filters the table of policies by name.
64 * @param {string} term The search string 91 * @param {string} term The search string
65 */ 92 */
66 filterTable: function(term) { 93 filterTable: function(term) {
67 this.searchTerm_ = term.toLowerCase(); 94 this.searchTerm_ = term.toLowerCase();
68 var table = $('policy-table'); 95 var table = $('policy-table');
69 var showUnsent = $('toggle-unsent-policies').checked; 96 var showUnsent = $('toggle-unsent-policies').checked;
(...skipping 20 matching lines...) Expand all
90 */ 117 */
91 updatePolicyVisibility: function() { 118 updatePolicyVisibility: function() {
92 if ($('toggle-unsent-policies').checked) 119 if ($('toggle-unsent-policies').checked)
93 $('policies').style.display = ''; 120 $('policies').style.display = '';
94 else if (this.noActivePolicies_) 121 else if (this.noActivePolicies_)
95 $('policies').style.display = 'none'; 122 $('policies').style.display = 'none';
96 123
97 var tableRows = document.getElementsByClassName('policy-unset'); 124 var tableRows = document.getElementsByClassName('policy-unset');
98 for (var i = 0; i < tableRows.length; i++) { 125 for (var i = 0; i < tableRows.length; i++) {
99 if ($('toggle-unsent-policies').checked) 126 if ($('toggle-unsent-policies').checked)
100 tableRows[i].style.visibility = 'visible'; 127 tableRows[i].style.display = 'table-row';
101 else 128 else
102 tableRows[i].style.visibility = 'hidden'; 129 tableRows[i].style.display = 'none';
103 } 130 }
104 131
105 // Filter table again in case a search was active. 132 // Filter table again in case a search was active.
106 this.filterTable(this.searchTerm_); 133 this.filterTable(this.searchTerm_);
134 },
135
136 /**
137 * Set event handlers for the "Show more"/"Hide" links generated by
138 * jstemplate.
139 */
140 setToggleEventHandlers_: function() {
141 var toggles = document.querySelectorAll('.policy-set * .toggler');
142 for (var i = 0; i < toggles.length; i++) {
143 toggles[i].onclick = function() {
144 Policy.getInstance().toggleCellExpand_(this);
145 };
146 }
147 },
148
149 /**
150 * Expands or collapses a table cell that has overflowing text.
151 * @param {Object} toggler The toggler that was clicked on
152 */
153 toggleCellExpand_: function(toggler) {
154 var tableCell = toggler.parentElement;
155 var textContainer = tableCell.querySelector('.text-container');
156
157 if (textContainer.collapsed)
158 this.expandCell_(textContainer);
159 else
160 this.collapseCell_(textContainer);
161
162 textContainer.collapsed = !textContainer.collapsed;
163 var expand = tableCell.querySelector('.expand');
164 var collapse = tableCell.querySelector('.collapse');
165 expand.style.display = textContainer.collapsed ? '' : 'none';
166 collapse.style.display = textContainer.collapsed ? 'none' : '';
167 },
168
169 /**
170 * Collapses all expanded table cells and updates the visibility of the
171 * toggles accordingly. Should be called before the policy information in
172 * the table is updated.
173 */
174 collapseExpandedCells: function() {
175 var toggles = document.querySelectorAll('.policy-set * .toggler');
176 for (var i = 0; i < toggles.length; i++)
177 toggles[i].style.display = 'none';
178
179 var textContainers =
180 document.querySelectorAll('.expanded');
181 for (var i = 0; i < textContainers.length; i++)
182 this.collapseCell_(textContainers[i]);
183 },
184
185 /**
186 * Expands a table cell so that all the text it contains is visible.
187 * @param {Object} textContainer The cell's div element that contains the
188 * text
189 */
190 expandCell_: function(textContainer) {
191 textContainer.classList.remove('collapsed');
192 textContainer.classList.add('expanded');
193 },
194
195 /**
196 * Collapses a table cell so that overflowing text is hidden.
197 * @param {Object} textContainer The cell's div element that contains the
198 * text
199 */
200 collapseCell_: function(textContainer) {
201 textContainer.classList.remove('expanded');
202 textContainer.classList.add('collapsed');
107 } 203 }
108 }; 204 };
109 205
110 /** 206 /**
111 * Asks the C++ PolicyUIHandler to get details about policies. The 207 * Asks the C++ PolicyUIHandler to get details about policies and status
112 * PolicyDOMHandler should reply to returnPolicyData() (below). 208 * information. The PolicyUIHandler should reply to returnData() (below).
113 */ 209 */
114 Policy.requestPolicyData = function() { 210 Policy.requestData = function() {
115 chrome.send('requestPolicyData'); 211 chrome.send('requestData');
116 }; 212 };
117 213
118 /** 214 /**
119 * Called by the C++ PolicyUIHandler when it has the requested policy data. 215 * Called by the C++ PolicyUIHandler when it has the requested data.
216 * @param {Object} data The data
120 */ 217 */
121 Policy.returnPolicyData = function(policyData) { 218 Policy.returnData = function(data) {
Mattias Nissler (ping if slow) 2011/09/02 11:16:09 Hm, so we now have multiple entry points to push d
simo 2011/09/02 15:32:02 Okay, true I can use a single entry point to push
219 Policy.getInstance().renderTemplate(data);
220 if (Policy.getInstance().displayStatusSection_)
221 Policy.updateFetchTimes();
222 };
223
224 /**
225 * Called by the C++ PolicyUIHandler when the policy data has changed.
226 * @param {Object} policyData The data
227 */
228 Policy.updatePolicyData = function(policyData) {
229 Policy.getInstance().collapseExpandedCells();
122 Policy.getInstance().renderTemplate(policyData); 230 Policy.getInstance().renderTemplate(policyData);
231 Policy.getInstance().updatePolicyVisibility();
232 };
233
234 /**
235 * Asks the C++ PolicyUIHandler for updated policy fetch times.
236 */
237 Policy.updateFetchTimes = function() {
238 chrome.send('updateFetchTimes');
239 var t = setTimeout('Policy.updateFetchTimes()',
240 Policy.getInstance().fetchTimeRefreshInterval_);
241 };
242
243 /**
244 * Called by the C++ PolicyUIHandler when it has the requested updated fetch
245 * times.
246 * @param {Object} fetchTimes The new fetch times
247 */
248 Policy.returnFetchTimes = function(fetchTimes) {
249 if (fetchTimes.deviceLastFetchTime)
250 $('device-last-fetch-time').textContent = fetchTimes.deviceLastFetchTime;
251 if (fetchTimes.userLastFetchTime)
252 $('user-last-fetch-time').textContent = fetchTimes.userLastFetchTime;
253 };
254
255 Policy.triggerPolicyFetch = function() {
256 chrome.send('fetchPolicy');
123 }; 257 };
124 258
125 /** 259 /**
126 * Determines whether a policy should be visible or not. 260 * Determines whether a policy should be visible or not.
127 * @param {policy} policy information in the format given by above the 261 * @param {Object} policy An entry in the 'policies' array given by the above
128 * PolicyDataFormat 262 * PolicyDataFormat
129 */ 263 */
130 Policy.shouldDisplayPolicy = function(policy) { 264 Policy.shouldDisplayPolicy = function(policy) {
131 return $('toggle-unsent-policies').checked || policy.set; 265 return $('toggle-unsent-policies').checked || policy.set;
132 }; 266 };
133 267
134 /** 268 /**
135 * Initializes the page and loads the list of policies. 269 * Returns true if the "Show more" toggle should appear in a table cell and
270 * false if not.
271 * @param {Object} expandToggle The "Show more" DOM element
272 */
273 Policy.shouldShowExpand = function(expandToggle) {
274 var textContainer =
275 expandToggle.parentNode.querySelector('.text-container');
276 textContainer.collapsed = true;
277 var cellText = textContainer.querySelector('.cellText');
278
279 // If the text is wider than the text container, the expand sign should
280 // appear.
281 return (textContainer.offsetWidth < cellText.offsetWidth);
282 };
283
284 /**
285 * Initializes the page and loads the list of policies and the policy
286 * status data.
136 */ 287 */
137 Policy.initialize = function() { 288 Policy.initialize = function() {
138 i18nTemplate.process(document, templateData); 289 i18nTemplate.process(document, templateData);
139 Policy.requestPolicyData(); 290 Policy.requestData();
140 291
141 // Set HTML event handlers. 292 // Set HTML event handlers.
293 $('fetch-policies-button').onclick = function(event) {
294 Policy.triggerPolicyFetch();
295 }
296
142 $('toggle-unsent-policies').onchange = function(event) { 297 $('toggle-unsent-policies').onchange = function(event) {
143 Policy.getInstance().updatePolicyVisibility(); 298 Policy.getInstance().updatePolicyVisibility();
144 }; 299 };
145 300
146 $('search-field').onsearch = function(event) { 301 $('search-field').onsearch = function(event) {
147 Policy.getInstance().filterTable(this.value); 302 Policy.getInstance().filterTable(this.value);
148 }; 303 };
149 }; 304 };
150 305
151 // Export 306 // Export
152 return { 307 return {
153 Policy: Policy 308 Policy: Policy
154 }; 309 };
155 }); 310 });
156 311
157 var Policy = policies.Policy; 312 var Policy = policies.Policy;
158 313
159 // Get data and have it displayed upon loading. 314 // Get data and have it displayed upon loading.
160 document.addEventListener('DOMContentLoaded', policies.Policy.initialize); 315 document.addEventListener('DOMContentLoaded', policies.Policy.initialize);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698