jam-cloud/web/app/assets/javascripts/react-components/RateUserDialog.js.jsx.coffee

103 lines
2.4 KiB
CoffeeScript

context = window
@RateUserDialog = React.createClass({
mixins: [Reflux.listenTo(@AppStore, "onAppInit")]
teacher: false
parseId:(id) ->
if !id?
{id: null, type: null}
else
bits = id.split('_')
if bits.length == 2
{id: bits[1], type: bits[0]}
else
{id: null, type: null}
beforeShow: (args) ->
logger.debug("RateUserDialog.beforeShow", args.d1)
@firstName = ''
@lastName = ''
@email = ''
@setState({target: null})
rest.getUserDetail({id: args.d1}).done((response) => @userLookupDone(response)).fail((jqXHR) => @userLookupFail(jqXHR))
afterHide: () ->
userLookupDone: (response) ->
@setState({target: response})
userLookupFail: (jqXHR) ->
@app.ajaxError(jqXHR, null, null)
onAppInit: (@app) ->
dialogBindings = {
'beforeShow': @beforeShow,
'afterHide': @afterHide
};
@app.bindDialog('rate-user', dialogBindings);
componentDidMount: () ->
@root = $(@getDOMNode())
getInitialState: () ->
{inviteErrors: null}
doCancel: (e) ->
e.preventDefault()
@app.layout.closeDialog('rate-user', true);
doRating: (e) ->
e.preventDefault()
rest.createReview({id: target})
createDone:(response) ->
context.SchoolActions.addInvitation(@state.teacher, response)
context.JK.Banner.showNotice("invitation sent", "Your invitation has been sent!")
@app.layout.closeDialog('invite-school-user')
createFail: (jqXHR) ->
handled = false
if jqXHR.status == 422
errors = JSON.parse(jqXHR.responseText)
@setState({inviteErrors: errors})
handled = true
if !handled
@app.ajaxError(jqXHR, null, null)
render: () ->
if @state.user?.teacher?
title = 'Rate Teacher'
help = `<p>Please rate this teacher based on your experience with them.</p>`
else
title = 'Rate Student'
help = `<p>Please rate this student based on your experience with them.</p>`
`<div>
<div className="content-head">
<img className="content-icon" src="/assets/content/icon_add.png" height={19} width={19}/>
<h1>{title}</h1>
</div>
<div className="dialog-inner">
{help}
<div className="actions">
<a onClick={this.doCancel} className="button-grey">CANCEL</a>
<a onClick={this.doRating} className="button-orange">SUBMIT RATING</a>
</div>
</div>
</div>`
})