Improve user experience for avatar cropping

- Avoid incomprehensible errors on non-integer cropping values
- Set the default cropping area to 80%
This commit is contained in:
Johann Pardanaud 2016-02-16 19:50:23 +01:00
parent 3ca16ec2ec
commit 78588cfca1
2 changed files with 8 additions and 2 deletions

View file

@ -31,7 +31,6 @@ class @Profile
setTimeout ( -> # The cropper must be asynchronously initialized
$modalCropImg.cropper
aspectRatio: 1
autoCropArea: 1
modal: false
scalable: false
rotatable: false

View file

@ -10,8 +10,15 @@ class AvatarUploader < CarrierWave::Uploader::Base
process :cropper
def is_integer? string
true if Integer(string) rescue false
end
def cropper
if model.instance_of? User
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
manipulate! do |img|
img.crop "#{model.avatar_crop_size}x#{model.avatar_crop_size}+#{model.avatar_crop_x}+#{model.avatar_crop_y}"
end