| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2008 Nokia Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY | |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 24 */ | |
| 25 | |
| 26 WebInspector.DOMStorageItemsView = function(domStorage) | |
| 27 { | |
| 28 WebInspector.View.call(this); | |
| 29 | |
| 30 this.domStorage = domStorage; | |
| 31 | |
| 32 this.element.addStyleClass("storage-view"); | |
| 33 this.element.addStyleClass("table"); | |
| 34 | |
| 35 this.deleteButton = new WebInspector.StatusBarButton(WebInspector.UIString("
Delete"), "delete-storage-status-bar-item"); | |
| 36 this.deleteButton.visible = false; | |
| 37 this.deleteButton.addEventListener("click", this._deleteButtonClicked.bind(t
his), false); | |
| 38 | |
| 39 this.refreshButton = new WebInspector.StatusBarButton(WebInspector.UIString(
"Refresh"), "refresh-storage-status-bar-item"); | |
| 40 this.refreshButton.addEventListener("click", this._refreshButtonClicked.bind
(this), false); | |
| 41 } | |
| 42 | |
| 43 WebInspector.DOMStorageItemsView.prototype = { | |
| 44 get statusBarItems() | |
| 45 { | |
| 46 return [this.refreshButton.element, this.deleteButton.element]; | |
| 47 }, | |
| 48 | |
| 49 show: function(parentElement) | |
| 50 { | |
| 51 WebInspector.View.prototype.show.call(this, parentElement); | |
| 52 this.update(); | |
| 53 }, | |
| 54 | |
| 55 hide: function() | |
| 56 { | |
| 57 WebInspector.View.prototype.hide.call(this); | |
| 58 this.deleteButton.visible = false; | |
| 59 }, | |
| 60 | |
| 61 update: function() | |
| 62 { | |
| 63 this.element.removeChildren(); | |
| 64 var callback = this._showDOMStorageEntries.bind(this); | |
| 65 this.domStorage.getEntries(callback); | |
| 66 }, | |
| 67 | |
| 68 _showDOMStorageEntries: function(entries) | |
| 69 { | |
| 70 if (entries.length > 0) { | |
| 71 this._dataGrid = this._dataGridForDOMStorageEntries(entries); | |
| 72 this.element.appendChild(this._dataGrid.element); | |
| 73 this._dataGrid.updateWidths(); | |
| 74 this.deleteButton.visible = true; | |
| 75 } else { | |
| 76 var emptyMsgElement = document.createElement("div"); | |
| 77 emptyMsgElement.className = "storage-table-empty"; | |
| 78 if (this.domStorage) | |
| 79 emptyMsgElement.textContent = WebInspector.UIString("This storag
e is empty."); | |
| 80 this.element.appendChild(emptyMsgElement); | |
| 81 this._dataGrid = null; | |
| 82 this.deleteButton.visible = false; | |
| 83 } | |
| 84 }, | |
| 85 | |
| 86 resize: function() | |
| 87 { | |
| 88 if (this._dataGrid) | |
| 89 this._dataGrid.updateWidths(); | |
| 90 }, | |
| 91 | |
| 92 _dataGridForDOMStorageEntries: function(entries) | |
| 93 { | |
| 94 var columns = {}; | |
| 95 columns[0] = {}; | |
| 96 columns[1] = {}; | |
| 97 columns[0].title = WebInspector.UIString("Key"); | |
| 98 columns[0].width = columns[0].title.length; | |
| 99 columns[1].title = WebInspector.UIString("Value"); | |
| 100 columns[1].width = columns[1].title.length; | |
| 101 | |
| 102 var nodes = []; | |
| 103 | |
| 104 var keys = []; | |
| 105 var length = entries.length; | |
| 106 for (var i = 0; i < entries.length; i++) { | |
| 107 var data = {}; | |
| 108 | |
| 109 var key = entries[i][0]; | |
| 110 data[0] = key; | |
| 111 if (key.length > columns[0].width) | |
| 112 columns[0].width = key.length; | |
| 113 | |
| 114 var value = entries[i][1]; | |
| 115 data[1] = value; | |
| 116 if (value.length > columns[1].width) | |
| 117 columns[1].width = value.length; | |
| 118 var node = new WebInspector.DataGridNode(data, false); | |
| 119 node.selectable = true; | |
| 120 nodes.push(node); | |
| 121 keys.push(key); | |
| 122 } | |
| 123 | |
| 124 var totalColumnWidths = columns[0].width + columns[1].width; | |
| 125 var width = Math.round((columns[0].width * 100) / totalColumnWidths); | |
| 126 const minimumPrecent = 10; | |
| 127 if (width < minimumPrecent) | |
| 128 width = minimumPrecent; | |
| 129 if (width > 100 - minimumPrecent) | |
| 130 width = 100 - minimumPrecent; | |
| 131 columns[0].width = width; | |
| 132 columns[1].width = 100 - width; | |
| 133 columns[0].width += "%"; | |
| 134 columns[1].width += "%"; | |
| 135 | |
| 136 var dataGrid = new WebInspector.DOMStorageDataGrid(columns, this.domStor
age, keys); | |
| 137 var length = nodes.length; | |
| 138 for (var i = 0; i < length; ++i) | |
| 139 dataGrid.appendChild(nodes[i]); | |
| 140 dataGrid.addCreationNode(false); | |
| 141 if (length > 0) | |
| 142 nodes[0].selected = true; | |
| 143 return dataGrid; | |
| 144 }, | |
| 145 | |
| 146 _deleteButtonClicked: function(event) | |
| 147 { | |
| 148 if (this._dataGrid) { | |
| 149 this._dataGrid.deleteSelectedRow(); | |
| 150 | |
| 151 this.show(); | |
| 152 } | |
| 153 }, | |
| 154 | |
| 155 _refreshButtonClicked: function(event) | |
| 156 { | |
| 157 this.update(); | |
| 158 } | |
| 159 } | |
| 160 | |
| 161 WebInspector.DOMStorageItemsView.prototype.__proto__ = WebInspector.View.prototy
pe; | |
| OLD | NEW |