DOMStorageDataGrid.js [plain text]
WebInspector.DOMStorageDataGrid = function(columns)
{
WebInspector.DataGrid.call(this, columns);
this.dataTableBody.addEventListener("dblclick", this._ondblclick.bind(this), false);
}
WebInspector.DOMStorageDataGrid.prototype = {
_ondblclick: function(event)
{
if (this._editing)
return;
if (this._editingNode)
return;
this._startEditing(event);
},
_startEditing: function(event)
{
var element = event.target.enclosingNodeOrSelfWithNodeName("td");
if (!element)
return;
this._editingNode = this.dataGridNodeFromEvent(event);
if (!this._editingNode)
return;
this._editing = true;
WebInspector.startEditing(element, this._editingCommitted.bind(this), this._editingCancelled.bind(this), element.textContent);
window.getSelection().setBaseAndExtent(element, 0, element, 1);
},
_editingCommitted: function(element, newText)
{
if (element.hasStyleClass("0-column"))
columnIdentifier = 0;
else
columnIdentifier = 1;
textBeforeEditing = this._editingNode.data[columnIdentifier];
if (textBeforeEditing == newText) {
this._editingCancelled(element);
return;
}
var domStorage = WebInspector.panels.databases.visibleView.domStorage.domStorage;
if (domStorage) {
if (columnIdentifier == 0) {
if (domStorage.getItem(newText) != null) {
element.textContent = this._editingNode.data[0];
this._editingCancelled(element);
return;
}
domStorage.removeItem(this._editingNode.data[0]);
domStorage.setItem(newText, this._editingNode.data[1]);
this._editingNode.data[0] = newText;
} else {
domStorage.setItem(this._editingNode.data[0], newText);
this._editingNode.data[1] = newText;
}
}
this._editingCancelled(element);
},
_editingCancelled: function(element, context)
{
delete this._editing;
this._editingNode = null;
},
deleteSelectedRow: function()
{
var node = this.selectedNode;
var domStorage = WebInspector.panels.databases.visibleView.domStorage.domStorage;
if (node && domStorage)
domStorage.removeItem(node.data[0]);
}
}
WebInspector.DOMStorageDataGrid.prototype.__proto__ = WebInspector.DataGrid.prototype;