• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
26WebInspector.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 = document.createElement("button");
36    this.deleteButton.title = WebInspector.UIString("Delete");
37    this.deleteButton.className = "delete-storage-status-bar-item status-bar-item hidden";
38    this.deleteButton.addEventListener("click", this._deleteButtonClicked.bind(this), false);
39
40    this.refreshButton = document.createElement("button");
41    this.refreshButton.title = WebInspector.UIString("Refresh");
42    this.refreshButton.className = "refresh-storage-status-bar-item status-bar-item";
43    this.refreshButton.addEventListener("click", this._refreshButtonClicked.bind(this), false);
44}
45
46WebInspector.DOMStorageItemsView.prototype = {
47    get statusBarItems()
48    {
49        return [this.refreshButton, this.deleteButton];
50    },
51
52    show: function(parentElement)
53    {
54        WebInspector.View.prototype.show.call(this, parentElement);
55        this.update();
56    },
57
58    hide: function()
59    {
60        WebInspector.View.prototype.hide.call(this);
61        this.deleteButton.addStyleClass("hidden");
62    },
63
64    update: function()
65    {
66        this.element.removeChildren();
67        var hasDOMStorage = this.domStorage;
68        if (hasDOMStorage)
69            hasDOMStorage = this.domStorage.domStorage;
70
71        if (hasDOMStorage) {
72            var dataGrid = WebInspector.panels.databases.dataGridForDOMStorage(this.domStorage.domStorage);
73            if (!dataGrid)
74                hasDOMStorage = 0;
75            else {
76                this._dataGrid = dataGrid;
77                this.element.appendChild(dataGrid.element);
78                this._dataGrid.updateWidths();
79                this.deleteButton.removeStyleClass("hidden");
80            }
81        }
82
83        if (!hasDOMStorage) {
84            var emptyMsgElement = document.createElement("div");
85            emptyMsgElement.className = "storage-table-empty";
86            if (this.domStorage)
87            emptyMsgElement.textContent = WebInspector.UIString("This storage is empty.");
88            this.element.appendChild(emptyMsgElement);
89            this._dataGrid = null;
90            this.deleteButton.addStyleClass("hidden");
91        }
92    },
93
94    resize: function()
95    {
96        if (this._dataGrid)
97            this._dataGrid.updateWidths();
98    },
99
100    _deleteButtonClicked: function(event)
101    {
102        if (this._dataGrid) {
103            this._dataGrid.deleteSelectedRow();
104
105            this.show();
106        }
107    },
108
109    _refreshButtonClicked: function(event)
110    {
111        this.update();
112    }
113}
114
115WebInspector.DOMStorageItemsView.prototype.__proto__ = WebInspector.View.prototype;
116