@daphneb/phonereporting
Version:
131 lines (114 loc) • 5.81 kB
JavaScript
/*
See License / Disclaimer https://raw.githubusercontent.com/DynamicTyped/Griddle/master/LICENSE
*/
;
var _extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}return target;
};
var React = require('react');
var ColumnProperties = require('./columnProperties.js');
var assign = require('lodash/assign');
var DefaultHeaderComponent = React.createClass({
displayName: 'DefaultHeaderComponent',
render: function render() {
return React.createElement('span', null, this.props.displayName);
}
});
var GridTitle = React.createClass({
displayName: 'GridTitle',
getDefaultProps: function getDefaultProps() {
return {
"columnSettings": null,
"filterByColumn": function filterByColumn() {},
"rowSettings": null,
"sortSettings": null,
"multipleSelectionSettings": null,
"headerStyle": null,
"useGriddleStyles": true,
"useGriddleIcons": true,
"headerStyles": {}
};
},
componentWillMount: function componentWillMount() {
this.verifyProps();
},
sort: function sort(column) {
var that = this;
return function (event) {
that.props.sortSettings.changeSort(column);
};
},
toggleSelectAll: function toggleSelectAll(event) {
this.props.multipleSelectionSettings.toggleSelectAll();
},
handleSelectionChange: function handleSelectionChange(event) {
//hack to get around warning message that's not helpful in this case
return;
},
verifyProps: function verifyProps() {
if (this.props.columnSettings === null) {
console.error("gridTitle: The columnSettings prop is null and it shouldn't be");
}
if (this.props.sortSettings === null) {
console.error("gridTitle: The sortSettings prop is null and it shouldn't be");
}
},
render: function render() {
this.verifyProps();
var that = this;
var titleStyles = {};
var nodes = this.props.columnSettings.getColumns().map(function (col, index) {
var defaultTitleStyles = {};
var columnSort = "";
var columnIsSortable = that.props.columnSettings.getMetadataColumnProperty(col, "sortable", true);
var sortComponent = columnIsSortable ? that.props.sortSettings.sortDefaultComponent : null;
if (that.props.sortSettings.sortColumn == col && that.props.sortSettings.sortDirection === 'asc') {
columnSort = that.props.sortSettings.sortAscendingClassName;
sortComponent = that.props.useGriddleIcons && that.props.sortSettings.sortAscendingComponent;
} else if (that.props.sortSettings.sortColumn == col && that.props.sortSettings.sortDirection === 'desc') {
columnSort += that.props.sortSettings.sortDescendingClassName;
sortComponent = that.props.useGriddleIcons && that.props.sortSettings.sortDescendingComponent;
}
console.log("coltitle",col);
var meta = that.props.columnSettings.getColumnMetadataByName(col);
var displayName = that.props.columnSettings.getMetadataColumnProperty(col, "displayName", col);
var HeaderComponent = that.props.columnSettings.getMetadataColumnProperty(col, "customHeaderComponent", DefaultHeaderComponent);
var headerProps = that.props.columnSettings.getMetadataColumnProperty(col, "customHeaderComponentProps", {});
columnSort = meta == null ? columnSort : (columnSort && columnSort + " " || columnSort) + that.props.columnSettings.getMetadataColumnProperty(col, "cssClassName", "");
if (that.props.useGriddleStyles) {
defaultTitleStyles = {
backgroundColor: "#EDEDEF",
border: "0px",
borderBottom: "1px solid #DDD",
color: "#222",
padding: "5px",
cursor: columnIsSortable ? "pointer" : "default"
};
}
titleStyles = meta && meta.titleStyles ? assign({}, defaultTitleStyles, meta.titleStyles) : assign({}, defaultTitleStyles);
var ComponentClass = displayName ? 'th' : 'td';
return React.createElement(ComponentClass, { onClick: columnIsSortable ? that.sort(col) : null, 'data-title': col, className: columnSort, key: col,
style: titleStyles }, React.createElement(HeaderComponent, _extends({ columnName: col, displayName: displayName,
filterByColumn: that.props.filterByColumn }, headerProps)), sortComponent);
});
if (nodes && this.props.multipleSelectionSettings.isMultipleSelection) {
nodes.unshift(React.createElement('th', { key: 'selection', onClick: this.toggleSelectAll, style: titleStyles, className: 'griddle-select griddle-select-title' }, React.createElement('input', {
type: 'checkbox',
checked: this.props.multipleSelectionSettings.getIsSelectAllChecked(),
onChange: this.handleSelectionChange
})));
}
//Get the row from the row settings.
var className = that.props.rowSettings && that.props.rowSettings.getHeaderRowMetadataClass() || null;
return React.createElement('thead', null, React.createElement('tr', {
className: className,
style: this.props.headerStyles }, nodes));
}
});
module.exports = GridTitle;