This commit is contained in:
z9hang 2014-10-16 15:07:53 +08:00
commit 2cabec22f2
9 changed files with 107 additions and 14 deletions

View File

@ -14,7 +14,7 @@ class CoursesController < ApplicationController
menu_item l(:label_sort_by_influence), :only => :index
before_filter :can_show_course, :except => []
before_filter :find_course, :except => [ :index, :search,:list, :new,:join,:unjoin, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches]
before_filter :find_course, :except => [ :index, :search,:list, :new,:join,:unjoin, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches,:join_private_courses]
before_filter :authorize_course, :only => [:show, :settings, :edit, :update, :modules, :close, :reopen, :view_homework_attaches, :course]
before_filter :authorize_course_global, :only => [:view_homework_attaches, :new,:create]
before_filter :require_admin, :only => [:copy, :archive, :unarchive, :destroy, :calendar]
@ -26,21 +26,30 @@ class CoursesController < ApplicationController
def join
if User.current.logged?
course = Course.find(params[:object_id])
unless User.current.member_of_course? course
if params[:course_password] == course.password
members = []
members << Member.new(:role_ids => [10], :user_id => User.current.id)
course.members << members
StudentsForCourse.create(:student_id => User.current.id, :course_id => params[:object_id])
@state = 0
else
@state = 1
end
else
@state = 3
end
end
respond_to do |format|
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Course.find(params[:object_id]), :object_id => params[:object_id]} }
end
rescue Exception => e
@state = 4
respond_to do |format|
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => nil, :object_id => nil} }
end
end
def unjoin
@ -60,6 +69,12 @@ class CoursesController < ApplicationController
end
end
def join_private_courses
respond_to do |format|
format.js
end
end
#更新课程信息
def update
@course.safe_attributes = params[:course]

View File

@ -0,0 +1,60 @@
<!-- added by fq -->
<style>
input[type="submit"].bid_btn {
vertical-align: middle;
width: 60px;/*modified by ming*/
height: 25px;
line-height: 19px;
font-size: 14px;
color: rgb(0, 0, 0);
background: buttonface;/*url("/images/button/bg103.jpg") no-repeat scroll left top transparent;*/
padding: 0px 0px 4px 0px;
border-radius: 2px;
border: 1px solid rgb(148, 148, 148);
box-shadow: none;
text-shadow: none;
/*margin-top: -10px;*/
/*margin-right: -4px;*/
}
input[type="button"].bid_btn {
width: 60px;/*modified by ming*/
height: 25px;
line-height: 19px;
font-size: 14px;
color: rgb(0, 0, 0);
background: buttonface;/*url("/images/button/bg103.jpg") no-repeat scroll left top transparent;*/
padding: 0px 0px 4px 0px;
border-radius: 2px;
border: 1px solid rgb(148, 148, 148);
box-shadow: none;
text-shadow: none;
/*margin-top: -10px;*/
margin-right: -2px;
}
textarea:focus {
border: #d5dee9 1px solid;
}
</style>
<h3 class="title">加入公开课程或私有课程</h3>
<%= form_tag({:controller => 'courses',
:action => 'join'},
:remote => true,
:method => :post,
:id => 'new-watcher-form') do %>
<div>
<span>课程ID</span>
<%= text_field_tag 'object_id', nil, :style=>'width:80%'%>
<span style="padding-left: 55px;color: red;">(课程ID是课程的网址中出现的序号)</span>
</div>
<div>
<span>密码&nbsp;&nbsp;&nbsp;</span>
<%= text_field_tag 'course_password', nil, :style=>'width:80%'%>
</div>
<p class="buttons" style="padding-top: 10px; padding-bottom: 1px; margin-bottom: 1px">
<%= submit_tag l(:label_new_join), :name => nil, :class => "bid_btn", :onclick => "hideModal(this);" %>
<%= submit_tag l(:button_cancel), :name => nil, :class => "bid_btn", :onclick => "hideModal(this);", :type => 'button' %>
</p>
<% end %>

View File

@ -1,4 +1,6 @@
<% if object_id%>
$("#<%=object_id%>").replaceWith('<%= escape_javascript join_in_course_for_list(course, user) %>');
<% end %>
<% if @state %>
<% if @state == 0 %>
alert("加入成功")
@ -6,6 +8,10 @@ $("#<%=object_id%>").replaceWith('<%= escape_javascript join_in_course_for_list(
alert("密码错误")
<% elsif @state == 2 %>
alert("课程已过期\n请联系课程管理员重启课程。(在配置课程处)")
<% elsif @state == 3 %>
alert("您已经加入了课程");
<% elsif @state == 3 %>
alert("您已经的课程不存在")
<% else %>
alert("未知错误,请稍后再试")
<% end %>

View File

@ -0,0 +1,3 @@
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'join_private_course') %>');
showModal('ajax-modal', '400px');
$('#ajax-modal').addClass('new-watcher');

View File

@ -80,9 +80,9 @@
<% else %>
<%= join_in_course(@course, User.current) %>
<% end %>
<% unless User.current.member_of_course?(@course) %>
<%# unless User.current.member_of_course?(@course) %>
<!-- <%#= image_tag "/images/fav.png" %> -->
<% end %>
<%# end %>
<% end %>
</div>
</td>

View File

@ -56,6 +56,7 @@
<p class="buttons" style="padding-top: 10px; padding-bottom: 1px; margin-bottom: 1px">
<%= submit_tag l(:label_new_join), :name => nil, :class => "bid_btn", :onclick => "hideModal(this);" %>
<%= submit_tag l(:button_cancel), :name => nil, :class => "bid_btn", :onclick => "hideModal(this);", :type => 'button' %>
</p>
</td>
</tr></table>
<% end %>

View File

@ -3,6 +3,8 @@
<%= link_to(l(:label_course_new), {:controller => 'courses', :action => 'new'},
:class => 'icon icon-add') if User.current.allowed_to?(:add_course,nil, :global => true) %>
<% end %>
&nbsp;&nbsp;&nbsp;&nbsp;
<% end %>
<%= link_to l(:label_course_join_student), join_private_courses_courses_path ,:remote => true, :class => 'icon icon-add' %>
&nbsp;&nbsp;&nbsp;&nbsp;
<%= link_to l(:label_more), {:controller => 'courses', :action => 'index', :school_id => school_id} %>

View File

@ -127,6 +127,8 @@
<strong><%= l(:label_issue_feedback_activities)%></strong>
<%= link_to l(:label_my_question), newbie_send_path, {:class => 'orangeButton idea_btn', :style => "color: #EEEEEE"} %>
<%= link_to l(:label_my_feedback), suggestion_send_path, {:class => 'orangeButton idea_btn', :style => "color: #EEEEEE"} %>
<!-- 加入课程按钮 -->
</h3>
<span style="margin-top: -20px;float: right; display: block;"><%= link_to "更多>>", forums_path %></span>

View File

@ -31,7 +31,6 @@ RedmineApp::Application.routes.draw do
#match '/contests/:id/contestnotifications', :controller => 'contestnotifications', :action => 'index'
resources :homework_users
resources :no_uses
delete 'no_uses', :to => 'no_uses#delete'
@ -626,7 +625,12 @@ RedmineApp::Application.routes.draw do
get 'member', :controller => 'courses', :action => 'member', :as => 'member'
post 'finishcourse'
post 'restartcourse'
end
collection do
match 'join_private_courses', :via => [:get, :post]
end
match '/member', :to => 'courses#member', :as => 'member', :via => :get
resources :boards
resources :files, :only => [:index, :new, :create] do