From 7f3bb0be637c455bc17166b3c97647b898ba4fa2 Mon Sep 17 00:00:00 2001 From: cxt Date: Sat, 8 Oct 2016 13:54:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=99=E5=B8=88=E5=9B=A2=E9=98=9F=E4=B8=AD?= =?UTF-8?q?=E4=B8=8A=E7=A7=BB=E3=80=81=E4=B8=8B=E7=A7=BB=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E7=9A=84=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/syllabus_member_controller.rb | 4 +-- app/models/user.rb | 7 ++++ .../syllabuses/_syllabus_course_list.html.erb | 4 +-- .../syllabuses/_syllabus_member_list.html.erb | 32 +++++++++---------- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/app/controllers/syllabus_member_controller.rb b/app/controllers/syllabus_member_controller.rb index ac686c0a2..b6da3290e 100644 --- a/app/controllers/syllabus_member_controller.rb +++ b/app/controllers/syllabus_member_controller.rb @@ -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) diff --git a/app/models/user.rb b/app/models/user.rb index c1a830809..3386836ed 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/syllabuses/_syllabus_course_list.html.erb b/app/views/syllabuses/_syllabus_course_list.html.erb index 26eda1c3b..05219f4d0 100644 --- a/app/views/syllabuses/_syllabus_course_list.html.erb +++ b/app/views/syllabuses/_syllabus_course_list.html.erb @@ -76,8 +76,8 @@ <% else %>
- <% if User.current == @syllabus.user %> -

您建立的课程还未创建班级,请 + <% if User.current.member_of_syl?(@syllabus) %> +

该课程还未创建班级,请 <%= link_to "新建班级", new_course_path(:host=> Setting.host_course, :syllabus_id => @syllabus.id), :class => "sy_corange", :target => '_blank'%> ,谢谢啦!

<% else %> diff --git a/app/views/syllabuses/_syllabus_member_list.html.erb b/app/views/syllabuses/_syllabus_member_list.html.erb index 2a726ac18..84bbe1d01 100644 --- a/app/views/syllabuses/_syllabus_member_list.html.erb +++ b/app/views/syllabuses/_syllabus_member_list.html.erb @@ -13,13 +13,14 @@ + <% 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? %> <%= member.rank %> - <% if member.rank == 1 %> + <% if user == @syllabus.user %>
<%= user.show_name %>创建者
<% else %> <%= user.show_name %> @@ -35,23 +36,20 @@ <%= courses.where("tea_id != #{user.id}").count %> <% if is_admin %> - <% if i == 0 %> -   + <% 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 %> - 删除 - <% 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 %> + 删除 <% 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 %> <% end %>