Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

groups_controller.rb 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2012 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. class GroupsController < ApplicationController
  18. layout 'admin'
  19. before_filter :require_admin
  20. helper :custom_fields
  21. # GET /groups
  22. # GET /groups.xml
  23. def index
  24. @groups = Group.find(:all, :order => 'lastname')
  25. respond_to do |format|
  26. format.html # index.html.erb
  27. format.xml { render :xml => @groups }
  28. end
  29. end
  30. # GET /groups/1
  31. # GET /groups/1.xml
  32. def show
  33. @group = Group.find(params[:id])
  34. respond_to do |format|
  35. format.html # show.html.erb
  36. format.xml { render :xml => @group }
  37. end
  38. end
  39. # GET /groups/new
  40. # GET /groups/new.xml
  41. def new
  42. @group = Group.new
  43. respond_to do |format|
  44. format.html # new.html.erb
  45. format.xml { render :xml => @group }
  46. end
  47. end
  48. # GET /groups/1/edit
  49. def edit
  50. @group = Group.find(params[:id], :include => :projects)
  51. end
  52. # POST /groups
  53. # POST /groups.xml
  54. def create
  55. @group = Group.new(params[:group])
  56. respond_to do |format|
  57. if @group.save
  58. format.html {
  59. flash[:notice] = l(:notice_successful_create)
  60. redirect_to(params[:continue] ? new_group_path : groups_path)
  61. }
  62. format.xml { render :xml => @group, :status => :created, :location => @group }
  63. else
  64. format.html { render :action => "new" }
  65. format.xml { render :xml => @group.errors, :status => :unprocessable_entity }
  66. end
  67. end
  68. end
  69. # PUT /groups/1
  70. # PUT /groups/1.xml
  71. def update
  72. @group = Group.find(params[:id])
  73. respond_to do |format|
  74. if @group.update_attributes(params[:group])
  75. flash[:notice] = l(:notice_successful_update)
  76. format.html { redirect_to(groups_path) }
  77. format.xml { head :ok }
  78. else
  79. format.html { render :action => "edit" }
  80. format.xml { render :xml => @group.errors, :status => :unprocessable_entity }
  81. end
  82. end
  83. end
  84. # DELETE /groups/1
  85. # DELETE /groups/1.xml
  86. def destroy
  87. @group = Group.find(params[:id])
  88. @group.destroy
  89. respond_to do |format|
  90. format.html { redirect_to(groups_url) }
  91. format.xml { head :ok }
  92. end
  93. end
  94. def add_users
  95. @group = Group.find(params[:id])
  96. users = User.find_all_by_id(params[:user_ids])
  97. @group.users << users if request.post?
  98. respond_to do |format|
  99. format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
  100. format.js {
  101. render(:update) {|page|
  102. page.replace_html "tab-content-users", :partial => 'groups/users'
  103. users.each {|user| page.visual_effect(:highlight, "user-#{user.id}") }
  104. }
  105. }
  106. end
  107. end
  108. def remove_user
  109. @group = Group.find(params[:id])
  110. @group.users.delete(User.find(params[:user_id])) if request.delete?
  111. respond_to do |format|
  112. format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
  113. format.js { render(:update) {|page| page.replace_html "tab-content-users", :partial => 'groups/users'} }
  114. end
  115. end
  116. def autocomplete_for_user
  117. @group = Group.find(params[:id])
  118. @users = User.active.not_in_group(@group).like(params[:q]).all(:limit => 100)
  119. render :layout => false
  120. end
  121. def edit_membership
  122. @group = Group.find(params[:id])
  123. @membership = Member.edit_membership(params[:membership_id], params[:membership], @group)
  124. @membership.save if request.post?
  125. respond_to do |format|
  126. if @membership.valid?
  127. format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
  128. format.js {
  129. render(:update) {|page|
  130. page.replace_html "tab-content-memberships", :partial => 'groups/memberships'
  131. page.visual_effect(:highlight, "member-#{@membership.id}")
  132. }
  133. }
  134. else
  135. format.js {
  136. render(:update) {|page|
  137. page.alert(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', ')))
  138. }
  139. }
  140. end
  141. end
  142. end
  143. def destroy_membership
  144. @group = Group.find(params[:id])
  145. Member.find(params[:membership_id]).destroy if request.post?
  146. respond_to do |format|
  147. format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
  148. format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'groups/memberships'} }
  149. end
  150. end
  151. end