now updating the open aspects in js

This commit is contained in:
zhitomirskiyi 2011-02-01 16:34:05 -08:00
parent 55403d9bea
commit 7f026e8271
7 changed files with 61 additions and 21 deletions

View file

@ -18,6 +18,7 @@ class ApplicationController < ActionController::Base
@object_aspect_ids = []
@all_aspects = current_user.aspects.includes(:aspect_memberships)
@notification_count = Notification.for(current_user, :unread =>true).count
@user_id = current_user.id
end
end

View file

@ -15,9 +15,7 @@ class AspectsController < ApplicationController
else
@aspects = current_user.aspects.includes(:contacts => {:person => :profile})
end
current_user.open_aspects = params[:a_ids]
current_user.save
# redirect to signup
if current_user.getting_started == true || @aspects.blank?
redirect_to getting_started_path

View file

@ -21,8 +21,10 @@ class UsersController < ApplicationController
params[:user].delete(:password) if params[:user][:password].blank?
params[:user].delete(:password_confirmation) if params[:user][:password].blank? and params[:user][:password_confirmation].blank?
params[:user].delete(:language) if params[:user][:language].blank?
# change email notifications
# change email notifications
if params[:user][:disable_mail]
@user.update_attributes(:disable_mail => params[:user][:disable_mail])
flash[:notice] = I18n.t 'users.update.email_notifications_changed'
@ -39,6 +41,13 @@ class UsersController < ApplicationController
else
flash[:error] = I18n.t 'users.update.language_not_changed'
end
elsif params[:user][:a_ids]
if params[:user][:a_ids] == ["home"]
@user.open_aspects = nil
else
@user.open_aspects = params[:user][:a_ids]
end
@user.save!
end
redirect_to edit_user_path(@user)

View file

@ -135,7 +135,7 @@ module ApplicationHelper
end
def person_image_tag(person, size=:thumb_small)
"<img alt=\"#{h(person.name)}\" class=\"avatar\" data-person_id=\"#{person.id}\" src=\"#{image_or_default(person, size)}\" title=\"#{h(person.name)}\">".html_safe
"<img alt=\"#{h(person.name)}\" class=\"avatar\" #{("data-owner_id="+@user_id.to_s) if @user_id} data-person_id=\"#{person.id}\" src=\"#{image_or_default(person, size)}\" title=\"#{h(person.name)}\">".html_safe
end
def person_link(person)

View file

@ -17,6 +17,7 @@ $(document).ready(function(){
}
});
$("a.hard_aspect_link").live("click", function(e){
e.preventDefault();
requests++;
@ -101,6 +102,31 @@ $(document).ready(function(){
return baseURL;
}
$("a.home_selector").live("click", function(e){
performAspectUpdate("home");
});
function performAspectUpdate(home){
// update the open aspects in the user
updateURL = "/users/" + $('div.avatar').children('img').attr("data-owner_id");
updateURL += '?';
if(home == 'home'){
updateURL += 'user[a_ids][]=home';
} else {
for(i=0; i < selectedGUIDS.length; i++){
updateURL += 'user[a_ids][]='+ selectedGUIDS[i] +'&';
}
}
//alert(updateURL);
$.ajax({
url : updateURL,
type: "PUT",
});
}
function performAjax(newURL) {
var post = $("#publisher textarea").val(),
photos = {};
@ -150,14 +176,16 @@ $(document).ready(function(){
// reinit listeners on stream
photozone.html(photos_html);
Stream.initialize();
// fade contents back in
if(requests == 0){
$("#aspect_stream_container").fadeTo(100, 1);
$("#aspect_contact_pictures").fadeTo(100, 1);
performAspectUpdate();
}
}
});
}
});

View file

@ -88,22 +88,7 @@ describe AspectsController do
assigns(:posts).length.should == 8
end
context "storing state" do
before do
@index_params = {:a_ids => [@aspect0.id.to_s, @aspect1.id.to_s]}
end
it "stores the aspect params in the user" do
get :index, @index_params
@user.reload.open_aspects.should == @index_params[:a_ids]
end
it "correctly stores the aspect params" do
@user.open_aspects = @index_params[:a_ids]
@user.save
get :index
@user.reload.open_aspects.should == nil
end
end
end
context 'performance' do

View file

@ -10,6 +10,7 @@ describe UsersController do
before do
@user = alice
@aspect = @user.aspects.first
@aspect1 = @user.aspects.create(:name => "super!!")
sign_in :user, @user
end
@ -29,6 +30,24 @@ describe UsersController do
}.should_not change(@user, :diaspora_handle)
end
context "open aspects" do
before do
@index_params = {:id => @user.id, :user => {:a_ids => [@aspect.id.to_s, @aspect1.id.to_s]} }
end
it "stores the aspect params in the user" do
put :update, @index_params
@user.reload.open_aspects.should == @index_params[:user][:a_ids]
end
it "correctly resets the home state" do
@index_params[:user][:a_ids] = ["home"]
put :update, @index_params
@user.reload.open_aspects.should == nil
end
end
context 'password updates' do
before do
@password_params = {:current_password => 'bluepin7',