diaspora/app/views/photos/_new_photo.haml
2011-01-22 13:48:26 -08:00

75 lines
2.8 KiB
Text

-# Copyright (c) 2010, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
:javascript
function createUploader(){
var aspectIds = "#{aspect_ids}".split(',');
var uploader = new qq.FileUploaderBasic({
element: document.getElementById('file-upload'),
params: {'photo' : {'pending' : 'true', 'aspect_ids' : aspectIds}, 'set_profile_image' : "#{set_profile_image if defined?(set_profile_image)}"},
allowedExtensions: ['jpg', 'jpeg', 'png'],
action: "#{photos_path}",
debug: true,
button: document.getElementById('file-upload'),
sizeLimit: 4194304,
onProgress: function(id, fileName, loaded, total){
var progress = Math.round(loaded / total * 100 );
$('#fileInfo').text(fileName + ' ' + progress + '%');
},
messages: {
typeError: "#{t('.invalid_ext')}",
sizeError: "#{t('.size_error')}",
emptyError: "#{t('.empty')}"
},
onSubmit: function(id, fileName){
$('#file-upload').addClass("loading");
$('#publisher').find("input[type='submit']").attr('disabled','disabled');
$("#publisher .options_and_submit").fadeIn(50);
$("#publisher_spinner").fadeIn(100);
},
onComplete: function(id, fileName, responseJSON){
$('#fileInfo').text(fileName + ' completed').fadeOut(2000);
$("#publisher_spinner").fadeOut(100);
$('#file-upload').removeClass("loading");
var id = responseJSON.data.photo.id;
var url = responseJSON.data.photo.thumb_small;
$("#publisher textarea").addClass("with_attachments");
$('#new_status_message').append("<input type='hidden' value='" + id + "' name='photos[]' />");
$('#photodropzone').append(
"<li class='publisher_photo' style='position:relative;'>" +
"<img src='" + url +"' data-id='" + id + "' />" +
"<div class='x'> X </div>" +
"<div class='circle'></div>" +
"</li>"
);
$('#publisher').find("input[type='submit']").removeAttr('disabled');
$('.x').live('click', function(){
var photo = $(this).closest('.publisher_photo');
photo.addClass("dim");
$.ajax({url: "photos/" + photo.children('img').attr('data-id'),
type: 'DELETE',
success: function() {
photo.fadeOut(400, function(){
photo.remove();
if ( $('.publisher_photo').length == 0){
$("#publisher textarea").removeClass("with_attachments");
}
});
}
});
});
}
});
}
createUploader();