2014-05-29 20:02:02 +08:00
module HomeworkAttachHelper
2014-06-06 10:28:37 +08:00
#判断是否具有删除的权限
2014-05-29 20:02:02 +08:00
def attach_delete ( project )
if User . current . logged? && ( User . current . admin? || ( ! Member . where ( 'user_id = ? and project_id = ?' , User . current . id , project . bid . courses . first . id ) . first . nil? && ( Member . where ( 'user_id = ? and project_id = ?' , User . current . id , project . bid . courses . first . id ) . first . roles & Role . where ( 'id = ? or id = ?' , 3 , 7 ) ) . size > 0 ) || project . user_id == User . current . id )
true
else
false
end
2014-06-06 10:28:37 +08:00
end
#作业添加、编辑界面的tab页
def homework_settings_tabs f
@f = f
2014-06-10 14:27:55 +08:00
tabs = [ { :name = > 'info' , :partial = > 'homework_attach/edit_homework' , :label = > :label_information_plural } ,
{ :name = > 'members' , :partial = > 'homework_attach/homework_member' , :label = > :label_member_plural }
2014-06-06 10:28:37 +08:00
]
end
2014-06-10 08:47:21 +08:00
#作业可选成员列表分页
def render_new_members_for_homework members
#scope = Principal.active.sorted.not_member_of(project).like(params[:q])
#scope = project.members
2014-06-10 17:33:31 +08:00
#principals = paginateHelper members,10
principals = members
2014-06-10 15:44:10 +08:00
#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]
2014-06-10 08:47:21 +08:00
s = content_tag ( 'div' , member_check_box_tags_ex ( 'membership[user_ids][]' , principals ) , :id = > 'principals' )
2014-06-10 15:44:10 +08:00
links = pagination_links_full ( @obj_pages , @obj_count , :per_page_links = > false ) { | text , parameters , options |
2014-06-10 17:33:31 +08:00
link_to text , get_homework_member_list_homework_attach_index_path ( parameters . merge ( :q = > params [ :q ] , bid_id : params [ :id ] || @bid ) ) , :remote = > true }
2014-06-10 15:44:10 +08:00
return s + content_tag ( 'div' , content_tag ( 'ul' , links ) , :class = > 'pagination_new' )
2014-05-29 20:02:02 +08:00
end
2014-06-10 08:47:21 +08:00
#扩展的checkbox生成
def member_check_box_tags_ex ( name , principals )
s = ''
principals . each do | member |
2014-06-10 15:44:10 +08:00
s << " <label> #{ check_box_tag name , member . id , false , :id = > nil } #{ h member . user . name } </label><br/> "
2014-06-10 08:47:21 +08:00
end
s . html_safe
end
2014-06-10 15:44:10 +08:00
def paginateHelper obj , pre_size = 20
@obj_count = obj . count
@obj_pages = Redmine :: Pagination :: Paginator . new @obj_count , pre_size , params [ 'page' ]
if obj . kind_of? ActiveRecord :: Base or obj . kind_of? ActiveRecord :: Relation
obj . limit ( @obj_pages . per_page ) . offset ( @obj_pages . offset )
elsif obj . kind_of? Array
obj [ @obj_pages . offset , @obj_pages . per_page ]
else
logger . error " [ApplicationController] Error : application_controller # paginateHelper ===> unknow category: #{ obj . class } "
raise RuntimeError , 'unknow type, Please input you type into this helper.'
end
end
2014-05-29 20:02:02 +08:00
end