1.修改作业时实现作业添加参与人员与删除参与人员
2.homework_attach、homework_user、users关系添加 3.优化页面显示
This commit is contained in:
parent
130f9f87c2
commit
d0dd6eb781
|
@ -26,14 +26,40 @@ class HomeworkAttachController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def add_users users
|
||||
if users != nil && users.count > 0
|
||||
users.each do |user|
|
||||
@homework.homework_users.build(:user_id => user.id)
|
||||
@homework.save
|
||||
#作业添加成员(参与人员)
|
||||
def add_homework_users
|
||||
@homework = HomeworkAttach.find(params[:id])
|
||||
|
||||
if params[:membership]
|
||||
if params[:membership][:user_ids]
|
||||
attrs = params[:membership].dup
|
||||
user_ids = attrs.delete(:user_ids)
|
||||
user_ids.each do |user_id|
|
||||
@homework.homework_users.build(:user_id => user_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
@homework.save
|
||||
@hoemwork_users = users_for_homework(@homework)
|
||||
@members = members_for_homework(@homework,@hoemwork_users)
|
||||
@members = paginateHelper @members,10
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
#作业删除成员(参与人员)
|
||||
def destory_homework_users
|
||||
@homework = HomeworkAttach.find(params[:id])
|
||||
homework_user = @homework.homework_users.where("user_id = #{params[:user_id]}").first
|
||||
homework_user.destroy
|
||||
@hoemwork_users = users_for_homework(@homework)
|
||||
@members = members_for_homework(@homework,@hoemwork_users)
|
||||
@members = paginateHelper @members,10
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
bid = Bid.find params[:bid_id]
|
||||
|
@ -78,10 +104,10 @@ class HomeworkAttachController < ApplicationController
|
|||
def new
|
||||
@bid = Bid.find(params[:id])
|
||||
if User.current.admin? || User.current.member_of?(@bid.courses.first)
|
||||
#该课程的学生的集合
|
||||
@members = @bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and user_id <> #{User.current.id}", {:role_id => [5, 10]})
|
||||
#该课程的学生的集合(新建不实现功能:添加成员)
|
||||
#@members = @bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and user_id <> #{User.current.id}", {:role_id => [5, 10]})
|
||||
|
||||
@members = paginateHelper @members,10
|
||||
#@members = paginateHelper @members,10
|
||||
#@all_user = []
|
||||
#@bid.courses.first.members.each do |member|
|
||||
# @all_user << member.user
|
||||
|
@ -98,38 +124,43 @@ class HomeworkAttachController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
#获取作业成员的集合
|
||||
def get_homework_member_list
|
||||
@bid = Bid.find(params[:bid_id])
|
||||
if User.current.admin? || User.current.member_of?(@bid.courses.first)
|
||||
@homework = HomeworkAttach.includes(:homework_users).includes(:user).find(params[:bid_id])
|
||||
course = @homework.bid.courses.first
|
||||
if User.current.admin? || User.current.member_of?(course)
|
||||
@hoemwork_users = users_for_homework(@homework)
|
||||
@members = members_for_homework(@homework,@hoemwork_users)
|
||||
#该课程的学生的集合
|
||||
@members = @bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and user_id <> #{User.current.id}", {:role_id => [5, 10]})
|
||||
|
||||
#@members = course.members.joins(:member_roles).where("member_roles.role_id IN (:role_id)", {:role_id => [5, 10]})
|
||||
@members = paginateHelper @members,10
|
||||
else
|
||||
raise "error"
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
#获取指定作业的所有成员
|
||||
def members_for_homework homework
|
||||
people = []
|
||||
if homework != nil
|
||||
people << homework.user
|
||||
homework.homework_users do |homework_user|
|
||||
people << homework_user.user
|
||||
def users_for_homework homework
|
||||
homework.nil? ? [] : (homework.users + [homework.user])
|
||||
end
|
||||
else
|
||||
end
|
||||
people
|
||||
|
||||
#获取可选成员列表
|
||||
#homework:作业
|
||||
#users:该作业所有成员
|
||||
def members_for_homework homework,users
|
||||
homework.bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and user_id not in (:users)", {:role_id => [5, 10],:users => users})
|
||||
end
|
||||
|
||||
def edit
|
||||
@homework = HomeworkAttach.find(params[:id])
|
||||
@homework = HomeworkAttach.includes(:homework_users).includes(:user).find(params[:id])
|
||||
if User.current.admin? || User.current.member_of?(@homework.bid.courses.first)
|
||||
#@members = @homework.bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id)", {:role_id => [5, 10]})
|
||||
@hoemwork_users = users_for_homework(@homework)
|
||||
@members = members_for_homework(@homework,@hoemwork_users)
|
||||
@members = paginateHelper @members,10
|
||||
else
|
||||
render_403 :message => :notice_not_authorized
|
||||
end
|
||||
|
@ -137,7 +168,8 @@ class HomeworkAttachController < ApplicationController
|
|||
|
||||
def update
|
||||
@homework = HomeworkAttach.find(params[:id])
|
||||
if User.current.admin? || User.current.member_of?(@homework.bid.courses.first)
|
||||
course = @homework.bid.courses.first
|
||||
if User.current.admin? || User.current.member_of?(course)
|
||||
name = params[:homework_name]
|
||||
description = params[:homework_description]
|
||||
@homework.name = name
|
||||
|
|
|
@ -20,15 +20,16 @@ module HomeworkAttachHelper
|
|||
#scope = Principal.active.sorted.not_member_of(project).like(params[:q])
|
||||
#scope = project.members
|
||||
#principals = paginateHelper members,10
|
||||
principals = members
|
||||
#principals = members
|
||||
#principal_count = members.count
|
||||
#limit = 10
|
||||
#principal_pages = Redmine::Pagination::Paginator.new principal_count, limit, params['page'] #by young
|
||||
#offset ||= principal_pages.offset
|
||||
#principals = members[offset, limit]
|
||||
s = content_tag('div', member_check_box_tags_ex('membership[user_ids][]', principals), :id => 'principals')
|
||||
users = members.map(&:user)
|
||||
s = content_tag('div', member_check_box_tags_ex('membership[user_ids][]', users), :id => 'principals')
|
||||
links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false) {|text, parameters, options|
|
||||
link_to text, get_homework_member_list_homework_attach_index_path( parameters.merge(:q => params[:q], bid_id: params[:id]||@bid)), :remote => true }
|
||||
link_to text, get_homework_member_list_homework_attach_index_path( parameters.merge(:q => params[:q], bid_id: params[:id]||@homework)), :remote => true }
|
||||
return s + content_tag('div', content_tag('ul', links), :class => 'pagination_new')
|
||||
end
|
||||
|
||||
|
@ -36,7 +37,7 @@ module HomeworkAttachHelper
|
|||
def member_check_box_tags_ex(name, principals)
|
||||
s = ''
|
||||
principals.each do |member|
|
||||
s << "<label>#{ check_box_tag name, member.id, false, :id => nil } #{h member.user.name }</label><br/>"
|
||||
s << "<label>#{ check_box_tag name, member.id, false, :id => nil } #{h member.name }</label><br/>"
|
||||
end
|
||||
s.html_safe
|
||||
end
|
||||
|
|
|
@ -7,6 +7,7 @@ class HomeworkAttach < ActiveRecord::Base
|
|||
belongs_to :bid
|
||||
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
|
||||
has_many :homework_users, :dependent => :destroy
|
||||
has_many :users, :through => :homework_users
|
||||
seems_rateable :allow_update => true, :dimensions => :quality
|
||||
|
||||
safe_attributes "bid_id",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class HomeworkUser < ActiveRecord::Base
|
||||
attr_accessible :homework_attach_id, :user_id
|
||||
|
||||
belongs_to :homework_attach
|
||||
belongs_to :homework_attach, :foreign_key => :homework_attach_id
|
||||
belongs_to :user
|
||||
end
|
||||
|
|
|
@ -73,7 +73,8 @@ class User < Principal
|
|||
['none', :label_user_mail_option_none]
|
||||
]
|
||||
|
||||
belongs_to :homework_user
|
||||
has_many :homework_users
|
||||
has_many :homework_attaches, :through => :homework_users
|
||||
|
||||
has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)},
|
||||
:after_remove => Proc.new {|user, group| group.user_removed(user)}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<%= error_messages_for 'member' %>
|
||||
<div style="float:left; width:60%;height:400px;padding-left: 10px;padding-right: 10px">
|
||||
<div style="float:left; width:60%;padding-left: 10px;padding-right: 10px"
|
||||
xmlns="http://www.w3.org/1999/html" id = "homework_of_users">
|
||||
<table class="list members" style="width: 100%">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -9,25 +10,34 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% for m in (1..10) %>
|
||||
<tr id="member-<%= User.current.id %>" class="<%= cycle 'odd', 'even' %> member" style="text-align: center">
|
||||
<td style="width: 40%"><%= link_to_user User.current %></td>
|
||||
<!-- 发布人员不能被删除,将发布人员放在第一位 -->
|
||||
<tr id="member-<%= homework.user.id %>" class="<%= cycle 'odd', 'even' %> member" style="text-align: center">
|
||||
<td style="width: 40%"><%= link_to_user homework.user %></td>
|
||||
<td style="text-align: center;width: 50%"> 发布人员 </td>
|
||||
<td><a>删除</a></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<% hoemwork_users.each do |user| %>
|
||||
<tr id="member-<%= user.id %>" class="<%= cycle 'odd', 'even' %> member" style="text-align: center">
|
||||
<% if homework.user != user %>
|
||||
<td style="width: 40%"><%= link_to_user user %></td>
|
||||
<td style="text-align: center;width: 50%"> 开发人员 </td>
|
||||
<td><%= link_to l(:button_delete),destory_homework_users_homework_attach_path(:user_id=>user),:remote => true, :method => :post %></td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="splitcontentright" style="width: 37%;height: 400px">
|
||||
<div class="splitcontentright" style="width: 37%">
|
||||
<%= form_for(hoemwork_users, {:url => add_homework_users_homework_attach_path(homework), :remote => true, :method => :post}) do |f| %>
|
||||
<fieldset>
|
||||
<legend><%= l(:label_member_new) %></legend>
|
||||
|
||||
<p><%= label_tag "principal_search", l(:label_principal_search) %><%= text_field_tag 'principal_search', nil %></p>
|
||||
<div id="principals_for_new_member">
|
||||
<%= render_new_members_for_homework(members) %>
|
||||
</div>
|
||||
<p><%= submit_tag l(:button_add), :id => 'member-add-submit' %></p>
|
||||
</fieldset>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
$('#content2').html('<%= escape_javascript(render(:partial => 'homework_member', :locals => {:members => @members,:hoemwork_users =>@hoemwork_users,:homework => @homework} )) %>');
|
|
@ -0,0 +1 @@
|
|||
$('#content2').html('<%= escape_javascript(render(:partial => 'homework_member', :locals => {:members => @members,:hoemwork_users =>@hoemwork_users,:homework => @homework} )) %>');
|
|
@ -1,5 +1,29 @@
|
|||
<p style="font-weight: bold; color: rgb(237,137,36)" xmlns="http://www.w3.org/1999/html"> <%=raw l(:label_new_homework)%> </p>
|
||||
<div class="box">
|
||||
<script type="text/javascript">
|
||||
function switchTab(ProTag) {
|
||||
var display_index = 3 - ProTag;
|
||||
document.getElementById("tab" + ProTag).className = "selected";
|
||||
document.getElementById("tab" + display_index).className = "";
|
||||
document.getElementById("content" + ProTag).style.display = "";
|
||||
document.getElementById("content" + display_index).style.display = "none";
|
||||
}
|
||||
</script>
|
||||
|
||||
<p style="font-weight: bold; color: rgb(237,137,36)" xmlns="http://www.w3.org/1999/html"> <%=raw l(:label_edit_homework)%> </p>
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li>
|
||||
<a id = "tab1" href="#" class = "selected" onclick="switchTab(1);this.blur();return false;">
|
||||
<%= l(:label_information_plural) %>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a id="tab2" href="#" onclick="switchTab(2); this.blur(); return false;">
|
||||
<%= l(:label_member_plural) %>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="box" id="content1">
|
||||
<%= form_for(@homework) do |f|%>
|
||||
<p style=" padding: 3px 0 3px 0;padding-left: 50px; clear:left;">
|
||||
<strong>标 题:</strong>
|
||||
|
@ -33,3 +57,7 @@
|
|||
</p>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div id="content2" style="display: none" >
|
||||
<%= render :partial => "homework_member",:locals => {:members => @members,:hoemwork_users =>@hoemwork_users,:homework => @homework} %>
|
||||
</div>
|
||||
|
|
|
@ -1,13 +1,3 @@
|
|||
<script type="text/javascript">
|
||||
function switchTab(ProTag) {
|
||||
var display_index = 3 - ProTag;
|
||||
document.getElementById("tab" + ProTag).className = "selected";
|
||||
document.getElementById("tab" + display_index).className = "";
|
||||
document.getElementById("content" + ProTag).style.display = "";
|
||||
document.getElementById("content" + display_index).style.display = "none";
|
||||
}
|
||||
</script>
|
||||
|
||||
<p style="font-weight: bold; color: rgb(237,137,36)" xmlns="http://www.w3.org/1999/html"> <%=h l(:label_new_homework)%> </p>
|
||||
<div class="box">
|
||||
<%= form_for('new_form', :method => :post,
|
||||
|
@ -16,31 +6,28 @@
|
|||
:user_id => User.current.id,
|
||||
:bid_id => @bid
|
||||
}) do |f|%>
|
||||
<p style=" padding: 3px 0 3px 0;padding-left: 50px; clear:left;">
|
||||
<strong>标 题:</strong>
|
||||
<%= f.text_field "name", :required => true, :size => 60, :style => "width:490px;" %>
|
||||
</p>
|
||||
<p style=" padding: 3px 0 3px 0;padding-left: 50px; clear:left;">
|
||||
<strong style="vertical-align: top">描 述:</strong>
|
||||
<span style="margin-left:-10px;padding-right: 20px;">
|
||||
<%= f.text_area "description", :rows => 8, :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;" %>
|
||||
</span>
|
||||
</p>
|
||||
<p style="padding-left: 60px">
|
||||
<fieldset style="text-align: left;">
|
||||
<legend>
|
||||
<%= l(:label_attachment_plural) %>
|
||||
</legend>
|
||||
<p style=" padding: 3px 0 3px 0;padding-left: 50px; clear:left;">
|
||||
<%= render :partial => 'attachments/form' %>
|
||||
</p>
|
||||
</fieldset>
|
||||
</p>
|
||||
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li>
|
||||
<a id = "tab1" href="#" class = "selected" onclick="switchTab(1);this.blur();return false;">
|
||||
<%= l(:label_information_plural) %>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a id="tab2" href="#" onclick="switchTab(2); this.blur(); return false;">
|
||||
<%= l(:label_member_plural) %>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div id="content1">
|
||||
<%= render :partial => "new_homework",:locals => {:f => f} %>
|
||||
</div>
|
||||
|
||||
<div id="content2" style="display: none">
|
||||
<%= render :partial => "homework_member",:locals => {:members => @members} %>
|
||||
</div>
|
||||
|
||||
<p style="padding-left: 60px;padding-top: 10px;">
|
||||
<p style="padding-left: 60px;padding-top: 5px;">
|
||||
<span >
|
||||
<%= submit_tag t(:label_button_ok), :sta => 0, :class => "enterprise"%>
|
||||
</span>
|
||||
|
|
|
@ -30,6 +30,11 @@ RedmineApp::Application.routes.draw do
|
|||
match 'addjours', via: [:get, :post]
|
||||
match 'add_jour_reply', via: [:get,:post]
|
||||
match 'destroy_jour', via: [:get,:post]
|
||||
|
||||
end
|
||||
member do
|
||||
match 'add_homework_users', via:[:get,:post]
|
||||
match 'destory_homework_users',via:[:get,:post]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue