message: Refactor Invitation AJAX Request
  Add reusable callback functions
diff: @@ -8,27 +8,10 @@ module.exports = ($el) ->
  $submit = $el.find '.js-submit'
  $errors = $el.find '.js-errors'
  - submissionTimeout = null;
  -
  - $form.on 'submit', (e) ->
  - e.preventDefault()
  -
  - submissionTimeout && clearTimeout(submissionTimeout);
  -
  - serializer = new Serializer $form
  -
  + submissionTimeout = null
  label = $submit.text()
  - $submit
  - .prop 'disabled', true
  - .text 'Sending...'
  -
  - Promise $.ajax
  - url: "#{API_URL}/invitees/invite"
  - type: 'POST'
  - data: serializer.data()
  -
  - .then ->
  + onSuccess = () ->
  $form.trigger 'reset'
  $submit
  @@ -39,13 +22,10 @@ module.exports = ($el) ->
  track.submit 'Invitation sent from user'
  - .catch ({ responseJSON: { message, description }}) ->
  + onFailure = (message) ->
  $errors
  .show()
  - .html """
  - #{message}<br>
  - #{description}
  - """
  + .html message
  $submit
  .prop 'disabled', false
  @@ -58,19 +38,26 @@ module.exports = ($el) ->
  track.error 'Invitation not sent, try again.'
  - .catch ->
  - $errors
  - .show()
  - .html """
  - Something went wrong, please contact <a href='mailto:info@are.na'>info@are.na</a> if the problem persists.
  - """
  + $form.on 'submit', (e) ->
  + e.preventDefault()
  +
  + submissionTimeout && clearTimeout(submissionTimeout);
  +
  + serializer = new Serializer $form
  $submit
  - .prop 'disabled', false
  - .text label
  + .prop 'disabled', true
  + .text 'Sending...'
  - submissionTimeout = setTimeout ->
  - $errors.empty()
  - , 15000
  + Promise $.ajax
  + url: "#{API_URL}/invitees/invite"
  + type: 'POST'
  + data: serializer.data()
  +
  + .then onSuccess
  - track.error 'Invitation not sent: server error. Try again.'
  + .catch ({ responseJSON: { message, description }}) ->
  + onFailure("#{message}<br/>#{description}")
  +
  + .catch ->
  + onFailure("Something went wrong, please contact <a href='mailto:info@are.na'>info@are.na</a> if the problem persists.")
  