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

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

Powered by Google App Engine
This is Rietveld 408576698