@LessonBookingDecision = React.createClass({ #slot.creatorRole #slot.slotTime # props.initial # props.counter # props.slots # props.is_recurring # props.slot_decision # props.otherRole # props.cancelErrors # props.counterErrors mixins: [ ICheckMixin, ] propTypes: { onSlotDecision: React.PropTypes.func.isRequired onUserCancel: React.PropTypes.func.isRequired onUserDecision: React.PropTypes.func.isRequired } getInitialState: () -> { slot_decision: null } componentWillMount: () -> @days = [] @days.push(``) @days.push(``) @days.push(``) @days.push(``) @days.push(``) @days.push(``) @days.push(``) @days.push(``) @hours = [] for hour in ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'] if hour == '12' key = '00' else key = hour @hours.push(``) @minutes = [] for minute in ['00', '15', '30', '45'] @minutes.push(``) @am_pm = [``, ``] componentDidMount: () -> @checkboxes = [{selector: 'input.slot-decision', stateKey: 'slot-decision'}] @root = $(@getDOMNode()) @iCheckify() componentDidUpdate: () -> @iCheckify() @slotDate = @root.find('.date-picker') @slotDate.datepicker({ dateFormat: "D M d yy", onSelect: ((e) => @toggleDate(e)) }) checkboxChanged: (e) -> checked = $(e.target).is(':checked') value = $(e.target).val() @props.onSlotDecision({slot_decision: value}) onUserDecision: (e) -> e.preventDefault() if this.props.disabled return this.props.onUserDecision(this.state.slot_decision) onUserCancel: (e) -> e.preventDefault() if this.props.disabled return this.props.onUserCancel() dayOfWeek: (slot) -> switch slot.day_of_week when 0 then "Sunday" when 1 then "Monday" when 2 then "Tuesday" when 3 then "Wednesday" when 4 then "Thursday" when 5 then "Friday" when 6 then "Saturday" slotLabelText: (index, slot) -> if @props.counter "Accept #{slot.creatorRoleRelative} proposed day/time" else if index == 0 "Accept #{slot.creatorRoleRelative} preferred day/time" else "Accept #{slot.creatorRoleRelative} secondary day/time" showDeclineVerb: () -> this.props.initial && this.props.otherRole == 'student' render: () -> if (!this.props.initial && !this.props.counter) || this.props.selfLastToAct userPromptHeader = `

Would you like to change this lesson?

` messagePromptHeader = `

Send message to {this.props.otherRole} with your update.

` else userPromptHeader = `

How do you want to handle this request?

` messagePromptHeader = `

Send message to {this.props.otherRole} with your response.

` if this.props.slot_decision == 'counter' actionBtnText = "PROPOSE ALTERNATE TIME" else if this.props.slot_decision == 'decline' if @showDeclineVerb() verb = "DECLINE" else verb = "CANCEL" actionBtnText = "#{verb} LESSON" else if this.props.initial actionBtnText = "ACCEPT & SCHEDULE LESSON" else actionBtnText = "ACCEPT & UPDATE LESSON" counterClasses={field: true, 'slot-decision-field': true, error: this.props.counterErrors?} if this.props.counterErrors? errorText = window.JK.reactErrors(this.props.counterErrors, {day_of_week: 'Day' }) if this.props.is_recurring slotAltPrompt = `
Day: Time: :
* Time will be local to {window.jstz.determine().name()} {errorText}
` else slotAltPrompt = `
Date: Time: :
*Time will be local to {window.jstz.determine().name()} {errorText}
` if @showDeclineVerb() declineVerb = "Decline" else declineVerb = "Cancel" cancelClasses = {cancel: true, "button-grey": true, disabled: this.props.disabled} scheduleClasses = {schedule: true, "button-orange": true, disabled: this.props.disabled} slots = [] if !(this.props.counter && this.props.selfLastToAct) proposeAltLabelText = "Propose alternate day/time" for slot, i in @props.slots if this.props.is_recurring slotDetail = `
Each {slot.slotTime}
` else slotDetail = `
{slot.slotTime}
` slots.push(`
{slotDetail}
`) else proposeAltLabelText = "Propose new alternate day/time" # if you have issued a counter, you should be able to withdraw it # TODO `
{userPromptHeader}
{slots}
{slotAltPrompt}
{messagePromptHeader}
CANCEL {actionBtnText}
` })