This commit is contained in:
huang 2015-08-15 16:51:28 +08:00
commit f731af0134
12 changed files with 77 additions and 97 deletions

View File

@ -106,74 +106,17 @@ class CoursesController < ApplicationController
# 课程搜索
# add by nwb
def search
courses_all = Course.all_course
name = params[:name]
if name.blank?
@courses = []
@courses_all = []
@course_count = 0
@course_pages = Paginator.new @course_count, per_page_option, params['page']
if params[:name].empty?
courses = Course.visible
@courses = paginateHelper courses,10
else
@courses = courses_all.visible
if params[:name].present?
@courses_all = @courses.like(params[:name])
else
@courses_all = @courses;
end
@course_count = @courses_all.count
@course_pages = Paginator.new @course_count, per_page_option, params['page']
# 课程的动态数
# @course_activity_count=Hash.new
# @courses_all.each do |course|
# @course_activity_count[course.id]=0
# end
#
# case params[:course_sort_type]
# when '0'
# @courses = @courses_all.order("created_at desc")
# @s_type = 0
# @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
#
# @course_activity_count=get_course_activity @courses,@course_activity_count
#
# when '1'
# @courses = @courses_all.order("course_ac_para desc")
# @s_type = 1
# @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
#
# @course_activity_count=get_course_activity @courses,@course_activity_count
#
# when '2'
# @courses = @courses_all.order("watchers_count desc")
# @s_type = 2
# @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
#
# @course_activity_count=get_course_activity @courses,@course_activity_count
#
# when '3'
# @course_activity_count=get_course_activity @courses_all,@course_activity_count_array
# @courses=handle_course @courses_all,@course_activity_count
# @s_type = 3
# @courses = @courses[@course_pages.offset, @course_pages.per_page]
#
# else
# @s_type = 0
# @courses = @courses_all.order("created_at desc")
# @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
#
# @course_activity_count=get_course_activity @courses,@course_activity_count
#
# end
courses = Course.visible.where("LOWER(name) like '%#{params[:name].to_s.downcase}%'")
@courses = paginateHelper courses,10
end
respond_to do |format|
format.html {
render :layout => 'course_base'
scope = Course
unless params[:closed]
scope = scope.active
end
}
format.atom {
courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all

View File

@ -704,7 +704,7 @@ module CoursesHelper
url = course_feedback_path(activity.course)
when "Poll"
title = "问卷&nbsp;" + activity.course_act.polls_name
url = poll_index_path(:polls_type => "Course", :polls_group_id => activity.course_id)
url = poll_path(activity.course_act_id)
end
end
link_to title.gsub(/<(?!img)[^>]*>/,'').html_safe, url, :class => "problem_tit c_dblue fl fb"

View File

@ -10,7 +10,7 @@ class Poll < ActiveRecord::Base
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
# 课程动态
has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy
after_create :act_as_activity, :act_as_course_activity
before_save :act_as_activity, :act_as_course_activity
acts_as_event :title => Proc.new {|o| "#{l(:label_course_poll)}: #{o.polls_name}" },
:description => :polls_description,
@ -32,7 +32,11 @@ class Poll < ActiveRecord::Base
#课程动态公共表记录
def act_as_course_activity
if self.polls_type == "Course"
self.course_acts << CourseActivity.new(:user_id => self.user_id,:course_id => self.polls_group_id)
if self.polls_status == 2 #问卷是发布状态
self.course_acts << CourseActivity.new(:user_id => self.user_id,:course_id => self.polls_group_id)
elsif self.polls_status == 1 #问卷是新建状态
self.course_acts.destroy_all
end
end
end
end

View File

@ -39,17 +39,17 @@
<% end %>
</div>
<% if @courses.size == 0 %>
<%= render :partial => 'layouts/no_content'%>
<% if @courses && !@courses.empty? %>
<div id="courses-index">
<%= render_course_hierarchy(@courses)%>
</div>
<% else %>
<div id="courses-index">
<%= render_course_hierarchy(@courses)%>
</div>
<%= render :partial => 'layouts/no_content'%>
<% end %>
<div class="pagination">
<ul>
<%= pagination_links_full @course_pages %>
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false %>
</ul>
</div>

View File

@ -24,7 +24,7 @@
<%= course_activity_desc activity%>
<br />
<div class="cl"></div>
<%= l :label_activity_time %> <%= format_time(activity.created_at) %>
<%= activity.course_act_type == "Course" ? l(:label_create_time) : l(:label_activity_time) %> <%= format_time(activity.created_at) %>
</p>
<%= link_to_attachments_course(activity.course_act) if activity.course_act_type.to_s == "News" %>
</div>

View File

@ -48,7 +48,8 @@
<ul class="ml10">
<li>
<label class="label02">迟交扣分:&nbsp;</label>
<%= select_tag :late_penalty,options_for_select(late_penalty_option,homework.late_penalty), {:class => "fl mb10 h26 w70"} %>
<%#= select_tag :late_penalty,options_for_select(late_penalty_option,homework.late_penalty), {:class => "fl mb10 h26 w70"} %>
<input type="number" value="<%= homework.late_penalty%>" min="0" max="50" class="fl mb10 h26 w70" name="late_penalty" onkeyup="check_late_penalty()">
<span class="fl mt5">&nbsp;分</span>
<div class="cl"></div>
</li>

View File

@ -43,7 +43,8 @@
<li>
<label class="label02">迟交扣分:&nbsp;</label>
<%= select_tag :late_penalty,options_for_select(late_penalty_option,homework.late_penalty), {:class => "fl mb10 h26 w70"} %>
<%#= select_tag :late_penalty,options_for_select(late_penalty_option,homework.late_penalty), {:class => "fl mb10 h26 w70"} %>
<input type="number" value="<%= homework.late_penalty%>" min="0" max="50" class="fl mb10 h26 w70" name="late_penalty" onkeyup="check_late_penalty()">
<span class="fl mt5">&nbsp;分</span>
<div class="cl"></div>
</li>

View File

@ -1,22 +0,0 @@
class UpdateCourseActivityTime < ActiveRecord::Migration
def up
count = CourseActivity.all.count / 10 + 1
transaction do
for i in 1 ... count do i
CourseActivity.page(i).per(10).each do |activity|
if activity.course_act
if activity.course_act.respond_to?("created_at")
activity.created_at = activity.course_act.created_at
elsif activity.course_act.respond_to?("created_on")
activity.created_at = activity.course_act.created_on
end
activity.save
end
end
end
end
end
def down
end
end

View File

@ -0,0 +1,13 @@
class ChangeAttachmentTime < ActiveRecord::Migration
def up
Attachment.where("container_type = 'Course'").each do |attachment|
if attachment.container && attachment.container.created_at.to_i > attachment.created_on.to_i
attachment.created_on = attachment.container.created_at + 3600 * 24
attachment.save
end
end
end
def down
end
end

View File

@ -0,0 +1,22 @@
class UpdateCourseActivityTime < ActiveRecord::Migration
def up
count = CourseActivity.all.count / 10 + 1
transaction do
for i in 1 ... count do i
CourseActivity.page(i).per(10).each do |activity|
if activity.course_act
if activity.course_act.respond_to?("created_at")
activity.created_at = activity.course_act.created_at
elsif activity.course_act.respond_to?("created_on")
activity.created_at = activity.course_act.created_on
end
activity.save
end
end
end
end
end
def down
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20150811083234) do
ActiveRecord::Schema.define(:version => 20150814031258) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false

View File

@ -412,6 +412,24 @@ function regex_homework_name()
}
}
//处理迟交扣分
function check_late_penalty()
{
var obj = $("input[name='late_penalty']");
var regex = /^\d+$/;
if(regex.test(obj.val()))
{
if(obj.val() > 50)
{
obj.val("50");
}
}
else
{
obj.val("0");
}
}
//验证匿评数量
function regex_evaluation_num()
{