now updating the open aspects in js
This commit is contained in:
parent
55403d9bea
commit
7f026e8271
7 changed files with 61 additions and 21 deletions
|
|
@ -18,6 +18,7 @@ class ApplicationController < ActionController::Base
|
||||||
@object_aspect_ids = []
|
@object_aspect_ids = []
|
||||||
@all_aspects = current_user.aspects.includes(:aspect_memberships)
|
@all_aspects = current_user.aspects.includes(:aspect_memberships)
|
||||||
@notification_count = Notification.for(current_user, :unread =>true).count
|
@notification_count = Notification.for(current_user, :unread =>true).count
|
||||||
|
@user_id = current_user.id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,7 @@ class AspectsController < ApplicationController
|
||||||
else
|
else
|
||||||
@aspects = current_user.aspects.includes(:contacts => {:person => :profile})
|
@aspects = current_user.aspects.includes(:contacts => {:person => :profile})
|
||||||
end
|
end
|
||||||
current_user.open_aspects = params[:a_ids]
|
|
||||||
current_user.save
|
|
||||||
|
|
||||||
# redirect to signup
|
# redirect to signup
|
||||||
if current_user.getting_started == true || @aspects.blank?
|
if current_user.getting_started == true || @aspects.blank?
|
||||||
redirect_to getting_started_path
|
redirect_to getting_started_path
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,10 @@ class UsersController < ApplicationController
|
||||||
params[:user].delete(:password) if params[:user][:password].blank?
|
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(:password_confirmation) if params[:user][:password].blank? and params[:user][:password_confirmation].blank?
|
||||||
params[:user].delete(:language) if params[:user][:language].blank?
|
params[:user].delete(:language) if params[:user][:language].blank?
|
||||||
|
|
||||||
|
|
||||||
# change email notifications
|
|
||||||
|
# change email notifications
|
||||||
if params[:user][:disable_mail]
|
if params[:user][:disable_mail]
|
||||||
@user.update_attributes(:disable_mail => params[:user][:disable_mail])
|
@user.update_attributes(:disable_mail => params[:user][:disable_mail])
|
||||||
flash[:notice] = I18n.t 'users.update.email_notifications_changed'
|
flash[:notice] = I18n.t 'users.update.email_notifications_changed'
|
||||||
|
|
@ -39,6 +41,13 @@ class UsersController < ApplicationController
|
||||||
else
|
else
|
||||||
flash[:error] = I18n.t 'users.update.language_not_changed'
|
flash[:error] = I18n.t 'users.update.language_not_changed'
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
redirect_to edit_user_path(@user)
|
redirect_to edit_user_path(@user)
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def person_image_tag(person, size=:thumb_small)
|
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
|
end
|
||||||
|
|
||||||
def person_link(person)
|
def person_link(person)
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ $(document).ready(function(){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
$("a.hard_aspect_link").live("click", function(e){
|
$("a.hard_aspect_link").live("click", function(e){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
requests++;
|
requests++;
|
||||||
|
|
@ -101,6 +102,31 @@ $(document).ready(function(){
|
||||||
return baseURL;
|
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) {
|
function performAjax(newURL) {
|
||||||
var post = $("#publisher textarea").val(),
|
var post = $("#publisher textarea").val(),
|
||||||
photos = {};
|
photos = {};
|
||||||
|
|
@ -150,14 +176,16 @@ $(document).ready(function(){
|
||||||
// reinit listeners on stream
|
// reinit listeners on stream
|
||||||
photozone.html(photos_html);
|
photozone.html(photos_html);
|
||||||
Stream.initialize();
|
Stream.initialize();
|
||||||
|
|
||||||
// fade contents back in
|
// fade contents back in
|
||||||
if(requests == 0){
|
if(requests == 0){
|
||||||
$("#aspect_stream_container").fadeTo(100, 1);
|
$("#aspect_stream_container").fadeTo(100, 1);
|
||||||
$("#aspect_contact_pictures").fadeTo(100, 1);
|
$("#aspect_contact_pictures").fadeTo(100, 1);
|
||||||
|
performAspectUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -88,22 +88,7 @@ describe AspectsController do
|
||||||
assigns(:posts).length.should == 8
|
assigns(:posts).length.should == 8
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context 'performance' do
|
context 'performance' do
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ describe UsersController do
|
||||||
before do
|
before do
|
||||||
@user = alice
|
@user = alice
|
||||||
@aspect = @user.aspects.first
|
@aspect = @user.aspects.first
|
||||||
|
@aspect1 = @user.aspects.create(:name => "super!!")
|
||||||
sign_in :user, @user
|
sign_in :user, @user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -29,6 +30,24 @@ describe UsersController do
|
||||||
}.should_not change(@user, :diaspora_handle)
|
}.should_not change(@user, :diaspora_handle)
|
||||||
end
|
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
|
context 'password updates' do
|
||||||
before do
|
before do
|
||||||
@password_params = {:current_password => 'bluepin7',
|
@password_params = {:current_password => 'bluepin7',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue