This commit is contained in:
z9hang 2014-06-27 11:15:20 +08:00
commit 0717148a0a
5 changed files with 90 additions and 6 deletions

View File

@ -556,22 +556,47 @@ class CoursesController < ApplicationController
end end
end end
def get_courses
@user = User.current
membership = @user.coursememberships.all
membership.sort! {|older, newer| newer.created_on <=> older.created_on }
@memberships = []
membership.collect { |e|
@memberships.push(e)
}
@memberships_doing = []
@memberships_done = []
now_time = Time.now.year
@memberships.map { |e|
end_time = e.course.get_time.year
isDone = course_endTime_timeout?(e.course)
if isDone
@memberships_done.push e
else
@memberships_doing.push e
end
}
end
def finishcourse def finishcourse
yesterday = Date.today.prev_day.to_time yesterday = Date.today.prev_day.to_time
@course_prefs.endup_time = yesterday @course_prefs.endup_time = yesterday
@save_flag = @course_prefs.save @save_flag = @course_prefs.save
get_courses
respond_to do |format| respond_to do |format|
format.js format.js
end end
end end
def restartcourse def restartcourse
day = Time.parse("3000-01-01") day = Time.parse("3000-01-01")
@course_prefs.endup_time = day @course_prefs.endup_time = day
@save_flag = @course_prefs.save @save_flag = @course_prefs.save
get_courses
respond_to do |format| respond_to do |format|
format.js { format.js {

View File

@ -1,8 +1,12 @@
<% if @save_flag %> <% if @save_flag %>
<% if Rails.env.development? %> <% if Rails.env.development? %>
console.debug('课程修改成功:结束时间改为<%=Course.find_by_extra(@course.extra).try(:endup_time)%>'); console.debug('课程修改成功:结束时间改为<%=Course.find_by_extra(@course.extra).try(:endup_time)%>');
<% end %> <% end %>
$('#finish_course_<%=@course.id%>').replaceWith("<%= j(render partial: 'courses/set_course_time', :locals => {:course => @course} )%>") $('#content-title-top-div').html("<%= j(render partial: 'users/my_course_ex', :locals => {:memberships => @memberships,:user=>@user,
:memberships_doing=>@memberships_doing,:memberships_done=>@memberships_done} )%>")
//$('#finish_course_ <%=@course.id%>').replaceWith("<%= j(render partial: 'courses/set_course_time', :locals => {:course => @course} )%>")
<% else %> <% else %>
alert('权限不足,设置失败,请在论坛提交问题,等待管理员处理。'); alert('权限不足,设置失败,请在论坛提交问题,等待管理员处理。');
<% end %> <% end %>

View File

@ -0,0 +1,22 @@
<div class="user_course_list menu-div">
<div class="menu">
<%= link_to "#{l(:label_course_new)}", new_course_path, class: 'icon icon-add' if user == User.current %>
<ul>
<li mode='doing' class="on">进行中</li>
<li mode='end'>已完结</li>
</ul>
</div>
<div class="dyn_list_wrapper" mode='doing'>
<div class='created_course'>
<%= render :partial => 'users/course_form', :locals => {:memberships => memberships_doing} %>
</div>
</div>
<div class="dyn_list_wrapper hidden" mode='end'>
<div class="created_course ">
<%= render :partial => 'users/course_form', :locals => {:memberships => memberships_done} %>
</div>
</div>
</div>

View File

@ -1,4 +1,4 @@
<div class="content-title-top"> <div class="content-title-top" id="content-title-top-div">
<% if @memberships.empty? %> <% if @memberships.empty? %>
<% if @user != User.current %> <% if @user != User.current %>
<p class="font_description"> <p class="font_description">

View File

@ -0,0 +1,33 @@
<% if memberships.empty? %>
<% if user != User.current %>
<p class="font_description">
<%= l(:label_project_course_un) %>
</p>
<% else %>
<p class="font_description">
<!--teacher could create the course directly-->
<%= l(:label_project_course_unadd) %><%= link_to "#{l(:label_course_new)}", {:controller => 'courses', :action => 'new'}, :class => 'icon icon-add' %>
</p>
<% end %>
<% else %>
<%= render partial: 'users/course_list_have_entity_ex',:locals => {:user => user,:memberships_doing=>memberships_doing,:memberships_done=>memberships_done} %>
<% end %>
<script type="text/javascript">
$(document).ready(function() {
var $menu = $('.user_course_list .menu');
var $li_tags = $menu.find('[mode]');
var $dyn_list = $('.dyn_list_wrapper');
$menu.find('[mode]').each(function(index, el) {
$(el).click(function() {
mode = $(el).attr('mode');
$menu.find('[mode]').removeClass( "on" );
$( this ).addClass( "on" );
var wrapper = $('[mode='+mode+']')
$dyn_list.addClass( "hidden" );
wrapper.removeClass('hidden')
})
});
});
</script>