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

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: Resolve cl comments Created 4 years, 6 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
jianli 2016/05/25 00:17:17 Comment is not consistent with the operation below
chili 2016/05/25 02:14:48 Done.
21 */
22 function clearTable(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) {
jianli 2016/05/25 00:17:17 nit: be consistent with line 24
chili 2016/05/25 02:14:48 Done.
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) {
jianli 2016/05/25 00:17:17 ditto
chili 2016/05/25 02:14:48 Done.
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 * Delete all pages in the offline store.
86 */
87 function deleteAllPages() {
88 chrome.send('deleteAllPages', []);
89 }
90
91 /**
92 * Callback when pages are deleted.
93 */
94 function pagesDeleted() {
95 // TODO(chili): decide what to do here. Perhaps a refresh of just
96 // the stored pages table?
97 }
98
99 /**
100 * Callback when information is loaded.
101 */
102 function setOfflineInternalsInfo(info) {
103 clearTable('stored-pages');
104 clearTable('request-queue');
105
106 fillStoredPages($('stored-pages'), info.AllPages);
107 fillRequestQueue($('request-queue'), info.Queue);
108 }
109
110 /**
111 * Delete selected pages from the offline store.
112 */
113 function deleteSelectedPages() {
114 var selectedIds = new Array();
115 $('input:checkbox[name=stored]:checked').each(function() {
116 selectedIds.push($(this).val());
117 });
118 chrome.send('deleteSelectedPages', [selectedIds]);
119 }
120
121 /**
122 * Initializing everything.
123 */
124 function initialize() {
125 $('clear-all').onclick = deleteAllPages;
126 $('clear-selected').onClick = deleteSelectedPages;
127 $('refresh').onclick = refreshAll;
128 chrome.send('getOfflineInternalsInfo', []);
129 }
130
131 // Return an object with all of the exports.
132 return {
133 initialize: initialize,
134 setOfflineInternalsInfo: setOfflineInternalsInfo,
135 pagesDeleted: pagesDeleted
136 };
137 });
138
139 document.addEventListener('DOMContentLoaded', offlineInternals.initialize);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698