diff options
author | simo@google.com <simo@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-31 16:10:04 +0000 |
---|---|---|
committer | simo@google.com <simo@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-31 16:10:04 +0000 |
commit | a8171203aadbc0d452ec3b46eb16d6b5b5e8427b (patch) | |
tree | 2c2b6003fa94f743bc6e6e4b5121a0edc93f62f0 /chrome/browser/resources/policy.js | |
parent | 5a2b69999950076443aa3c9c1def3c676eeeb870 (diff) | |
download | chromium_src-a8171203aadbc0d452ec3b46eb16d6b5b5e8427b.zip chromium_src-a8171203aadbc0d452ec3b46eb16d6b5b5e8427b.tar.gz chromium_src-a8171203aadbc0d452ec3b46eb16d6b5b5e8427b.tar.bz2 |
First CL for the about:policy page. This only implements the policy section of the page.
Preliminary design doc:
https://docs.google.com/a/google.com/document/d/1KWsF52ImY4eJbNgizaA6Gw_aMVg24zgZfypKZBs376k/edit?hl=en_US&ndplr=1
TEST=set some policies, start chrome and go to chrome://policy
Review URL: http://codereview.chromium.org/7585036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98977 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/resources/policy.js')
-rw-r--r-- | chrome/browser/resources/policy.js | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/chrome/browser/resources/policy.js b/chrome/browser/resources/policy.js new file mode 100644 index 0000000..db4f404 --- /dev/null +++ b/chrome/browser/resources/policy.js @@ -0,0 +1,160 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +var localStrings = new LocalStrings(); + +/** + * This variable structure is here to document the structure that the template + * expects to correctly populate the page. + */ +var policyDataformat = { + 'policies': [ + { + 'level': 'managed', + 'name': 'AllowXYZ', + 'set': true, + 'sourceType': 'Device', + 'status': 'ok', + 'value': true, + }, + ], + 'anyPoliciesSet': true +}; + +cr.define('policies', function() { + + function Policy() { + } + + cr.addSingletonGetter(Policy); + + Policy.prototype = { + + /** + * True if none of the received policies are actually set, false otherwise. + * @type {boolean} + */ + noActivePolicies_: false, + + /** + * The current search term for filtering of the policy table. + * @type {string} + * @private + */ + searchTerm_: '', + + /** + * Takes the |policyData| input argument which represents data about the + * policies supported by the device/client and populates the html jstemplate + * with that data. It expects an object structure like the above. + * @param {Object} policyData Detailed info about policies + */ + renderTemplate: function(policyData) { + this.noActivePolicies_ = !policyData.anyPoliciesSet; + + // This is the javascript code that processes the template: + var input = new JsEvalContext(policyData); + var output = $('policiesTemplate'); + jstProcess(input, output); + }, + + /** + * Filters the table of policies by name. + * @param {string} term The search string + */ + filterTable: function(term) { + this.searchTerm_ = term.toLowerCase(); + var table = $('policy-table'); + var showUnsent = $('toggle-unsent-policies').checked; + for (var r = 1; r < table.rows.length; r++) { + var row = table.rows[r]; + + // Don't change visibility of policies that aren't set if the checkbox + // isn't checked. + if (!showUnsent && row.className == 'policy-unset') + continue; + + var nameCell = row.querySelector('.policy-name'); + var cellContents = nameCell.textContent; + if (cellContents.toLowerCase().indexOf(this.searchTerm_) >= 0) + row.style.display = 'table-row'; + else + row.style.display = 'none'; + } + }, + + /** + * Updates the visibility of the policies depending on the state of the + * 'toggle-unsent-policies' checkbox. + */ + updatePolicyVisibility: function() { + if ($('toggle-unsent-policies').checked) + $('policies').style.display = ''; + else if (this.noActivePolicies_) + $('policies').style.display = 'none'; + + var tableRows = document.getElementsByClassName('policy-unset'); + for (var i = 0; i < tableRows.length; i++) { + if ($('toggle-unsent-policies').checked) + tableRows[i].style.visibility = 'visible'; + else + tableRows[i].style.visibility = 'hidden'; + } + + // Filter table again in case a search was active. + this.filterTable(this.searchTerm_); + } + }; + + /** + * Asks the C++ PolicyUIHandler to get details about policies. The + * PolicyDOMHandler should reply to returnPolicyData() (below). + */ + Policy.requestPolicyData = function() { + chrome.send('requestPolicyData'); + }; + + /** + * Called by the C++ PolicyUIHandler when it has the requested policy data. + */ + Policy.returnPolicyData = function(policyData) { + Policy.getInstance().renderTemplate(policyData); + }; + + /** + * Determines whether a policy should be visible or not. + * @param {policy} policy information in the format given by above the + * PolicyDataFormat + */ + Policy.shouldDisplayPolicy = function(policy) { + return $('toggle-unsent-policies').checked || policy.set; + }; + + /** + * Initializes the page and loads the list of policies. + */ + Policy.initialize = function() { + i18nTemplate.process(document, templateData); + Policy.requestPolicyData(); + + // Set HTML event handlers. + $('toggle-unsent-policies').onchange = function(event) { + Policy.getInstance().updatePolicyVisibility(); + }; + + $('search-field').onsearch = function(event) { + Policy.getInstance().filterTable(this.value); + }; + }; + + // Export + return { + Policy: Policy + }; +}); + +var Policy = policies.Policy; + +// Get data and have it displayed upon loading. +document.addEventListener('DOMContentLoaded', policies.Policy.initialize); |