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 = $('componentTemplate');
18 jstProcess(input, output);
22 * Asks the C++ ComponentsDOMHandler to get details about the installed
24 * The ComponentsDOMHandler should reply to returnComponentsData() (below).
26 function requestComponentsData() {
27 chrome.send('requestComponentsData');
31 * Called by the WebUI to re-populate the page with data representing the
32 * current state of installed components.
33 * @param {Object} componentsData Detailed info about installed components. The
34 * template expects each component's format to match the following
35 * structure to correctly populate the page:
49 function returnComponentsData(componentsData) {
50 var bodyContainer = $('body-container');
51 var body = document.body;
53 bodyContainer.style.visibility = 'hidden';
56 renderTemplate(componentsData);
58 // Add handlers to dynamically created HTML elements.
59 var links = document.getElementsByClassName('button-check-update');
60 for (var i = 0; i < links.length; i++) {
61 links[i].onclick = function(e) {
62 handleCheckUpdate(this);
67 // Disable some controls for Guest in ChromeOS.
69 uiAccountTweaks.UIAccountTweaks.applyGuestModeVisibility(document);
71 bodyContainer.style.visibility = 'visible';
72 body.className = 'show-tmi-mode-initial';
76 * Handles an 'enable' or 'disable' button getting clicked.
77 * @param {HTMLElement} node The HTML element representing the component
78 * being checked for update.
80 function handleCheckUpdate(node) {
82 // Tell the C++ ComponentssDOMHandler to check for update.
83 chrome.send('checkUpdate', [String(node.id)]);
86 // Get data and have it displayed upon loading.
87 document.addEventListener('DOMContentLoaded', requestComponentsData);
89 // Add handlers to static HTML elements.
90 $('button-check-update').onclick = handleCheckUpdate;