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 * Callback to refresh the list of directives. | |
7 * @param {Array.<Object>} directives | |
Dan Beam
2014/12/08 22:41:59
can you make this type stricter (e.g. {{type: stri
Charlie
2014/12/08 23:37:07
Done. Can I run closure for just this file and hav
Dan Beam
2014/12/08 23:52:56
create a chrome/browser/resources/compiled_resourc
| |
8 */ | |
9 function refreshDirectives(directives) { | |
10 var table = $('directives-table').tBodies[0]; | |
11 | |
12 // Fix the directives table to have the correct number of rows. | |
13 while (table.rows.length < directives.length) | |
14 table.insertRow(); | |
15 while (table.rows.length > directives.length) | |
16 table.deleteRow(); | |
17 | |
18 // Populate the directives into the table. | |
19 directives.forEach(function(directive, index) { | |
20 var row = table.rows.item(index); | |
21 while (row.cells.length < 3) | |
22 row.insertCell(); | |
23 | |
24 row.cells.item(0).textContent = directive.type; | |
25 row.cells.item(1).textContent = directive.medium; | |
26 row.cells.item(2).textContent = directive.duration; | |
27 }); | |
28 } | |
29 | |
30 /** | |
31 * Callback to add or update sent tokens. | |
32 * @param {Object} token | |
33 */ | |
34 function updateSentToken(token) { | |
35 updateTokenTable($('sent-tokens-table'), token); | |
36 } | |
37 | |
38 /** | |
39 * Callback to add or update received tokens. | |
40 * @param {Object} token | |
41 */ | |
42 function updateReceivedToken(token) { | |
43 updateTokenTable($('received-tokens-table'), token); | |
44 } | |
45 | |
46 /** | |
47 * Add or update a token in the specified table. | |
48 * @param {HTMLTableElement} table | |
49 * @param {Object} token | |
50 */ | |
51 function updateTokenTable(table, token) { | |
52 var rows = table.tBodies[0].rows; | |
53 | |
54 var index; | |
55 for (index = 0; index < rows.length; index++) { | |
56 var row = rows.item(index); | |
57 if (row.cells[0].textContent == token.id) { | |
58 updateTokenRow(row, token); | |
59 break; | |
60 } | |
61 } | |
62 | |
63 if (index == rows.length) | |
64 updateTokenRow(table.tBodies[0].insertRow(), token); | |
65 } | |
66 | |
67 /* | |
68 * Update a token on the specified row. | |
69 * @param {HTMLTableRowElement} row | |
70 * @param {Object} token | |
Dan Beam
2014/12/08 22:41:59
nit: can you @typedef tokens as well?
Charlie
2014/12/08 23:37:07
Done.
| |
71 */ | |
72 function updateTokenRow(row, token) { | |
73 while (row.cells.length < 4) | |
74 row.insertCell(); | |
75 row.className = token.statuses; | |
76 | |
77 row.cells[0].textContent = token.id; | |
78 row.cells[1].textContent = | |
79 token.statuses.replace('confirmed', '(Confirmed)'); | |
Dan Beam
2014/12/08 22:41:59
i18n?
Charlie
2014/12/08 23:37:07
i18n of our debug UI is currently a non-goal. More
| |
80 row.cells[2].textContent = token.medium; | |
81 row.cells[3].textContent = token.time; | |
82 } | |
83 | |
84 document.addEventListener('DOMContentLoaded', function() { | |
85 chrome.send('populateCopresenceState'); | |
86 }); | |
OLD | NEW |