Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 /** | 5 /** |
| 6 * 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 |
| 7 * expects to correctly populate the page. | 7 * expects to correctly populate the page. |
| 8 */ | 8 */ |
| 9 var policyDataFormat = { | 9 var policyDataFormat = { |
| 10 // Whether any of the policies in 'policies' have a value. | 10 // Whether any of the policies in 'policies' have a value. |
| 11 'anyPoliciesSet': true, | 11 'anyPoliciesSet': true, |
|
Dan Beam
2012/04/05 22:24:13
'damnIt'
| |
| 12 | 12 |
| 13 // False if the policy information is being sent due to an initial page load | 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. | 14 // and true if it is being sent due to a change of policy values. |
| 15 'isPolicyUpdate': false, | 15 'isPolicyUpdate': false, |
| 16 'policies': [ | 16 'policies': [ |
| 17 { | 17 { |
| 18 'level': 'managed', | 18 'level': 'managed', |
| 19 'name': 'AllowXYZ', | 19 'name': 'AllowXYZ', |
| 20 'set': true, | 20 'set': true, |
| 21 'scope': 'Machine', | 21 'scope': 'Machine', |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 40 } | 40 } |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 cr.define('policies', function() { | 43 cr.define('policies', function() { |
| 44 | 44 |
| 45 function Policy() { | 45 function Policy() { |
| 46 } | 46 } |
| 47 | 47 |
| 48 cr.addSingletonGetter(Policy); | 48 cr.addSingletonGetter(Policy); |
| 49 | 49 |
| 50 Policy.prototype = { | 50 Policy.prototype = { |
|
Dan Beam
2012/04/05 22:24:13
nit: I don't think we usually have an \n here
Tyler Breisacher (Chromium)
2012/04/05 22:49:55
Done.
| |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * True if none of the received policies are actually set, false otherwise. | 53 * True if none of the received policies are actually set, false otherwise. |
| 54 * @type {boolean} | 54 * @type {boolean} |
| 55 */ | 55 */ |
| 56 noActivePolicies_: false, | 56 noActivePolicies_: false, |
| 57 | 57 |
| 58 /** | 58 /** |
| 59 * The current search term for filtering of the policy table. | 59 * The current search term for filtering of the policy table. |
| 60 * @type {string} | 60 * @type {string} |
| 61 * @private | 61 * @private |
| 62 */ | 62 */ |
| 63 searchTerm_: '', | 63 searchTerm_: '', |
| 64 | 64 |
| 65 /** | 65 /** |
| 66 * Takes the |policyData| argument and populates the page with this data. It | 66 * Takes the |policyData| argument and populates the page with this data. It |
| 67 * expects an object structure like the policyDataFormat above. | 67 * expects an object structure like the policyDataFormat above. |
| 68 * @param {Object} policyData Detailed info about policies. | 68 * @param {Object} policyData Detailed info about policies. |
| 69 */ | 69 */ |
| 70 renderTemplate: function(policyData) { | 70 renderTemplate: function(policyData) { |
| 71 this.noActivePolicies_ = !policyData.anyPoliciesSet; | 71 this.noActivePolicies_ = !policyData.anyPoliciesSet; |
| 72 | 72 |
| 73 if (this.noActivePolicies_) | 73 if (this.noActivePolicies_) |
| 74 $('no-policies').hidden = false; | 74 $('no-policies').hidden = false; |
| 75 if (policyData.status.displayStatusSection) | 75 if (policyData.status.displayStatusSection) |
| 76 $('status-section').hidden = false;; | 76 $('status-section').hidden = false; |
| 77 | 77 |
| 78 // This is the javascript code that processes the template: | 78 // This is the javascript code that processes the template: |
| 79 var input = new JsEvalContext(policyData); | 79 var input = new JsEvalContext(policyData); |
| 80 var output = $('data-template'); | 80 var output = $('data-template'); |
| 81 jstProcess(input, output); | 81 jstProcess(input, output); |
| 82 | 82 |
| 83 var toggles = document.querySelectorAll('.policy-set * .toggler'); | 83 var toggles = document.querySelectorAll('.policy-set * .toggler'); |
| 84 for (var i = 0; i < toggles.length; i++) { | 84 for (var i = 0; i < toggles.length; i++) { |
| 85 toggles[i].hidden = true; | 85 toggles[i].hidden = true; |
| 86 toggles[i].onclick = function() { | 86 toggles[i].onclick = function() { |
| 87 Policy.getInstance().toggleCellExpand_(this); | 87 Policy.getInstance().toggleCellExpand_(this); |
| 88 }; | 88 }; |
| 89 } | 89 } |
| 90 | 90 |
| 91 var containers = document.querySelectorAll('.text-container'); | 91 var containers = document.querySelectorAll('.text-container'); |
| 92 for (var i = 0; i < containers.length; i++) | 92 for (var i = 0; i < containers.length; i++) |
| 93 this.initTextContainer_(containers[i]) | 93 this.initTextContainer_(containers[i]); |
| 94 }, | 94 }, |
| 95 | 95 |
| 96 /** | 96 /** |
| 97 * Filters the table of policies by name. | 97 * Filters the table of policies by name. |
| 98 * @param {string} term The search string. | 98 * @param {string} term The search string. |
| 99 */ | 99 */ |
| 100 filterTable: function(term) { | 100 filterTable: function(term) { |
| 101 this.searchTerm_ = term.toLowerCase(); | 101 this.searchTerm_ = term.toLowerCase(); |
| 102 var table = $('policy-table'); | 102 var table = $('policy-table'); |
| 103 var showUnsent = $('toggle-unsent-policies').checked; | 103 var showUnsent = $('toggle-unsent-policies').checked; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 * status data. | 249 * status data. |
| 250 */ | 250 */ |
| 251 Policy.initialize = function() { | 251 Policy.initialize = function() { |
| 252 i18nTemplate.process(document, templateData); | 252 i18nTemplate.process(document, templateData); |
| 253 Policy.requestData(); | 253 Policy.requestData(); |
| 254 | 254 |
| 255 // Set HTML event handlers. | 255 // Set HTML event handlers. |
| 256 $('fetch-policies-button').onclick = function(event) { | 256 $('fetch-policies-button').onclick = function(event) { |
| 257 this.disabled = true; | 257 this.disabled = true; |
| 258 Policy.triggerPolicyFetch(); | 258 Policy.triggerPolicyFetch(); |
| 259 } | 259 } |
|
Dan Beam
2012/04/05 22:24:13
;
Tyler Breisacher (Chromium)
2012/04/05 22:49:55
Done.
| |
| 260 | 260 |
| 261 $('toggle-unsent-policies').onchange = function(event) { | 261 $('toggle-unsent-policies').onchange = function(event) { |
| 262 Policy.getInstance().updatePolicyVisibility(); | 262 Policy.getInstance().updatePolicyVisibility(); |
| 263 }; | 263 }; |
| 264 | 264 |
| 265 $('search-field').onsearch = function(event) { | 265 $('search-field').onsearch = function(event) { |
| 266 Policy.getInstance().filterTable(this.value); | 266 Policy.getInstance().filterTable(this.value); |
| 267 }; | 267 }; |
| 268 }; | 268 }; |
| 269 | 269 |
| 270 // Export | 270 // Export |
| 271 return { | 271 return { |
| 272 Policy: Policy | 272 Policy: Policy |
| 273 }; | 273 }; |
| 274 }); | 274 }); |
| 275 | 275 |
| 276 var Policy = policies.Policy; | 276 var Policy = policies.Policy; |
| 277 | 277 |
| 278 // Get data and have it displayed upon loading. | 278 // Get data and have it displayed upon loading. |
|
Dan Beam
2012/04/05 22:24:13
delicious copy pasta is not so delicious
Tyler Breisacher (Chromium)
2012/04/05 22:49:55
♨
| |
| 279 document.addEventListener('DOMContentLoaded', policies.Policy.initialize); | 279 document.addEventListener('DOMContentLoaded', policies.Policy.initialize); |
| OLD | NEW |