ajax form on the getting started

This commit is contained in:
Ilya Zhitomirskiy
2011-10-18 20:56:05 -07:00
committed by danielgrippi
parent 80216cb024
commit bfd2d440d1
3 changed files with 42 additions and 26 deletions

View File

@@ -38,30 +38,30 @@ class ProfilesController < ApplicationController
:id => params[:photo_id]).first if params[:photo_id]
if current_user.update_profile params[:profile]
flash[:notice] = I18n.t 'profiles.update.updated'
if current_user.getting_started?
respond_to do |format|
format.js { render :nothing => true, :status => 200 }
format.html { redirect_to getting_started_path }
end
else
respond_to do |format|
format.js { render :nothing => true, :status => 200 }
format.html { redirect_to edit_profile_path }
end
respond_to do |format|
format.js { render :nothing => true, :status => 200 }
format.html {
flash[:notice] = I18n.t 'profiles.update.updated'
if current_user.getting_started?
redirect_to getting_started_path
else
redirect_to edit_profile_path
end
}
end
else
flash[:error] = I18n.t 'profiles.update.failed'
if params[:getting_started]
respond_to do |format|
format.js { render :nothing => true, :status => 409 }
format.html { redirect_to getting_started_path(:step => params[:getting_started]) }
end
else
respond_to do |format|
format.js { render :nothing => true, :status => 409 }
format.html { redirect_to edit_profile_path }
end
respond_to do |format|
format.js { render :nothing => true, :status => 200 }
format.html {
flash[:error] = I18n.t 'profiles.update.failed'
if params[:getting_started]
redirect_to getting_started_path(:step => params[:getting_started])
else
redirect_to edit_profile_path
end
}
end
end

View File

@@ -75,11 +75,17 @@
to Diaspora. We can pull your name and photo, and enable cross-positng.
.span-12
= form_for current_user.person.profile do |profile|
/= form_for(current_user.person.profile, :remote => true) do |profile|
= form_tag profile_path, :method => :put, :remote => true, :id => 'edit_profile' do |profile|
.span-5
= profile.text_field :first_name, :placeholder => t('profiles.edit.first_name')
%br
= profile.submit "Save"
= text_field_tag 'profile[first_name]', current_user.person.profile.first_name, :placeholder => t('profiles.edit.first_name')
= image_tag 'ajax-loader.gif', :id => "form_spinner", :class => "hidden"
%span.saved{:class => "hidden"}
Saved!
/%br
/= submit_tag "Save"
.span-7.last
= render 'photos/new_profile_photo', :aspect => :getting_started, :person => current_user.person

View File

@@ -4,5 +4,15 @@ Diaspora.Pages.UsersGettingStarted = function() {
this.subscribe("page/ready", function(evt, body) {
self.peopleSearch = self.instantiate("Search", body.find("form.people.search_form"));
self.tagSearch = self.instantiate("Search", body.find("form.tag_input.search_form"));
$("#profile_first_name").bind("change", function(){
$('#edit_profile').bind('ajax:success', function(evt, data, status, xhr){
$('#form_spinner').addClass("hidden");
$('.profile .saved').removeClass("hidden");
$('.profile .saved').fadeOut(2000);
});
$('#edit_profile').submit();
$('#form_spinner').removeClass("hidden");
});
});
};