photomix/app/views/photos/upload.html.erb

78 lines
3.0 KiB
Plaintext

<%= content_for :javascript do %>
<script type="text/javascript">
$(document).ready(function () {
$("#uploader").pluploadQueue({
runtimes:'flash,html5,browserplus,silverlight,gears',
url:'<%= photos_path %>',
max_file_size:'10mb',
multipart:true,
multipart_params:{
'<%= get_session_key %>':encodeURIComponent('<%= cookies[get_session_key] %>'),
'authenticity_token':'<%= form_authenticity_token %>',
'photo[album_id]':"<%= @album.id %>"
},
// Resize images on clientside if we can
//resize : {width : 320, height : 240, quality : 90},
// Specify what files to browse for
filters:[
{title:"Image files", extensions:"jpg,gif,png,bmp,jpeg,tif,tiff,JPG,GIF,PNG,BMP,JPEG,TIF,TIFF"}
],
// Flash settings
flash_swf_url:'/assets/plupload.flash.swf',
// Silverlight settings
silverlight_xap_url:'/assets/plupload.silverlight.xap',
// Post init events, bound after the internal events
init:{
FileUploaded:function (up, file, info) {
// Called when a file has finished uploading
res = info.response;
if (res.substring(0, 7) === "FILEID:") {
var image = $('<img>').appendTo('#thumbs')
image.css('display', 'none')
image.attr('src', res.substring(7))
image.fadeIn('slow')
}
}
}
});
// Client side form validation
$('form').submit(function (e) {
var uploader = $('#uploader').pluploadQueue();
// Validate number of uploaded files
if (uploader.total.uploaded == 0) {
// Files in queue upload them first
if (uploader.files.length > 0) {
// When all files are uploaded submit form
uploader.bind('UploadProgress', function () {
if (uploader.total.uploaded == uploader.files.length)
$('form').submit();
});
uploader.start();
} else
alert('You must at least upload one file.');
e.preventDefault();
}
});
})
</script>
<% end %>
<form>
<div id="uploader">
<p>You browser doesn't have Flash, Silverlight, Gears, BrowserPlus or HTML5 support.</p>
</div>
<br>
<div id="thumbs"></div>
</form>
<br><%= link_to "Edit uploaded photos", untouched_album_photos_path(@album) %>
<br><%= link_to "Back to #{@album.title}", @album %>