1 /* 2 * Copyright (C) 2011 Google 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 are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 /** 32 * @constructor 33 * @extends {WebInspector.DataGridNode} 34 * @param {function(number, number)} callback 35 * @param {number} startPosition 36 * @param {number} endPosition 37 * @param {number} chunkSize 38 */ 39 WebInspector.ShowMoreDataGridNode = function(callback, startPosition, endPosition, chunkSize) 40 { 41 WebInspector.DataGridNode.call(this, {summaryRow:true}, false); 42 this._callback = callback; 43 this._startPosition = startPosition; 44 this._endPosition = endPosition; 45 this._chunkSize = chunkSize; 46 47 this.showNext = document.createElement("button"); 48 this.showNext.setAttribute("type", "button"); 49 this.showNext.addEventListener("click", this._showNextChunk.bind(this), false); 50 this.showNext.textContent = WebInspector.UIString("Show %d before", this._chunkSize); 51 52 this.showAll = document.createElement("button"); 53 this.showAll.setAttribute("type", "button"); 54 this.showAll.addEventListener("click", this._showAll.bind(this), false); 55 56 this.showLast = document.createElement("button"); 57 this.showLast.setAttribute("type", "button"); 58 this.showLast.addEventListener("click", this._showLastChunk.bind(this), false); 59 this.showLast.textContent = WebInspector.UIString("Show %d after", this._chunkSize); 60 61 this._updateLabels(); 62 this.selectable = false; 63 } 64 65 WebInspector.ShowMoreDataGridNode.prototype = { 66 _showNextChunk: function() 67 { 68 this._callback(this._startPosition, this._startPosition + this._chunkSize); 69 }, 70 71 _showAll: function() 72 { 73 this._callback(this._startPosition, this._endPosition); 74 }, 75 76 _showLastChunk: function() 77 { 78 this._callback(this._endPosition - this._chunkSize, this._endPosition); 79 }, 80 81 _updateLabels: function() 82 { 83 var totalSize = this._endPosition - this._startPosition; 84 if (totalSize > this._chunkSize) { 85 this.showNext.classList.remove("hidden"); 86 this.showLast.classList.remove("hidden"); 87 } else { 88 this.showNext.classList.add("hidden"); 89 this.showLast.classList.add("hidden"); 90 } 91 this.showAll.textContent = WebInspector.UIString("Show all %d", totalSize); 92 }, 93 94 createCells: function() 95 { 96 var cell = document.createElement("td"); 97 if (this.depth) 98 cell.style.setProperty("padding-left", (this.depth * this.dataGrid.indentWidth) + "px"); 99 cell.appendChild(this.showNext); 100 cell.appendChild(this.showAll); 101 cell.appendChild(this.showLast); 102 this._element.appendChild(cell); 103 104 var columns = this.dataGrid.columns; 105 var count = 0; 106 for (var c in columns) 107 ++count; 108 while (--count > 0) { 109 cell = document.createElement("td"); 110 this._element.appendChild(cell); 111 } 112 }, 113 114 /** 115 * @param {number} from 116 */ 117 setStartPosition: function(from) 118 { 119 this._startPosition = from; 120 this._updateLabels(); 121 }, 122 123 /** 124 * @param {number} to 125 */ 126 setEndPosition: function(to) 127 { 128 this._endPosition = to; 129 this._updateLabels(); 130 }, 131 132 /** 133 * @override 134 * @return {number} 135 */ 136 nodeHeight: function() 137 { 138 return 32; 139 }, 140 141 dispose: function() 142 { 143 }, 144 145 __proto__: WebInspector.DataGridNode.prototype 146 } 147 148