import React, { Component } from 'react' import PropTypes from 'prop-types' import actions from '../../actions' import _ from 'lodash' export default class NotesEditVehicleJourney extends Component { constructor(props) { super(props) } handleSubmit() { this.props.onNotesEditVehicleJourney(this.props.modal.modalProps.vehicleJourney.footnotes) this.props.onModalClose() $('#NotesEditVehicleJourneyModal').modal('hide') } footnotes() { let { footnotes } = this.props.modal.modalProps.vehicleJourney let fnIds = footnotes.map(fn => fn.id) return { associated: footnotes, to_associate: window.line_footnotes.filter(fn => !fnIds.includes(fn.id)) } } renderFootnoteButton(lf) { if (!this.props.editMode) return false if (this.footnotes().associated.includes(lf)) { return } else { return } } renderAssociatedFN() { if (this.footnotes().associated.length == 0) { return

{I18n.t('vehicle_journeys.vehicle_journeys_matrix.no_associated_footnotes')}

} else { return (

{I18n.t('vehicle_journeys.form.purchase_windows')} :

{this.footnotes().associated.map((lf, i) =>

{lf.code}
{this.renderFootnoteButton(lf, this.props.modal.modalProps.vehicleJourney.footnotes)}

{lf.label}

)}
) } } renderToAssociateFN() { if (window.line_footnotes.length == 0) return

{I18n.t('vehicle_journeys.vehicle_journeys_matrix.no_line_footnotes')}

if (this.footnotes().to_associate.length == 0) return false return (

{I18n.t('vehicle_journeys.vehicle_journeys_matrix.select_footnotes')} :

{this.footnotes().to_associate.map((lf, i) =>

{lf.code}
{this.renderFootnoteButton(lf)}

{lf.label}

)}
) } render() { if (this.props.status.isFetching == true) return false if (this.props.status.fetchSuccess == true) { return (
  • {I18n.t('vehicle_journeys.form.footnotes')}

    ×
    {(this.props.modal.type == 'notes_edit') && (
    {this.renderAssociatedFN()} {this.props.editMode && this.renderToAssociateFN()}
    { this.props.editMode &&
    }
    )}
  • ) } else { return false } } } NotesEditVehicleJourney.propTypes = { onOpenNotesEditModal: PropTypes.func.isRequired, onModalClose: PropTypes.func.isRequired, onToggleFootnoteModal: PropTypes.func.isRequired, onNotesEditVehicleJourney: PropTypes.func.isRequired, disabled: PropTypes.bool.isRequired }