OLD | NEW |
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 /** | 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. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 this.setToggleEventHandlers_(); | 82 |
| 83 var toggles = document.querySelectorAll('.policy-set * .toggler'); |
| 84 for (var i = 0; i < toggles.length; i++) { |
| 85 toggles[i].hidden = true; |
| 86 toggles[i].onclick = function() { |
| 87 Policy.getInstance().toggleCellExpand_(this); |
| 88 }; |
| 89 } |
| 90 |
| 91 var containers = document.querySelectorAll('.text-container'); |
| 92 for (var i = 0; i < containers.length; i++) |
| 93 this.initTextContainer_(containers[i]) |
83 }, | 94 }, |
84 | 95 |
85 /** | 96 /** |
86 * Filters the table of policies by name. | 97 * Filters the table of policies by name. |
87 * @param {string} term The search string. | 98 * @param {string} term The search string. |
88 */ | 99 */ |
89 filterTable: function(term) { | 100 filterTable: function(term) { |
90 this.searchTerm_ = term.toLowerCase(); | 101 this.searchTerm_ = term.toLowerCase(); |
91 var table = $('policy-table'); | 102 var table = $('policy-table'); |
92 var showUnsent = $('toggle-unsent-policies').checked; | 103 var showUnsent = $('toggle-unsent-policies').checked; |
(...skipping 24 matching lines...) Expand all Loading... |
117 | 128 |
118 var tableRows = document.getElementsByClassName('policy-unset'); | 129 var tableRows = document.getElementsByClassName('policy-unset'); |
119 for (var i = 0; i < tableRows.length; i++) | 130 for (var i = 0; i < tableRows.length; i++) |
120 tableRows[i].hidden = !($('toggle-unsent-policies').checked); | 131 tableRows[i].hidden = !($('toggle-unsent-policies').checked); |
121 | 132 |
122 // Filter table again in case a search was active. | 133 // Filter table again in case a search was active. |
123 this.filterTable(this.searchTerm_); | 134 this.filterTable(this.searchTerm_); |
124 }, | 135 }, |
125 | 136 |
126 /** | 137 /** |
127 * Set event handlers for the "Show more"/"Hide" links generated by | |
128 * jstemplate. | |
129 * @private | |
130 */ | |
131 setToggleEventHandlers_: function() { | |
132 var toggles = document.querySelectorAll('.policy-set * .toggler'); | |
133 for (var i = 0; i < toggles.length; i++) { | |
134 toggles[i].onclick = function() { | |
135 Policy.getInstance().toggleCellExpand_(this); | |
136 }; | |
137 } | |
138 }, | |
139 | |
140 /** | |
141 * Expands or collapses a table cell that has overflowing text. | 138 * Expands or collapses a table cell that has overflowing text. |
142 * @param {Object} toggler The toggler that was clicked on. | 139 * @param {Object} toggler The toggler that was clicked on. |
143 * @private | 140 * @private |
144 */ | 141 */ |
145 toggleCellExpand_: function(toggler) { | 142 toggleCellExpand_: function(toggler) { |
146 var tableCell = toggler.parentElement; | 143 var textContainer = toggler.parentElement; |
147 var textContainer = tableCell.querySelector('.text-container'); | 144 textContainer.collapsed = !textContainer.collapsed; |
148 | 145 |
149 if (textContainer.collapsed) | 146 if (textContainer.collapsed) |
| 147 this.collapseCell_(textContainer); |
| 148 else |
150 this.expandCell_(textContainer); | 149 this.expandCell_(textContainer); |
151 else | |
152 this.collapseCell_(textContainer); | |
153 | |
154 textContainer.collapsed = !textContainer.collapsed; | |
155 var expand = tableCell.querySelector('.expand'); | |
156 var collapse = tableCell.querySelector('.collapse'); | |
157 expand.style.display = textContainer.collapsed ? '' : 'none'; | |
158 collapse.style.display = textContainer.collapsed ? 'none' : ''; | |
159 }, | 150 }, |
160 | 151 |
161 /** | 152 /** |
162 * Collapses all expanded table cells and updates the visibility of the | 153 * Collapses all expanded table cells and updates the visibility of the |
163 * toggles accordingly. Should be called before the policy information in | 154 * toggles accordingly. Should be called before the policy information in |
164 * the table is updated. | 155 * the table is updated. |
165 */ | 156 */ |
166 collapseExpandedCells: function() { | 157 collapseExpandedCells: function() { |
167 var toggles = document.querySelectorAll('.policy-set * .toggler'); | 158 var textContainers = document.querySelectorAll('.text-expanded'); |
168 for (var i = 0; i < toggles.length; i++) | |
169 toggles[i].style.display = 'none'; | |
170 | |
171 var textContainers = document.querySelectorAll('.expanded'); | |
172 for (var i = 0; i < textContainers.length; i++) | 159 for (var i = 0; i < textContainers.length; i++) |
173 this.collapseCell_(textContainers[i]); | 160 this.collapseCell_(textContainers[i]); |
174 }, | 161 }, |
175 | 162 |
176 /** | 163 /** |
177 * Expands a table cell so that all the text it contains is visible. | 164 * Expands a table cell so that all the text it contains is visible. |
178 * @param {Object} textContainer The cell's div element that contains the | 165 * @param {Object} textContainer The cell's div element that contains the |
179 * text. | 166 * text. |
180 * @private | 167 * @private |
181 */ | 168 */ |
182 expandCell_: function(textContainer) { | 169 expandCell_: function(textContainer) { |
183 textContainer.classList.remove('collapsed'); | 170 textContainer.classList.remove('text-collapsed'); |
184 textContainer.classList.add('expanded'); | 171 textContainer.classList.add('text-expanded'); |
| 172 textContainer.querySelector('.expand').hidden = true; |
| 173 textContainer.querySelector('.collapse').hidden = false; |
185 }, | 174 }, |
186 | 175 |
187 /** | 176 /** |
188 * Collapses a table cell so that overflowing text is hidden. | 177 * Collapses a table cell so that overflowing text is hidden. |
189 * @param {Object} textContainer The cell's div element that contains the | 178 * @param {Object} textContainer The cell's div element that contains the |
190 * text. | 179 * text. |
191 * @private | 180 * @private |
192 */ | 181 */ |
193 collapseCell_: function(textContainer) { | 182 collapseCell_: function(textContainer) { |
194 textContainer.classList.remove('expanded'); | 183 textContainer.classList.remove('text-expanded'); |
195 textContainer.classList.add('collapsed'); | 184 textContainer.classList.add('text-collapsed'); |
| 185 textContainer.querySelector('.expand').hidden = false; |
| 186 textContainer.querySelector('.collapse').hidden = true; |
| 187 }, |
| 188 |
| 189 /** |
| 190 * Initializes a text container, showing the expand toggle if necessary. |
| 191 * @param {Object} textContainer The text container element. |
| 192 */ |
| 193 initTextContainer_: function(textContainer) { |
| 194 textContainer.collapsed = true; |
| 195 var textValue = textContainer.querySelector('.text-value'); |
| 196 |
| 197 // If the text is wider than the text container, the expand toggler should |
| 198 // appear. |
| 199 if (textContainer.offsetWidth < textValue.offsetWidth || |
| 200 textContainer.offsetHeight < textValue.offsetHeight) { |
| 201 this.collapseCell_(textContainer); |
| 202 } |
196 } | 203 } |
197 }; | 204 }; |
198 | 205 |
199 /** | 206 /** |
200 * Asks the C++ PolicyUIHandler to get details about policies and status | 207 * Asks the C++ PolicyUIHandler to get details about policies and status |
201 * information. The PolicyUIHandler should reply to returnData() (below). | 208 * information. The PolicyUIHandler should reply to returnData() (below). |
202 */ | 209 */ |
203 Policy.requestData = function() { | 210 Policy.requestData = function() { |
204 chrome.send('requestData'); | 211 chrome.send('requestData'); |
205 }; | 212 }; |
(...skipping 25 matching lines...) Expand all Loading... |
231 /** | 238 /** |
232 * Determines whether a policy should be visible or not. | 239 * Determines whether a policy should be visible or not. |
233 * @param {Object} policy An entry in the 'policies' array given by the above | 240 * @param {Object} policy An entry in the 'policies' array given by the above |
234 * PolicyDataFormat. | 241 * PolicyDataFormat. |
235 */ | 242 */ |
236 Policy.shouldDisplayPolicy = function(policy) { | 243 Policy.shouldDisplayPolicy = function(policy) { |
237 return $('toggle-unsent-policies').checked || policy.set; | 244 return $('toggle-unsent-policies').checked || policy.set; |
238 }; | 245 }; |
239 | 246 |
240 /** | 247 /** |
241 * Returns true if the "Show more" toggle should appear in a table cell and | |
242 * false if not. | |
243 * @param {Object} expandToggle The "Show more" DOM element. | |
244 */ | |
245 Policy.shouldShowExpand = function(expandToggle) { | |
246 var textContainer = | |
247 expandToggle.parentNode.querySelector('.text-container'); | |
248 textContainer.collapsed = true; | |
249 var cellText = textContainer.querySelector('.cell-text'); | |
250 | |
251 // If the text is wider than the text container, the expand toggler should | |
252 // appear. | |
253 return textContainer.offsetWidth < cellText.offsetWidth; | |
254 }; | |
255 | |
256 /** | |
257 * Initializes the page and loads the list of policies and the policy | 248 * Initializes the page and loads the list of policies and the policy |
258 * status data. | 249 * status data. |
259 */ | 250 */ |
260 Policy.initialize = function() { | 251 Policy.initialize = function() { |
261 i18nTemplate.process(document, templateData); | 252 i18nTemplate.process(document, templateData); |
262 Policy.requestData(); | 253 Policy.requestData(); |
263 | 254 |
264 // Set HTML event handlers. | 255 // Set HTML event handlers. |
265 $('fetch-policies-button').onclick = function(event) { | 256 $('fetch-policies-button').onclick = function(event) { |
266 this.disabled = true; | 257 this.disabled = true; |
(...skipping 12 matching lines...) Expand all Loading... |
279 // Export | 270 // Export |
280 return { | 271 return { |
281 Policy: Policy | 272 Policy: Policy |
282 }; | 273 }; |
283 }); | 274 }); |
284 | 275 |
285 var Policy = policies.Policy; | 276 var Policy = policies.Policy; |
286 | 277 |
287 // Get data and have it displayed upon loading. | 278 // Get data and have it displayed upon loading. |
288 document.addEventListener('DOMContentLoaded', policies.Policy.initialize); | 279 document.addEventListener('DOMContentLoaded', policies.Policy.initialize); |
OLD | NEW |