class ActionView::Helpers::FormBuilder include ActionView::Helpers::FormTagHelper def assets_upload(key = nil, options = {}) papermill_upload_tag key, { :thumbnail => false }.update(options) end def asset_upload(key = nil, options = {}) papermill_upload_tag key, { :gallery => false, :thumbnail => false }.update(options) end def images_upload(key = nil, options = {}) papermill_upload_tag key, options end def image_upload(key = nil, options = {}) papermill_upload_tag key, { :gallery => false }.update(options) end end module ActionView::Helpers::FormTagHelper def assets_upload_tag(assetable, key = nil, options = {}) papermill_upload_tag key, { :thumbnail => false, :assetable => assetable }.update(options) end def asset_upload_tag(assetable, key = nil, options = {}) papermill_upload_tag key, { :gallery => false, :thumbnail => false, :assetable => assetable }.update(options) end def images_upload_tag(assetable, key = nil, options = {}) papermill_upload_tag key, { :assetable => assetable }.update(options) end def image_upload_tag(assetable, key = nil, options = {}) papermill_upload_tag key, { :gallery => false, :assetable => assetable }.update(options) end private def papermill_upload_tag(key, options) if key.nil? && [String, Symbol].include?(options[:assetable].class) key = options[:assetable].to_s options[:assetable] = nil end assetable = options[:assetable] || @template.instance_variable_get("@#{@object_name}") raise PapermillException.new("Your form instance object is not @#{@object_name}, and therefor cannot be found. \nPlease provide your object name in your form_for initialization. \nform_for :my_object_name, @my_object_name, :url => { :action => 'create'/'update'}") if @object_name && !assetable assetable_id = assetable && (assetable.id || assetable.timestamp) || nil assetable_type = assetable && assetable.class.base_class.name || nil options = PapermillAsset.papermill_options(assetable && assetable.class.name, key).deep_merge(options) dom_id = "papermill_#{assetable_type}_#{assetable_id}_#{key}" 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" set_papermill_inline_css(dom_id, w, h, options) end set_papermill_inline_js(dom_id, compute_papermill_create_url(assetable_id, assetable_type, key, computed_style, options), options) html = {} html[:upload_button] = %{
} html[:container] = @template.content_tag(:div, :id => dom_id, :class => "papermill-#{key.to_s} #{(options[:thumbnail] ? "papermill-thumb-container" : "papermill-asset-container")} #{(options[:gallery] ? "papermill-multiple-items" : "papermill-unique-item")}") do conditions = {:assetable_type => assetable_type, :assetable_id => assetable_id} conditions.merge!({:assetable_key => key.to_s}) if key @template.render :partial => "papermill/asset", :collection => PapermillAsset.all(:conditions => conditions), :locals => { :thumbnail_style => computed_style, :targetted_geometry => options[:targetted_geometry] } end if options[:gallery] html[:dashboard] = {} html[:dashboard][:mass_edit] = %{#{I18n.t("papermill.modify-all")}} html[:dashboard][:mass_delete] = %{#{I18n.t("papermill.delete-all")}} html[:dashboard][:mass_thumbnail_reset] = %{#{I18n.t("papermill.mass-thumbnail-reset")}} html[:dashboard] = @template.content_tag(:ul, options[:dashboard].map{|action| @template.content_tag(:li, html[:dashboard][action], :class => action.to_s) }.join("\n"), :class => "dashboard") end if assetable && assetable.new_record? && !@timestamped @timestamp_field = @template.hidden_field(assetable_type.underscore, :timestamp, :value => assetable.timestamp) @timestamped = true end %{