lib/reports/ReportTable.rb in taskjuggler-0.0.4 vs lib/reports/ReportTable.rb in taskjuggler-0.0.5
- old
+ new
@@ -24,11 +24,11 @@
# The height in pixels of a horizontal scrollbar on an HTML page. This
# value should be large enough to work for all browsers.
SCROLLBARHEIGHT = 20
attr_reader :maxIndent, :headerLineHeight, :headerFontSize
- attr_accessor :equiLines
+ attr_accessor :equiLines, :embedded
# Create a new ReportTable object.
def initialize
# The height if the header lines in screen pixels.
@headerLineHeight = 19
@@ -39,10 +39,12 @@
# Array of ReportTableLine objects.
@lines = []
@maxIndent = 0
# Whether or not all table lines must have same height.
@equiLines = false
+ # True if the table is embedded as a column of another ReportTable.
+ @embedded = false
end
# This function should only be called by the ReportTableColumn constructor.
def addColumn(col)
@columns << col
@@ -71,27 +73,43 @@
# Output the table as HTML.
def to_html
determineMaxIndents
- table = XMLElement.new('table', 'align' => 'center', 'cellspacing' => '1',
- 'cellpadding' => '2', 'width' => '100%',
- 'class' => 'tabback')
+ attr = { 'class' => 'tj_table',
+ 'cellspacing' => '1' }
+ attr['style'] = 'width:100%; ' if @embedded
+ table = XMLElement.new('table', attr)
table << (tbody = XMLElement.new('tbody'))
# Generate the 1st table header line.
+ allCellsHave2Rows = true
+ lineHeight = @headerLineHeight
+ @columns.each do |col|
+ if col.cell1.rows != 2 && !col.cell1.special
+ allCellsHave2Rows = false
+ break;
+ end
+ end
+ if allCellsHave2Rows
+ @columns.each { |col| col.cell1.rows = 1 }
+ lineHeight = @headerLineHeight * 2 + 1
+ end
+
tbody << (tr =
XMLElement.new('tr', 'class' => 'tabhead',
- 'style' => "height:#{@headerLineHeight}px; " +
+ 'style' => "height:#{lineHeight}px; " +
"font-size:#{@headerFontSize}px;"))
@columns.each { |col| tr << col.to_html(1) }
- # Generate the 2nd table header line.
- tbody << (tr =
- XMLElement.new('tr', 'class' => 'tabhead',
- 'style' => "height:#{@headerLineHeight}px; " +
- "font-size:#{@headerFontSize}px;"))
- @columns.each { |col| tr << col.to_html(2) }
+ unless allCellsHave2Rows
+ # Generate the 2nd table header line.
+ tbody << (tr =
+ XMLElement.new('tr', 'class' => 'tabhead',
+ 'style' => "height:#{@headerLineHeight}px; " +
+ "font-size:#{@headerFontSize}px;"))
+ @columns.each { |col| tr << col.to_html(2) }
+ end
# Generate the rest of the table.
@lines.each { |line| tbody << line.to_html }
# In case we have columns with scrollbars, we generate an extra line with