md5 the user's diaspora id for wallpaper image filename; clean up photo_form.js a little (thx max)

This commit is contained in:
danielgrippi 2012-05-06 10:44:24 -07:00
parent 56913ffb80
commit 6010579c39
2 changed files with 24 additions and 22 deletions

View file

@ -4,7 +4,8 @@ app.forms.PictureBase = app.views.Base.extend({
"change input[name='photo[user_file]']" : "submitForm"
},
photoUploaded : $.noop,
onSubmit : $.noop,
uploadSuccess : $.noop,
postRenderTemplate : function(){
this.$("input[name=authenticity_token]").val($("meta[name=csrf-token]").attr("content"))
@ -12,6 +13,16 @@ app.forms.PictureBase = app.views.Base.extend({
submitForm : function (){
this.$("form").submit();
this.onSubmit();
},
photoUploaded : function(evt, xhr) {
resp = JSON.parse(xhr.responseText)
if(resp.success) {
this.uploadSuccess(resp)
} else {
alert("Upload failed! Please try again. " + resp.error);
}
}
});
@ -30,18 +41,12 @@ app.forms.Picture = app.forms.PictureBase.extend({
this.renderPhotos();
},
submitForm : function (){
this.$("form").submit();
onSubmit : function (){
this.$(".photos").append($('<span class="loader" style="margin-left: 80px;"></span>'))
},
photoUploaded : function(evt, xhr) {
resp = JSON.parse(xhr.responseText)
if(resp.success) {
this.photos.add(new Backbone.Model(resp.data))
} else {
alert("Upload failed! Please try again. " + resp.error);
}
uploadSuccess : function(resp) {
this.photos.add(new Backbone.Model(resp.data))
},
renderPhotos : function(){
@ -57,12 +62,7 @@ app.forms.Picture = app.forms.PictureBase.extend({
app.forms.Wallpaper = app.forms.PictureBase.extend({
templateName : "wallpaper-form",
photoUploaded : function(evt, xhr) {
resp = JSON.parse(xhr.responseText)
if(resp.success) {
$("#profile").css("background-image", "url(" + resp.data.wallpaper + ")")
} else {
alert("Upload failed! Please try again. " + resp.error);
}
uploadSuccess : function(resp) {
$("#profile").css("background-image", "url(" + resp.data.wallpaper + ")")
}
});

View file

@ -3,8 +3,6 @@ class WallpaperUploader < CarrierWave::Uploader::Base
storage :file
process :darken
def store_dir
"uploads/images"
end
@ -13,9 +11,13 @@ class WallpaperUploader < CarrierWave::Uploader::Base
%w(jpg jpeg png tiff)
end
#def filename
# SecureRandom.hex(10) + File.extname(@filename) if @filename
#end
# Filename is associated with the user's diaspora handle, ensuring uniqueness
# and that only one copy is kept in the filesystem.
def filename
Digest::MD5.hexdigest(model.diaspora_handle) + File.extname(@filename) if @filename
end
process :darken
def darken
manipulate! do |img|