Example #1
0
  static initClass() {
    this.prototype.template = template

    this.prototype.AVATAR_SIZE = {
      h: 128,
      w: 128
    }

    this.child('uploadFileView', '#upload-picture')
    this.child('takePictureView', '#take-picture')
    this.child('gravatarView', '#from-gravatar')

    this.prototype.messages = {
      selectAvatar: I18n.t('buttons.select_profile_picture', 'Select Profile Picture'),
      cancel: I18n.t('#buttons.cancel', 'Cancel'),
      selectImage: I18n.t('buttons.save', 'Save'),
      selectingImage: I18n.t('buttons.selecting_image', 'Selecting Image...')
    }

    this.prototype.events = {
      'click .nav-pills a': 'onNav',
      'click .select-photo-link': 'onUploadClick',
      'change #selected-photo': 'onSelectAvatar'
    }
  }
Example #2
0
  handleErrorUpdating(response) {
    if (response) {
      // try to get an error message out of JSON string
      const errors = (() => {
        try {
          return JSON.parse(response).errors
        } catch (error) {
          return undefined
        }
      })()

      if (errors) {
        const errorReducer = (errorString, currentError) => (errorString += currentError.message)

        const message = _.isString(errors.base)
          ? errors.base
          : _.isArray(errors.base)
            ? errors.base.reduce(errorReducer, '')
            : I18n.t(
                'Your profile photo could not be uploaded. You may have exceeded your upload limit.'
              )

        $.flashError(message)
        return this.enableSelectButton()
      }
    }
  }
Example #3
0
 return $.getJSON('/api/v1/users/self/avatars').then(avatarList => {
   const processedAvatar = _.find(avatarList, avatar => avatar.token === token)
   if (processedAvatar) {
     return this.saveUserAvatar(token, url)
   } else if (count < 50) {
     return window.setTimeout(() => this.waitAndSaveUserAvatar(token, url, count + 1), 100)
   } else {
     return this.handleErrorUpdating(
       JSON.stringify({
         errors: {
           base: I18n.t('Profile photo save failed too many times')
         }
       })
     )
   }
 })
Example #4
0
  $('.re_send_confirmation_link').click(preventDefault(function () {
    const $this = $(this)
    const text = $this.text()

    if (resending) return
    resending = true
    $this.text(I18n.t('resending', 'resending...'))

    $.ajaxJSON($this.attr('href'), 'POST', {}, (data) => {
      resending = false
      $this.text(text)
      $.flashMessage(I18n.t('done_resending', 'Done! Message delivery may take a few minutes.'))
    }, (data) => {
      resending = false
      $this.text(text)
      $.flashError(I18n.t('failed_resending', 'Request failed. Try again.'))
    })
  }))
Example #5
0
 }, (data) => {
   resending = false
   $this.text(text)
   $.flashError(I18n.t('failed_resending', 'Request failed. Try again.'))
 })
Example #6
0
 $.ajaxJSON($this.attr('href'), 'POST', {}, (data) => {
   resending = false
   $this.text(text)
   $.flashMessage(I18n.t('done_resending', 'Done! Message delivery may take a few minutes.'))
 }, (data) => {