Chromium Code Reviews| Index: components/offline_pages/resources/offline_internals.js |
| diff --git a/components/offline_pages/resources/offline_internals.js b/components/offline_pages/resources/offline_internals.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..672eaa1e50073fc4babff1aa2f4523b4ec60ee7c |
| --- /dev/null |
| +++ b/components/offline_pages/resources/offline_internals.js |
| @@ -0,0 +1,138 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +cr.define('offlineInternals', function() { |
| + 'use strict'; |
| + |
| + var storedPagesAttributes = ['onlineUrl', 'namespace', 'size']; |
| + var queueAttributes = ['onlineUrl', 'creation time', 'status']; |
| + |
| + /** |
| + * Remove all the child nodes of the element |
| + * @param {HTMLElement} element A HTML element |
| + */ |
| + function clearChildren(element) { |
| + element.textContent = ''; |
| + } |
| + |
| + /** |
| + * Refresh the tables |
| + */ |
| + function refreshTable(tableId) { |
| + var element = $(tableId); |
| + if (!element) |
| + return; |
| + |
| + clearChildren(element); |
| + } |
| + |
| + /** |
| + * Fill stored pages table. |
| + */ |
| + function fillStoredPages(element, data) { |
| + if (element == null) { |
| + return; |
| + } |
| + for (var i = 0; i < data.length; i++) { |
| + var row = document.createElement('tr'); |
| + |
| + var checkboxCell = document.createElement('td'); |
| + var checkbox = document.createElement('input'); |
| + checkbox.setAttribute('type', 'checkbox'); |
| + checkbox.setAttribute('name', 'stored'); |
| + checkbox.setAttribute('value', data[i]['id']); |
| + |
| + checkboxCell.appendChild(checkbox); |
| + row.appendChild(checkboxCell); |
| + |
| + for (var key in storedPagesAttributes) { |
| + var cell = document.createElement('td'); |
| + cell.textContent = data[i][key]; |
| + row.appendChild(cell); |
| + } |
| + element.appendChild(row); |
| + } |
| + } |
| + |
| + /** |
| + * Fill requests table. |
| + */ |
| + function fillRequestQueue(element, data) { |
| + if (element == null) { |
| + return; |
| + } |
| + for (var i = 0; i < data.length; i++) { |
| + var row = document.createElement('tr'); |
| + |
| + for (var key in queueAttributes) { |
| + var cell = document.createElement('td'); |
| + cell.textContent = data[i][key]; |
| + row.appendChild(cell); |
| + } |
| + element.appendChild(row); |
| + } |
| + } |
| + |
| + /** |
| + * Refresh all displayed information. |
| + */ |
| + function refreshAll() { |
| + chrome.send('getOfflineInternalsInfo', []); |
| + } |
| + |
| + /** |
| + * Clear pages. |
| + */ |
| + function clearPages() { |
| + chrome.send('clearPages', []); |
| + } |
| + |
| + /** |
| + * Callback when pages are cleared. |
| + */ |
| + function pagesCleared() { |
| + // does nothing yet. |
|
fgorski
2016/05/24 17:50:18
add TODO and explain what will be done here.
chili
2016/05/24 22:52:30
Done.
|
| + } |
| + |
| + /** |
| + * Callback when information is loaded. |
| + */ |
| + function setOfflineInternalsInfo(info) { |
| + refreshTable('stored-pages'); |
|
fgorski
2016/05/24 17:50:18
this sounds more like clearTable.
chili
2016/05/24 22:52:30
Done.
|
| + refreshTable('request-queue'); |
| + |
| + fillStoredPages($('stored-pages'), info.AllPages); |
| + fillRequestQueue($('request-queue'), info.Queue); |
| + } |
| + |
| + /** |
| + * Clear selected pages. |
| + */ |
| + function clearSelectedPages() { |
|
fgorski
2016/05/24 17:50:18
would delete selected pages be more suitable here?
chili
2016/05/24 22:52:30
Renamed clear -> delete.
This will eventually cal
|
| + var selectedIds = new Array(); |
| + $('input:checkbox[name=stored]:checked').each(function() { |
| + selectedIds.push($(this).val()); |
| + }); |
| + chrome.send('clearSelectedPages', [selectedIds]); |
| + } |
| + |
| + /** |
| + * Initializing everything. |
| + */ |
| + function initialize() { |
| + $('clear-all').onclick = clearPages; |
| + $('clear-selected').onClick = clearSelectedPages; |
| + $('refresh').onclick = refreshAll; |
| + chrome.send('getOfflineInternalsInfo', []); |
| + } |
| + |
| + // Return an object with all of the exports. |
| + return { |
| + initialize: initialize, |
| + setOfflineInternalsInfo: setOfflineInternalsInfo, |
| + pagesCleared: pagesCleared |
| + }; |
| +}); |
| + |
| +document.addEventListener('DOMContentLoaded', offlineInternals.initialize); |