Skip to content
Extraits de code Groupes Projets
Valider 1ec2b73d rédigé par Dennis Collinson's avatar Dennis Collinson
Parcourir les fichiers

DG DC remotipartjarvascripts

parent 6dce04d2
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -41,38 +41,11 @@ class PhotosController < ApplicationController
end
def create
raise "THAT IS NOT OKAY"
rescuing_photo_errors do |p|
rescuing_photo_errors do
if remotipart_submitted?
@photo = current_user.build_post(:photo, params[:photo])
else
raise "not remotipart" unless params[:photo][:aspect_ids]
if params[:photo][:aspect_ids] == "all"
params[:photo][:aspect_ids] = current_user.aspects.collect { |x| x.id }
elsif params[:photo][:aspect_ids].is_a?(Hash)
params[:photo][:aspect_ids] = params[:photo][:aspect_ids].values
end
params[:photo][:user_file] = file_handler(params)
@photo = current_user.build_post(:photo, params[:photo])
if @photo.save
aspects = current_user.aspects_from_ids(params[:photo][:aspect_ids])
unless @photo.pending
current_user.add_to_streams(@photo, aspects)
current_user.dispatch_post(@photo, :to => params[:photo][:aspect_ids])
end
if params[:photo][:set_profile_photo]
profile_params = {:image_url => @photo.url(:thumb_large),
:image_url_medium => @photo.url(:thumb_medium),
:image_url_small => @photo.url(:thumb_small)}
current_user.update_profile(profile_params)
end
end
legacy_create
end
if @photo.save
......@@ -194,6 +167,33 @@ class PhotosController < ApplicationController
end
end
def legacy_create
if params[:photo][:aspect_ids] == "all"
params[:photo][:aspect_ids] = current_user.aspects.collect { |x| x.id }
elsif params[:photo][:aspect_ids].is_a?(Hash)
params[:photo][:aspect_ids] = params[:photo][:aspect_ids].values
end
params[:photo][:user_file] = file_handler(params)
@photo = current_user.build_post(:photo, params[:photo])
if @photo.save
aspects = current_user.aspects_from_ids(params[:photo][:aspect_ids])
unless @photo.pending
current_user.add_to_streams(@photo, aspects)
current_user.dispatch_post(@photo, :to => params[:photo][:aspect_ids])
end
if params[:photo][:set_profile_photo]
profile_params = {:image_url => @photo.url(:thumb_large),
:image_url_medium => @photo.url(:thumb_medium),
:image_url_small => @photo.url(:thumb_small)}
current_user.update_profile(profile_params)
end
end
end
def rescuing_photo_errors
begin
......
......@@ -16,7 +16,7 @@ class PostsController < ApplicationController
:xml
def new
render :text => "", :layout => true
end
def show
......@@ -40,7 +40,7 @@ class PostsController < ApplicationController
format.xml{ render :xml => @post.to_diaspora_xml }
format.mobile{render 'posts/show.mobile.haml'}
format.json{ render :json => PostPresenter.new(@post, current_user).to_json }
format.any{render 'posts/show.html.haml'}
format.any{render 'posts/show.html.haml'}
end
else
......
= form_for Photo.new, :html => { :multipart => true }, :remote => true do |f|
= f.label :user_file
= f.file_field :user_file
= f.submit
:javascript
// ugly hax to take us from remotipart land to normal backbone land
$(function(){
$('#new_photo').bind('ajax:complete', function(evt, xhr) {
resp = JSON.parse(xhr.responseText)
if(resp.success) {
console.log("response was successful");
} else {
console.log(resp.error);
};
});
//console.log(new Backbone.Model(data)); // Your newly created Backbone.js model
});
\ No newline at end of file
app.forms.Picture = app.forms.Base.extend({
templateName : "picture-form",
events : {
'ajax:complete .new_photo' : "photoUploaded"
},
postRenderTemplate : function(){
this.$("input[name=authenticity_token]").val($("meta[name=csrf-token]").attr("content"))
},
photoUploaded : function(evt, xhr) {
resp = JSON.parse(xhr.responseText)
if(resp.success) {
console.log(new Backbone.Model(resp.data.photo));
} else {
console.log(resp.error);
};
}
})
\ No newline at end of file
......@@ -3,8 +3,9 @@ app.forms.Post = app.forms.Base.extend({
subviews : {
".aspect_selector" : "aspectsDropdown",
".service_selector" : "servicesSelector"
},
".service_selector" : "servicesSelector",
".new_picture" : "pictureForm"
},
formAttrs : {
"textarea#text_with_markup" : "text",
......@@ -15,6 +16,7 @@ app.forms.Post = app.forms.Base.extend({
initialize : function() {
this.aspectsDropdown = new app.views.AspectsDropdown();
this.servicesSelector = new app.views.ServicesSelector();
this.pictureForm = new app.forms.Picture();
},
postRenderTemplate : function() {
......
<form accept-charset="UTF-8" action="/photos" class="new_photo" data-remote="true" enctype="multipart/form-data" method="post">
<input name="authenticity_token" type="hidden"/>
<div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="✓"/>
</div>
<input name="photo[user_file]" type="file"/>
<input name="commit" type="submit" value="Create Photo"/>
</form>
......@@ -12,5 +12,7 @@
<input type="submit" class="btn-primary" value="Share" />
</form>
<div class="new_picture"/>
</div>
</div>
......@@ -25,7 +25,25 @@ var View = {
/* Avatars */
$(this.avatars.selector).error(this.avatars.fallback);
/* Clear forms after successful submit */
/* Clear forms after successful submit, this is some legacy dan hanson stuff, do we still want it? */
$.fn.clearForm = function() {
return this.each(function() {
if ($(this).is('form')) {
return $(':input', this).clearForm();
}
if ($(this).hasClass('clear_on_submit') || $(this).is(':text') || $(this).is(':password') || $(this).is('textarea')) {
$(this).val('');
} else if ($(this).is(':checkbox') || $(this).is(':radio')) {
$(this).attr('checked', false);
} else if ($(this).is('select')) {
this.selectedIndex = -1;
} else if ($(this).attr('name') == 'photos[]') {
$(this).val('');
}
$(this).blur();
});
};
$('form[data-remote]').live('ajax:success', function (e) {
$(this).clearForm();
$(this).focusout();
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter