/
RideTable.jsx
104 lines (97 loc) · 2.97 KB
/
RideTable.jsx
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
var RideRow = require('./RideRow.jsx');
module.exports = React.createClass({
getInitialState() {
var list = this.props.rides;
list.sort(function(a,b) {return (a.DisplayName > b.DisplayName) ? 1 : ((b.DisplayName > a.DisplayName) ? -1 : 0);} );
return {
rides: list
}
},
render() {
var rideRows = this.state.rides.map((item) => {
return <RideRow ride={item} key={item.RideId} />
});
var addPanel = this.props.security.IsTraveller ? (
<div className="row">
<div className="col-sm-12">
<a href="#" className="btn btn-primary" onClick={this.addClick}>Add</a>
</div>
</div>
) : null;
return (
<div class="container">
<div className="row">
<div className="col-sm-12">
<table className="table table-responsive table-striped">
<thead>
<tr>
<th>Name</th>
<th>Location</th>
<th>Nr Places</th>
</tr>
</thead>
<tbody>
{rideRows}
</tbody>
</table>
</div>
</div>
{addPanel}
<div className="modal fade" id="editRide" tabindex="-1" role="dialog" aria-labelledby="editRideLabel">
<div className="modal-dialog" role="document">
<div className="modal-content">
<div className="modal-header">
<button type="button" className="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 className="modal-title" id="editRideLabel">Ride</h4>
</div>
<div className="modal-body">
<div className="checkbox">
<label>
<input type="checkbox" ref="chkIncoming" /> Incoming
</label>
</div>
<div className="form-group">
<label for="txtLocation">Location</label>
<input type="text" className="form-control" ref="txtLocation" placeholder="Location" />
</div>
<div className="form-group">
<label for="txtPlaces">Nr Places</label>
<input type="text" className="form-control" ref="txtPlaces" placeholder="Nr Places" />
</div>
<div className="form-group">
<label for="txtNotes">Notes</label>
<textarea className="form-control" ref="txtNotes" placeholder="Notes" rows="5" />
</div>
</div>
<div className="modal-footer">
<button type="button" className="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" className="btn btn-primary" onClick={this.updateRide}>Save</button>
</div>
</div>
</div>
</div>
</div>
);
},
addClick(e) {
e.preventDefault();
$('#editRide').modal('show');
},
updateRide(e) {
e.preventDefault();
this.props.service.addRide({
Incoming: this.refs.chkIncoming.checked,
Location: this.refs.txtLocation.value,
Places: this.refs.txtPlaces.value,
Notes: this.refs.txtNotes.value
}, (data) => {
var newList = this.state.rides;
newList.push(data);
newList.sort(function(a,b) {return (a.DisplayName > b.DisplayName) ? 1 : ((b.DisplayName > a.DisplayName) ? -1 : 0);} );
this.setState({
rides: newList
});
});
$('#editRide').modal('hide');
}
});