Chromium Code Reviews| Index: chrome/browser/resources/policy.js |
| diff --git a/chrome/browser/resources/policy.js b/chrome/browser/resources/policy.js |
| index a044bc92efd8a1f9e5a0eb6f8032e7b40a345ebe..470f5a75bf807ab501c0dfdd165d87f1d2b2e58e 100644 |
| --- a/chrome/browser/resources/policy.js |
| +++ b/chrome/browser/resources/policy.js |
| @@ -88,9 +88,8 @@ cr.define('policy', function() { |
| * @param {string} name The policy name. |
| * @param {Object} value Dictionary with information about the policy value. |
| * @param {boolean} unknown Whether the policy name is not recognized. |
| - * @param {boolean} includeStatus Whether the table has a status column. |
| */ |
| - initialize: function(name, value, unknown, includeStatus) { |
| + initialize: function(name, value, unknown) { |
| this.name = name; |
| this.unset = !value; |
| @@ -110,29 +109,23 @@ cr.define('policy', function() { |
| this.querySelector('.expanded-value').textContent = value.value; |
| } |
| - if (includeStatus) { |
| - // Populate the status column. |
| - var status; |
| - if (!value) { |
| - // If the policy value has not been set, show an error message. |
| - status = loadTimeData.getString('unset'); |
| - } else if (unknown) { |
| - // If the policy name is not recognized, show an error message. |
| - status = loadTimeData.getString('unknown'); |
| - } else if (value.error) { |
| - // If an error occurred while parsing the policy value, show the error |
| - // message. |
| - status = value.error; |
| - } else { |
| - // Otherwise, indicate that the policy value was parsed correctly. |
| - status = loadTimeData.getString('ok'); |
| - } |
| - this.querySelector('.status').textContent = status; |
| + // Populate the status column. |
| + var status; |
| + if (!value) { |
| + // If the policy value has not been set, show an error message. |
| + status = loadTimeData.getString('unset'); |
| + } else if (unknown) { |
| + // If the policy name is not recognized, show an error message. |
| + status = loadTimeData.getString('unknown'); |
| + } else if (value.error) { |
| + // If an error occurred while parsing the policy value, show the error |
| + // message. |
| + status = value.error; |
| } else { |
| - // Remove status column. |
| - this.querySelector('.status-container').remove(); |
| - this.querySelector('.expanded-value').setAttribute('colspan', 4); |
| + // Otherwise, indicate that the policy value was parsed correctly. |
| + status = loadTimeData.getString('ok'); |
| } |
| + this.querySelector('.status').textContent = status; |
| }, |
| /** |
| @@ -305,8 +298,7 @@ cr.define('policy', function() { |
| */ |
| setPolicyValue_: function(name, value, unknown) { |
| var policy = new Policy; |
| - var includeStatus = this.querySelector('.status-column') != null; |
| - policy.initialize(name, value, unknown, includeStatus); |
| + policy.initialize(name, value, unknown); |
| this.appendChild(policy); |
| }, |
| }; |
| @@ -327,8 +319,24 @@ cr.define('policy', function() { |
| * @param {Object} names Dictionary containing all known policy names. |
| */ |
| Page.setPolicyNames = function(names) { |
| - var table = this.getInstance().policyTables['chrome']; |
| - table.setPolicyNames(names); |
| + var page = this.getInstance(); |
| + |
| + // Clear all policy tables. |
| + page.mainSection.innerHTML = ''; |
| + page.policyTables = {}; |
| + |
| + // Create tables and set known policy names for Chrome and extensions. |
| + if (names.hasOwnProperty('chromePolicyNames')) { |
| + var table = page.appendNewTable('chrome', 'Chrome policies', ''); |
| + table.setPolicyNames(names.chromePolicyNames); |
| + } |
|
James Hawkins
2013/06/20 18:18:52
Optional nit: Blank lines between blocks.
anitawoodruff
2013/06/21 10:16:16
Done.
|
| + if (names.hasOwnProperty('extensionPolicyNames')) { |
| + for (var ext in names.extensionPolicyNames) { |
| + var table = page.appendNewTable('extension-' + ext, |
| + names.extensionPolicyNames[ext].name, 'ID: ' + ext); |
| + table.setPolicyNames(names.extensionPolicyNames[ext].policyNames); |
| + } |
| + } |
| }; |
| /** |
| @@ -339,7 +347,6 @@ cr.define('policy', function() { |
| */ |
| Page.setPolicyValues = function(values) { |
| var page = this.getInstance(); |
| - |
| if (values.hasOwnProperty('chromePolicies')) { |
| var table = page.policyTables['chrome']; |
| table.setPolicyValues(values.chromePolicies); |
| @@ -347,10 +354,9 @@ cr.define('policy', function() { |
| if (values.hasOwnProperty('extensionPolicies')) { |
| for (var extensionId in values.extensionPolicies) { |
| - var tableName = values.extensionPolicies[extensionId].name; |
| - var table = page.getOrCreateTable('extension-' + extensionId, tableName, |
| - 'ID: ' + extensionId, false); |
| - table.setPolicyValues(values.extensionPolicies[extensionId].policies); |
| + var table = page.policyTables['extension-' + extensionId]; |
| + if (table) |
| + table.setPolicyValues(values.extensionPolicies[extensionId]); |
| } |
| } |
| }; |
| @@ -382,9 +388,6 @@ cr.define('policy', function() { |
| this.mainSection = $('main-section'); |
| this.policyTables = {}; |
| - var chromeTable = this.getOrCreateTable('chrome', 'Chrome policies', '', |
| - true); |
| - |
| // Place the initial focus on the filter input field. |
| $('filter').focus(); |
| @@ -411,35 +414,30 @@ cr.define('policy', function() { |
| chrome.send('initialized'); |
| }, |
| - /** |
| - * Gets the existing policy table for the given id, or if none exists, |
| - * creates a new policy table section, adds the section to the page, |
| + /** |
| + * Creates a new policy table section, adds the section to the page, |
| * and returns the new table from that section. |
| - * @param {string} id The key for the table in policyTables. |
| + * @param {string} id The key for storing the new table in policyTables. |
| * @param {string} label_title Title for this policy table. |
| * @param {string} label_content Description for the policy table. |
| - * @return {Element} Policy table associated with the given id. |
| + * @return {Element} The newly created table. |
| */ |
| - getOrCreateTable: function(id, label_title, label_content, includeStatus) { |
| - if (!this.policyTables.hasOwnProperty(id)) { |
| - var newSection = this.createPolicyTableSection(id, label_title, |
| - label_content, includeStatus); |
| - this.mainSection.appendChild(newSection); |
| - } |
| + appendNewTable: function(id, label_title, label_content) { |
| + var newSection = this.createPolicyTableSection(id, label_title, |
| + label_content); |
| + this.mainSection.appendChild(newSection); |
| return this.policyTables[id]; |
| }, |
| /** |
| * Creates a new section containing a title, description and table of |
| * policies. |
| - * @param {string} id Used as key when storing new table in policyTables. |
| + * @param {id} id The key for storing the new table in policyTables. |
| * @param {string} label_title Title for this policy table. |
| * @param {string} label_content Description for the policy table. |
| - * @param {boolean} includeStatus Whether to display a status column. |
| * @return {Element} The newly created section. |
| */ |
| - createPolicyTableSection: function(id, label_title, label_content, |
| - includeStatus) { |
| + createPolicyTableSection: function(id, label_title, label_content) { |
| var section = document.createElement('section'); |
| section.setAttribute('class', 'policy-table-section'); |
| @@ -462,7 +460,7 @@ cr.define('policy', function() { |
| section.appendChild(noPolicies); |
| // Add table of policies. |
| - var newTable = this.createPolicyTable(includeStatus); |
| + var newTable = this.createPolicyTable(); |
| this.policyTables[id] = newTable; |
| section.appendChild(newTable); |
| @@ -471,29 +469,19 @@ cr.define('policy', function() { |
| /** |
| * Creates a new table for displaying policies. |
| - * @param {boolean} includeStatus Whether to include a status column. |
| * @return {Element} The newly created table. |
| */ |
| - createPolicyTable: function(includeStatus) { |
| + createPolicyTable: function() { |
| var newTable = window.document.createElement('table'); |
| var tableHead = window.document.createElement('thead'); |
| var tableRow = window.document.createElement('tr'); |
| var tableHeadings = ['headerScope', 'headerLevel', |
| - 'headerName', 'headerValue']; |
| - |
| + 'headerName', 'headerValue', 'headerStatus']; |
| for (var i = 0; i < tableHeadings.length; i++) { |
| var tableHeader = window.document.createElement('th'); |
| tableHeader.textContent = loadTimeData.getString(tableHeadings[i]); |
| tableRow.appendChild(tableHeader); |
| } |
| - |
| - if (includeStatus) { |
| - var statusHeader = window.document.createElement('th'); |
| - statusHeader.classList.add('status-column'); |
| - statusHeader.textContent = loadTimeData.getString('headerStatus'); |
| - tableRow.appendChild(statusHeader); |
| - } |
| - |
| tableHead.appendChild(tableRow); |
| newTable.appendChild(tableHead); |
| cr.ui.decorate(newTable, PolicyTable); |