Rename GetIconID to GetIconId
[chromium-blink-merge.git] / chrome / browser / resources / copresence.js
blobce38e8896a84cb0005b2d574c439fa0d7b404231
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.
5 /**
6 * Debug information about an active copresence directive.
7 * @typedef {{
8 * type: string,
9 * medium: string,
10 * duration: string
11 * }}
13 var Directive;
15 /**
16 * Debug information about a recent copresence token.
17 * @typedef {{
18 * id: string,
19 * statuses: string,
20 * medium: string,
21 * time: string
22 * }}
24 var Token;
26 /**
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)
35 table.insertRow();
36 while (table.rows.length > directives.length)
37 table.deleteRow();
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)
43 row.insertCell();
45 row.cells.item(0).textContent = directive.type;
46 row.cells.item(1).textContent = directive.medium;
47 row.cells.item(2).textContent = directive.duration;
48 });
51 /**
52 * Callback to add or update transmitted tokens.
53 * @param {Token} token
55 function updateTransmittedToken(token) {
56 updateTokenTable($('transmitted-tokens-table'), token);
59 /**
60 * Callback to add or update received tokens.
61 * @param {Token} token
63 function updateReceivedToken(token) {
64 updateTokenTable($('received-tokens-table'), token);
67 /**
68 * Callback to clear out the token tables.
70 function clearTokens() {
71 clearTable($('transmitted-tokens-table'));
72 clearTable($('received-tokens-table'));
75 /**
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;
83 var index;
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);
88 break;
92 if (index == rows.length)
93 updateTokenRow(table.tBodies[0].insertRow(), token);
96 /**
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)
103 row.insertCell();
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)
120 body.deleteRow();
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');