OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 /** | |
6 * Debug information about an active copresence directive. | |
7 * @typedef {{ | |
8 * type:string, | |
Dan Beam
2014/12/09 05:33:38
nit: type: string
^ \s
Charlie
2014/12/17 23:39:55
Done.
| |
9 * medium:string, | |
10 * duration:string | |
11 * }} | |
12 */ | |
13 var Directive; | |
14 | |
15 /** | |
16 * Debug information about a recent copresence token. | |
17 * @typedef {{ | |
18 * id:string, | |
19 * statuses:string, | |
20 * medium:string, | |
21 * time:string | |
22 * }} | |
23 */ | |
24 var Token; | |
25 | |
26 /** | |
27 * Callback to refresh the list of directives. | |
28 * @param {Array.<Directive>} directives | |
Dan Beam
2014/12/09 05:33:38
nit: Array<Directive>
Charlie
2014/12/17 23:39:55
Oh. I thought jsdoc required the dot?
http://usej
| |
29 */ | |
30 function refreshDirectives(directives) { | |
31 var table = $('directives-table').tBodies[0]; | |
32 | |
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(); | |
38 | |
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(); | |
44 | |
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 }); | |
49 } | |
50 | |
51 /** | |
52 * Callback to add or update sent tokens. | |
53 * @param {Token} token | |
54 */ | |
55 function updateSentToken(token) { | |
56 updateTokenTable($('sent-tokens-table'), token); | |
57 } | |
58 | |
59 /** | |
60 * Callback to add or update received tokens. | |
61 * @param {Token} token | |
62 */ | |
63 function updateReceivedToken(token) { | |
64 updateTokenTable($('received-tokens-table'), token); | |
65 } | |
66 | |
67 /** | |
68 * Add or update a token in the specified table. | |
69 * @param {HTMLTableElement} table | |
70 * @param {Token} token | |
71 */ | |
72 function updateTokenTable(table, token) { | |
73 var rows = table.tBodies[0].rows; | |
74 | |
75 var index; | |
76 for (index = 0; index < rows.length; index++) { | |
77 var row = rows.item(index); | |
78 if (row.cells[0].textContent == token.id) { | |
79 updateTokenRow(row, token); | |
80 break; | |
81 } | |
82 } | |
83 | |
84 if (index == rows.length) | |
85 updateTokenRow(table.tBodies[0].insertRow(), token); | |
86 } | |
87 | |
88 /** | |
89 * Update a token on the specified row. | |
90 * @param {HTMLTableRowElement} row | |
91 * @param {Token} token | |
92 */ | |
93 function updateTokenRow(row, token) { | |
94 while (row.cells.length < 4) | |
95 row.insertCell(); | |
96 row.className = token.statuses; | |
97 | |
98 row.cells[0].textContent = token.id; | |
99 row.cells[1].textContent = | |
100 token.statuses.replace('confirmed', '(Confirmed)'); | |
101 row.cells[2].textContent = token.medium; | |
102 row.cells[3].textContent = token.time; | |
103 } | |
104 | |
105 document.addEventListener('DOMContentLoaded', function() { | |
106 chrome.send('populateCopresenceState'); | |
107 }); | |
OLD | NEW |