2016-04-06 02:23:15 +00:00
@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
2016-04-21 14:23:29 +00:00
onUpdateAllDecision: React . PropTypes . func . isRequired
2016-04-06 02:23:15 +00:00
}
getInitialState: () ->
{
slot_decision: null
}
componentWillMount: () ->
@days = [ ]
@ days . push ( ` < option key = ' choose ' value = ' ' > Choose a day of the week . . . < / option > ` )
@ days . push ( ` < option key = ' 0 ' value = " 0 " > Sunday < / option > ` )
@ days . push ( ` < option key = ' 1 ' value = " 1 " > Monday < / option > ` )
@ days . push ( ` < option key = ' 2 ' value = " 2 " > Tuesday < / option > ` )
@ days . push ( ` < option key = ' 3 ' value = " 3 " > Wednesday < / option > ` )
@ days . push ( ` < option key = ' 4 ' value = " 4 " > Thursday < / option > ` )
@ days . push ( ` < option key = ' 5 ' value = " 5 " > Friday < / option > ` )
@ days . push ( ` < option key = ' 6 ' value = " 6 " > Saturday < / option > ` )
@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 ( ` < option key = { key } value = { key } > { hour } < / option > ` )
@minutes = [ ]
for minute in [ ' 00 ' , ' 15 ' , ' 30 ' , ' 45 ' ]
@ minutes . push ( ` < option key = { minute } value = { minute } > { minute } < / option > ` )
@am_pm = [ ` < option key = " AM " value = " AM " > AM < / option > ` , ` < option key = " PM " value = " PM " > PM < / option > ` ]
componentDidMount: () ->
2016-04-21 14:23:29 +00:00
@checkboxes = [ { selector: ' input.slot-decision ' , stateKey: ' slot-decision ' } , { selector: ' input.update-all ' , propsKey: ' update_all ' } ]
2016-04-06 02:23:15 +00:00
@root = $ ( @ getDOMNode ( ) )
@ iCheckify ( )
2016-05-30 21:43:55 +00:00
@slotDate = @ root . find ( ' .date-picker ' )
@ slotDate . datepicker ( {
dateFormat: " D M d yy " ,
onSelect: ( (e) => @ toggleDate ( e ) )
} )
2016-04-06 02:23:15 +00:00
componentDidUpdate: () ->
@ iCheckify ( )
@slotDate = @ root . find ( ' .date-picker ' )
@ slotDate . datepicker ( {
dateFormat: " D M d yy " ,
onSelect: ( (e) => @ toggleDate ( e ) )
} )
2016-05-30 21:43:55 +00:00
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 " } )
2016-04-06 02:23:15 +00:00
checkboxChanged: (e) ->
2016-04-21 14:23:29 +00:00
name = $ ( e . target ) . attr ( ' name ' )
if name == ' slot-decision '
value = $ ( e . target ) . val ( )
2016-05-18 20:18:38 +00:00
logger . debug ( " LessonBookingDecision: slot-decision made with value: " + value )
2016-05-20 20:33:44 +00:00
@ setState ( { " slot-decision " : value } )
2016-04-21 14:23:29 +00:00
@ props . onSlotDecision ( { slot_decision: value } )
else if name == ' update-all '
checked = $ ( e . target ) . is ( ' :checked ' )
2016-05-18 20:18:38 +00:00
logger . debug ( " LessonBookingDecision: update-all changed: " + checked )
2016-04-21 14:23:29 +00:00
@ props . onUpdateAllDecision ( { update_all: checked } )
else
throw " checkbox changed with unknown name #{ name } "
2016-04-06 02:23:15 +00:00
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 '
2016-04-21 14:23:29 +00:00
nullOp: ()->
2016-05-30 21:43:55 +00:00
onlyOption: () ->
# (!this.props.initial && this.props.selfLastToAct ) || !(this.props.counter && !this.props.selfLastToAct)
! @ multipleOptions ( )
multipleOptions: () ->
if this . props . initial
2016-06-03 04:32:09 +00:00
if this . props . noSlots
false
else
! ( ! this . props . counter && this . props . selfLastToAct )
2016-05-30 21:43:55 +00:00
else if this . props . counter
! this . props . selfLastToAct
else
false
2016-04-06 02:23:15 +00:00
2016-05-30 21:43:55 +00:00
render: () ->
2016-04-06 02:23:15 +00:00
2016-05-30 21:43:55 +00:00
#showUpdateAll = !this.props.initial
2016-04-06 02:23:15 +00:00
if ( ! this . props . initial && ! this . props . counter ) || this . props . selfLastToAct
2016-06-03 04:32:09 +00:00
userPromptHeader = ` < h3 > Would you like to update this lesson ? < / h3 > `
2016-04-06 02:23:15 +00:00
messagePromptHeader = ` < h3 > Send message to { this . props . otherRole } with your update . < / h3 > `
else
userPromptHeader = ` < h3 > How do you want to handle this request ? < / h3 > `
messagePromptHeader = ` < h3 > Send message to { this . props . otherRole } with your response . < / h3 > `
if this . props . slot_decision == ' counter '
2016-06-03 04:32:09 +00:00
if this . props . is_recurring && this . props . update_all
actionBtnText = " PROPOSE TIME FOR ALL LESSONS "
2016-04-21 14:23:29 +00:00
else
2016-06-03 04:32:09 +00:00
if @ props . noSlots
actionBtnText = ' PROPOSE TIME '
else
actionBtnText = " PROPOSE ALTERNATE TIME "
2016-04-21 14:23:29 +00:00
2016-04-06 02:23:15 +00:00
else if this . props . slot_decision == ' decline '
if @ showDeclineVerb ( )
verb = " DECLINE "
else
verb = " CANCEL "
2016-04-21 14:23:29 +00:00
2016-05-30 21:43:55 +00:00
if this . props . update_all
2016-04-21 14:23:29 +00:00
actionBtnText = " #{ verb } ALL LESSONS "
else
actionBtnText = " #{ verb } LESSON "
2016-04-06 02:23:15 +00:00
else if this . props . initial
actionBtnText = " ACCEPT & SCHEDULE LESSON "
else
actionBtnText = " ACCEPT & UPDATE LESSON "
2016-05-30 21:43:55 +00:00
counterClasses = { field: true , ' slot-decision-field ' : true , error: this . props . counterErrors ? , counterSelected: this . props . slot_decision == ' counter ' , onlyOption: @ onlyOption ( ) }
2016-04-06 02:23:15 +00:00
2016-04-21 14:23:29 +00:00
2016-04-06 02:23:15 +00:00
if this . props . counterErrors ?
errorText = window . JK . reactErrors ( this . props . counterErrors , { day_of_week: ' Day ' } )
2017-07-17 00:38:40 +00:00
console . log ( " LessonBookingDecision props " , this . props )
if ( this . props . is_recurring && this . props . update_all ) # || (this.props.counter && this.props.slots[0]['is_recurring?'])
2016-04-06 02:23:15 +00:00
slotAltPrompt = ` < div className = " slot-alt-prompt " >
< span className = " alt-date-block " >
< span className = " alt-date " > Day : < / span >
< select disabled = { this . props . disabled } className = " day_of_week " data - slot = { i } > { this . days } < / select >
< / span >
< span className = " alt-time-block " >
< span className = " alt-time " > Time : < / span >
2016-06-18 01:59:58 +00:00
< select className = " hour " defaultValue = " 06 " disabled = { this . props . disabled } > { this . hours } < / select > : < select disabled = { this . props . disabled } className = " minute " > { this . minutes } < / select >
< select disabled = { this . props . disabled } className = " am_pm " defaultValue = " PM " > { this . am_pm } < / select >
2016-04-06 02:23:15 +00:00
< br / >
2016-05-26 23:10:05 +00:00
< span > * Time will be local to { window . JK . currentTimezone ( ) } < / span >
2016-04-06 02:23:15 +00:00
{ errorText }
< / span >
< / div > `
2016-05-30 21:43:55 +00:00
#if @props.update_all
# updateAllField =
# `<div className="field update-all-field">
# <input disabled={this.props.disabled} className="update-all" type="checkbox" name="update-all" readyOnly="true" onChange={this.nullOp} checked={this.props.update_all} /><label>Update all lessons</label>
# </div>`
updateAllField = null
2016-04-21 14:23:29 +00:00
2016-04-06 02:23:15 +00:00
else
slotAltPrompt = ` < div className = " slot-alt-prompt " >
< span className = " alt-date-block " >
< span className = " alt-date " > Date : < / span >
2016-05-30 21:43:55 +00:00
< input className = " date-picker " name = " alt-date-input " type = " text " data - slot = { i } > < / input >
2016-04-06 02:23:15 +00:00
< / span >
< span className = " alt-time-block " >
< span className = " alt-time " > Time : < / span >
2016-06-18 01:59:58 +00:00
< select className = " hour " defaultValue = " 06 " disabled = { this . props . disabled } > { this . hours } < / select > : < select disabled = { this . props . disabled } className = " minute " > { this . minutes } < / select >
< select disabled = { this . props . disabled } className = " am_pm " defaultValue = " PM " > { this . am_pm } < / select >
2016-04-06 02:23:15 +00:00
< br / >
2016-05-26 23:10:05 +00:00
< span > * Time will be local to { window . JK . currentTimezone ( ) } < / span >
2016-04-06 02:23:15 +00:00
{ errorText }
< / span >
< / div > `
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 )
2016-06-03 04:32:09 +00:00
if this . props . noSlots
proposeAltLabelText = ' Propose a day/time '
else
proposeAltLabelText = " Propose alternate day/time "
2016-04-06 02:23:15 +00:00
for slot , i in @ props . slots
2017-07-10 02:21:29 +00:00
if slot . is_recurring
2016-04-06 02:23:15 +00:00
slotDetail = ` < div className = " slot-detail " > Each { slot . slotTime } < / div > `
else
slotDetail = ` < div className = " slot-detail " > { slot . slotTime } < / div > `
2016-05-30 21:43:55 +00:00
slots . push ( ` < div key = { slot . id } data - slot - id = { slot . id } className = " field slot-decision-field " >
2016-04-06 02:23:15 +00:00
< div className = " label-area " >
< input disabled = { this . props . disabled } className = " slot-decision " type = " radio " name = " slot-decision "
value = { slot . id } readyOnly = { true } defaultChecked = { slot . id == this . props . slot_decision } / > < label > { this . slotLabelText ( i , slot ) } < / label >
< / div >
{ slotDetail }
< / div > ` )
else
2016-06-03 04:32:09 +00:00
if this . props . noSlots
proposeAltLabelText = ' Propose a day/time '
else
proposeAltLabelText = " Propose new alternate day/time "
2016-04-06 02:23:15 +00:00
# if you have issued a counter, you should be able to withdraw it
# TODO
2016-05-30 21:43:55 +00:00
#cancelField = `<div className="field slot-decision-field">
# <input disabled={this.props.disabled} className="slot-decision" type="radio" name="slot-decision" value="decline" readyOnly={true} defaultChecked={this.props.slot_decision == 'decline'} /><label>{declineVerb} lesson
# request</label>
#</div>`
cancelField = null
2016-04-06 02:23:15 +00:00
` < div className = " row " >
< div className = " column column-left " >
{ userPromptHeader }
< div className = " slot-decision slot-1 " >
{ slots }
< div className = { classNames ( counterClasses ) } >
< div className = " label-area " >
< input disabled = { this . props . disabled } className = " slot-decision " type = " radio " readyOnly = { true } name = " slot-decision " value = " counter " defaultChecked = { this . props . slot_decision == ' counter ' } / >
< label > { proposeAltLabelText } < / label >
< / div >
{ slotAltPrompt }
< / div >
2016-05-30 21:43:55 +00:00
{ cancelField }
2016-04-21 14:23:29 +00:00
{ updateAllField }
2016-04-06 02:23:15 +00:00
< / div >
< / div >
< div className = " column column-right " >
{ messagePromptHeader }
< textarea className = " message " name = " message " disabled = { this . props . disabled } > < / textarea >
< div className = " actions " >
< a className = { classNames ( cancelClasses ) } onClick = { this . onUserCancel } > CANCEL < / a >
< a className = { classNames ( scheduleClasses ) } onClick = { this . onUserDecision } > { actionBtnText } < / a >
< / div >
< / div >
< / div > `
} )