1.修改添加评论、留言的action

2.添加评论、留言时界面数据刷新
3.修改删除留言的action
4.删除留言后界面刷新
5.增加权限控制
This commit is contained in:
sw 2014-12-05 09:43:03 +08:00
parent 4bbc76a217
commit bed9adaa7a
5 changed files with 75 additions and 150 deletions

View File

@ -370,54 +370,6 @@ class HomeworkAttachController < ApplicationController
@cur_page = params[:cur_page] || 1
@cur_type = params[:cur_type] || 5
#if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
# # 打分统计
# #stars_reates = @homework. rates(:quality)
# #是否已经进行过评价
# temp = HomeworkAttach.find_by_sql("SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = #{@homework.id} AND rater_id = #{User.current.id}").first
# @m_score = temp.nil? ? 0:temp.stars
# @has_evaluation = @homework.has_rated?( User.current,:quality)
# #@jours留言 is null条件用以兼容历史数据
# @jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC")
# @cur_page = params[:cur_page] || 1
# @cur_type = params[:cur_type] || 5
# @jour = paginateHelper @jours,5
#
# teachers = searchTeacherAndAssistant @course
# @comprehensive_evaluation = []
# #JourForMessage的is_comprehensive_evaluation字段
# #1老师评价
# #2学生评价
# #3 || null学生留言
# teachers.each do|teacher|
# temp = @homework.journals_for_messages.where("is_comprehensive_evaluation = 1 and user_id = #{teacher.user_id}").order("created_on DESC").first
# @comprehensive_evaluation << temp if temp
# end
# annymous_users = @homework.homework_evaluations.map { |homework_evaluation| homework_evaluation.user.id}.join(',')
# unless annymous_users.nil? || annymous_users == ""
# @anonymous_comments = @homework.journals_for_messages.where("is_comprehensive_evaluation = 2 and user_id in (#{annymous_users})").order("created_on DESC")
# end
# #@totle_score = score_for_homework @homework
# #@teaher_score = teacher_score_for_homework @homework
#
# #is_student = is_cur_course_student @homework.bid.courses.first
# @is_teacher = is_course_teacher User.current,@homework.bid.courses.first
# @is_anonymous_comments = @homework.bid.comment_status == 1 #是否开启了匿评
# #@is_comprehensive_evaluation 1教师评论2学生匿评3学生留言
# if User.current.member_of_course?(@homework.bid.courses.first)
# if @is_teacher
# @is_comprehensive_evaluation = 1 #教师评论
# else
# if @is_anonymous_comments && !@has_evaluation #是学生且开启了匿评且未进行评分
# @is_comprehensive_evaluation = 2 #匿评
# else #是学生未开启匿评或者已经进行评分
# @is_comprehensive_evaluation = 3 #留言
# end
# end
# else
# @is_comprehensive_evaluation = 3
# end
respond_to do |format|
format.html
format.js
@ -429,27 +381,40 @@ class HomeworkAttachController < ApplicationController
#删除留言
def destroy_jour
@homework = HomeworkAttach.find(params[:jour_id])
@course=@homework.bid.courses.first
@homework = HomeworkAttach.find(params[:homework_id])
@journal_destroyed = JournalsForMessage.find(params[:object_id])
@is_comprehensive_evaluation = @journal_destroyed.is_comprehensive_evaluation
@journal_destroyed.destroy
if @is_comprehensive_evaluation == 3
@jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC")
@jour = paginateHelper @jours,5
elsif @is_comprehensive_evaluation == 2
annymous_users = @homework.homework_evaluations.map { |homework_evaluation| homework_evaluation.user.id}.join(',')
unless annymous_users.nil? || annymous_users.count == ""
@anonymous_comments = @homework.journals_for_messages.where("is_comprehensive_evaluation = 2 and user_id in (#{annymous_users})").order("created_on DESC")
end
elsif @is_comprehensive_evaluation == 1
teachers = searchTeacherAndAssistant @course
@comprehensive_evaluation = []
teachers.each do|teacher|
temp = @homework.journals_for_messages.where("is_comprehensive_evaluation = 1 and user_id = #{teacher.user_id}").order("created_on DESC").first
@comprehensive_evaluation << temp if temp
end
if @journal_destroyed.is_comprehensive_evaluation == 3 && @journal_destroyed.destroy
render_403 unless User.current == @journal_destroyed.user || User.current.admin?
teachers = find_course_teachers(@homework.bid.courses.first)
@stars_reates = @homework.rates(:quality)
@teacher_stars = @stars_reates.where("rater_id in (#{teachers})") #老师评分列表
@student_stars = @stars_reates.where("rater_id not in (#{teachers})") #学生评分列表
jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC")#jours留言 is null条件用以兼容历史数据
@jour = paginateHelper jours,5 #留言
else
render_404
end
#@course=@homework.bid.courses.first
#@journal_destroyed = JournalsForMessage.find(params[:object_id])
#@is_comprehensive_evaluation = @journal_destroyed.is_comprehensive_evaluation
#@journal_destroyed.destroy
#if @is_comprehensive_evaluation == 3
# @jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC")
# @jour = paginateHelper @jours,5
#elsif @is_comprehensive_evaluation == 2
# annymous_users = @homework.homework_evaluations.map { |homework_evaluation| homework_evaluation.user.id}.join(',')
# unless annymous_users.nil? || annymous_users.count == ""
# @anonymous_comments = @homework.journals_for_messages.where("is_comprehensive_evaluation = 2 and user_id in (#{annymous_users})").order("created_on DESC")
# end
#elsif @is_comprehensive_evaluation == 1
# teachers = searchTeacherAndAssistant @course
# @comprehensive_evaluation = []
# teachers.each do|teacher|
# temp = @homework.journals_for_messages.where("is_comprehensive_evaluation = 1 and user_id = #{teacher.user_id}").order("created_on DESC").first
# @comprehensive_evaluation << temp if temp
# end
#end
respond_to do |format|
format.js
end
@ -457,79 +422,49 @@ class HomeworkAttachController < ApplicationController
#添加留言
def addjours
@homework = HomeworkAttach.find(params[:jour_id])
@is_teacher,@is_anonymous_comments,@m_score = params[:is_teacher]=="true",params[:is_anonymous_comments]=="true",params[:stars_value]
@cur_page,@cur_type = params[:cur_page] || 1,params[:cur_type] || 5
@homework = HomeworkAttach.find(params[:homework_id])
#保存评分
@homework.rate(params[:stars_value],User.current.id,:quality) if params[:stars_value] && params[:stars_value] != "0"
@homework.rate(@m_score,User.current.id,:quality) if @m_score && @m_score != "0"
#保存评论
@cur_is_comprehensive_evaluation = params[:is_comprehensive_evaluation]
if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != "" #有没有留言
@homework.addjours User.current.id, params[:new_form][:user_message],0,@cur_is_comprehensive_evaluation
@is_comprehensive_evaluation = @is_teacher ? 1 : (@is_anonymous_comments ? 2 : 3) #判断当前评论是老师评论?匿评?留言
if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != "" #有没有留言
@homework.addjours User.current.id, params[:new_form][:user_message],0,@is_comprehensive_evaluation
end
@cur_page = params[:cur_page] || 1
@cur_type = params[:cur_type] || 5
teachers = searchTeacherAndAssistant @homework.bid.courses.first
if @cur_is_comprehensive_evaluation == "3"
@jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC")
@jour = paginateHelper @jours,5
elsif @cur_is_comprehensive_evaluation == "2"
annymous_users = @homework.homework_evaluations.map { |homework_evaluation| homework_evaluation.user.id}.join(',')
unless annymous_users.nil? || annymous_users == ""
@anonymous_comments = @homework.journals_for_messages.where("is_comprehensive_evaluation = 2 and user_id in (#{annymous_users})").order("created_on DESC")
end
@m_score = params[:stars_value].to_i
elsif @cur_is_comprehensive_evaluation == "1"
@comprehensive_evaluation = []
teachers.each do|teacher|
temp = @homework.journals_for_messages.where("is_comprehensive_evaluation = 1 and user_id = #{teacher.user_id}").order("created_on DESC").first
@comprehensive_evaluation << temp if temp
end
end
teachers = find_course_teachers(@homework.bid.courses.first)
@stars_reates = @homework.rates(:quality)
@teacher_stars = @stars_reates.where("rater_id in (#{teachers})") #老师评分列表
@student_stars = @stars_reates.where("rater_id not in (#{teachers})") #学生评分列表
jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC")#jours留言 is null条件用以兼容历史数据
@jour = paginateHelper jours,5 #留言
is_teacher = is_course_teacher User.current,@homework.bid.courses.first
@is_anonymous_comments = @homework.bid.comment_status == 1 #是否开启了匿评
#@is_comprehensive_evaluation 1教师评论2学生匿评3学生留言
if User.current.member_of_course?(@homework.bid.courses.first)
if is_teacher
@is_comprehensive_evaluation = 1 #教师评论
else
if @is_anonymous_comments && !@has_evaluation #是学生且开启了匿评且未进行评分
@is_comprehensive_evaluation = 2 #匿评
else #是学生未开启匿评或者已经进行评分
@is_comprehensive_evaluation = 3 #留言
end
end
else
@is_comprehensive_evaluation = 3
end
#teachers = find_course_teachers @homework.bid.courses.first
teachers_str = teachers.map{|teacher| teacher.user_id}.join(",")
if @cur_type == "1" #如果当前是老师未批列表,需要刷新整个作业列表界面
@bid = @homework.bid
get_not_batch_homework_list "s_socre","desc",teachers_str,@homework.bid_id
get_not_batch_homework_list "s_socre","desc",teachers,@homework.bid_id
elsif @cur_type == "2" #老师已批列表
@result_homework = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers_str}) and stars IS NOT NULL) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (#{teachers_str})) AS s_score
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers}) and stars IS NOT NULL) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (#{teachers})) AS s_score
FROM homework_attaches WHERE id = #{@homework.id}").first
elsif @cur_type == "3" #全部作业列表
@result_homework = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id in (#{teachers_str})) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id not in (#{teachers_str})) AS s_score
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id in (#{teachers})) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id not in (#{teachers})) AS s_score
FROM homework_attaches WHERE id = #{@homework.id}").first
elsif @cur_type == "4" #匿评作业列表
@is_student_batch_homework = true
@result_homework = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers_str})) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (#{teachers_str})) AS s_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers})) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (#{teachers})) AS s_score,
(SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{User.current.id}) AS m_score
FROM homework_attaches
WHERE homework_attaches.id = #{@homework.id}").first
else #其他的不用管
end
respond_to do |format|
format.js
end

View File

@ -32,7 +32,9 @@
:action => 'addjours',
:homework_id => homework_attach.id,
:cur_page => cur_page,
:cur_type => cur_type
:cur_type => cur_type,
:is_anonymous_comments => @is_anonymous_comments,
:is_teacher => @is_teacher
}) do |f|%>
<!-- 打分 -->
<div class="ping_star" id="star_score">

View File

@ -1,4 +1,4 @@
<% if !jours.nil? && jours.is_a?(Array)%>
<% unless jours.nil?%>
<% jours.each do |jour| %>
<div class="ping_C">
<div class="ping_dispic">
@ -19,7 +19,10 @@
<% ids = 'project_respond_form_'+ jour.id.to_s%>
<span>
<% if jour.user==User.current|| User.current.admin? %>
<%= link_to(l(:label_bid_respond_delete), {:controller => 'homework_attach', :action => 'destroy_jour', :object_id => jour, :user_id => jour.user,:jour_id =>homework.id },
<%= link_to(l(:label_bid_respond_delete), {:controller => 'homework_attach', :action => 'destroy_jour',
:object_id => jour,
:user_id => jour.user,
:homework_id =>homework.id },
:remote => true, :confirm => l(:text_are_you_sure), :title => l(:button_delete)) %>
<% end %>
<%= link_to l(:label_projects_feedback_respond),'',

View File

@ -1,35 +1,31 @@
//教师评论
<% if @cur_is_comprehensive_evaluation == "1" %>
<% if @is_teacher %>
HoverLi(4);
$('#jour_count_4').html('<%= @comprehensive_evaluation.count %>');
$('#tbc_04').html('<%= escape_javascript(render(:partial => 'homework_attach/jour',:locals => {:jours => @comprehensive_evaluation,:show_score => true,:show_name => true,:is_jour => false})) %>');
$('#jour_count_4').html('<%= @teacher_stars.count %>');
$('#tbc_04').html('<%= escape_javascript(render(:partial => 'homework_attach/review',:locals => {:review_list => @teacher_stars,:show_name => true})) %>');
//匿评
<% elsif @cur_is_comprehensive_evaluation == "2" %>
$('#add_jour').html('<%= escape_javascript(render(:partial => 'addjour', :locals => {:homework_attach => @homework, :sta => 0,
:is_comprehensive_evaluation => @is_comprehensive_evaluation,
:cur_type => @cur_type, :cur_page => @cur_page, :m_score => @m_score, :is_teacher => false})) %>');
<% elsif @is_anonymous_comments %>
HoverLi(5);
$('#jour_count_5').html('<%= @anonymous_comments.count %>');
$('#tbc_05').html('<%= escape_javascript(render(:partial => 'homework_attach/jour',:locals => {:jours => @anonymous_comments,:show_score => true,:show_name => false,:is_jour => false})) %>');
$('#jour_count_5').html('<%= @student_stars.count %>');
$('#tbc_05').html('<%= escape_javascript(render(:partial => 'homework_attach/review',:locals => {:review_list => @student_stars,:show_name => true})) %>');
//留言
<% else %>
HoverLi(3);
$('#jour_count_3').html('<%= @jours.count %>');
$('#tbc_03').html('<%= escape_javascript(render(:partial => 'homework_attach/jour',:locals => {:jours => @jour,:show_score => false,:show_name => true,:is_jour => true})) %>');
$('#jour_count_3').html('<%= @obj_count %>');
$('#tbc_03').html('<%= escape_javascript(render(:partial => 'homework_attach/jour',:locals => {:jours => @jour, :obj_pages => @obj_pages, :obj_count => @obj_count,:homework => @homework})) %>');
<% end %>
$('#new_form_user_message').val("");
$('#new_form_reference_user_id').val("");
<% if @cur_is_comprehensive_evaluation == "1" || @cur_is_comprehensive_evaluation == "2" %>
<% if @is_anonymous_comments || @is_teacher %>
<% if @cur_type == "1" %>
$("#tbc_01").html('<%= escape_javascript(render(:partial => 'homework_attach/homeworks_list',:locals => {:homeworks => @homework_list,
:homework_count => @obj_count,
:remote => false,:is_student_batch_homework => false})) %>');
<% elsif @cur_type == "2" || @cur_type == "3" || @cur_type == "4" %>
<% is_teacher = is_course_teacher(User.current,@homework.bid.courses.first) %>
$("#homework_li_<%= @homework.id%>").html('<%= escape_javascript(render(:partial => 'homework_attach/homework',:locals => {:homework => @result_homework || @homework,
:is_student_batch_homework => @is_student_batch_homework || false,
:is_my_homework => false, :is_teacher => is_teacher})) %>');
:is_my_homework => false, :is_teacher => @is_teacher})) %>');
<% end %>
<% end %>

View File

@ -1,19 +1,8 @@
<% if @journal_destroyed.nil? %>
alert('<%=l(:notice_failed_delete)%>');
<% else %>
<% if @is_comprehensive_evaluation == 1 %>
HoverLi(4);
$('#jour_count_4').html('<%= @comprehensive_evaluation.count %>');
$('#tbc_04').html('<%= escape_javascript(render(:partial => "homework_attach/jour",:locals => {:jours => @comprehensive_evaluation,:show_score => true,:show_name => true,:is_jour => false})) %>');
//匿评
<% elsif @is_comprehensive_evaluation == 2 %>
HoverLi(5);
$('#jour_count_5').html('<%= @anonymous_comments.count %>');
$('#tbc_05').html('<%= escape_javascript(render(:partial => "homework_attach/jour",:locals => {:jours => @anonymous_comments,:show_score => true,:show_name => false,:is_jour => false})) %>');
//留言
<% else %>
HoverLi(3);
$('#jour_count_3').html('<%= @jours.count %>');
$('#tbc_03').html('<%= escape_javascript(render(:partial => "homework_attach/jour",:locals => {:jours => @jour,:show_score => false,:show_name => true,:is_jour => true})) %>');
<% end %>
//只有留言才能被删除
HoverLi(3);
$('#jour_count_3').html('<%= @obj_count %>');
$('#tbc_03').html('<%= escape_javascript(render(:partial => "homework_attach/jour",:locals => {:jours => @jour, :obj_pages => @obj_pages, :obj_count => @obj_count, :homework => @homework})) %>');
<% end %>