md5 the user's diaspora id for wallpaper image filename; clean up photo_form.js a little (thx max)
This commit is contained in:
parent
56913ffb80
commit
6010579c39
2 changed files with 24 additions and 22 deletions
|
|
@ -4,7 +4,8 @@ app.forms.PictureBase = app.views.Base.extend({
|
||||||
"change input[name='photo[user_file]']" : "submitForm"
|
"change input[name='photo[user_file]']" : "submitForm"
|
||||||
},
|
},
|
||||||
|
|
||||||
photoUploaded : $.noop,
|
onSubmit : $.noop,
|
||||||
|
uploadSuccess : $.noop,
|
||||||
|
|
||||||
postRenderTemplate : function(){
|
postRenderTemplate : function(){
|
||||||
this.$("input[name=authenticity_token]").val($("meta[name=csrf-token]").attr("content"))
|
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 (){
|
submitForm : function (){
|
||||||
this.$("form").submit();
|
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();
|
this.renderPhotos();
|
||||||
},
|
},
|
||||||
|
|
||||||
submitForm : function (){
|
onSubmit : function (){
|
||||||
this.$("form").submit();
|
|
||||||
this.$(".photos").append($('<span class="loader" style="margin-left: 80px;"></span>'))
|
this.$(".photos").append($('<span class="loader" style="margin-left: 80px;"></span>'))
|
||||||
},
|
},
|
||||||
|
|
||||||
photoUploaded : function(evt, xhr) {
|
uploadSuccess : function(resp) {
|
||||||
resp = JSON.parse(xhr.responseText)
|
this.photos.add(new Backbone.Model(resp.data))
|
||||||
if(resp.success) {
|
|
||||||
this.photos.add(new Backbone.Model(resp.data))
|
|
||||||
} else {
|
|
||||||
alert("Upload failed! Please try again. " + resp.error);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
renderPhotos : function(){
|
renderPhotos : function(){
|
||||||
|
|
@ -57,12 +62,7 @@ app.forms.Picture = app.forms.PictureBase.extend({
|
||||||
app.forms.Wallpaper = app.forms.PictureBase.extend({
|
app.forms.Wallpaper = app.forms.PictureBase.extend({
|
||||||
templateName : "wallpaper-form",
|
templateName : "wallpaper-form",
|
||||||
|
|
||||||
photoUploaded : function(evt, xhr) {
|
uploadSuccess : function(resp) {
|
||||||
resp = JSON.parse(xhr.responseText)
|
$("#profile").css("background-image", "url(" + resp.data.wallpaper + ")")
|
||||||
if(resp.success) {
|
|
||||||
$("#profile").css("background-image", "url(" + resp.data.wallpaper + ")")
|
|
||||||
} else {
|
|
||||||
alert("Upload failed! Please try again. " + resp.error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -3,8 +3,6 @@ class WallpaperUploader < CarrierWave::Uploader::Base
|
||||||
|
|
||||||
storage :file
|
storage :file
|
||||||
|
|
||||||
process :darken
|
|
||||||
|
|
||||||
def store_dir
|
def store_dir
|
||||||
"uploads/images"
|
"uploads/images"
|
||||||
end
|
end
|
||||||
|
|
@ -13,9 +11,13 @@ class WallpaperUploader < CarrierWave::Uploader::Base
|
||||||
%w(jpg jpeg png tiff)
|
%w(jpg jpeg png tiff)
|
||||||
end
|
end
|
||||||
|
|
||||||
#def filename
|
# Filename is associated with the user's diaspora handle, ensuring uniqueness
|
||||||
# SecureRandom.hex(10) + File.extname(@filename) if @filename
|
# and that only one copy is kept in the filesystem.
|
||||||
#end
|
def filename
|
||||||
|
Digest::MD5.hexdigest(model.diaspora_handle) + File.extname(@filename) if @filename
|
||||||
|
end
|
||||||
|
|
||||||
|
process :darken
|
||||||
|
|
||||||
def darken
|
def darken
|
||||||
manipulate! do |img|
|
manipulate! do |img|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue