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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/resources/DOMStorageItemsView.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month 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
1 /* 1 /*
2 * Copyright (C) 2008 Nokia Inc. All rights reserved. 2 * Copyright (C) 2008 Nokia Inc. All rights reserved.
3 * Copyright (C) 2013 Samsung Electronics. All rights reserved. 3 * Copyright (C) 2013 Samsung Electronics. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
13 * 13 *
14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY 14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 /** 27 /**
28 * @unrestricted 28 * @unrestricted
29 */ 29 */
30 WebInspector.DOMStorageItemsView = class extends WebInspector.SimpleView { 30 Resources.DOMStorageItemsView = class extends UI.SimpleView {
31 constructor(domStorage) { 31 constructor(domStorage) {
32 super(WebInspector.UIString('DOM Storage')); 32 super(Common.UIString('DOM Storage'));
33 33
34 this.domStorage = domStorage; 34 this.domStorage = domStorage;
35 35
36 this.element.classList.add('storage-view', 'table'); 36 this.element.classList.add('storage-view', 'table');
37 37
38 this.deleteButton = new WebInspector.ToolbarButton(WebInspector.UIString('De lete'), 'largeicon-delete'); 38 this.deleteButton = new UI.ToolbarButton(Common.UIString('Delete'), 'largeic on-delete');
39 this.deleteButton.setVisible(false); 39 this.deleteButton.setVisible(false);
40 this.deleteButton.addEventListener('click', this._deleteButtonClicked, this) ; 40 this.deleteButton.addEventListener('click', this._deleteButtonClicked, this) ;
41 41
42 this.refreshButton = new WebInspector.ToolbarButton(WebInspector.UIString('R efresh'), 'largeicon-refresh'); 42 this.refreshButton = new UI.ToolbarButton(Common.UIString('Refresh'), 'large icon-refresh');
43 this.refreshButton.addEventListener('click', this._refreshButtonClicked, thi s); 43 this.refreshButton.addEventListener('click', this._refreshButtonClicked, thi s);
44 44
45 this.domStorage.addEventListener( 45 this.domStorage.addEventListener(
46 WebInspector.DOMStorage.Events.DOMStorageItemsCleared, this._domStorageI temsCleared, this); 46 Resources.DOMStorage.Events.DOMStorageItemsCleared, this._domStorageItem sCleared, this);
47 this.domStorage.addEventListener( 47 this.domStorage.addEventListener(
48 WebInspector.DOMStorage.Events.DOMStorageItemRemoved, this._domStorageIt emRemoved, this); 48 Resources.DOMStorage.Events.DOMStorageItemRemoved, this._domStorageItemR emoved, this);
49 this.domStorage.addEventListener( 49 this.domStorage.addEventListener(
50 WebInspector.DOMStorage.Events.DOMStorageItemAdded, this._domStorageItem Added, this); 50 Resources.DOMStorage.Events.DOMStorageItemAdded, this._domStorageItemAdd ed, this);
51 this.domStorage.addEventListener( 51 this.domStorage.addEventListener(
52 WebInspector.DOMStorage.Events.DOMStorageItemUpdated, this._domStorageIt emUpdated, this); 52 Resources.DOMStorage.Events.DOMStorageItemUpdated, this._domStorageItemU pdated, this);
53 } 53 }
54 54
55 /** 55 /**
56 * @override 56 * @override
57 * @return {!Array.<!WebInspector.ToolbarItem>} 57 * @return {!Array.<!UI.ToolbarItem>}
58 */ 58 */
59 syncToolbarItems() { 59 syncToolbarItems() {
60 return [this.refreshButton, this.deleteButton]; 60 return [this.refreshButton, this.deleteButton];
61 } 61 }
62 62
63 /** 63 /**
64 * @override 64 * @override
65 */ 65 */
66 wasShown() { 66 wasShown() {
67 this._update(); 67 this._update();
68 } 68 }
69 69
70 /** 70 /**
71 * @override 71 * @override
72 */ 72 */
73 willHide() { 73 willHide() {
74 this.deleteButton.setVisible(false); 74 this.deleteButton.setVisible(false);
75 } 75 }
76 76
77 /** 77 /**
78 * @param {!WebInspector.Event} event 78 * @param {!Common.Event} event
79 */ 79 */
80 _domStorageItemsCleared(event) { 80 _domStorageItemsCleared(event) {
81 if (!this.isShowing() || !this._dataGrid) 81 if (!this.isShowing() || !this._dataGrid)
82 return; 82 return;
83 83
84 this._dataGrid.rootNode().removeChildren(); 84 this._dataGrid.rootNode().removeChildren();
85 this._dataGrid.addCreationNode(false); 85 this._dataGrid.addCreationNode(false);
86 this.deleteButton.setVisible(false); 86 this.deleteButton.setVisible(false);
87 event.consume(true); 87 event.consume(true);
88 } 88 }
89 89
90 /** 90 /**
91 * @param {!WebInspector.Event} event 91 * @param {!Common.Event} event
92 */ 92 */
93 _domStorageItemRemoved(event) { 93 _domStorageItemRemoved(event) {
94 if (!this.isShowing() || !this._dataGrid) 94 if (!this.isShowing() || !this._dataGrid)
95 return; 95 return;
96 96
97 var storageData = event.data; 97 var storageData = event.data;
98 var rootNode = this._dataGrid.rootNode(); 98 var rootNode = this._dataGrid.rootNode();
99 var children = rootNode.children; 99 var children = rootNode.children;
100 100
101 event.consume(true); 101 event.consume(true);
102 102
103 for (var i = 0; i < children.length; ++i) { 103 for (var i = 0; i < children.length; ++i) {
104 var childNode = children[i]; 104 var childNode = children[i];
105 if (childNode.data.key === storageData.key) { 105 if (childNode.data.key === storageData.key) {
106 rootNode.removeChild(childNode); 106 rootNode.removeChild(childNode);
107 this.deleteButton.setVisible(children.length > 1); 107 this.deleteButton.setVisible(children.length > 1);
108 return; 108 return;
109 } 109 }
110 } 110 }
111 } 111 }
112 112
113 /** 113 /**
114 * @param {!WebInspector.Event} event 114 * @param {!Common.Event} event
115 */ 115 */
116 _domStorageItemAdded(event) { 116 _domStorageItemAdded(event) {
117 if (!this.isShowing() || !this._dataGrid) 117 if (!this.isShowing() || !this._dataGrid)
118 return; 118 return;
119 119
120 var storageData = event.data; 120 var storageData = event.data;
121 var rootNode = this._dataGrid.rootNode(); 121 var rootNode = this._dataGrid.rootNode();
122 var children = rootNode.children; 122 var children = rootNode.children;
123 123
124 event.consume(true); 124 event.consume(true);
125 this.deleteButton.setVisible(true); 125 this.deleteButton.setVisible(true);
126 126
127 for (var i = 0; i < children.length; ++i) 127 for (var i = 0; i < children.length; ++i)
128 if (children[i].data.key === storageData.key) 128 if (children[i].data.key === storageData.key)
129 return; 129 return;
130 130
131 var childNode = new WebInspector.DataGridNode({key: storageData.key, value: storageData.value}, false); 131 var childNode = new UI.DataGridNode({key: storageData.key, value: storageDat a.value}, false);
132 rootNode.insertChild(childNode, children.length - 1); 132 rootNode.insertChild(childNode, children.length - 1);
133 } 133 }
134 134
135 /** 135 /**
136 * @param {!WebInspector.Event} event 136 * @param {!Common.Event} event
137 */ 137 */
138 _domStorageItemUpdated(event) { 138 _domStorageItemUpdated(event) {
139 if (!this.isShowing() || !this._dataGrid) 139 if (!this.isShowing() || !this._dataGrid)
140 return; 140 return;
141 141
142 var storageData = event.data; 142 var storageData = event.data;
143 var rootNode = this._dataGrid.rootNode(); 143 var rootNode = this._dataGrid.rootNode();
144 var children = rootNode.children; 144 var children = rootNode.children;
145 145
146 event.consume(true); 146 event.consume(true);
(...skipping 26 matching lines...) Expand all
173 _showDOMStorageItems(error, items) { 173 _showDOMStorageItems(error, items) {
174 if (error) 174 if (error)
175 return; 175 return;
176 176
177 this._dataGrid = this._dataGridForDOMStorageItems(items); 177 this._dataGrid = this._dataGridForDOMStorageItems(items);
178 this._dataGrid.asWidget().show(this.element); 178 this._dataGrid.asWidget().show(this.element);
179 this.deleteButton.setVisible(this._dataGrid.rootNode().children.length > 1); 179 this.deleteButton.setVisible(this._dataGrid.rootNode().children.length > 1);
180 } 180 }
181 181
182 _dataGridForDOMStorageItems(items) { 182 _dataGridForDOMStorageItems(items) {
183 var columns = /** @type {!Array<!WebInspector.DataGrid.ColumnDescriptor>} */ ([ 183 var columns = /** @type {!Array<!UI.DataGrid.ColumnDescriptor>} */ ([
184 {id: 'key', title: WebInspector.UIString('Key'), sortable: false, editable : true, weight: 50}, 184 {id: 'key', title: Common.UIString('Key'), sortable: false, editable: true , weight: 50},
185 {id: 'value', title: WebInspector.UIString('Value'), sortable: false, edit able: true, weight: 50} 185 {id: 'value', title: Common.UIString('Value'), sortable: false, editable: true, weight: 50}
186 ]); 186 ]);
187 187
188 var nodes = []; 188 var nodes = [];
189 189
190 var keys = []; 190 var keys = [];
191 var length = items.length; 191 var length = items.length;
192 for (var i = 0; i < items.length; i++) { 192 for (var i = 0; i < items.length; i++) {
193 var key = items[i][0]; 193 var key = items[i][0];
194 var value = items[i][1]; 194 var value = items[i][1];
195 var node = new WebInspector.DataGridNode({key: key, value: value}, false); 195 var node = new UI.DataGridNode({key: key, value: value}, false);
196 node.selectable = true; 196 node.selectable = true;
197 nodes.push(node); 197 nodes.push(node);
198 keys.push(key); 198 keys.push(key);
199 } 199 }
200 200
201 var dataGrid = 201 var dataGrid =
202 new WebInspector.DataGrid(columns, this._editingCallback.bind(this), thi s._deleteCallback.bind(this)); 202 new UI.DataGrid(columns, this._editingCallback.bind(this), this._deleteC allback.bind(this));
203 dataGrid.setName('DOMStorageItemsView'); 203 dataGrid.setName('DOMStorageItemsView');
204 length = nodes.length; 204 length = nodes.length;
205 for (var i = 0; i < length; ++i) 205 for (var i = 0; i < length; ++i)
206 dataGrid.rootNode().appendChild(nodes[i]); 206 dataGrid.rootNode().appendChild(nodes[i]);
207 dataGrid.addCreationNode(false); 207 dataGrid.addCreationNode(false);
208 if (length > 0) 208 if (length > 0)
209 nodes[0].selected = true; 209 nodes[0].selected = true;
210 return dataGrid; 210 return dataGrid;
211 } 211 }
212 212
(...skipping 13 matching lines...) Expand all
226 if (columnIdentifier === 'key') { 226 if (columnIdentifier === 'key') {
227 if (typeof oldText === 'string') 227 if (typeof oldText === 'string')
228 domStorage.removeItem(oldText); 228 domStorage.removeItem(oldText);
229 domStorage.setItem(newText, editingNode.data.value || ''); 229 domStorage.setItem(newText, editingNode.data.value || '');
230 this._removeDupes(editingNode); 230 this._removeDupes(editingNode);
231 } else 231 } else
232 domStorage.setItem(editingNode.data.key || '', newText); 232 domStorage.setItem(editingNode.data.key || '', newText);
233 } 233 }
234 234
235 /** 235 /**
236 * @param {!WebInspector.DataGridNode} masterNode 236 * @param {!UI.DataGridNode} masterNode
237 */ 237 */
238 _removeDupes(masterNode) { 238 _removeDupes(masterNode) {
239 var rootNode = this._dataGrid.rootNode(); 239 var rootNode = this._dataGrid.rootNode();
240 var children = rootNode.children; 240 var children = rootNode.children;
241 for (var i = children.length - 1; i >= 0; --i) { 241 for (var i = children.length - 1; i >= 0; --i) {
242 var childNode = children[i]; 242 var childNode = children[i];
243 if ((childNode.data.key === masterNode.data.key) && (masterNode !== childN ode)) 243 if ((childNode.data.key === masterNode.data.key) && (masterNode !== childN ode))
244 rootNode.removeChild(childNode); 244 rootNode.removeChild(childNode);
245 } 245 }
246 } 246 }
247 247
248 _deleteCallback(node) { 248 _deleteCallback(node) {
249 if (!node || node.isCreationNode) 249 if (!node || node.isCreationNode)
250 return; 250 return;
251 251
252 if (this.domStorage) 252 if (this.domStorage)
253 this.domStorage.removeItem(node.data.key); 253 this.domStorage.removeItem(node.data.key);
254 } 254 }
255 }; 255 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698