class ActionView::Helpers::FormBuilder include ActionView::Helpers::FormTagHelper def assets_upload(method, options = {}) papermill_upload_tag method, { :thumbnail => false }.update(options) end def asset_upload(method, options = {}) papermill_upload_tag method, { :gallery => false, :thumbnail => false }.update(options) end def images_upload(method, options = {}) papermill_upload_tag method, options end def image_upload(method, options = {}) papermill_upload_tag method, { :gallery => false }.update(options) end end module ActionView::Helpers::FormTagHelper def assets_upload_tag(assetable, method, options = {}) papermill_upload_tag method, { :thumbnail => false, :assetable => assetable }.update(options) end def asset_upload_tag(assetable, method, options = {}) papermill_upload_tag method, { :gallery => false, :thumbnail => false, :assetable => assetable }.update(options) end def images_upload_tag(assetable, method, options = {}) papermill_upload_tag method, { :assetable => assetable }.update(options) end def image_upload_tag(assetable, method, options = {}) papermill_upload_tag method, { :gallery => false, :assetable => assetable }.update(options) end private def papermill_upload_tag(method, options) assetable = options[:object] || options[:assetable] || @object || @template.instance_variable_get("@#{@object_name}") raise PapermillException.new("Form object not found. Please provide it with :object => @assetable with the Papermill helper call") unless assetable assetable_name = @object_name && "#{@object_name}#{(i = @options[:index]) ? "[#{i}]" : ""}" sanitized_method = method.to_s.gsub(/[\?\/\-]$/, '') sanitized_object_name = @object_name.to_s.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "") field_id = @object_name && "#{sanitized_object_name}#{(i = @options[:index]) ? "_#{i}" : ""}_#{sanitized_method}" assetable.class.papermill(method) association_options = assetable.class.papermill_options[method.to_sym] raise PapermillException.new("Papermill association #{method} failed to be generated dynamically for #{assetable.class.name}") unless association_options options = association_options.deep_merge(options) field_name = "#{assetable_name}[papermill_#{method}_ids][]" html = {} if ot = options[:thumbnail] w = ot[:width] || ot[:height] && ot[:aspect_ratio] && (ot[:height] * ot[:aspect_ratio]).to_i || nil h = ot[:height] || ot[:width] && ot[:aspect_ratio] && (ot[:width] / ot[:aspect_ratio]).to_i || nil computed_style = ot[:style] || (w || h) && "#{w}x#{h}>" || "original" html[:css] = set_papermill_inline_css(field_id, w, h, options) end html[:js] = set_papermill_inline_js(field_id, compute_papermill_url(:create, computed_style, field_name, field_id, options), options) html[:upload_button] = %{\
} # I don't use the full :through association that is not updated if assetable.new_record?. collection = association_options[:through] ? assetable.send("#{method}_associations").map(&:papermill_asset) : assetable.send(method) locals = { :thumbnail_style => computed_style, :targetted_size => options[:targetted_size], :field_name => field_name, :field_id => field_id } html[:container] = @template.content_tag(:div, :id => field_id, :class => "papermill-#{method.to_s} #{(options[:thumbnail] ? "papermill-thumb-container" : "papermill-asset-container")} #{(options[:gallery] ? "papermill-multiple-items" : "papermill-unique-item")}") do @template.render(:partial => "papermill/asset", :collection => collection, :locals => locals) end if options[:gallery] && options[:mass_edit] html[:mass_edit] = %{\ #{I18n.t("papermill.modify-all")} } end if options[:through] browser_url = compute_papermill_url(:browser, computed_style, field_name, field_id, options) html[:browser] = %{Ajouter...} end # hidden_field needed to empty a list. %{