// 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 LoadingScreen = require('./loading_screen.jsx'); var utils = require('../utils/utils.jsx'); export default class AccessHistoryModal extends React.Component { constructor(props) { super(props); this.onAuditChange = this.onAuditChange.bind(this); this.handleMoreInfo = this.handleMoreInfo.bind(this); this.state = this.getStateFromStoresForAudits(); this.state.moreInfo = []; } getStateFromStoresForAudits() { return { audits: UserStore.getAudits() }; } componentDidMount() { UserStore.addAuditsChangeListener(this.onAuditChange); $(this.refs.modal.getDOMNode()).on('shown.bs.modal', function show() { AsyncClient.getAudits(); }); var self = this; $(this.refs.modal.getDOMNode()).on('hidden.bs.modal', function hide() { $('#user_settings').modal('show'); self.setState({moreInfo: []}); }); } componentWillUnmount() { UserStore.removeAuditsChangeListener(this.onAuditChange); } onAuditChange() { var newState = this.getStateFromStoresForAudits(); if (!utils.areStatesEqual(newState.audits, this.state.audits)) { this.setState(newState); } } handleMoreInfo(index) { var newMoreInfo = this.state.moreInfo; newMoreInfo[index] = true; this.setState({moreInfo: newMoreInfo}); } render() { 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 = (