1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 * Takes the |componentsData| input argument which represents data about the
9 * currently installed components and populates the html jstemplate with
10 * that data. It expects an object structure like the above.
11 * @param {Object} componentsData Detailed info about installed components.
12 * Same expected format as returnComponentsData().
14 function renderTemplate(componentsData) {
15 // This is the javascript code that processes the template:
16 var input = new JsEvalContext(componentsData);
17 var output = $('component-template').cloneNode(true);
18 $('component-placeholder').innerHTML = '';
19 $('component-placeholder').appendChild(output);
20 jstProcess(input, output);
21 output.removeAttribute('hidden');
25 * Asks the C++ ComponentsDOMHandler to get details about the installed
27 * The ComponentsDOMHandler should reply to returnComponentsData() (below).
29 function requestComponentsData() {
30 chrome.send('requestComponentsData');
34 * Called by the WebUI to re-populate the page with data representing the
35 * current state of installed components.
36 * @param {Object} componentsData Detailed info about installed components. The
37 * template expects each component's format to match the following
38 * structure to correctly populate the page:
52 function returnComponentsData(componentsData) {
53 var bodyContainer = $('body-container');
54 var body = document.body;
56 bodyContainer.style.visibility = 'hidden';
59 renderTemplate(componentsData);
61 // Add handlers to dynamically created HTML elements.
62 var links = document.getElementsByClassName('button-check-update');
63 for (var i = 0; i < links.length; i++) {
64 links[i].onclick = function(e) {
65 handleCheckUpdate(this);
70 // Disable some controls for Guest in ChromeOS.
72 uiAccountTweaks.UIAccountTweaks.applyGuestModeVisibility(document);
74 bodyContainer.style.visibility = 'visible';
75 body.className = 'show-tmi-mode-initial';
79 * This event function is called from component UI indicating changed state
80 * of component updater service.
81 * @param {Object} eventArgs Contains event and component ID. Component ID is
84 function onComponentEvent(eventArgs) {
85 if (eventArgs['id']) {
86 var id = eventArgs['id'];
87 $('status-' + id).textContent = eventArgs['event'];
92 * Handles an 'enable' or 'disable' button getting clicked.
93 * @param {HTMLElement} node The HTML element representing the component
94 * being checked for update.
96 function handleCheckUpdate(node) {
97 $('status-' + String(node.id)).textContent =
98 loadTimeData.getString('checkingLabel');
100 // Tell the C++ ComponentssDOMHandler to check for update.
101 chrome.send('checkUpdate', [String(node.id)]);
104 // Get data and have it displayed upon loading.
105 document.addEventListener('DOMContentLoaded', requestComponentsData);