/** @jsx React.DOM */ /* global conjur, React, _ */ (function(conjur, React, _) { 'use strict'; var RoleLink = conjur.views.RoleLink; var GenericListItem = React.createClass({ render: function() { var recordUrl = '/ui/' + this.props.data.kind + '/' + window.encodeURIComponent(this.props.data.record.identifier); return ( {this.props.data.record.identifier} ); } }); this.GenericList = React.createClass({ getInitialState: function() { return { sort: { column: this.props.defaultColumn || 'id', order: this.props.defaultOrder || 'asc' }, columns: this.props.columns || { id: { id: 'id', name: 'Id', defaultSortOrder: 'desc' }, owner: { id: 'owner', name: 'Owner', defaultSortOrder: 'desc' } } }; }, sortColumn: function(column) { return function(e) { e.preventDefault(); var order = (this.state.sort.order === 'asc') ? 'desc' : 'asc'; if (this.state.sort.column !== column) { order = this.state.columns[column].defaultSortOrder; } this.setState({sort: {column: column, order: order}}); }.bind(this); }, sortClass: function(column) { var order = (this.state.sort.order === 'asc') ? 'glyphicon glyphicon-chevron-up' : 'glyphicon glyphicon-chevron-down'; return (this.state.sort.column === column) ? order : ''; }, render: function() { var items = this.props.data.members.map(function(o) { return o; }); items = _.sortBy(items, this.state.sort.column); if (this.state.sort.order === 'desc') { items.reverse(); } var rows = items.map(function (o) { var componentName = _.str.capitalize( this.props.data.kind.substring(0, this.props.data.kind.length-1) ) + 'ListItem'; var itemKind = window[componentName] || GenericListItem; // Caution! return itemKind({data: {kind: this.props.data.kind, record: o}, key: o.id}); }.bind(this)); var columns = _.values(this.state.columns).map(function(c) { return ( {c.name} ); }, this); return ( {columns} {rows}
); } }); }).bind(conjur.views) ( conjur, React, _ );