diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 78ab33477..7e7126173 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -2,8 +2,8 @@ class StudentWorkController < ApplicationController layout "base_courses" include StudentWorkHelper before_filter :find_homework, :only => [:new, :index, :create] - before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score] - before_filter :member_of_course, :only => [:index, :new, :create, :show, :add_score] + before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work] + before_filter :member_of_course, :only => [:index, :new, :create, :show, :add_score, :praise_student_work] before_filter :author_of_work, :only => [:edit, :update, :destroy] def index @@ -166,6 +166,22 @@ class StudentWorkController < ApplicationController end end + #为作品点赞 + def praise_student_work + pt = PraiseTread.new + pt.user_id = User.current.id + pt.praise_tread_object_id = @work.id + pt.praise_tread_object_type = "StudentWork" + pt.praise_or_tread = 1 + if pt.save + respond_to do |format| + format.js + end + else + render_404 + end + end + private #获取作业 def find_homework diff --git a/app/helpers/student_work_helper.rb b/app/helpers/student_work_helper.rb index 94da5f152..990a563c4 100644 --- a/app/helpers/student_work_helper.rb +++ b/app/helpers/student_work_helper.rb @@ -50,4 +50,14 @@ module StudentWorkHelper end result end + + #获取赞的总数 + def praise_homework_count obj_id + PraiseTread.where("praise_tread_object_id = #{obj_id} AND praise_tread_object_type = 'StudentWork'").count + end + + #判断指定用户是不是已经赞过该作业 + def is_praise_homework user_id, obj_id + PraiseTread.where("user_id = #{user_id} AND praise_tread_object_id = #{obj_id} AND praise_tread_object_type = 'StudentWork'").empty? + end end \ No newline at end of file diff --git a/app/views/student_work/_show.html.erb b/app/views/student_work/_show.html.erb index fd5396b7f..97c6125f7 100644 --- a/app/views/student_work/_show.html.erb +++ b/app/views/student_work/_show.html.erb @@ -15,8 +15,8 @@ <% end%> <% if (@homework.homework_type != 1 || @homework.homework_detail_manual.comment_status == 3) && @work.user != User.current%> -
  • - 赞(10) +
  • + <%= render :partial => 'student_work_praise' %>
  • <% end%>
    diff --git a/app/views/student_work/_student_work_praise.html.erb b/app/views/student_work/_student_work_praise.html.erb new file mode 100644 index 000000000..4cabfd631 --- /dev/null +++ b/app/views/student_work/_student_work_praise.html.erb @@ -0,0 +1,5 @@ +<% if is_praise_homework User.current.id,@homework.id %> + <%= link_to "赞(#{praise_homework_count @homework.id})",praise_student_work_student_work_path(@homework), :remote => true,:class => 'orange_btn', :style => 'font-size:12px;'%> +<% else %> + <%= link_to "赞(#{praise_homework_count @homework.id})","javascript:void(0)",:class => 'grey_btn', :style => 'font-size:12px;'%> +<% end %> \ No newline at end of file diff --git a/app/views/student_work/praise_student_work.js.erb b/app/views/student_work/praise_student_work.js.erb new file mode 100644 index 000000000..dc6d57481 --- /dev/null +++ b/app/views/student_work/praise_student_work.js.erb @@ -0,0 +1 @@ +$('#student_work_praise_<%= @homework.id%>').html('<%= escape_javascript(render :partial => 'student_work_praise')%>'); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index ecdaac48c..1d57a091b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -94,6 +94,7 @@ RedmineApp::Application.routes.draw do resources :student_work do member do post 'add_score' + get 'praise_student_work' end collection do post 'add_score_reply'