实时刷新(ajax轮询)

This commit is contained in:
z9hang 2014-06-21 15:34:10 +08:00
parent 55b28296a0
commit f9612ca63f
5 changed files with 36 additions and 7 deletions

View File

@ -33,7 +33,7 @@ class UsersController < ApplicationController
before_filter :require_admin, :except => [:show, :index, :search, :tag_save, :tag_saveEx,:user_projects, :user_newfeedback, :user_comments, :watch_bids, :watch_contests, :info,
:user_watchlist, :user_fanslist,:update, :user_courses, :user_homeworks, :watch_projects, :show_score, :topic_score_index, :project_score_index,
:activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index,
:activity_new_score_index, :influence_new_score_index, :score_new_index]
:activity_new_score_index, :influence_new_score_index, :score_new_index,:update_score]
#edit has been deleted by huang, 2013-9-23
before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses,
:user_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments,
@ -792,6 +792,11 @@ class UsersController < ApplicationController
def score_new_index
end
def update_score
@user = User.find(params[:id])
end
private
def find_user

View File

@ -16,7 +16,25 @@
<%= call_hook :view_layouts_base_html_head %>
<!-- page specific tags -->
<%= yield :header_tags -%>
<script type="text/javascript">
function startXMLHttp()
{
$.ajax({
url: '<%= update_score_user_path(:format => 'js') %>',
type: 'get',
data: 'id=<%= @user.id %>',
remote: true
}) ;
}
function t()
{
setInterval("startXMLHttp()",5000);
}
</script>
</head>
<!--加上 onload="Javascript:t()" 开始定时刷新分数 -->
<body class="<%= h body_css_classes %>">
<div id="wrapper">
<div id="wrapper2">
@ -97,12 +115,9 @@
<!-- modified by zjc 新得分显示 -->
<tr><td class="score">
<%= l(:label_user_grade)%>:
<%= link_to(format("%.2f" , @user.user_score_attr.total_score).to_f, {:controller => 'users',
:action => 'show_new_score',
:remote => true,
:id => @user.id
}, :style => 'color :#E8770D;') %>
<div id="score_div">
<%= render :partial => 'users/user_score', :locals => {:user => @user}%>
</div>
</td>
</tr>
<!-- end -->

View File

@ -0,0 +1,6 @@
<%= l(:label_user_grade)%>:
<%= link_to(format("%.2f" , @user.user_score_attr.total_score).to_f, {:controller => 'users',
:action => 'show_new_score',
:remote => true,
:id => user.id
}, :style => 'color :#E8770D;',:id => 'user_score') %>

View File

@ -0,0 +1,2 @@
$('#score_div').html('<%= escape_javascript(render(:partial => 'users/user_score',
:locals => {:user => @user} )) %>');

View File

@ -238,6 +238,7 @@ RedmineApp::Application.routes.draw do
match 'activity_new_score_index', :to => 'users#activity_new_score_index', :via => :get
match 'influence_new_score_index', :to => 'users#influence_new_score_index', :via => :get
match 'score_new_index', :to => 'users#score_new_index', :via => :get
match 'update_score', :to => 'users#update_score', :via => [:get,:post]
match 'show_projects_score', :to => 'projects#show_projects_score', :via => [:get, :post]
match 'issue_score_index', :to => 'projects#issue_score_index', :via => [:get, :post]