From bfd2d440d11677356346569ae2eb9413b8a4f019 Mon Sep 17 00:00:00 2001 From: Ilya Zhitomirskiy Date: Tue, 18 Oct 2011 20:56:05 -0700 Subject: [PATCH] ajax form on the getting started --- app/controllers/profiles_controller.rb | 44 +++++++++---------- app/views/users/getting_started.haml | 14 ++++-- .../pages/users-getting-started.js | 10 +++++ 3 files changed, 42 insertions(+), 26 deletions(-) diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index 8b3f39752..171ede5b0 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -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 diff --git a/app/views/users/getting_started.haml b/app/views/users/getting_started.haml index 689b31e3b..f2f0e4e4c 100644 --- a/app/views/users/getting_started.haml +++ b/app/views/users/getting_started.haml @@ -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 diff --git a/public/javascripts/pages/users-getting-started.js b/public/javascripts/pages/users-getting-started.js index ebc62dc60..043b2f2c3 100644 --- a/public/javascripts/pages/users-getting-started.js +++ b/public/javascripts/pages/users-getting-started.js @@ -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"); + }); }); };