@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 onUpdateAllDecision: 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'}, {selector: 'input.update-all', propsKey: 'update_all'}] @root = $(@getDOMNode()) @iCheckify() @slotDate = @root.find('.date-picker') @slotDate.datepicker({ dateFormat: "D M d yy", onSelect: ((e) => @toggleDate(e)) }) componentDidUpdate: () -> @iCheckify() @slotDate = @root.find('.date-picker') @slotDate.datepicker({ dateFormat: "D M d yy", onSelect: ((e) => @toggleDate(e)) }) toggleDate: (e) -> componentWillReceiveProps: (nextProps) -> if @onlyOption() console.log("setting it counter") # if this isn't a counter situation, then there is no 'Accept their time', so there should only be one radio button, and we'll select that value already @setState({"slot-decision": "counter"}) checkboxChanged: (e) -> name = $(e.target).attr('name') if name == 'slot-decision' value = $(e.target).val() logger.debug("LessonBookingDecision: slot-decision made with value: " + value) @setState({"slot-decision": value}) @props.onSlotDecision({slot_decision: value}) else if name == 'update-all' checked = $(e.target).is(':checked') logger.debug("LessonBookingDecision: update-all changed: " + checked) @props.onUpdateAllDecision({update_all: checked}) else throw "checkbox changed with unknown name #{name}" 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' nullOp: ()-> onlyOption: () -> # (!this.props.initial && this.props.selfLastToAct ) || !(this.props.counter && !this.props.selfLastToAct) !@multipleOptions() multipleOptions: () -> if this.props.initial if this.props.noSlots false else !(!this.props.counter && this.props.selfLastToAct) else if this.props.counter !this.props.selfLastToAct else false render: () -> #showUpdateAll = !this.props.initial if (!this.props.initial && !this.props.counter) || this.props.selfLastToAct userPromptHeader = `

Would you like to update 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' if this.props.is_recurring && this.props.update_all actionBtnText = "PROPOSE TIME FOR ALL LESSONS" else if @props.noSlots actionBtnText = 'PROPOSE TIME' else actionBtnText = "PROPOSE ALTERNATE TIME" else if this.props.slot_decision == 'decline' if @showDeclineVerb() verb = "DECLINE" else verb = "CANCEL" if this.props.update_all actionBtnText = "#{verb} ALL LESSONS" else 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?, counterSelected: this.props.slot_decision == 'counter', onlyOption: @onlyOption()} if this.props.counterErrors? errorText = window.JK.reactErrors(this.props.counterErrors, {day_of_week: 'Day' }) if this.props.is_recurring && this.props.update_all slotAltPrompt = `
Day: Time: :
* Time will be local to {window.JK.currentTimezone()} {errorText}
` #if @props.update_all # updateAllField = # `
# #
` updateAllField = null else slotAltPrompt = `
Date: Time: :
*Time will be local to {window.JK.currentTimezone()} {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) if this.props.noSlots proposeAltLabelText = 'Propose a day/time' else 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 if this.props.noSlots proposeAltLabelText = 'Propose a day/time' else proposeAltLabelText = "Propose new alternate day/time" # if you have issued a counter, you should be able to withdraw it # TODO #cancelField = `
# #
` cancelField = null `
{userPromptHeader}
{slots}
{slotAltPrompt}
{cancelField} {updateAllField}
{messagePromptHeader}
CANCEL {actionBtnText}
` })