Module: UploaderHelper
- Defined in:
- app/helpers/uploader_helper.rb
Instance Method Summary collapse
- #make_parent_params(parent) ⇒ Object
- #new_upload_path_with_parent_information(upload_parent, format = 'js') ⇒ Object
- #new_upload_path_with_session_information(upload_parent, format = 'js') ⇒ Object
- #session_key ⇒ Object
-
#show_degraded_container_link ⇒ Object
Outputs a link that will show the degraded container.
-
#show_swfupload_container_link ⇒ Object
Outputs a link that will show the swfupload container.
-
#upload_form(parent, display_upload_indicators = true, container_prefix = '', options = {}) ⇒ Object
Output a form capable of uploading files to the server using swfupload.
-
#uploadify_form(parent, display_upload_indicators = true, container_prefix = '', options = {}) ⇒ Object
Output a form capable of uploading multiple files to the server using uploadify.
Instance Method Details
#make_parent_params(parent) ⇒ Object
81 82 83 84 |
# File 'app/helpers/uploader_helper.rb', line 81 def make_parent_params(parent) return {} if parent.blank? { :parent_id => parent.id, :parent_type => parent.class.to_s } end |
#new_upload_path_with_parent_information(upload_parent, format = 'js') ⇒ Object
69 70 71 |
# File 'app/helpers/uploader_helper.rb', line 69 def new_upload_path_with_parent_information(upload_parent, format = 'js') multiupload_uploads_path({:format => format}.merge(make_parent_params(upload_parent))) end |
#new_upload_path_with_session_information(upload_parent, format = 'js') ⇒ Object
65 66 67 |
# File 'app/helpers/uploader_helper.rb', line 65 def new_upload_path_with_session_information(upload_parent, format = 'js') multiupload_uploads_path({:format => format, :session_key => [session_key], :request_forgery_protection_token => form_authenticity_token}.merge(make_parent_params(upload_parent))) end |
#session_key ⇒ Object
73 74 75 76 77 78 79 |
# File 'app/helpers/uploader_helper.rb', line 73 def session_key if defined?(Rails.application) Rails.application.config.[:key] else ActionController::Base.[:key] end end |
#show_degraded_container_link ⇒ Object
Outputs a link that will show the degraded container. Use if users are having problems with the Flash uploader
87 88 89 |
# File 'app/helpers/uploader_helper.rb', line 87 def show_degraded_container_link %Q{<a class="show_degraded_container" href="#">#{I18n.t('uploader.show_degraded_container')}</a>} end |
#show_swfupload_container_link ⇒ Object
Outputs a link that will show the swfupload container
92 93 94 |
# File 'app/helpers/uploader_helper.rb', line 92 def show_swfupload_container_link %Q{<a class="show_swfupload_container" style="display:none;" href="#">#{I18n.t('uploader.show_swfupload_container')}</a>} end |
#upload_form(parent, display_upload_indicators = true, container_prefix = '', options = {}) ⇒ Object
Output a form capable of uploading files to the server using swfupload. parent: The object to which the uploads will be attached display_upload_indicators: Indicates whether or not to show the upload progress container_prefix: Prefixes each id in the html with the specified text. Useful if there is to be more than one form on a page. options: Options to pass to the swf javascript for setting up the swfupload object:
upload_url: Url to upload to. Default is '<%= new_upload_path_with_session_information(parent) %>'
file_size_limit: Largest allowable file size. Default is '100 MB'
file_types: Allowed file types. Default is "*.*"
file_types_description: Description for file types. Default is "All Files"
file_upload_limit: Maximum number of files per upload. Default is 100
button_image_url: Url of button image to use for swf upload. Default is "/images/SWFUploadButton.png"
button_width: Width of the image button being used. Default is 61
button_height: Height of the button being used. Default is 22
transparent: Turns the swfupload transparent so you can use the html behind it for the upload button.
This will override any settings provided for button_image_url
transparent_html: If transparent is true this html will be rendered under the transparent swfupload button.
19 20 21 22 23 24 |
# File 'app/helpers/uploader_helper.rb', line 19 def upload_form(parent, display_upload_indicators = true, container_prefix = '', = {}) render :partial => 'uploads/swf_upload', :locals => {:parent => parent, :display_upload_indicators => display_upload_indicators, :container_prefix => container_prefix, :options => } end |
#uploadify_form(parent, display_upload_indicators = true, container_prefix = '', options = {}) ⇒ Object
Output a form capable of uploading multiple files to the server using uploadify. parent: The object to which the uploads will be attached display_upload_indicators: Indicates whether or not to show the upload progress container_prefix: Prefixes each id in the html with the specified text. Useful if there is to be more than one form on a page. Options is a hash containing any valid option for uploadify: www.uploadify.com/documentation/
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/helpers/uploader_helper.rb', line 32 def uploadify_form(parent, display_upload_indicators = true, container_prefix = '', = {}) container_prefix = 'uploadify' if container_prefix.blank? format = 'js' = { :uploader => '/swf/uploadify.swf', :script => multiupload_uploads_path({:format => format}), :cancelImg => '/images/uploadify/cancel.png', :fileDesc => "All Files", :fileExt => "*.*", :auto => true, :multi => true, :buttonText => 'Upload', :onComplete => 'oncomplete_replace_', :scriptData => { '_http_accept' => 'application/javascript', '_method' => 'post', "#{session_key}" => 'session_key_replace_', 'authenticity_token' => 'authenticity_token_replace_' }.merge(make_parent_params(parent)) }.merge() = .to_json # This is a bit of a hack but to_json will surround 'encodeURIComponent' with quotes so it won't execute. # We need it to execute. The double encode is required - u on the server and encodeURIComponent on the client. .gsub!('"session_key_replace_"', "encodeURIComponent('#{u([session_key])}')") .gsub!('"authenticity_token_replace_"', "encodeURIComponent('#{u(form_authenticity_token)}')") .gsub!('"oncomplete_replace_"', 'function(event, queueID, fileObj, response, data){ upload_completed_callback(response); return true; }') render :partial => 'uploads/uploadify', :locals => { :parent => parent, :container_prefix => container_prefix, :uploadify_options => } end |