You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

my_controller.rb 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. # redMine - project management software
  2. # Copyright (C) 2006 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 MyController < ApplicationController
  18. layout 'base'
  19. before_filter :require_login
  20. BLOCKS = { 'issues_assigned_to_me' => :label_assigned_to_me_issues,
  21. 'issues_reported_by_me' => :label_reported_issues,
  22. 'latest_news' => :label_news_latest,
  23. 'calendar' => :label_calendar,
  24. 'documents' => :label_document_plural
  25. }.freeze
  26. verify :xhr => true,
  27. :session => :page_layout,
  28. :only => [:add_block, :remove_block, :order_blocks]
  29. def index
  30. page
  31. render :action => 'page'
  32. end
  33. # Show user's page
  34. def page
  35. @user = self.logged_in_user
  36. @blocks = @user.pref[:my_page_layout] || { 'left' => ['issues_assigned_to_me'], 'right' => ['issues_reported_by_me'] }
  37. end
  38. # Edit user's account
  39. def account
  40. @user = self.logged_in_user
  41. @pref = @user.pref
  42. @user.attributes = params[:user]
  43. @user.pref.attributes = params[:pref]
  44. if request.post? and @user.save
  45. set_localization
  46. flash.now[:notice] = l(:notice_account_updated)
  47. self.logged_in_user.reload
  48. end
  49. end
  50. # Change user's password
  51. def change_password
  52. @user = self.logged_in_user
  53. flash[:notice] = l(:notice_can_t_change_password) and redirect_to :action => 'account' and return if @user.auth_source_id
  54. if @user.check_password?(@params[:password])
  55. @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
  56. if @user.save
  57. flash[:notice] = l(:notice_account_password_updated)
  58. else
  59. render :action => 'account'
  60. return
  61. end
  62. else
  63. flash[:notice] = l(:notice_account_wrong_password)
  64. end
  65. redirect_to :action => 'account'
  66. end
  67. # User's page layout configuration
  68. def page_layout
  69. @user = self.logged_in_user
  70. @blocks = @user.pref[:my_page_layout] || { 'left' => ['issues_assigned_to_me'], 'right' => ['issues_reported_by_me'] }
  71. session[:page_layout] = @blocks
  72. %w(top left right).each {|f| session[:page_layout][f] ||= [] }
  73. @block_options = []
  74. BLOCKS.each {|k, v| @block_options << [l(v), k]}
  75. end
  76. # Add a block to user's page
  77. # The block is added on top of the page
  78. # params[:block] : id of the block to add
  79. def add_block
  80. @user = self.logged_in_user
  81. block = params[:block]
  82. # remove if already present in a group
  83. %w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
  84. # add it on top
  85. session[:page_layout]['top'].unshift block
  86. render :partial => "block", :locals => {:user => @user, :block_name => block}
  87. end
  88. # Remove a block to user's page
  89. # params[:block] : id of the block to remove
  90. def remove_block
  91. block = params[:block]
  92. # remove block in all groups
  93. %w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
  94. render :nothing => true
  95. end
  96. # Change blocks order on user's page
  97. # params[:group] : group to order (top, left or right)
  98. # params[:list-(top|left|right)] : array of block ids of the group
  99. def order_blocks
  100. group = params[:group]
  101. group_items = params["list-#{group}"]
  102. if group_items and group_items.is_a? Array
  103. # remove group blocks if they are presents in other groups
  104. %w(top left right).each {|f|
  105. session[:page_layout][f] = (session[:page_layout][f] || []) - group_items
  106. }
  107. session[:page_layout][group] = group_items
  108. end
  109. render :nothing => true
  110. end
  111. # Save user's page layout
  112. def page_layout_save
  113. @user = self.logged_in_user
  114. @user.pref[:my_page_layout] = session[:page_layout] if session[:page_layout]
  115. @user.pref.save
  116. session[:page_layout] = nil
  117. redirect_to :action => 'page'
  118. end
  119. end