1 // Copyright 2014 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.
6 * Debug information about an active copresence directive.
16 * Debug information about a recent copresence token.
27 * Callback to refresh the list of directives.
28 * @param {Array<Directive>} directives
30 function refreshDirectives(directives) {
31 var table = $('directives-table').tBodies[0];
33 // Fix the directives table to have the correct number of rows.
34 while (table.rows.length < directives.length)
36 while (table.rows.length > directives.length)
39 // Populate the directives into the table.
40 directives.forEach(function(directive, index) {
41 var row = table.rows.item(index);
42 while (row.cells.length < 3)
45 row.cells.item(0).textContent = directive.type;
46 row.cells.item(1).textContent = directive.medium;
47 row.cells.item(2).textContent = directive.duration;
52 * Callback to add or update transmitted tokens.
53 * @param {Token} token
55 function updateTransmittedToken(token) {
56 updateTokenTable($('transmitted-tokens-table'), token);
60 * Callback to add or update received tokens.
61 * @param {Token} token
63 function updateReceivedToken(token) {
64 updateTokenTable($('received-tokens-table'), token);
68 * Callback to clear out the token tables.
70 function clearTokens() {
71 clearTable($('transmitted-tokens-table'));
72 clearTable($('received-tokens-table'));
76 * Add or update a token in the specified table.
77 * @param {HTMLTableElement} table
78 * @param {Token} token
80 function updateTokenTable(table, token) {
81 var rows = table.tBodies[0].rows;
84 for (index = 0; index < rows.length; index++) {
85 var row = rows.item(index);
86 if (row.cells[0].textContent == token.id) {
87 updateTokenRow(row, token);
92 if (index == rows.length)
93 updateTokenRow(table.tBodies[0].insertRow(), token);
97 * Update a token on the specified row.
98 * @param {HTMLTableRowElement} row
99 * @param {Token} token
101 function updateTokenRow(row, token) {
102 while (row.cells.length < 4)
104 row.className = token.statuses;
106 row.cells[0].textContent = token.id;
107 row.cells[1].textContent =
108 token.statuses.replace('confirmed', '(Confirmed)');
109 row.cells[2].textContent = token.medium;
110 row.cells[3].textContent = token.time;
114 * Delete all the rows in a table.
115 * @param {HTMLTableElement} table
117 function clearTable(table) {
118 var body = table.tBodies[0];
119 while (body.rows.length > 0)
123 document.addEventListener('DOMContentLoaded', function() {
124 chrome.send('populateCopresenceState');
126 $('reset-button').addEventListener('click', function() {
127 if (confirm(loadTimeData.getString('confirm_delete')))
128 chrome.send('clearCopresenceState');