vita_app/app/inputs/qi_image_select_input.rb
Nicolas Bally 1d3af87d4c initial
2016-04-28 10:07:08 +02:00

39 lines
1.3 KiB
Ruby
Executable File

class QiImageSelectInput < Formtastic::Inputs::TextInput
include FormtasticBootstrap::Inputs::Base
def to_html
r = rand(1000000000000000000000000000)
label_html +
template.content_tag(:fieldset, image_preview(method, options, r) + remove_image_link(method, options, r) + builder.hidden_field(method.to_s, input_html_options.merge!(:id => "input_"+r.to_s)) )
end
def remove_image_link(method, options, r)
template.content_tag(:a, "Supprimer", :href => "#", :onclick => "remove_image_cible('"+r.to_s+"');return false;")
end
def manager_select_link(method, options, r)
template.content_tag(:a, "Modifier cette image", :href => "#", :onclick => "select_image_from_manager('"+r.to_s+"');return false;")
end
def image_preview(method, options,r)
if object.send("#{method}?") and ImageFile.exists?(object.send("#{method}"))
template.content_tag(:span, template.image_tag(eval("object.#{method[0..-4]}.file.large.medium.small.thumb.url"), :id => "img_"+r.to_s, :onclick => "select_image_from_manager('"+r.to_s+"');return false;"), :class => "preview ")
else
template.content_tag(:span, template.image_tag("admin/default_image.png", :id => "img_"+r.to_s, :onclick => "select_image_from_manager('"+r.to_s+"');return false;"), :class => "preview ")
end
end
end