From e79b8ab5cc26d970c4e615740237c26ebc3df397 Mon Sep 17 00:00:00 2001 From: Andrea Dal Ponte Date: Fri, 19 Jun 2015 14:49:39 +0200 Subject: [PATCH 1/2] Fix: better html markup for input fields --- app/assets/stylesheets/rails_admin/base/theming.scss | 12 ++++++++++++ app/assets/stylesheets/rails_admin/ra.widgets.scss | 1 + .../rails_admin/main/_form_file_upload.html.haml | 8 ++++++-- lib/rails_admin/config/fields/types/file_upload.rb | 3 ++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/rails_admin/base/theming.scss b/app/assets/stylesheets/rails_admin/base/theming.scss index a2d2f1795a..c05c4b3ccc 100644 --- a/app/assets/stylesheets/rails_admin/base/theming.scss +++ b/app/assets/stylesheets/rails_admin/base/theming.scss @@ -62,6 +62,18 @@ body.rails_admin { display:none; } + .control-group.image_field { + .img-thumbnail { + margin-bottom: 10px; + } + + .btn-remove-image { + &.btn-info { + margin-top: 10px; + } + } + } + legend { cursor:pointer; i { diff --git a/app/assets/stylesheets/rails_admin/ra.widgets.scss b/app/assets/stylesheets/rails_admin/ra.widgets.scss index 5128c1da28..7508100334 100644 --- a/app/assets/stylesheets/rails_admin/ra.widgets.scss +++ b/app/assets/stylesheets/rails_admin/ra.widgets.scss @@ -2,6 +2,7 @@ iframe.wysihtml5-sandbox{ height: 250px !important; width: 75% !important; } + .controls img.preview{ max-height: 100px; max-width: 100px; diff --git a/app/views/rails_admin/main/_form_file_upload.html.haml b/app/views/rails_admin/main/_form_file_upload.html.haml index 2e66079c73..409a7c6b9b 100644 --- a/app/views/rails_admin/main/_form_file_upload.html.haml +++ b/app/views/rails_admin/main/_form_file_upload.html.haml @@ -3,11 +3,15 @@ .toggle{style: ('display:none;' if file && field.delete_method && form.object.send(field.delete_method) == '1')} - 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"} + %a.btn.btn-info.btn-remove-image{href: '#', :'data-toggle' => 'button', role: '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 = I18n.t('admin.actions.delete.menu').capitalize + " #{field.label.downcase}" - = form.check_box(field.delete_method, style: 'display:none;' ) + + = form.check_box(field.delete_method, style: 'display:none;') + - if field.cache_method = form.hidden_field(field.cache_method) diff --git a/lib/rails_admin/config/fields/types/file_upload.rb b/lib/rails_admin/config/fields/types/file_upload.rb index 5eff910117..df3dafe28b 100644 --- a/lib/rails_admin/config/fields/types/file_upload.rb +++ b/lib/rails_admin/config/fields/types/file_upload.rb @@ -33,7 +33,8 @@ class FileUpload < RailsAdmin::Config::Fields::Base url = resource_url if image thumb_url = resource_url(thumb_method) - url != thumb_url ? v.link_to(v.image_tag(thumb_url, class: 'img-polaroid'), url, target: '_blank') : v.image_tag(thumb_url) + image_html = v.image_tag(thumb_url, class: 'img-thumbnail') + url != thumb_url ? v.link_to(image_html, url, target: '_blank') : image_html else v.link_to(nil, url, target: '_blank') end From ae888255d453d127bfda64a87ee0257f7a0f0786 Mon Sep 17 00:00:00 2001 From: Andrea Dal Ponte Date: Fri, 19 Jun 2015 18:57:51 +0200 Subject: [PATCH 2/2] Fix: better image preview from browsed images --- app/assets/javascripts/rails_admin/ra.widgets.coffee | 2 +- app/assets/stylesheets/rails_admin/ra.widgets.scss | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/rails_admin/ra.widgets.coffee b/app/assets/javascripts/rails_admin/ra.widgets.coffee index 621695d87a..37ffa2dce6 100644 --- a/app/assets/javascripts/rails_admin/ra.widgets.coffee +++ b/app/assets/javascripts/rails_admin/ra.widgets.coffee @@ -46,7 +46,7 @@ $(document).on 'rails_admin.dom_ready', (e, content) -> input = this image_container = $("#" + input.id).parent().children(".preview") unless image_container.length - image_container = $("#" + input.id).parent().prepend($('').addClass('preview')).find('img.preview') + image_container = $("#" + input.id).parent().prepend($('').addClass('preview').addClass('img-thumbnail')).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 diff --git a/app/assets/stylesheets/rails_admin/ra.widgets.scss b/app/assets/stylesheets/rails_admin/ra.widgets.scss index 7508100334..a5628acf24 100644 --- a/app/assets/stylesheets/rails_admin/ra.widgets.scss +++ b/app/assets/stylesheets/rails_admin/ra.widgets.scss @@ -4,6 +4,6 @@ iframe.wysihtml5-sandbox{ } .controls img.preview{ - max-height: 100px; - max-width: 100px; + max-height: 200px; + max-width: 300px; }