Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: components/offline_pages/resources/offline_internals.js

Issue 2003883002: [Offline pages] Create offline internals page for Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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'];
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 * Refresh the tables
21 */
22 function refreshTable(tableId) {
23 var element = $(tableId);
24 if (!element)
25 return;
26
27 clearChildren(element);
28 }
29
30 /**
31 * Fill stored pages table.
32 */
33 function fillStoredPages(element, data) {
34 if (element == null) {
35 return;
36 }
37 for (var i = 0; i < data.length; i++) {
38 var row = document.createElement('tr');
39
40 var checkboxCell = document.createElement('td');
41 var checkbox = document.createElement('input');
42 checkbox.setAttribute('type', 'checkbox');
43 checkbox.setAttribute('name', 'stored');
44 checkbox.setAttribute('value', data[i]['id']);
45
46 checkboxCell.appendChild(checkbox);
47 row.appendChild(checkboxCell);
48
49 for (var key in storedPagesAttributes) {
50 var cell = document.createElement('td');
51 cell.textContent = data[i][key];
52 row.appendChild(cell);
53 }
54 element.appendChild(row);
55 }
56 }
57
58 /**
59 * Fill requests table.
60 */
61 function fillRequestQueue(element, data) {
62 if (element == null) {
63 return;
64 }
65 for (var i = 0; i < data.length; i++) {
66 var row = document.createElement('tr');
67
68 for (var key in queueAttributes) {
69 var cell = document.createElement('td');
70 cell.textContent = data[i][key];
71 row.appendChild(cell);
72 }
73 element.appendChild(row);
74 }
75 }
76
77 /**
78 * Refresh all displayed information.
79 */
80 function refreshAll() {
81 chrome.send('getOfflineInternalsInfo', []);
82 }
83
84 /**
85 * Clear pages.
86 */
87 function clearPages() {
88 chrome.send('clearPages', []);
89 }
90
91 /**
92 * Callback when pages are cleared.
93 */
94 function pagesCleared() {
95 // 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.
96 }
97
98 /**
99 * Callback when information is loaded.
100 */
101 function setOfflineInternalsInfo(info) {
102 refreshTable('stored-pages');
fgorski 2016/05/24 17:50:18 this sounds more like clearTable.
chili 2016/05/24 22:52:30 Done.
103 refreshTable('request-queue');
104
105 fillStoredPages($('stored-pages'), info.AllPages);
106 fillRequestQueue($('request-queue'), info.Queue);
107 }
108
109 /**
110 * Clear selected pages.
111 */
112 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
113 var selectedIds = new Array();
114 $('input:checkbox[name=stored]:checked').each(function() {
115 selectedIds.push($(this).val());
116 });
117 chrome.send('clearSelectedPages', [selectedIds]);
118 }
119
120 /**
121 * Initializing everything.
122 */
123 function initialize() {
124 $('clear-all').onclick = clearPages;
125 $('clear-selected').onClick = clearSelectedPages;
126 $('refresh').onclick = refreshAll;
127 chrome.send('getOfflineInternalsInfo', []);
128 }
129
130 // Return an object with all of the exports.
131 return {
132 initialize: initialize,
133 setOfflineInternalsInfo: setOfflineInternalsInfo,
134 pagesCleared: pagesCleared
135 };
136 });
137
138 document.addEventListener('DOMContentLoaded', offlineInternals.initialize);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698