summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorJohann Pardanaud <pardanaud.j@gmail.com>2016-02-17 18:35:16 +0100
committerJohann Pardanaud <pardanaud.j@gmail.com>2016-02-17 18:35:16 +0100
commitbf6aa15512cc6d31be320204fbc3c115bfd11b1b (patch)
treecaa9b9df87b31afc6ff144efac7045a6e4dd7386 /app
parentfb6d7df347016726d84155d18b6d6f406d0121e9 (diff)
downloadgitlab-ce-bf6aa15512cc6d31be320204fbc3c115bfd11b1b.tar.gz
Improve avatar cropping internals, based on suggestions made by @rspeicher on !2773
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/profile.js.coffee2
-rw-r--r--app/models/user.rb6
-rw-r--r--app/uploaders/avatar_uploader.rb9
-rw-r--r--app/views/profiles/show.html.haml4
4 files changed, 6 insertions, 15 deletions
diff --git a/app/assets/javascripts/profile.js.coffee b/app/assets/javascripts/profile.js.coffee
index d13c6007819..69d590a7533 100644
--- a/app/assets/javascripts/profile.js.coffee
+++ b/app/assets/javascripts/profile.js.coffee
@@ -53,7 +53,7 @@ class @Profile
$avatarInput.on "change", ->
form = $(this).closest("form")
filename = $(this).val().replace(/^.*[\\\/]/, '')
- $filename.text(filename)
+ $filename.data('label', $filename.text()).text(filename)
reader = new FileReader
diff --git a/app/models/user.rb b/app/models/user.rb
index 1b0c82f45c4..37285c2a9d4 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -99,9 +99,7 @@ class User < ActiveRecord::Base
attr_accessor :login
# Virtual attributes to define avatar cropping
- [:avatar_crop_x, :avatar_crop_y, :avatar_crop_size].each do |field|
- attr_accessor field
- end
+ attr_accessor :avatar_crop_x, :avatar_crop_y, :avatar_crop_size
#
# Relations
@@ -169,7 +167,7 @@ class User < ActiveRecord::Base
validates :avatar, file_size: { maximum: 200.kilobytes.to_i }
[:avatar_crop_x, :avatar_crop_y, :avatar_crop_size].each do |field|
- validates field, numericality: { only_integer: true }, allow_blank: true
+ validates field, numericality: { only_integer: true }, presence: true, if: ->(user) { user.avatar_changed? }
end
before_validation :generate_password, on: :create
diff --git a/app/uploaders/avatar_uploader.rb b/app/uploaders/avatar_uploader.rb
index 60ee80cf002..c8d9ab072e8 100644
--- a/app/uploaders/avatar_uploader.rb
+++ b/app/uploaders/avatar_uploader.rb
@@ -10,15 +10,8 @@ class AvatarUploader < CarrierWave::Uploader::Base
process :cropper
- def is_integer? string
- true if Integer(string) rescue false
- end
-
def cropper
- is_compliant = model.kind_of?(User) && is_integer?(model.avatar_crop_size)
- is_compliant = is_compliant && is_integer?(model.avatar_crop_x) && is_integer?(model.avatar_crop_y)
-
- if is_compliant
+ if model.kind_of?(User) && model.valid?
manipulate! do |img|
img.crop "#{model.avatar_crop_size}x#{model.avatar_crop_size}+#{model.avatar_crop_x}+#{model.avatar_crop_y}"
end
diff --git a/app/views/profiles/show.html.haml b/app/views/profiles/show.html.haml
index 6686c037b60..04f738c2759 100644
--- a/app/views/profiles/show.html.haml
+++ b/app/views/profiles/show.html.haml
@@ -88,7 +88,7 @@
%i.fa.fa-paperclip
%span Choose File ...
&nbsp;
- %span.file_name.js-avatar-filename{:'data-label' => 'File name...'} File name...
+ %span.file_name.js-avatar-filename File name...
= f.file_field :avatar, class: "js-user-avatar-input hidden"
= f.hidden_field :avatar_crop_x
= f.hidden_field :avatar_crop_y
@@ -107,7 +107,7 @@
.modal-dialog
.modal-content
.modal-header
- %button.close{:type => "button", :'data-dismiss' => "modal"}
+ %button.close{type: 'button', data: {dismiss: 'modal'}}
%span
&times;
%h4.modal-title