BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
707be371
Commit
707be371
authored
Mar 17, 2016
by
Alfredo Sumaran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle form submit via ajax and crop avatar on the client
parent
8ffc04eb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
8 deletions
+35
-8
profile.js.coffee
app/assets/javascripts/profile.js.coffee
+35
-8
No files found.
app/assets/javascripts/profile.js.coffee
View file @
707be371
class
@
Profile
constructor
:
->
constructor
:
(
opts
=
{})
->
{
@
form
=
$
(
'.edit-user'
)
}
=
opts
# 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
()
...
...
@@ -17,14 +21,37 @@ class @Profile
$
(
'.update-notifications'
).
on
'ajax:complete'
,
->
$
(
this
).
find
(
'.btn-save'
).
enable
()
$
(
'.js-choose-user-avatar-button'
).
bind
"click"
,
->
form
=
$
(
this
).
closest
(
"form"
)
form
.
find
(
".js-user-avatar-input"
).
click
()
@
bindEvents
()
@
avatarGlCrop
=
$
(
'.js-user-avatar-input'
).
glCrop
().
data
'glcrop'
bindEvents
:
->
@
form
.
on
'submit'
,
@
onSubmitForm
onSubmitForm
:
(
e
)
=>
e
.
preventDefault
()
@
saveForm
()
saveForm
:
->
self
=
@
formData
=
new
FormData
(
@
form
[
0
])
formData
.
append
(
'user[avatar]'
,
@
avatarGlCrop
.
getBlob
(),
'avatar.png'
)
$
(
'.js-user-avatar-input'
).
bind
"change"
,
->
form
=
$
(
this
).
closest
(
"form"
)
filename
=
$
(
this
).
val
().
replace
(
/^.*[\\\/]/
,
''
)
form
.
find
(
".js-avatar-filename"
).
text
(
filename
)
$
.
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
self
.
form
.
find
(
':input[disabled]'
).
enable
()
$
->
# Extract the SSH Key title from its comment
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment