OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * Each row in the filtered items list is backed by a SourceEntry. This |
| 7 * instance contains all of the data pertaining to that row, and notifies |
| 8 * its parent view (the RequestsView) whenever its data changes. |
| 9 * |
| 10 * @constructor |
| 11 */ |
| 12 function SourceEntry(parentView) { |
| 13 this.entries_ = []; |
| 14 this.parentView_ = parentView; |
| 15 this.isSelected_ = false; |
| 16 this.isMatchedByFilter_ = false; |
| 17 } |
| 18 |
| 19 SourceEntry.prototype.isSelected = function() { |
| 20 return this.isSelected_; |
| 21 }; |
| 22 |
| 23 SourceEntry.prototype.setSelectedStyles = function(isSelected) { |
| 24 changeClassName(this.row_, 'selected', isSelected); |
| 25 this.getSelectionCheckbox().checked = isSelected; |
| 26 }; |
| 27 |
| 28 SourceEntry.prototype.setMouseoverStyle = function(isMouseOver) { |
| 29 changeClassName(this.row_, 'mouseover', isMouseOver); |
| 30 }; |
| 31 |
| 32 SourceEntry.prototype.setIsMatchedByFilter = function(isMatchedByFilter) { |
| 33 if (this.isMatchedByFilter() == isMatchedByFilter) |
| 34 return; // No change. |
| 35 |
| 36 this.isMatchedByFilter_ = isMatchedByFilter; |
| 37 |
| 38 this.setFilterStyles(isMatchedByFilter); |
| 39 |
| 40 if (isMatchedByFilter) { |
| 41 this.parentView_.incrementPostfilterCount(1); |
| 42 } else { |
| 43 this.parentView_.incrementPostfilterCount(-1); |
| 44 // If we are filtering an entry away, make sure it is no longer |
| 45 // part of the selection. |
| 46 this.setSelected(false); |
| 47 } |
| 48 }; |
| 49 |
| 50 SourceEntry.prototype.isMatchedByFilter = function() { |
| 51 return this.isMatchedByFilter_; |
| 52 }; |
| 53 |
| 54 SourceEntry.prototype.setFilterStyles = function(isMatchedByFilter) { |
| 55 // Hide rows which have been filtered away. |
| 56 if (isMatchedByFilter) { |
| 57 this.row_.style.display = ''; |
| 58 } else { |
| 59 this.row_.style.display = 'none'; |
| 60 } |
| 61 }; |
| 62 |
| 63 SourceEntry.prototype.update = function(logEntry) { |
| 64 this.entries_.push(logEntry); |
| 65 |
| 66 if (this.entries_.length == 1) { |
| 67 this.createRow_(); |
| 68 |
| 69 // Only apply the filter during the first update. |
| 70 // TODO(eroman): once filters use other data, apply it on each update. |
| 71 var matchesFilter = this.matchesFilter(this.parentView_.currentFilter_); |
| 72 this.setIsMatchedByFilter(matchesFilter); |
| 73 } |
| 74 }; |
| 75 |
| 76 SourceEntry.prototype.onCheckboxToggled_ = function() { |
| 77 this.setSelected(this.getSelectionCheckbox().checked); |
| 78 }; |
| 79 |
| 80 SourceEntry.prototype.matchesFilter = function(filterText) { |
| 81 // TODO(eroman): Support more advanced filter syntax. |
| 82 if (filterText == '') |
| 83 return true; |
| 84 |
| 85 var filterText = filterText.toLowerCase(); |
| 86 |
| 87 return this.getDescription().toLowerCase().indexOf(filterText) != -1 || |
| 88 this.getSourceTypeString().toLowerCase().indexOf(filterText) != -1; |
| 89 }; |
| 90 |
| 91 SourceEntry.prototype.setSelected = function(isSelected) { |
| 92 if (isSelected == this.isSelected()) |
| 93 return; |
| 94 |
| 95 this.isSelected_ = isSelected; |
| 96 |
| 97 this.setSelectedStyles(isSelected); |
| 98 this.parentView_.modifySelectionArray(this, isSelected); |
| 99 this.parentView_.onSelectionChanged(); |
| 100 }; |
| 101 |
| 102 SourceEntry.prototype.onClicked_ = function() { |
| 103 this.parentView_.clearSelection(); |
| 104 this.setSelected(true); |
| 105 }; |
| 106 |
| 107 SourceEntry.prototype.onMouseover_ = function() { |
| 108 this.setMouseoverStyle(true); |
| 109 }; |
| 110 |
| 111 SourceEntry.prototype.onMouseout_ = function() { |
| 112 this.setMouseoverStyle(false); |
| 113 }; |
| 114 |
| 115 SourceEntry.prototype.createRow_ = function() { |
| 116 // Create a row. |
| 117 var tr = addNode(this.parentView_.tableBody_, 'tr'); |
| 118 tr.style.display = 'none'; |
| 119 this.row_ = tr; |
| 120 |
| 121 var selectionCol = addNode(tr, 'td'); |
| 122 var checkbox = addNode(selectionCol, 'input'); |
| 123 checkbox.type = 'checkbox'; |
| 124 |
| 125 var idCell = addNode(tr, 'td'); |
| 126 var typeCell = addNode(tr, 'td'); |
| 127 var descriptionCell = addNode(tr, 'td'); |
| 128 |
| 129 // Connect listeners. |
| 130 checkbox.onchange = this.onCheckboxToggled_.bind(this); |
| 131 |
| 132 var onclick = this.onClicked_.bind(this); |
| 133 idCell.onclick = onclick; |
| 134 typeCell.onclick = onclick; |
| 135 descriptionCell.onclick = onclick; |
| 136 |
| 137 tr.onmouseover = this.onMouseover_.bind(this); |
| 138 tr.onmouseout = this.onMouseout_.bind(this); |
| 139 |
| 140 // Set the cell values to match this source's data. |
| 141 addTextNode(idCell, this.getSourceId()); |
| 142 var sourceTypeString = this.getSourceTypeString(); |
| 143 addTextNode(typeCell, sourceTypeString); |
| 144 addTextNode(descriptionCell, this.getDescription()); |
| 145 |
| 146 // Add a CSS classname specific to this source type (so CSS can specify |
| 147 // different stylings for different types). |
| 148 changeClassName(this.row_, "source_" + sourceTypeString, true); |
| 149 }; |
| 150 |
| 151 SourceEntry.prototype.getDescription = function() { |
| 152 var e = this.entries_[0]; |
| 153 if (e.type == LogEntryType.TYPE_EVENT && |
| 154 e.event.phase == LogEventPhase.PHASE_BEGIN && |
| 155 e.string != undefined) { |
| 156 return e.string; // The URL / hostname / whatever. |
| 157 } |
| 158 return ''; |
| 159 }; |
| 160 |
| 161 SourceEntry.prototype.getLogEntries = function() { |
| 162 return this.entries_; |
| 163 }; |
| 164 |
| 165 SourceEntry.prototype.getSourceTypeString = function() { |
| 166 return getKeyWithValue(LogSourceType, this.entries_[0].source.type); |
| 167 }; |
| 168 |
| 169 SourceEntry.prototype.getSelectionCheckbox = function() { |
| 170 return this.row_.childNodes[0].firstChild; |
| 171 }; |
| 172 |
| 173 SourceEntry.prototype.getSourceId = function() { |
| 174 return this.entries_[0].source.id; |
| 175 }; |
| 176 |
| 177 SourceEntry.prototype.remove = function() { |
| 178 this.setSelected(false); |
| 179 this.setIsMatchedByFilter(false); |
| 180 this.row_.parentNode.removeChild(this.row_); |
| 181 }; |
| 182 |
OLD | NEW |