Fixed table width in admin interface if delete col. is shown.

This commit is contained in:
Martin Edenhofer 2018-01-10 11:28:56 +01:00
parent 23018aa603
commit 48f3a7efe5

View file

@ -97,6 +97,7 @@ class App.ControllerTable extends App.Controller
checkBoxColWidth: 40 checkBoxColWidth: 40
radioColWidth: 22 radioColWidth: 22
sortableColWidth: 36 sortableColWidth: 36
destroyColWidth: 70
elements: elements:
'.js-tableHead': 'tableHead' '.js-tableHead': 'tableHead'
@ -510,6 +511,7 @@ class App.ControllerTable extends App.Controller
# get header data # get header data
@headers = [] @headers = []
availableWidth = @availableWidth
for item in @overviewAttributes for item in @overviewAttributes
headerFound = false headerFound = false
for attributeName, attribute of @attributesList for attributeName, attribute of @attributesList
@ -524,7 +526,7 @@ class App.ControllerTable extends App.Controller
# e.g. column: owner # e.g. column: owner
headerFound = true headerFound = true
if @headerWidth[attribute.name] if @headerWidth[attribute.name]
attribute.displayWidth = @headerWidth[attribute.name] * @availableWidth attribute.displayWidth = @headerWidth[attribute.name] * availableWidth
else if !attribute.width else if !attribute.width
attribute.displayWidth = @baseColWidth attribute.displayWidth = @baseColWidth
else else
@ -533,7 +535,7 @@ class App.ControllerTable extends App.Controller
unit = attribute.width.match(/[px|%]+/)[0] unit = attribute.width.match(/[px|%]+/)[0]
if unit is '%' if unit is '%'
attribute.displayWidth = value / 100 * @el.width() attribute.displayWidth = value / 100 * availableWidth
else else
attribute.displayWidth = value attribute.displayWidth = value
@headers.push attribute @headers.push attribute
@ -542,7 +544,7 @@ class App.ControllerTable extends App.Controller
if attributeName is "#{item}_id" || attributeName is "#{item}_ids" if attributeName is "#{item}_id" || attributeName is "#{item}_ids"
headerFound = true headerFound = true
if @headerWidth[attribute.name] if @headerWidth[attribute.name]
attribute.displayWidth = @headerWidth[attribute.name] * @availableWidth attribute.displayWidth = @headerWidth[attribute.name] * availableWidth
else if !attribute.width else if !attribute.width
attribute.displayWidth = @baseColWidth attribute.displayWidth = @baseColWidth
else else
@ -551,7 +553,7 @@ class App.ControllerTable extends App.Controller
unit = attribute.width.match(/[px|%]+/)[0] unit = attribute.width.match(/[px|%]+/)[0]
if unit is '%' if unit is '%'
attribute.displayWidth = value / 100 * @el.width() attribute.displayWidth = value / 100 * availableWidth
else else
attribute.displayWidth = value attribute.displayWidth = value
@headers.push attribute @headers.push attribute
@ -745,8 +747,10 @@ class App.ControllerTable extends App.Controller
if @availableWidth is 0 if @availableWidth is 0
@availableWidth = @minTableWidth @availableWidth = @minTableWidth
availableWidth = @availableWidth
widths = @getHeaderWidths() widths = @getHeaderWidths()
shrinkBy = Math.ceil (widths - @availableWidth) / @getShrinkableHeadersCount() shrinkBy = Math.ceil (widths - availableWidth) / @getShrinkableHeadersCount()
# make all cols evenly smaller # make all cols evenly smaller
@headers = _.map @headers, (col) => @headers = _.map @headers, (col) =>
@ -755,7 +759,8 @@ class App.ControllerTable extends App.Controller
return col return col
# give left-over space from rounding to last column to get to 100% # give left-over space from rounding to last column to get to 100%
roundingLeftOver = @availableWidth - @getHeaderWidths() roundingLeftOver = availableWidth - @getHeaderWidths()
# but only if there is something left over (will get negative when there are too many columns for each column to stay in their min width) # but only if there is something left over (will get negative when there are too many columns for each column to stay in their min width)
if roundingLeftOver > 0 if roundingLeftOver > 0
@headers[@headers.length - 1].displayWidth = @headers[@headers.length - 1].displayWidth + roundingLeftOver @headers[@headers.length - 1].displayWidth = @headers[@headers.length - 1].displayWidth + roundingLeftOver
@ -781,6 +786,9 @@ class App.ControllerTable extends App.Controller
if @dndCallback if @dndCallback
widths += @sortableColWidth widths += @sortableColWidth
if @destroy
widths += @destroyColWidth
widths widths
setHeaderWidths: => setHeaderWidths: =>