// Copyright (c) 2015 Mattermost, 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.onHide = this.onHide.bind(this); this.onShow = this.onShow.bind(this); let state = this.getStateFromStoresForAudits(); state.moreInfo = []; this.state = state; } getStateFromStoresForAudits() { return { audits: UserStore.getAudits() }; } onShow() { AsyncClient.getAudits(); } onHide() { $('#user_settings').modal('show'); this.setState({moreInfo: []}); } componentDidMount() { UserStore.addAuditsChangeListener(this.onAuditChange); $(React.findDOMNode(this.refs.modal)).on('shown.bs.modal', this.onShow); $(React.findDOMNode(this.refs.modal)).on('hidden.bs.modal', this.onHide); } 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 = (