Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 cr.define('offlineInternals', function() { | |
| 6 'use strict'; | |
| 7 | |
| 8 var storedPagesAttributes = ['onlineUrl', 'namespace', 'size']; | |
|
Dan Beam
2016/05/26 00:54:39
nit: FINAL_CONST_LIKE_THIS (i.e. STORED_PAGE_ATTRI
chili
2016/05/27 01:36:59
Done.
| |
| 9 var queueAttributes = ['onlineUrl', 'creation time', 'status']; | |
| 10 | |
| 11 /** | |
| 12 * Remove all the child nodes of the element. | |
| 13 * @param {HTMLElement} element A HTML element | |
| 14 */ | |
| 15 function clearChildren(element) { | |
| 16 element.textContent = ''; | |
| 17 } | |
| 18 | |
| 19 /** | |
| 20 * Clear the specified table. | |
| 21 */ | |
| 22 function clearTable(tableId) { | |
| 23 var element = $(tableId); | |
| 24 if (!element) | |
| 25 return; | |
|
Dan Beam
2016/05/26 00:54:39
shouldn't this blow up because of programmer error
chili
2016/05/27 01:36:59
I've removed the checks.
Not sure what you mean b
| |
| 26 | |
| 27 clearChildren(element); | |
| 28 } | |
| 29 | |
| 30 /** | |
| 31 * Fill stored pages table. | |
| 32 * @param {HTMLElement} element A HTML element | |
| 33 * @param {Object} data An array object representing stored offline pages | |
| 34 */ | |
| 35 function fillStoredPages(element, data) { | |
| 36 if (!element) { | |
|
Dan Beam
2016/05/26 00:54:39
nit: no curlies around 1-line conditionals
Dan Beam
2016/05/26 00:54:39
when should this validly just return?
chili
2016/05/27 01:36:59
Acknowledged.
chili
2016/05/27 01:36:59
Done.
| |
| 37 return; | |
| 38 } | |
| 39 for (var i = 0; i < data.length; i++) { | |
| 40 var row = document.createElement('tr'); | |
| 41 | |
| 42 var checkboxCell = document.createElement('td'); | |
| 43 var checkbox = document.createElement('input'); | |
| 44 checkbox.setAttribute('type', 'checkbox'); | |
| 45 checkbox.setAttribute('name', 'stored'); | |
| 46 checkbox.setAttribute('value', data[i]['id']); | |
| 47 | |
| 48 checkboxCell.appendChild(checkbox); | |
| 49 row.appendChild(checkboxCell); | |
| 50 | |
| 51 for (var keyIndex = 0; | |
| 52 keyIndex < storedPagesAttributes.length; | |
| 53 keyIndex++) { | |
|
Dan Beam
2016/05/26 00:54:39
i don't know if this runs on iOS (or if the linter
chili
2016/05/27 01:36:59
offline stuff is only available on android. trying
| |
| 54 var cell = document.createElement('td'); | |
| 55 cell.textContent = data[i][storedPagesAttributes[keyIndex]]; | |
| 56 row.appendChild(cell); | |
| 57 } | |
| 58 element.appendChild(row); | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 /** | |
| 63 * Fill requests table. | |
| 64 * @param {HTMLElement} element A HTML element | |
| 65 * @param {Object} data An array object representing the request queue | |
|
Dan Beam
2016/05/26 00:54:39
Object -> !Array
chili
2016/05/27 01:36:59
Done.
| |
| 66 */ | |
| 67 function fillRequestQueue(element, data) { | |
| 68 if (!element) { | |
| 69 return; | |
| 70 } | |
| 71 for (var i = 0; i < data.length; i++) { | |
| 72 var row = document.createElement('tr'); | |
| 73 | |
| 74 for (var keyIndex = 0; | |
| 75 keyIndex < queueAttributes.length; | |
| 76 keyIndex++) { | |
| 77 var cell = document.createElement('td'); | |
| 78 cell.textContent = data[i][queueAttributes[keyIndex]]; | |
| 79 row.appendChild(cell); | |
| 80 } | |
| 81 element.appendChild(row); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 /** | |
| 86 * Refresh all displayed information. | |
| 87 */ | |
| 88 function refreshAll() { | |
| 89 chrome.send('getOfflineInternalsInfo'); | |
| 90 } | |
| 91 | |
| 92 /** | |
| 93 * Delete all pages in the offline store. | |
| 94 */ | |
| 95 function deleteAllPages() { | |
| 96 chrome.send('deleteAllPages'); | |
| 97 } | |
| 98 | |
| 99 /** | |
| 100 * Callback when pages are deleted. | |
| 101 */ | |
| 102 function pagesDeleted() { | |
| 103 // TODO(chili): decide what to do here. Perhaps a refresh of just | |
| 104 // the stored pages table? | |
| 105 } | |
| 106 | |
| 107 /** | |
| 108 * Callback when information is loaded. | |
| 109 * @param {Object} info An object containing both stored pages and | |
|
Dan Beam
2016/05/26 00:54:39
it'd be useful to type this more strongly, i.e.
chili
2016/05/27 01:36:59
Done.
| |
| 110 * request queue status | |
| 111 */ | |
| 112 function setOfflineInternalsInfo(info) { | |
| 113 clearTable('stored-pages'); | |
| 114 clearTable('request-queue'); | |
| 115 | |
| 116 fillStoredPages($('stored-pages'), info.AllPages); | |
| 117 fillRequestQueue($('request-queue'), info.Queue); | |
| 118 } | |
| 119 | |
| 120 /** | |
| 121 * Delete selected pages from the offline store. | |
| 122 */ | |
| 123 function deleteSelectedPages() { | |
| 124 var selectedIds = new Array(); | |
| 125 $('input:checkbox[name=stored]:checked').each(function() { | |
| 126 selectedIds.push($(this).val()); | |
|
Dan Beam
2016/05/26 00:54:39
$ is not jQuery
chili
2016/05/27 01:36:59
Darn :(
| |
| 127 }); | |
| 128 chrome.send('deleteSelectedPages', [selectedIds]); | |
| 129 } | |
| 130 | |
| 131 /** | |
| 132 * Initializing everything. | |
|
Dan Beam
2016/05/26 00:54:39
is this comment useful?
chili
2016/05/27 01:36:59
Done.
| |
| 133 */ | |
| 134 function initialize() { | |
| 135 $('clear-all').onclick = deleteAllPages; | |
| 136 $('clear-selected').onClick = deleteSelectedPages; | |
| 137 $('refresh').onclick = refreshAll; | |
| 138 chrome.send('getOfflineInternalsInfo'); | |
| 139 } | |
| 140 | |
| 141 // Return an object with all of the exports. | |
| 142 return { | |
| 143 initialize: initialize, | |
| 144 setOfflineInternalsInfo: setOfflineInternalsInfo, | |
| 145 pagesDeleted: pagesDeleted | |
| 146 }; | |
| 147 }); | |
| 148 | |
| 149 document.addEventListener('DOMContentLoaded', offlineInternals.initialize); | |
| OLD | NEW |