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

Side by Side Diff: chrome/browser/resources/offline_pages/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, 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.
dewittj 2016/05/25 21:03:50 I think you have not added this to compiled resour
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 * Clear the specified table.
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 * @param {HTMLElement} element A HTML element
dewittj 2016/05/25 21:03:50 @param {?HTMLElement} if nullable, does $() return
33 * @param {Object} data An array object representing stored offline pages
dewittj 2016/05/25 21:03:50 If i understand data right, this should be: @para
34 */
35 function fillStoredPages(element, data) {
36 if (!element) {
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++) {
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
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
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());
127 });
128 chrome.send('deleteSelectedPages', [selectedIds]);
129 }
130
131 /**
132 * Initializing everything.
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);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698