Skip to content

Instantly share code, notes, and snippets.

@acid
Created January 13, 2010 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acid/275807 to your computer and use it in GitHub Desktop.
Save acid/275807 to your computer and use it in GitHub Desktop.
There seem to be no u helper on jruby, but you can use url_escape http://github.com/bougyman/url_escape
require 'url_escape'
module Fileservr::WorksHelper
def new_work_path_with_session_information
session_key = ActionController::Base.session_options[:key]
new_fileservr_work_path(session_key => cookies[session_key], request_forgery_protection_token => form_authenticity_token)
end
def javascript_for_uploader
session_key_name = ActionController::Base.session_options[:key]
max_size = Parameter.get_parameter("maximum_filesize")
code = " $(document).ready(function() {
$('#work_asset').uploadify({
'uploader': '/flash/uploadify.swf',
'script': '#{ fileservr_works_path }',
'scriptData': {
'format': 'json',
'#{ session_key_name }' : encodeURIComponent('#{URLEscape.escape cookies[session_key_name] }'),
'authenticity_token' : encodeURIComponent('#{URLEscape.escape form_authenticity_token if protect_against_forgery? }')
},
//'scriptAccess': 'always', // Incomment this, if for some reason it doesn't work·
'multi': true,
//'auto': true,
'fileDesc': 'asset',
'fileDataName' : $('#uploadr input:file')[0].name, // Extract correct name of upload field from form field
//'fileExt': '*',
'sizeLimit': #{max_size},
'simUploadLimit': 1,
//'buttonImg': '/images/button-fixed.png',
buttonText : ' #{t("fileservr.works.new.choose_files") }',
'cancelImg': '/images/cancel.png',
onComplete : function(event, queueID, fileObj, response, data) {
var data = eval('(' + response + ')');
//alert(data.asset);
$.getScript(data.asset + '.js'
)
},
onAllComplete : function(event, data){
$('#uploadify_cancel').hide('blind');
$('#uploadify_submit').show('blind');
},
onSelect: function(event, queueID, fileObj){
if (fileObj.size > #{max_size}) {
alert('The image' + fileObj.name + ' is too large.');
return false;
}
}
});
$('#uploadify_submit').click(function(event){
event.preventDefault();
$('#work_asset').uploadifyUpload();
$('#uploadify_submit').hide();
$('#uploadify_cancel').show();
});
$('#uploadify_cancel').click(function(event){
event.preventDefault();
$('#work_asset').uploadifyClearQueue();
$('#uploadify_cancel').hide();
$('#uploadify_submit').show();
});
});"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment