2016-12-28 09:25:20 -05:00
|
|
|
var React = require('react');
|
|
|
|
|
|
|
|
var ReactBootstrap = require('react-bootstrap');
|
|
|
|
var FormGroup = ReactBootstrap.FormGroup;
|
|
|
|
var ControlLabel = ReactBootstrap.ControlLabel;
|
2016-12-29 20:15:39 -05:00
|
|
|
var Grid = ReactBootstrap.Grid;
|
|
|
|
var Row = ReactBootstrap.Row;
|
|
|
|
var Col = ReactBootstrap.Col;
|
2017-01-01 08:10:58 -05:00
|
|
|
var Panel = ReactBootstrap.Panel;
|
|
|
|
var Button = ReactBootstrap.Button;
|
2016-12-28 09:25:20 -05:00
|
|
|
|
|
|
|
var Multiselect = require('react-widgets').Multiselect;
|
|
|
|
|
2016-12-29 20:15:39 -05:00
|
|
|
var models = require('../models');
|
|
|
|
var Attendee = models.Attendee;
|
|
|
|
|
|
|
|
var NewSuggestion = require('./NewSuggestion');
|
2016-12-28 09:25:20 -05:00
|
|
|
|
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: "RecordLunch",
|
|
|
|
getAttendeeList: function() {
|
|
|
|
var attendeeList = [];
|
|
|
|
for (var attendeeId in this.props.attendees) {
|
|
|
|
attendeeList.push(this.props.attendees[attendeeId]);
|
|
|
|
}
|
|
|
|
return attendeeList;
|
|
|
|
},
|
|
|
|
getAttendeeMap: function() {
|
|
|
|
var attendeeMap = {};
|
|
|
|
for (var attendeeId in this.props.attendees) {
|
|
|
|
var attendee = this.props.attendees[attendeeId];
|
|
|
|
attendeeMap[attendee.Name] = attendee;
|
|
|
|
}
|
|
|
|
return attendeeMap;
|
|
|
|
},
|
|
|
|
onChangeAttendees: function(attendees) {
|
|
|
|
var attendeeMap = this.getAttendeeMap();
|
|
|
|
for (var i in attendees) {
|
|
|
|
if (attendeeMap.hasOwnProperty(attendees[i].Name)) {
|
|
|
|
delete attendeeMap[attendees[i].Name];
|
|
|
|
} else {
|
|
|
|
var attendee = new Attendee();
|
|
|
|
attendee.Name = attendees[i].Name;
|
|
|
|
this.props.createAttendee(attendee);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (var i in attendeeMap) {
|
|
|
|
this.props.removeAttendee(attendeeMap[i]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onCreateAttendee: function(attendeeName) {
|
|
|
|
var attendee = new Attendee();
|
|
|
|
attendee.Name = attendeeName;
|
|
|
|
this.props.createAttendee(attendee);
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
var attendeeList = this.getAttendeeList();
|
2016-12-29 20:15:39 -05:00
|
|
|
|
|
|
|
var suggestionIds = Object.keys(this.props.suggestions);
|
2017-01-01 08:10:58 -05:00
|
|
|
suggestionIds.sort(function(a, b){return parseInt(b, 10) - parseInt(a, 10);});
|
2016-12-29 20:15:39 -05:00
|
|
|
var suggestions = [];
|
|
|
|
for (var i in suggestionIds) {
|
|
|
|
var suggestion = this.props.suggestions[suggestionIds[i]];
|
2017-01-01 08:10:58 -05:00
|
|
|
var suggestorName = "Unknown";
|
|
|
|
if (this.props.attendees.hasOwnProperty(suggestion.AttendeeId))
|
|
|
|
suggestorName = this.props.attendees[suggestion.AttendeeId].Name;
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
var self = this;
|
|
|
|
var popFunction = function(){
|
|
|
|
return function(){self.props.removeSuggestion(suggestion);};
|
|
|
|
}();
|
|
|
|
suggestions.push((
|
|
|
|
<Row key={suggestion.SuggestionId}><Panel>
|
|
|
|
<Col xs={4}><ControlLabel>Current Suggestion:</ControlLabel></Col>
|
|
|
|
<Col xs={1}></Col>
|
|
|
|
<Col xs={4}>{suggestion.RestaurantName} (by {suggestorName})</Col>
|
|
|
|
<Col xs={1}></Col>
|
|
|
|
<Col xs={2}>
|
|
|
|
<Button bsStyle="danger" onClick={popFunction}>Pop</Button>
|
|
|
|
</Col>
|
|
|
|
</Panel></Row>
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
suggestions.push((
|
|
|
|
<Row key={suggestion.SuggestionId}>
|
|
|
|
<Col xs={4}><ControlLabel>{(suggestionIds.length - i).toString() + "."}</ControlLabel></Col>
|
|
|
|
<Col xs={1}></Col>
|
|
|
|
<Col xs={4}>{suggestion.RestaurantName} (by {suggestorName})</Col>
|
|
|
|
<Col xs={1}></Col>
|
|
|
|
<Col xs={2}>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
));
|
|
|
|
}
|
2016-12-29 20:15:39 -05:00
|
|
|
}
|
|
|
|
|
2016-12-28 09:25:20 -05:00
|
|
|
return (
|
|
|
|
<div><form>
|
2017-01-01 08:10:58 -05:00
|
|
|
<Grid fluid><Row><Col xs={12}>
|
2016-12-29 20:15:39 -05:00
|
|
|
<FormGroup controlId="attendees">
|
2016-12-28 09:25:20 -05:00
|
|
|
<ControlLabel>Attendees</ControlLabel>
|
|
|
|
<Multiselect
|
|
|
|
value={attendeeList}
|
|
|
|
data={this.props.popularAttendees}
|
|
|
|
valueField='Name'
|
|
|
|
textField='Name'
|
|
|
|
messages={{'createNew': "(create new attendee)"}}
|
|
|
|
onChange={this.onChangeAttendees}
|
|
|
|
onCreate={this.onCreateAttendee} />
|
|
|
|
</FormGroup>
|
2016-12-29 20:15:39 -05:00
|
|
|
</Col></Row>
|
|
|
|
<NewSuggestion
|
|
|
|
createSuggestion={this.props.createSuggestion}
|
|
|
|
attendees={this.props.attendees}
|
|
|
|
suggestions={this.props.suggestions}
|
|
|
|
popularSuggestions={this.props.popularSuggestions} />
|
2017-01-01 08:10:58 -05:00
|
|
|
{suggestions}
|
|
|
|
</Grid>
|
2016-12-28 09:25:20 -05:00
|
|
|
</form></div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|