1
0
mirror of https://github.com/ascribe/onion.git synced 2024-09-28 12:08:55 +02:00
onion/js/mixins/table_column_mixin.js

23 lines
858 B
JavaScript
Raw Normal View History

2015-05-20 14:48:57 +02:00
import GeneralUtils from '../utils/general_utils';
let TableColumnMixin = {
/**
* Generates the bootstrap grid column declarations automatically using
* the columnMap.
*/
calcColumnClasses(obj, i) {
2015-05-20 14:48:57 +02:00
let bootstrapClasses = ['col-xs-', 'col-sm-', 'col-md-', 'col-lg-'];
let rowData = GeneralUtils.valuesOfObject(obj);
let listOfRowValues = rowData.map((val) => val.rowWidth );
let numOfColumns = GeneralUtils.sumNumList(listOfRowValues);
2015-05-20 14:48:57 +02:00
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.')
} else {
return bootstrapClasses.join( listOfRowValues[i] + ' ') + listOfRowValues[i];
}
2015-05-20 14:48:57 +02:00
}
};
export default TableColumnMixin;