Project

General

Profile

RE: Writing plugins compatible with both Redmine 1.x and ... » rate_users_helper_patch.rb

Arun M V, 2013-06-19 12:37

 
1
require_dependency 'users_helper'
2
module RateUsersHelperPatch
3
  def self.included(base) # :nodoc:
4
    base.send(:include, InstanceMethods)
5
    base.class_eval do
6
      unloadable
7
      alias_method_chain :user_settings_tabs, :rate_tab
8
    end
9
  end
10
  
11
  module InstanceMethods
12
    # Adds a rates tab to the user administration page
13
    def user_settings_tabs_with_rate_tab
14
      tabs = user_settings_tabs_without_rate_tab
15
      tabs << { :name => 'rates', :partial => 'users/rates', :label => :rate_label_rate_history}
16
      return tabs
17
    end
18
    
19
    # Similar to +project_options_for_select+ but allows selecting the active value
20
    def project_options_for_select_with_selected(projects, selected = nil)
21
      options = content_tag('option', "--- #{l(:rate_label_default)} ---", :value => '')
22
      projects_by_root = projects.group_by(&:root)
23
      projects_by_root.keys.sort.each do |root|
24
        root_selected = (root == selected) ? 'selected' : nil
25

    
26
        options << content_tag('option', h(root.name), :value => root.id, :disabled => (!projects.include?(root)), :selected => root_selected)
27
        projects_by_root[root].sort.each do |project|
28
          next if project == root
29
          child_selected = (project == selected) ? 'selected' : nil
30

    
31
          options << content_tag('option', '&#187; ' + h(project.name), :value => project.id, :selected => child_selected)
32
        end
33
      end
34
      options
35
    end
36
    
37
  end
38
end
39

    
40

    
41
unless UsersHelper.included_modules.include? RateUsersHelperPatch
42
    UsersHelper.send(:include, RateUsersHelperPatch)
43
end
44

    
(2-2/2)