个人主页,添加、取消关注及相关效果

This commit is contained in:
sw 2015-08-21 15:23:03 +08:00
parent 73854cc35c
commit 8ef6225084
5 changed files with 25 additions and 67 deletions

View File

@ -1,11 +1,7 @@
<% if User.current.logged?%>
<% if User.current == target%>
<a href="<%= url_for(:controller => 'my', :action => 'account') %>" class="fr gz_btn mr10 ">编辑资料</a>
<%else%>
<%if(target.watched_by?(User.current))%>
<a id="user_watch_id" href="<%= watch_path(:object_type=> 'user',:object_id=>target.id,:target_id=>target.id) %>" class="fr qx_btn mr10" data-method="delete" data-remote="true" title="取消关注">取消关注</a>
<% else %>
<a id="user_watch_id" href="<%= watch_path(:object_type=>'user',:object_id=>target.id,:target_id=>target.id) %>" class="fr gz_btn mr10" data-method="post" data-remote="true" title="添加关注">添加关注</a>
<% end %>
<% end%>
<%if(target.watched_by?(User.current))%>
<%= link_to "",watch_path(:object_type=> 'user',:object_id=>target.id,:target_id=>target.id),:class => "homepageFollow", :method => "delete",:remote => "true", :title => "取消关注"%>
<% else %>
<%= link_to "",watch_path(:object_type=> 'user',:object_id=>target.id,:target_id=>target.id),:class => "homepageFollowCancel", :method => "post",:remote => "true", :title => "添加关注"%>
<% end %>
<% end %>

View File

@ -29,7 +29,7 @@
<div class="homepageContent">
<div class="homepageLeft" id="LSide">
<div class="homepagePortraitContainer">
<div class="homepagePortraitImage">
<div class="homepagePortraitImage" id="homepage_portrait_image">
<%= image_tag(url_to_avatar(@user),width:"206", height: "206", :id=>'nh_user_tx') %>
<% if User.current.logged?%>
<% if User.current == @user%>
@ -39,13 +39,8 @@
</div>
</div>
<% else %>
<div>
<a href="javascript:void(0);" class="homepageFollow"></a>
<%if(@user.watched_by?(User.current))%>
<%= link_to "",watch_path(:object_type=> 'user',:object_id=>@user.id,:target_id=>@user.id),:class => "homepageFollow", :method => "delete",:remote => "true", :title => "取消关注"%>
<% else %>
<%= link_to "",watch_path(:object_type=> 'user',:object_id=>@user.id,:target_id=>@user.id),:class => "homepageFollow", :method => "post",:remote => "true", :title => "添加关注"%>
<% end %>
<div id="watch_user_btn" class="none">
<%= render :partial => 'layouts/user_watch_btn', :locals => {:target => @user} %>
</div>
<% end %>
<% end%>
@ -89,7 +84,7 @@
<div class="homepageVerDiv"></div>
<div class="homepageImageBlock">
<div>
<%= link_to @user.watcher_users.count.to_s, {:controller=>"users", :action=>"user_fanslist",:id=>@user.id},:class=>"homepageImageNumber"%>
<%= link_to @user.watcher_users.count.to_s, {:controller=>"users", :action=>"user_fanslist",:id=>@user.id},:class=>"homepageImageNumber", :id => "user_fans_number"%>
</div>
<div class="homepageImageText">粉丝</div>
</div>

View File

@ -215,7 +215,7 @@
</div>
</div>
<!-- -->
<!-- 美化设置,勿删! -->
<div id="RSide" class="rside_back">
</div>

View File

@ -1,57 +1,15 @@
<% if( params[:object_type] == 'user') %>
//点击头像下面的添加关注按钮
<% if( params[:target_id] == params[:object_id] ) %>
<% target = User.find_by_id(params[:target_id]) %>
//btn
var btn_html = "<%= escape_javascript( render( :partial => 'layouts/user_watch_btn', :locals => {:target => target} ) )%>";
$('#user_watch_id').replaceWith(btn_html);
//count
$("*[nh_name='fans_count']").html("<%= target.watcher_users.count.to_s %>");
//left list
var list_left_html = "<%= escape_javascript( render( :partial => 'layouts/user_fans_list', :locals => {:user => target} ) )%>";
$('#fans_nav_list').replaceWith(list_left_html);
//list
if( $("#nh_fans_list") != undefined && $("#nh_fans_list").length != 0 ){
<% if( opt == 'add') %>
var list_html = "<%= escape_javascript( render( :partial => 'users/user_fans_item', :locals => {:item=>User.current,:target => target} ) )%>";
$("#nh_fans_list").after(list_html);
$("#nodata").hide();
<% else %>
$("#fans_item_<%= User.current.id %>",$("#nh_fans_list").parent('div')).remove();
if( $('>div',$("#nh_fans_list").parent('div')).length == 1 ){
$("#nodata").show();
}
<% end %>
}
$("#watch_user_btn").html("<%= escape_javascript render(:partial => "layouts/user_watch_btn", :locals => {:target => watched.first}) %>");
$("#user_fans_number").html("<%= watched.first.watcher_users.count.to_s%>");
//在当前用户的粉丝、关注页面
<% elsif( params[:target_id] == User.current.id.to_s )%>
<% target = User.find_by_id(params[:target_id]) %>
<% item = User.find_by_id(params[:object_id]) %>
//count
$("*[nh_name='watcher_count']").html("<%= User.watched_by(target.id).count.to_s %>");
//left list
var list_left_html = "<%= escape_javascript( render( :partial => 'layouts/user_watch_list', :locals => {:user => target} ) )%>";
$('#watcher_nav_list').replaceWith(list_left_html);
//list
if( $("#nh_wacth_list") != undefined && $("#nh_wacth_list").length != 0 ){
<% if( opt == 'delete') %>
$("#fans_item_<%= item.id %>",$("#nh_wacth_list").parent('div')).remove();
if( $('>div',$("#nh_wacth_list").parent('div')).length == 1 ){
$("#nodata").show();
}
<% end %>
}else if($("#nh_fans_list") != undefined && $("#nh_fans_list").length != 0){
var list_html = "<%= escape_javascript( render( :partial => 'users/user_fans_item', :locals => {:item=>item,:target => target} ) )%>";
$('#fans_item_<%= item.id %>').replaceWith(list_html);
}
//在其他用户的粉丝、关注页面
<% else %>
<% target = User.find_by_id(params[:target_id]) %>
<% item = User.find_by_id(params[:object_id]) %>
//list
var list_html = "<%= escape_javascript( render( :partial => 'users/user_fans_item', :locals => {:item=>item,:target => target} ) )%>";
$('#fans_item_<%= item.id %>').replaceWith(list_html);
<% end %>
<% end %>
<% else %>
<% selector = ".#{watcher_css(watched)}" %>

View File

@ -1,5 +1,14 @@
$(function(){
$("#RSide").css("min-height",$("#LSide").height()-40).css("padding","10px");
//头像相关
$("#homepage_portrait_image").live("mouseover",function(){
$("#edit_user_file_btn").show();
$("#watch_user_btn").show();
}).live("mouseout",function(){
$("#edit_user_file_btn").hide();
$("#watch_user_btn").hide();
});
});
$(function(){