| OLD | NEW |
| 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. | |
| 4 * | 3 * |
| 5 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 7 * are met: | 6 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 11 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 12 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 13 * | 12 * |
| 14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY |
| 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (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. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 24 */ |
| 26 | 25 |
| 27 /** | 26 /** |
| 28 * @constructor | 27 * @constructor |
| 29 * @extends {WebInspector.View} | 28 * @extends {WebInspector.View} |
| 30 */ | 29 */ |
| 31 WebInspector.DOMStorageItemsView = function(domStorage, domStorageModel) | 30 WebInspector.DOMStorageItemsView = function(domStorage) |
| 32 { | 31 { |
| 33 WebInspector.View.call(this); | 32 WebInspector.View.call(this); |
| 34 | 33 |
| 35 this.domStorage = domStorage; | 34 this.domStorage = domStorage; |
| 36 this.domStorageModel = domStorageModel; | |
| 37 | 35 |
| 38 this.element.addStyleClass("storage-view"); | 36 this.element.addStyleClass("storage-view"); |
| 39 this.element.addStyleClass("table"); | 37 this.element.addStyleClass("table"); |
| 40 | 38 |
| 41 this.deleteButton = new WebInspector.StatusBarButton(WebInspector.UIString("
Delete"), "delete-storage-status-bar-item"); | 39 this.deleteButton = new WebInspector.StatusBarButton(WebInspector.UIString("
Delete"), "delete-storage-status-bar-item"); |
| 42 this.deleteButton.visible = false; | 40 this.deleteButton.visible = false; |
| 43 this.deleteButton.addEventListener("click", this._deleteButtonClicked, this)
; | 41 this.deleteButton.addEventListener("click", this._deleteButtonClicked, this)
; |
| 44 | 42 |
| 45 this.refreshButton = new WebInspector.StatusBarButton(WebInspector.UIString(
"Refresh"), "refresh-storage-status-bar-item"); | 43 this.refreshButton = new WebInspector.StatusBarButton(WebInspector.UIString(
"Refresh"), "refresh-storage-status-bar-item"); |
| 46 this.refreshButton.addEventListener("click", this._refreshButtonClicked, thi
s); | 44 this.refreshButton.addEventListener("click", this._refreshButtonClicked, thi
s); |
| 47 | |
| 48 this.domStorageModel.addEventListener(WebInspector.DOMStorageModel.Events.DO
MStorageItemsCleared, this._domStorageItemsCleared, this); | |
| 49 this.domStorageModel.addEventListener(WebInspector.DOMStorageModel.Events.DO
MStorageItemRemoved, this._domStorageItemRemoved, this); | |
| 50 this.domStorageModel.addEventListener(WebInspector.DOMStorageModel.Events.DO
MStorageItemAdded, this._domStorageItemAdded, this); | |
| 51 this.domStorageModel.addEventListener(WebInspector.DOMStorageModel.Events.DO
MStorageItemUpdated, this._domStorageItemUpdated, this); | |
| 52 } | 45 } |
| 53 | 46 |
| 54 WebInspector.DOMStorageItemsView.prototype = { | 47 WebInspector.DOMStorageItemsView.prototype = { |
| 55 get statusBarItems() | 48 get statusBarItems() |
| 56 { | 49 { |
| 57 return [this.refreshButton.element, this.deleteButton.element]; | 50 return [this.refreshButton.element, this.deleteButton.element]; |
| 58 }, | 51 }, |
| 59 | 52 |
| 60 wasShown: function() | 53 wasShown: function() |
| 61 { | 54 { |
| 62 this._update(); | 55 this.update(); |
| 63 }, | 56 }, |
| 64 | 57 |
| 65 willHide: function() | 58 willHide: function() |
| 66 { | 59 { |
| 67 this.deleteButton.visible = false; | 60 this.deleteButton.visible = false; |
| 68 }, | 61 }, |
| 69 | 62 |
| 70 /** | 63 update: function() |
| 71 * @param {WebInspector.Event} event | |
| 72 */ | |
| 73 _domStorageItemsCleared: function(event) | |
| 74 { | |
| 75 if (!this.isShowing()) | |
| 76 return; | |
| 77 | |
| 78 this._dataGrid.rootNode().removeChildren(); | |
| 79 this._dataGrid.addCreationNode(false); | |
| 80 this.deleteButton.visible = false; | |
| 81 event.consume(true); | |
| 82 }, | |
| 83 | |
| 84 /** | |
| 85 * @param {WebInspector.Event} event | |
| 86 */ | |
| 87 _domStorageItemRemoved: function(event) | |
| 88 { | |
| 89 if (!this.isShowing()) | |
| 90 return; | |
| 91 | |
| 92 var storageData = event.data; | |
| 93 var rootNode = this._dataGrid.rootNode(); | |
| 94 var children = rootNode.children; | |
| 95 | |
| 96 event.consume(true); | |
| 97 | |
| 98 for (var i = 0; i < children.length; ++i) { | |
| 99 var childNode = children[i]; | |
| 100 if (childNode.data.key === storageData.key) { | |
| 101 rootNode.removeChild(childNode); | |
| 102 this.deleteButton.visible = (children.length > 1); | |
| 103 return; | |
| 104 } | |
| 105 } | |
| 106 }, | |
| 107 | |
| 108 /** | |
| 109 * @param {WebInspector.Event} event | |
| 110 */ | |
| 111 _domStorageItemAdded: function(event) | |
| 112 { | |
| 113 if (!this.isShowing()) | |
| 114 return; | |
| 115 | |
| 116 var storageData = event.data; | |
| 117 var rootNode = this._dataGrid.rootNode(); | |
| 118 var children = rootNode.children; | |
| 119 | |
| 120 event.consume(true); | |
| 121 this.deleteButton.visible = true; | |
| 122 | |
| 123 for (var i = 0; i < children.length; ++i) | |
| 124 if (children[i].data.key === storageData.key) | |
| 125 return; | |
| 126 | |
| 127 var childNode = new WebInspector.DataGridNode({key: storageData.key, val
ue: storageData.newValue}, false); | |
| 128 rootNode.insertChild(childNode, children.length - 1); | |
| 129 }, | |
| 130 | |
| 131 /** | |
| 132 * @param {WebInspector.Event} event | |
| 133 */ | |
| 134 _domStorageItemUpdated: function(event) | |
| 135 { | |
| 136 if (!this.isShowing()) | |
| 137 return; | |
| 138 | |
| 139 var storageData = event.data; | |
| 140 var rootNode = this._dataGrid.rootNode(); | |
| 141 var children = rootNode.children; | |
| 142 | |
| 143 event.consume(true); | |
| 144 | |
| 145 for (var i = 0; i < children.length; ++i) { | |
| 146 var childNode = children[i]; | |
| 147 if (childNode.data.key === storageData.key) { | |
| 148 childNode.data.value = storageData.newValue; | |
| 149 childNode.refresh(); | |
| 150 this.deleteButton.visible = true; | |
| 151 return; | |
| 152 } | |
| 153 } | |
| 154 }, | |
| 155 | |
| 156 _update: function() | |
| 157 { | 64 { |
| 158 this.detachChildViews(); | 65 this.detachChildViews(); |
| 159 this.domStorage.getEntries(this._showDOMStorageEntries.bind(this)); | 66 this.domStorage.getEntries(this._showDOMStorageEntries.bind(this)); |
| 160 }, | 67 }, |
| 161 | 68 |
| 162 _showDOMStorageEntries: function(error, entries) | 69 _showDOMStorageEntries: function(error, entries) |
| 163 { | 70 { |
| 164 if (error) | 71 if (error) |
| 165 return; | 72 return; |
| 166 | 73 |
| 167 this._dataGrid = this._dataGridForDOMStorageEntries(entries); | 74 this._dataGrid = this._dataGridForDOMStorageEntries(entries); |
| 168 this._dataGrid.show(this.element); | 75 this._dataGrid.show(this.element); |
| 169 this._dataGrid.autoSizeColumns(10); | 76 this._dataGrid.autoSizeColumns(10); |
| 170 this.deleteButton.visible = (this._dataGrid.rootNode().children.length >
1); | 77 this.deleteButton.visible = true; |
| 171 }, | 78 }, |
| 172 | 79 |
| 173 _dataGridForDOMStorageEntries: function(entries) | 80 _dataGridForDOMStorageEntries: function(entries) |
| 174 { | 81 { |
| 175 var columns = {key: {}, value: {}}; | 82 var columns = {key: {}, value: {}}; |
| 176 | 83 |
| 177 columns.key.title = WebInspector.UIString("Key"); | 84 columns.key.title = WebInspector.UIString("Key"); |
| 178 columns.key.editable = true; | 85 columns.key.editable = true; |
| 179 | 86 |
| 180 columns.value.title = WebInspector.UIString("Value"); | 87 columns.value.title = WebInspector.UIString("Value"); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 206 _deleteButtonClicked: function(event) | 113 _deleteButtonClicked: function(event) |
| 207 { | 114 { |
| 208 if (!this._dataGrid || !this._dataGrid.selectedNode) | 115 if (!this._dataGrid || !this._dataGrid.selectedNode) |
| 209 return; | 116 return; |
| 210 | 117 |
| 211 this._deleteCallback(this._dataGrid.selectedNode); | 118 this._deleteCallback(this._dataGrid.selectedNode); |
| 212 }, | 119 }, |
| 213 | 120 |
| 214 _refreshButtonClicked: function(event) | 121 _refreshButtonClicked: function(event) |
| 215 { | 122 { |
| 216 this._update(); | 123 this.update(); |
| 217 }, | 124 }, |
| 218 | 125 |
| 219 _editingCallback: function(editingNode, columnIdentifier, oldText, newText) | 126 _editingCallback: function(editingNode, columnIdentifier, oldText, newText) |
| 220 { | 127 { |
| 221 var domStorage = this.domStorage; | 128 var domStorage = this.domStorage; |
| 222 if ("key" === columnIdentifier) { | 129 if ("key" === columnIdentifier) { |
| 223 if (oldText) | 130 if (oldText) |
| 224 domStorage.removeItem(oldText); | 131 domStorage.removeItem(oldText); |
| 225 | 132 |
| 226 domStorage.setItem(newText, editingNode.data.value); | 133 domStorage.setItem(newText, editingNode.data.value); |
| 227 } else | 134 } else { |
| 228 domStorage.setItem(editingNode.data.key, newText); | 135 domStorage.setItem(editingNode.data.key, newText); |
| 136 } |
| 137 |
| 138 this.update(); |
| 229 }, | 139 }, |
| 230 | 140 |
| 231 _deleteCallback: function(node) | 141 _deleteCallback: function(node) |
| 232 { | 142 { |
| 233 if (!node || node.isCreationNode) | 143 if (!node || node.isCreationNode) |
| 234 return; | 144 return; |
| 235 | 145 |
| 236 if (this.domStorage) | 146 if (this.domStorage) |
| 237 this.domStorage.removeItem(node.data.key); | 147 this.domStorage.removeItem(node.data.key); |
| 148 |
| 149 this.update(); |
| 238 }, | 150 }, |
| 239 | 151 |
| 240 __proto__: WebInspector.View.prototype | 152 __proto__: WebInspector.View.prototype |
| 241 } | 153 } |
| OLD | NEW |