diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 092b04f9217982dea8529b5c0c0e051b32a94bf1..4f35d83e3e07b8fb20dc9021afdb7528d463c199 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -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 diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index e4cb4b10462fe486821f67454b20bf3103ecf99d..7fff7c82edc5c1eef2a1b5918206acd8249dd7ae 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -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 diff --git a/app/views/posts/new.html.haml b/app/views/posts/new.html.haml deleted file mode 100644 index 0279b94e8ecd8591ed410c02c2fc3f4e210ec64c..0000000000000000000000000000000000000000 --- a/app/views/posts/new.html.haml +++ /dev/null @@ -1,18 +0,0 @@ -= 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 diff --git a/public/javascripts/app/forms/picture_form.js b/public/javascripts/app/forms/picture_form.js new file mode 100644 index 0000000000000000000000000000000000000000..2fcc0707fd5504a342096636647e85d1d16b943b --- /dev/null +++ b/public/javascripts/app/forms/picture_form.js @@ -0,0 +1,20 @@ +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 diff --git a/public/javascripts/app/forms/post_form.js b/public/javascripts/app/forms/post_form.js index d2bc494c9625be9d0eb95ceba0694a4c03635abb..79edd754a34ae465e1a286addb3efd5be6f40ee2 100644 --- a/public/javascripts/app/forms/post_form.js +++ b/public/javascripts/app/forms/post_form.js @@ -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() { diff --git a/public/javascripts/app/templates/picture-form.handlebars b/public/javascripts/app/templates/picture-form.handlebars new file mode 100644 index 0000000000000000000000000000000000000000..f7f6f4a5aa24c3897b85ec3037bfadee3394e21a --- /dev/null +++ b/public/javascripts/app/templates/picture-form.handlebars @@ -0,0 +1,9 @@ +<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> + diff --git a/public/javascripts/app/templates/post-form.handlebars b/public/javascripts/app/templates/post-form.handlebars index 6b8a32d95c74329c1cd83697597a0b5c0cef2ee8..662c6532cc43c3270ec11a7e38252461c7bab046 100644 --- a/public/javascripts/app/templates/post-form.handlebars +++ b/public/javascripts/app/templates/post-form.handlebars @@ -12,5 +12,7 @@ <input type="submit" class="btn-primary" value="Share" /> </form> + + <div class="new_picture"/> </div> </div> diff --git a/public/javascripts/view.js b/public/javascripts/view.js index 39543a2cb5aa15c8f02057f328fe51e764b63312..977b7cded8005bdf7b8e7b03190bad6cc9a45786 100644 --- a/public/javascripts/view.js +++ b/public/javascripts/view.js @@ -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();