Merge branch 'cxt_course' into develop

This commit is contained in:
cxt 2016-10-08 14:24:47 +08:00
commit 6ef45a094f
9 changed files with 49 additions and 25 deletions

View File

@ -45,12 +45,12 @@ class SyllabusMemberController < ApplicationController
member = SyllabusMember.find(params[:id])
@syllabus = member.syllabus
members = @syllabus.syllabus_members
if params[:opr] == 'up' && member.rank > 2
if params[:opr] == 'up' && member.rank > 1
before_mem = members.where("rank = #{member.rank - 1}").first
if before_mem && member.update_attribute('rank', member.rank - 1)
before_mem.update_attribute('rank', before_mem.rank + 1)
end
elsif params[:opr] == 'down' && member.rank > 1 && member.rank < members.count
elsif params[:opr] == 'down' && member.rank < members.count
after_mem = members.where("rank = #{member.rank + 1}").first
if after_mem && member.update_attribute('rank', member.rank + 1)
after_mem.update_attribute('rank', after_mem.rank - 1)

View File

@ -33,6 +33,8 @@ class SyllabusesController < ApplicationController
@syllabus.user_id = User.current.id
@syllabus.description = Message.where("id = 19412").first.nil? ? '' : Message.where("id = 19412").first.content
if @syllabus && @syllabus.save
member = SyllabusMember.create(:user_id => @syllabus.user_id, :rank => 1)
@syllabus.syllabus_members << member
respond_to do |format|
flash[:notice] = l(:notice_successful_create)
format.html {redirect_to syllabus_path(@syllabus)}

View File

@ -3578,7 +3578,9 @@ def get_group_member_names work
end
def course_syllabus_option user = User.current
syllabuses = user.syllabuses
syllabus_members = SyllabusMember.where("user_id = #{user.id}")
syllabus_ids = syllabus_members.empty? ? "(-1)" : "(" + syllabus_members.map{|mem| mem.syllabus_id}.join(',') + ")"
syllabuses = Syllabus.where("id in #{syllabus_ids}")
type = []
option1 = []
option1 << "请选择课程"

View File

@ -853,6 +853,13 @@ class User < Principal
OrgMember.where("user_id =? and organization_id =?", self.id, org.id).count > 0
end
def member_of_syl?(syllabus)
if !self.logged?
return false
end
SyllabusMember.where("user_id =? and syllabus_id =?", self.id, syllabus.id).count > 0
end
def admin_of_org?(org)
if self.admin?
return true

View File

@ -32,8 +32,9 @@
</li>
<li class="ml45 mb10">
<label><span class="c_red">*</span>&nbsp;<%= l(:label_tags_syllabus_name)%>&nbsp;&nbsp;</label>
<%= select_tag :syllabus_id,options_for_select(course_syllabus_option,@course.syllabus_id), {:id=>"edit_syllabus_id", :class=>"syllabus_input", :style=>'width:210px'} %>
<span class="c_red" id="edit_syllabus_notice">如果列表中没有对应的课程,请您先<%=link_to '创建课程', new_syllabus_path(),:target => '_blank', :class => 'ml5 green_btn_share c_white'%>,然后【刷新】</span>
<span><%=@course.syllabus.title %></span>
<%#= select_tag :syllabus_id,options_for_select(course_syllabus_option,@course.syllabus_id), {:id=>"edit_syllabus_id", :class=>"syllabus_input", :style=>'width:210px'} %>
<!--<span class="c_red" id="edit_syllabus_notice">如果列表中没有对应的课程,请您先<%#=link_to '创建课程', new_syllabus_path(),:target => '_blank', :class => 'ml5 green_btn_share c_white'%>,然后【刷新】</span>-->
</li>
<li class="ml45">
<label><span class="c_red">*</span>&nbsp;<%= l(:label_tags_course_name)%>&nbsp;&nbsp;</label>

View File

@ -75,9 +75,9 @@
</div>
</div>
<% else %>
<div class="icons_tishi"><img src="../images/sy/icons_tan.png" width="110" height="110" alt="" ></div>
<% if User.current == @syllabus.user %>
<p class="sy_tab_con_p">您建立的课程还未创建班级,请
<div class="icons_tishi"><img src="/images/sy/icons_tan.png" width="110" height="110" alt="" ></div>
<% if User.current.member_of_syl?(@syllabus) %>
<p class="sy_tab_con_p">课程还未创建班级,请
<%= link_to "新建班级", new_course_path(:host=> Setting.host_course, :syllabus_id => @syllabus.id), :class => "sy_corange", :target => '_blank'%>
,谢谢啦!</p>
<% else %>

View File

@ -13,13 +13,14 @@
</tr>
</thead>
<tbody>
<% count = @members.count %>
<% @members.each_with_index do |member, i| %>
<% user = member.user %>
<% allow_delete = @syllabus.courses.where(:tea_id => member.user_id).empty? && i != 0 %>
<% allow_delete = is_admin && @syllabus.courses.where(:tea_id => member.user_id).empty? %>
<tr>
<td><%= member.rank %></td>
<td>
<% if member.rank == 1 %>
<% if user == @syllabus.user %>
<div style="display: inline-block"><span class="sy_new_name fl"><%= user.show_name %></span><span class="sy_new_orange ml5 fl mt12">创建者</span></div>
<% else %>
<span class="sy_new_long_name"><%= user.show_name %></span>
@ -35,23 +36,20 @@
<td><%= courses.where("tea_id != #{user.id}").count %></td>
<% if is_admin %>
<td>
<% if i == 0 %>
&nbsp;
<% if user == @syllabus.user %>
<% elsif allow_delete %>
<%= link_to('删除', {:controller => 'syllabus_member', :action => 'destroy', :id => member.id, :syllabus => @syllabus.id},:remote => true, :method => 'delete', :confirm => l(:text_are_you_sure), :class => "fr sy_btn_grey mr5", :title => l(:button_delete)) %>
<% else %>
<% if allow_delete %>
<%= link_to('删除', {:controller => 'syllabus_member', :action => 'destroy', :id => member.id, :syllabus => @syllabus.id},:remote => true, :method => 'delete', :confirm => l(:text_are_you_sure), :class => "fr sy_btn_grey mr5", :title => l(:button_delete)) %>
<% else %>
<a href="javascript:void(0)" class="fr sy_btn_grey mr5" title="该老师已在本课程下创建了班级,不能删除">删除</a>
<% end %>
<% if i == 1 %>
<%= link_to('下移', {:controller => 'syllabus_member', :action => 'update_rank', :id => member.id, :syllabus => @syllabus.id, :opr => 'down'},:remote => true, :method => 'post', :class => "fr sy_btn_blue mr5", :title => '下移') %>
<% elsif i == @members.count - 1 %>
<%= link_to('上移', {:controller => 'syllabus_member', :action => 'update_rank', :id => member.id, :syllabus => @syllabus.id, :opr => 'up'},:remote => true, :method => 'post', :class => "fr sy_btn_blue mr5", :title => '上移') %>
<% else %>
<%= link_to('下移', {:controller => 'syllabus_member', :action => 'update_rank', :id => member.id, :syllabus => @syllabus.id, :opr => 'down'},:remote => true, :method => 'post', :class => "fr sy_btn_blue mr5", :title => '下移') %>
<%= link_to('上移', {:controller => 'syllabus_member', :action => 'update_rank', :id => member.id, :syllabus => @syllabus.id, :opr => 'up'},:remote => true, :method => 'post', :class => "fr sy_btn_blue mr5", :title => '上移') %>
<% end %>
<a href="javascript:void(0)" class="fr sy_btn_grey mr5" title="该老师已在本课程下创建了班级,不能删除">删除</a>
<% end %>
<% if i != 0 && i < count - 1 %>
<%= link_to('下移', {:controller => 'syllabus_member', :action => 'update_rank', :id => member.id, :syllabus => @syllabus.id, :opr => 'down'},:remote => true, :method => 'post', :class => "fr sy_btn_blue mr5", :title => '下移') %>
<%= link_to('上移', {:controller => 'syllabus_member', :action => 'update_rank', :id => member.id, :syllabus => @syllabus.id, :opr => 'up'},:remote => true, :method => 'post', :class => "fr sy_btn_blue mr5", :title => '上移') %>
<% elsif i < count - 1 %>
<%= link_to('下移', {:controller => 'syllabus_member', :action => 'update_rank', :id => member.id, :syllabus => @syllabus.id, :opr => 'down'},:remote => true, :method => 'post', :class => "fr sy_btn_blue mr5", :title => '下移') %>
<% elsif i == count - 1 %>
<%= link_to('上移', {:controller => 'syllabus_member', :action => 'update_rank', :id => member.id, :syllabus => @syllabus.id, :opr => 'up'},:remote => true, :method => 'post', :class => "fr sy_btn_blue mr5", :title => '上移') %>
<% end %>
</td>
<% end %>
</tr>

View File

@ -5,6 +5,7 @@
$(function() {
sd_create_editor_from_data(<%= @syllabus.id %>, null, "100%", "<%= @syllabus.class.to_s %>");
showNormalImage('syllabus_description_<%= @syllabus.id %>');
autoUrl('syllabus_description_<%= @syllabus.id %>');
});
</script>
<ul id="sy_tab_nav">

View File

@ -0,0 +1,13 @@
class AddSyllabusMembers < ActiveRecord::Migration
def up
Syllabus.all.each do |syllabus|
if syllabus.syllabus_members.empty?
member = SyllabusMember.create(:user_id => syllabus.user_id, :rank => 1)
syllabus.syllabus_members << member
end
end
end
def down
end
end