Skip to content

Commit

Permalink
Clean up file upload preview generation
Browse files Browse the repository at this point in the history
  • Loading branch information
mshibuya committed Aug 22, 2012
1 parent dda117d commit 3c83b27
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 4 additions & 1 deletion app/assets/javascripts/rails_admin/ra.widgets.coffee
Expand Up @@ -42,7 +42,10 @@ $(document).live 'rails_admin.dom_ready', ->

$('form [data-fileupload]').change ->
input = this
image_container = $("#" + input.id).parent().children("#preview")
image_container = $("#" + input.id).parent().children(".preview")
unless image_container.length
image_container = $("#" + input.id).parent().prepend($('<img />').addClass('preview')).find('img.preview')
image_container.parent().find('img:not(.preview)').hide()
ext = $("#" + input.id).val().split('.').pop().toLowerCase()
if input.files and input.files[0] and $.inArray(ext, ['gif','png','jpg','jpeg','bmp']) != -1
reader = new FileReader()
Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/rails_admin/ra.widgets.css.scss
Expand Up @@ -2,3 +2,7 @@ iframe.wysihtml5-sandbox{
height: 250px !important;
width: 75% !important;
}
.controls img.preview{
max-height: 100px;
max-width: 100px;
}
8 changes: 3 additions & 5 deletions app/views/rails_admin/main/_form_file_upload.html.haml
@@ -1,11 +1,9 @@
- file = form.object.send(field.method_name).presence

.toggle{:style => ('display:none;' if file && field.delete_method && form.object.send(field.delete_method) == '1')}
.wrap
- if value = field.pretty_value
= value
%img#preview{:src => "#", :width => 100, :height => 100, :style => "display: none"}
= form.file_field(field.name, field.html_attributes.reverse_merge({ :data => { :fileupload => true }}))
- if value = field.pretty_value
= value
= form.file_field(field.name, field.html_attributes.reverse_merge({ :data => { :fileupload => true }}))
- if field.optional? && field.errors.blank? && file && field.delete_method
%a.btn.btn-info{:href => '#', :'data-toggle' => 'button', :onclick => "$(this).siblings('[type=checkbox]').click(); $(this).siblings('.toggle').toggle('slow'); jQuery(this).toggleClass('btn-danger btn-info'); return false"}
%i.icon-white.icon-trash
Expand Down

0 comments on commit 3c83b27

Please sign in to comment.