2014-10-21 04:40:36 -04:00
|
|
|
class @Profile
|
2016-03-17 10:46:50 -04:00
|
|
|
constructor: (opts = {}) ->
|
|
|
|
{
|
|
|
|
@form = $('.edit-user')
|
|
|
|
} = opts
|
|
|
|
|
2015-06-05 18:01:45 -04:00
|
|
|
# Automatically submit the Preferences form when any of its radio buttons change
|
|
|
|
$('.js-preferences-form').on 'change.preference', 'input[type=radio]', ->
|
|
|
|
$(this).parents('form').submit()
|
2012-12-02 06:29:24 -05:00
|
|
|
|
2016-02-29 08:39:29 -05:00
|
|
|
$('.update-username').on 'ajax:before', ->
|
|
|
|
$('.loading-username').show()
|
2014-10-21 04:40:36 -04:00
|
|
|
$(this).find('.update-success').hide()
|
|
|
|
$(this).find('.update-failed').hide()
|
2012-12-02 06:29:24 -05:00
|
|
|
|
2016-02-29 08:39:29 -05:00
|
|
|
$('.update-username').on 'ajax:complete', ->
|
|
|
|
$('.loading-username').hide()
|
2015-05-26 18:33:04 -04:00
|
|
|
$(this).find('.btn-save').enable()
|
2014-10-21 04:40:36 -04:00
|
|
|
$(this).find('.loading-gif').hide()
|
2013-08-27 05:18:53 -04:00
|
|
|
|
2016-03-29 12:59:03 -04:00
|
|
|
$('.update-notifications').on 'ajax:success', (e, data) ->
|
|
|
|
if data.saved
|
|
|
|
new Flash("Notification settings saved", "notice")
|
|
|
|
else
|
|
|
|
new Flash("Failed to save new settings", "alert")
|
2013-10-06 14:13:56 -04:00
|
|
|
|
2016-03-17 10:46:50 -04:00
|
|
|
@bindEvents()
|
|
|
|
|
2016-03-17 15:59:43 -04:00
|
|
|
cropOpts =
|
|
|
|
filename: '.js-avatar-filename'
|
|
|
|
previewImage: '.avatar-image .avatar'
|
|
|
|
modalCrop: '.modal-profile-crop'
|
|
|
|
pickImageEl: '.js-choose-user-avatar-button'
|
|
|
|
uploadImageBtn: '.js-upload-user-avatar'
|
|
|
|
modalCropImg: '.modal-profile-crop-image'
|
|
|
|
|
|
|
|
@avatarGlCrop = $('.js-user-avatar-input').glCrop(cropOpts).data 'glcrop'
|
2016-03-17 10:46:50 -04:00
|
|
|
|
|
|
|
bindEvents: ->
|
|
|
|
@form.on 'submit', @onSubmitForm
|
|
|
|
|
|
|
|
onSubmitForm: (e) =>
|
|
|
|
e.preventDefault()
|
|
|
|
@saveForm()
|
|
|
|
|
|
|
|
saveForm: ->
|
|
|
|
self = @
|
|
|
|
formData = new FormData(@form[0])
|
2016-04-18 14:04:36 -04:00
|
|
|
|
|
|
|
avatarBlob = @avatarGlCrop.getBlob()
|
|
|
|
formData.append('user[avatar]', avatarBlob, 'avatar.png') if avatarBlob?
|
2016-02-08 18:35:42 -05:00
|
|
|
|
2016-03-17 10:46:50 -04:00
|
|
|
$.ajax
|
|
|
|
url: @form.attr('action')
|
|
|
|
type: @form.attr('method')
|
|
|
|
data: formData
|
|
|
|
dataType: "json"
|
|
|
|
processData: false
|
|
|
|
contentType: false
|
|
|
|
success: (response) ->
|
|
|
|
new Flash(response.message, 'notice')
|
|
|
|
error: (jqXHR) ->
|
|
|
|
new Flash(jqXHR.responseJSON.message, 'alert')
|
|
|
|
complete: ->
|
|
|
|
window.scrollTo 0, 0
|
2016-03-22 13:54:51 -04:00
|
|
|
# Enable submit button after requests ends
|
2016-03-17 10:46:50 -04:00
|
|
|
self.form.find(':input[disabled]').enable()
|
2016-03-03 15:10:15 -05:00
|
|
|
|
|
|
|
$ ->
|
|
|
|
# Extract the SSH Key title from its comment
|
|
|
|
$(document).on 'focusout.ssh_key', '#key_key', ->
|
|
|
|
$title = $('#key_title')
|
|
|
|
comment = $(@).val().match(/^\S+ \S+ (.+)\n?$/)
|
|
|
|
|
|
|
|
if comment && comment.length > 1 && $title.val() == ''
|
|
|
|
$title.val(comment[1]).change()
|