aboutsummaryrefslogtreecommitdiffstats
path: root/app/javascript/vehicle_journeys/components/Tools.js
blob: 41a521d126cb8997b638f849228743472a977e3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import actions from '../actions'
import AddVehicleJourney from '../containers/tools/AddVehicleJourney'
import DeleteVehicleJourneys from '../containers/tools/DeleteVehicleJourneys'
import ShiftVehicleJourney from '../containers/tools/ShiftVehicleJourney'
import DuplicateVehicleJourney from '../containers/tools/DuplicateVehicleJourney'
import EditVehicleJourney from '../containers/tools/EditVehicleJourney'
import NotesEditVehicleJourney from '../containers/tools/NotesEditVehicleJourney'
import TimetablesEditVehicleJourney from '../containers/tools/TimetablesEditVehicleJourney'
import PurchaseWindowsEditVehicleJourney from '../containers/tools/PurchaseWindowsEditVehicleJourney'
import ConstraintExclusionEditVehicleJourney from '../containers/tools/ConstraintExclusionEditVehicleJourney'


export default class Tools extends Component {
  constructor(props) {
    super(props)
    this.hasPolicy = this.hasPolicy.bind(this)
  }

  hasPolicy(key) {
    // Check if the user has the policy to disable or not the action
    return this.props.filters.policy[`vehicle_journeys.${key}`]
  }

  hasFeature(key) {
    // Check if the organisation has the given feature
    return this.props.filters.features[key]
  }

  render() {
    let { vehicleJourneys, onCancelSelection, editMode } = this.props
    return (
      <div className='select_toolbox'>
        <ul>
          <AddVehicleJourney disabled={!this.hasPolicy("create") || !editMode} />
          <DuplicateVehicleJourney disabled={!this.hasPolicy("create") || !this.hasPolicy("update") || !editMode}/>
          <ShiftVehicleJourney disabled={!this.hasPolicy("update") || !editMode}/>
          <EditVehicleJourney disabled={false}/>

          <TimetablesEditVehicleJourney disabled={false}/>
          { this.hasFeature('purchase_windows') &&
            <PurchaseWindowsEditVehicleJourney disabled={false}/>
          }
          <ConstraintExclusionEditVehicleJourney disabled={false}/>
          <NotesEditVehicleJourney disabled={!this.hasPolicy("update")}/>
          <DeleteVehicleJourneys disabled={!this.hasPolicy("destroy") || !editMode}/>
        </ul>

        <span className='info-msg'>{I18n.t('vehicle_journeys.vehicle_journeys_matrix.selected_journeys', {count: actions.getSelected(vehicleJourneys).length})}</span>
        <button className='btn btn-xs btn-link pull-right' onClick={onCancelSelection}>{I18n.t('vehicle_journeys.vehicle_journeys_matrix.cancel_selection')}</button>
      </div>
    )
  }
}

Tools.propTypes = {
  vehicleJourneys : PropTypes.array.isRequired,
  onCancelSelection: PropTypes.func.isRequired,
  filters: PropTypes.object.isRequired
}