// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. // See License.txt for license information. var UserStore = require('../stores/user_store.jsx'); var AsyncClient = require('../utils/async_client.jsx'); var Utils = require('../utils/utils.jsx'); function getStateFromStoresForAudits() { return { audits: UserStore.getAudits() }; } module.exports = React.createClass({ componentDidMount: function() { UserStore.addAuditsChangeListener(this._onChange); AsyncClient.getAudits(); var self = this; $(this.refs.modal.getDOMNode()).on('hidden.bs.modal', function(e) { self.setState({ moreInfo: [] }); }); }, componentWillUnmount: function() { UserStore.removeAuditsChangeListener(this._onChange); }, _onChange: function() { this.setState(getStateFromStoresForAudits()); }, handleMoreInfo: function(index) { var newMoreInfo = this.state.moreInfo; newMoreInfo[index] = true; this.setState({ moreInfo: newMoreInfo }); }, getInitialState: function() { var initialState = getStateFromStoresForAudits(); initialState.moreInfo = []; return initialState; }, render: function() { var accessList = []; var currentHistoryDate = null; for (var i = 0; i < this.state.audits.length; i++) { var currentAudit = this.state.audits[i]; var newHistoryDate = new Date(currentAudit.create_at); var newDate = null; if (!currentHistoryDate || currentHistoryDate.toLocaleDateString() !== newHistoryDate.toLocaleDateString()) { currentHistoryDate = newHistoryDate; newDate = (