1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 01:25:17 +01:00

Refactor TableColumnMixin

This commit is contained in:
Tim Daubenschütz 2015-05-26 14:57:32 +02:00
parent 65ccaf10cf
commit ca97bd9af5
4 changed files with 7 additions and 7 deletions

View File

@ -23,7 +23,7 @@ let TableHeader = React.createClass({
<div className="row">
{this.props.columnList.map((val, i) => {
let columnClasses = this.calcColumnClasses(this.props.columnList, i);
let columnClasses = this.calcColumnClasses(this.props.columnList, i, 12);
let columnName = this.props.columnList[i].columnName;
let canBeOrdered = this.props.columnList[i].canBeOrdered;

View File

@ -18,7 +18,7 @@ let TableItem = React.createClass({
return this.props.columnList.map((column, i) => {
let TypeElement = column.displayType;
let columnClass = this.calcColumnClasses(this.props.columnList, i);
let columnClass = this.calcColumnClasses(this.props.columnList, i, 12);
return (
<div className={columnClass + ' ascribe-table-item-column'} key={i}>

View File

@ -56,7 +56,7 @@ let TableItemSubtable = React.createClass({
return this.props.columnList.map((column, i) => {
let TypeElement = column.displayType;
let columnClass = this.calcColumnClasses(this.props.columnList, i);
let columnClass = this.calcColumnClasses(this.props.columnList, i, 12);
return (
<div className={columnClass + ' ascribe-table-item-column'} key={i}>

View File

@ -7,14 +7,14 @@ let TableColumnMixin = {
* Generates the bootstrap grid column declarations automatically using
* the columnMap.
*/
calcColumnClasses(list, i) {
calcColumnClasses(list, i, numOfColumns) {
let bootstrapClasses = ['col-xs-', 'col-sm-', 'col-md-', 'col-lg-'];
let listOfRowValues = list.map((column) => column.rowWidth );
let numOfColumns = GeneralUtils.sumNumList(listOfRowValues);
let numOfUsedColumns = GeneralUtils.sumNumList(listOfRowValues);
if(numOfColumns > 12) {
throw new Error('Bootstrap has only 12 columns to assign. You defined ' + numOfColumns + '. Change this in the columnMap you\'re passing to the table.')
if(numOfUsedColumns > numOfColumns) {
throw new Error('This table has only ' + numOfColumns + ' columns to assign. You defined ' + numOfUsedColumns + '. Change this in the columnMap you\'re passing to the table.')
} else {
return bootstrapClasses.join( listOfRowValues[i] + ' ') + listOfRowValues[i];
}