Chromium Code Reviews| 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 | |
| 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).innerText = directive.type; | |
|
xiyuan
2014/12/05 18:56:55
nit: .innerText -> .textContent, here an other pla
Charlie
2014/12/05 21:26:08
Done.
| |
| 25 row.cells.item(1).innerText = directive.medium; | |
| 26 row.cells.item(2).innerText = 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].innerText == 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 | |
| 71 */ | |
| 72 function updateTokenRow(row, token) { | |
| 73 while (row.cells.length < 4) | |
| 74 row.insertCell(); | |
| 75 row.cells[0].innerText = token.id; | |
| 76 row.cells[1].innerText = token.status; | |
| 77 row.cells[2].innerText = token.medium; | |
| 78 row.cells[3].innerText = token.time; | |
| 79 } | |
| 80 | |
| 81 document.addEventListener('DOMContentLoaded', function() { | |
| 82 chrome.send('populateCopresenceState'); | |
| 83 }); | |
| OLD | NEW |