| 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. | 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 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 this.element.classList.add('storage-view', 'table'); | 36 this.element.classList.add('storage-view', 'table'); |
| 37 | 37 |
| 38 this.deleteButton = new UI.ToolbarButton(Common.UIString('Delete'), 'largeic
on-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 UI.ToolbarButton(Common.UIString('Refresh'), 'large
icon-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(Resources.DOMStorage.ItemsClearedEvent, thi
s._domStorageItemsCleared, this); |
| 46 Resources.DOMStorage.Events.DOMStorageItemsCleared, this._domStorageItem
sCleared, this); | 46 this.domStorage.addEventListener(Resources.DOMStorage.ItemRemovedEvent, this
._domStorageItemRemoved, this); |
| 47 this.domStorage.addEventListener( | 47 this.domStorage.addEventListener(Resources.DOMStorage.ItemAddedEvent, this._
domStorageItemAdded, this); |
| 48 Resources.DOMStorage.Events.DOMStorageItemRemoved, this._domStorageItemR
emoved, this); | 48 this.domStorage.addEventListener(Resources.DOMStorage.ItemUpdatedEvent, this
._domStorageItemUpdated, this); |
| 49 this.domStorage.addEventListener(Resources.DOMStorage.Events.DOMStorageItemA
dded, this._domStorageItemAdded, this); | |
| 50 this.domStorage.addEventListener( | |
| 51 Resources.DOMStorage.Events.DOMStorageItemUpdated, this._domStorageItemU
pdated, this); | |
| 52 } | 49 } |
| 53 | 50 |
| 54 /** | 51 /** |
| 55 * @override | 52 * @override |
| 56 * @return {!Array.<!UI.ToolbarItem>} | 53 * @return {!Array.<!UI.ToolbarItem>} |
| 57 */ | 54 */ |
| 58 syncToolbarItems() { | 55 syncToolbarItems() { |
| 59 return [this.refreshButton, this.deleteButton]; | 56 return [this.refreshButton, this.deleteButton]; |
| 60 } | 57 } |
| 61 | 58 |
| 62 /** | 59 /** |
| 63 * @override | 60 * @override |
| 64 */ | 61 */ |
| 65 wasShown() { | 62 wasShown() { |
| 66 this._update(); | 63 this._update(); |
| 67 } | 64 } |
| 68 | 65 |
| 69 /** | 66 /** |
| 70 * @override | 67 * @override |
| 71 */ | 68 */ |
| 72 willHide() { | 69 willHide() { |
| 73 this.deleteButton.setVisible(false); | 70 this.deleteButton.setVisible(false); |
| 74 } | 71 } |
| 75 | 72 |
| 76 /** | 73 /** |
| 77 * @param {!Common.Event} event | 74 * @param {!Resources.DOMStorage.ItemsClearedEvent} event |
| 78 */ | 75 */ |
| 79 _domStorageItemsCleared(event) { | 76 _domStorageItemsCleared(event) { |
| 80 if (!this.isShowing() || !this._dataGrid) | 77 if (!this.isShowing() || !this._dataGrid) |
| 81 return; | 78 return; |
| 82 | 79 |
| 83 this._dataGrid.rootNode().removeChildren(); | 80 this._dataGrid.rootNode().removeChildren(); |
| 84 this._dataGrid.addCreationNode(false); | 81 this._dataGrid.addCreationNode(false); |
| 85 this.deleteButton.setVisible(false); | 82 this.deleteButton.setVisible(false); |
| 86 event.consume(true); | |
| 87 } | 83 } |
| 88 | 84 |
| 89 /** | 85 /** |
| 90 * @param {!Common.Event} event | 86 * @param {!Resources.DOMStorage.ItemRemovedEvent} event |
| 91 */ | 87 */ |
| 92 _domStorageItemRemoved(event) { | 88 _domStorageItemRemoved(event) { |
| 93 if (!this.isShowing() || !this._dataGrid) | 89 if (!this.isShowing() || !this._dataGrid) |
| 94 return; | 90 return; |
| 95 | 91 |
| 96 var storageData = event.data; | |
| 97 var rootNode = this._dataGrid.rootNode(); | 92 var rootNode = this._dataGrid.rootNode(); |
| 98 var children = rootNode.children; | 93 var children = rootNode.children; |
| 99 | 94 |
| 100 event.consume(true); | |
| 101 | |
| 102 for (var i = 0; i < children.length; ++i) { | 95 for (var i = 0; i < children.length; ++i) { |
| 103 var childNode = children[i]; | 96 var childNode = children[i]; |
| 104 if (childNode.data.key === storageData.key) { | 97 if (childNode.data.key === event.key) { |
| 105 rootNode.removeChild(childNode); | 98 rootNode.removeChild(childNode); |
| 106 this.deleteButton.setVisible(children.length > 1); | 99 this.deleteButton.setVisible(children.length > 1); |
| 107 return; | 100 return; |
| 108 } | 101 } |
| 109 } | 102 } |
| 110 } | 103 } |
| 111 | 104 |
| 112 /** | 105 /** |
| 113 * @param {!Common.Event} event | 106 * @param {!Resources.DOMStorage.ItemAddedEvent} event |
| 114 */ | 107 */ |
| 115 _domStorageItemAdded(event) { | 108 _domStorageItemAdded(event) { |
| 116 if (!this.isShowing() || !this._dataGrid) | 109 if (!this.isShowing() || !this._dataGrid) |
| 117 return; | 110 return; |
| 118 | 111 |
| 119 var storageData = event.data; | |
| 120 var rootNode = this._dataGrid.rootNode(); | 112 var rootNode = this._dataGrid.rootNode(); |
| 121 var children = rootNode.children; | 113 var children = rootNode.children; |
| 122 | |
| 123 event.consume(true); | |
| 124 this.deleteButton.setVisible(true); | 114 this.deleteButton.setVisible(true); |
| 125 | 115 |
| 126 for (var i = 0; i < children.length; ++i) { | 116 for (var i = 0; i < children.length; ++i) { |
| 127 if (children[i].data.key === storageData.key) | 117 if (children[i].data.key === event.key) |
| 128 return; | 118 return; |
| 129 } | 119 } |
| 130 | 120 |
| 131 var childNode = new UI.DataGridNode({key: storageData.key, value: storageDat
a.value}, false); | 121 var childNode = new UI.DataGridNode({key: event.key, value: event.value}, fa
lse); |
| 132 rootNode.insertChild(childNode, children.length - 1); | 122 rootNode.insertChild(childNode, children.length - 1); |
| 133 } | 123 } |
| 134 | 124 |
| 135 /** | 125 /** |
| 136 * @param {!Common.Event} event | 126 * @param {!Resources.DOMStorage.ItemUpdatedEvent} event |
| 137 */ | 127 */ |
| 138 _domStorageItemUpdated(event) { | 128 _domStorageItemUpdated(event) { |
| 139 if (!this.isShowing() || !this._dataGrid) | 129 if (!this.isShowing() || !this._dataGrid) |
| 140 return; | 130 return; |
| 141 | 131 |
| 142 var storageData = event.data; | |
| 143 var rootNode = this._dataGrid.rootNode(); | 132 var rootNode = this._dataGrid.rootNode(); |
| 144 var children = rootNode.children; | 133 var children = rootNode.children; |
| 145 | 134 |
| 146 event.consume(true); | |
| 147 | |
| 148 var keyFound = false; | 135 var keyFound = false; |
| 149 for (var i = 0; i < children.length; ++i) { | 136 for (var i = 0; i < children.length; ++i) { |
| 150 var childNode = children[i]; | 137 var childNode = children[i]; |
| 151 if (childNode.data.key === storageData.key) { | 138 if (childNode.data.key === event.key) { |
| 152 if (keyFound) { | 139 if (keyFound) { |
| 153 rootNode.removeChild(childNode); | 140 rootNode.removeChild(childNode); |
| 154 return; | 141 return; |
| 155 } | 142 } |
| 156 keyFound = true; | 143 keyFound = true; |
| 157 if (childNode.data.value !== storageData.value) { | 144 if (childNode.data.value !== event.newValue) { |
| 158 childNode.data.value = storageData.value; | 145 childNode.data.value = event.newValue; |
| 159 childNode.refresh(); | 146 childNode.refresh(); |
| 160 childNode.select(); | 147 childNode.select(); |
| 161 childNode.reveal(); | 148 childNode.reveal(); |
| 162 } | 149 } |
| 163 this.deleteButton.setVisible(true); | 150 this.deleteButton.setVisible(true); |
| 164 } | 151 } |
| 165 } | 152 } |
| 166 } | 153 } |
| 167 | 154 |
| 168 _update() { | 155 _update() { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 } | 233 } |
| 247 | 234 |
| 248 _deleteCallback(node) { | 235 _deleteCallback(node) { |
| 249 if (!node || node.isCreationNode) | 236 if (!node || node.isCreationNode) |
| 250 return; | 237 return; |
| 251 | 238 |
| 252 if (this.domStorage) | 239 if (this.domStorage) |
| 253 this.domStorage.removeItem(node.data.key); | 240 this.domStorage.removeItem(node.data.key); |
| 254 } | 241 } |
| 255 }; | 242 }; |
| OLD | NEW |