@@ -1,92 +1,92 | |||
|
1 | 1 | # Be sure to restart your web server when you modify this file. |
|
2 | 2 | |
|
3 | 3 | # Uncomment below to force Rails into production mode when |
|
4 | 4 | # you don't control web/app server and can't set it the proper way |
|
5 | 5 | # ENV['RAILS_ENV'] ||= 'production' |
|
6 | 6 | |
|
7 | 7 | # Bootstrap the Rails environment, frameworks, and default configuration |
|
8 | 8 | require File.join(File.dirname(__FILE__), 'boot') |
|
9 | 9 | |
|
10 | 10 | Rails::Initializer.run do |config| |
|
11 | 11 | # Settings in config/environments/* take precedence those specified here |
|
12 | 12 | |
|
13 | 13 | # Skip frameworks you're not going to use |
|
14 | 14 | # config.frameworks -= [ :action_web_service, :action_mailer ] |
|
15 | 15 | |
|
16 | 16 | # Add additional load paths for sweepers |
|
17 | 17 | config.load_paths += %W( #{RAILS_ROOT}/app/sweepers ) |
|
18 | 18 | |
|
19 | 19 | # Force all environments to use the same logger level |
|
20 | 20 | # (by default production uses :info, the others :debug) |
|
21 | 21 | # config.log_level = :debug |
|
22 | 22 | |
|
23 | 23 | # Use the database for sessions instead of the file system |
|
24 | 24 | # (create the session table with 'rake create_sessions_table') |
|
25 | 25 | # config.action_controller.session_store = :active_record_store |
|
26 | 26 | config.action_controller.session_store = :PStore |
|
27 | 27 | |
|
28 | 28 | # Enable page/fragment caching by setting a file-based store |
|
29 | 29 | # (remember to create the caching directory and make it readable to the application) |
|
30 | 30 | # config.action_controller.fragment_cache_store = :file_store, "#{RAILS_ROOT}/cache" |
|
31 | 31 | |
|
32 | 32 | # Activate observers that should always be running |
|
33 | 33 | # config.active_record.observers = :cacher, :garbage_collector |
|
34 | 34 | config.active_record.observers = :message_observer |
|
35 | 35 | |
|
36 | 36 | # Make Active Record use UTC-base instead of local time |
|
37 | 37 | # config.active_record.default_timezone = :utc |
|
38 | 38 | |
|
39 | 39 | # Use Active Record's schema dumper instead of SQL when creating the test database |
|
40 | 40 | # (enables use of different database adapters for development and test environments) |
|
41 | 41 | # config.active_record.schema_format = :ruby |
|
42 | 42 | |
|
43 | 43 | # See Rails::Configuration for more options |
|
44 | 44 | |
|
45 | 45 | # SMTP server configuration |
|
46 | 46 | config.action_mailer.smtp_settings = { |
|
47 | 47 | :address => "127.0.0.1", |
|
48 | 48 | :port => 25, |
|
49 | 49 | :domain => "somenet.foo", |
|
50 | 50 | :authentication => :login, |
|
51 | :user_name => "redmine", | |
|
51 | :user_name => "redmine@somenet.foo", | |
|
52 | 52 | :password => "redmine", |
|
53 | 53 | } |
|
54 | 54 | |
|
55 | 55 | config.action_mailer.perform_deliveries = true |
|
56 | 56 | |
|
57 | 57 | # Tell ActionMailer not to deliver emails to the real world. |
|
58 | 58 | # The :test delivery method accumulates sent emails in the |
|
59 | 59 | # ActionMailer::Base.deliveries array. |
|
60 | 60 | #config.action_mailer.delivery_method = :test |
|
61 | 61 | config.action_mailer.delivery_method = :smtp |
|
62 | 62 | |
|
63 | 63 | end |
|
64 | 64 | |
|
65 | 65 | ActiveRecord::Errors.default_error_messages = { |
|
66 | 66 | :inclusion => "activerecord_error_inclusion", |
|
67 | 67 | :exclusion => "activerecord_error_exclusion", |
|
68 | 68 | :invalid => "activerecord_error_invalid", |
|
69 | 69 | :confirmation => "activerecord_error_confirmation", |
|
70 | 70 | :accepted => "activerecord_error_accepted", |
|
71 | 71 | :empty => "activerecord_error_empty", |
|
72 | 72 | :blank => "activerecord_error_blank", |
|
73 | 73 | :too_long => "activerecord_error_too_long", |
|
74 | 74 | :too_short => "activerecord_error_too_short", |
|
75 | 75 | :wrong_length => "activerecord_error_wrong_length", |
|
76 | 76 | :taken => "activerecord_error_taken", |
|
77 | 77 | :not_a_number => "activerecord_error_not_a_number" |
|
78 | 78 | } |
|
79 | 79 | |
|
80 | 80 | ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| "#{html_tag}" } |
|
81 | 81 | |
|
82 | 82 | Mime::SET << Mime::CSV unless Mime::SET.include?(Mime::CSV) |
|
83 | 83 | Mime::Type.register 'application/pdf', :pdf |
|
84 | 84 | |
|
85 | 85 | GLoc.set_config :default_language => :en |
|
86 | 86 | GLoc.clear_strings |
|
87 | 87 | GLoc.set_kcode |
|
88 | 88 | GLoc.load_localized_strings |
|
89 | 89 | GLoc.set_config(:raise_string_not_found_errors => false) |
|
90 | 90 | |
|
91 | 91 | require 'redmine' |
|
92 | 92 |
@@ -1,144 +1,146 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | require 'gloc' | |
|
19 | ||
|
18 | 20 | module Redmine |
|
19 | 21 | module MenuManager |
|
20 | 22 | module MenuController |
|
21 | 23 | def self.included(base) |
|
22 | 24 | base.extend(ClassMethods) |
|
23 | 25 | end |
|
24 | 26 | |
|
25 | 27 | module ClassMethods |
|
26 | 28 | @@menu_items = Hash.new {|hash, key| hash[key] = {:default => key, :actions => {}}} |
|
27 | 29 | mattr_accessor :menu_items |
|
28 | 30 | |
|
29 | 31 | # Set the menu item name for a controller or specific actions |
|
30 | 32 | # Examples: |
|
31 | 33 | # * menu_item :tickets # => sets the menu name to :tickets for the whole controller |
|
32 | 34 | # * menu_item :tickets, :only => :list # => sets the menu name to :tickets for the 'list' action only |
|
33 | 35 | # * menu_item :tickets, :only => [:list, :show] # => sets the menu name to :tickets for 2 actions only |
|
34 | 36 | # |
|
35 | 37 | # The default menu item name for a controller is controller_name by default |
|
36 | 38 | # Eg. the default menu item name for ProjectsController is :projects |
|
37 | 39 | def menu_item(id, options = {}) |
|
38 | 40 | if actions = options[:only] |
|
39 | 41 | actions = [] << actions unless actions.is_a?(Array) |
|
40 | 42 | actions.each {|a| menu_items[controller_name.to_sym][:actions][a.to_sym] = id} |
|
41 | 43 | else |
|
42 | 44 | menu_items[controller_name.to_sym][:default] = id |
|
43 | 45 | end |
|
44 | 46 | end |
|
45 | 47 | end |
|
46 | 48 | |
|
47 | 49 | def menu_items |
|
48 | 50 | self.class.menu_items |
|
49 | 51 | end |
|
50 | 52 | |
|
51 | 53 | # Returns the menu item name according to the current action |
|
52 | 54 | def current_menu_item |
|
53 | 55 | menu_items[controller_name.to_sym][:actions][action_name.to_sym] || |
|
54 | 56 | menu_items[controller_name.to_sym][:default] |
|
55 | 57 | end |
|
56 | 58 | end |
|
57 | 59 | |
|
58 | 60 | module MenuHelper |
|
59 | 61 | # Returns the current menu item name |
|
60 | 62 | def current_menu_item |
|
61 | 63 | @controller.current_menu_item |
|
62 | 64 | end |
|
63 | 65 | |
|
64 | 66 | # Renders the application main menu |
|
65 | 67 | def render_main_menu(project) |
|
66 | 68 | render_menu((project && !project.new_record?) ? :project_menu : :application_menu, project) |
|
67 | 69 | end |
|
68 | 70 | |
|
69 | 71 | def render_menu(menu, project=nil) |
|
70 | 72 | links = [] |
|
71 | 73 | Redmine::MenuManager.allowed_items(menu, User.current, project).each do |item| |
|
72 | 74 | unless item.condition && !item.condition.call(project) |
|
73 | 75 | url = case item.url |
|
74 | 76 | when Hash |
|
75 | 77 | project.nil? ? item.url : {item.param => project}.merge(item.url) |
|
76 | 78 | when Symbol |
|
77 | 79 | send(item.url) |
|
78 | 80 | else |
|
79 | 81 | item.url |
|
80 | 82 | end |
|
81 | 83 | #url = (project && item.url.is_a?(Hash)) ? {item.param => project}.merge(item.url) : (item.url.is_a?(Symbol) ? send(item.url) : item.url) |
|
82 | 84 | links << content_tag('li', |
|
83 | 85 | link_to(l(item.caption), url, (current_menu_item == item.name ? item.html_options.merge(:class => 'selected') : item.html_options))) |
|
84 | 86 | end |
|
85 | 87 | end |
|
86 | 88 | links.empty? ? nil : content_tag('ul', links.join("\n")) |
|
87 | 89 | end |
|
88 | 90 | end |
|
89 | 91 | |
|
90 | 92 | class << self |
|
91 | 93 | def map(menu_name) |
|
92 | 94 | mapper = Mapper.new |
|
93 | 95 | yield mapper |
|
94 | 96 | @items ||= {} |
|
95 | 97 | @items[menu_name.to_sym] ||= [] |
|
96 | 98 | @items[menu_name.to_sym] += mapper.items |
|
97 | 99 | end |
|
98 | 100 | |
|
99 | 101 | def items(menu_name) |
|
100 | 102 | @items[menu_name.to_sym] || [] |
|
101 | 103 | end |
|
102 | 104 | |
|
103 | 105 | def allowed_items(menu_name, user, project) |
|
104 | 106 | project ? items(menu_name).select {|item| user && user.allowed_to?(item.url, project)} : items(menu_name) |
|
105 | 107 | end |
|
106 | 108 | end |
|
107 | 109 | |
|
108 | 110 | class Mapper |
|
109 | 111 | # Adds an item at the end of the menu. Available options: |
|
110 | 112 | # * param: the parameter name that is used for the project id (default is :id) |
|
111 | 113 | # * if: a proc that is called before rendering the item, the item is displayed only if it returns true |
|
112 | 114 | # * caption: the localized string key that is used as the item label |
|
113 | 115 | # * html_options: a hash of html options that are passed to link_to |
|
114 | 116 | def push(name, url, options={}) |
|
115 | 117 | items << MenuItem.new(name, url, options) |
|
116 | 118 | end |
|
117 | 119 | |
|
118 | 120 | def items |
|
119 | 121 | @items ||= [] |
|
120 | 122 | end |
|
121 | 123 | end |
|
122 | 124 | |
|
123 | 125 | class MenuItem |
|
124 | 126 | include GLoc |
|
125 | 127 | attr_reader :name, :url, :param, :condition, :html_options |
|
126 | 128 | |
|
127 | 129 | def initialize(name, url, options) |
|
128 | 130 | raise "Invalid option :if for menu item '#{name}'" if options[:if] && !options[:if].respond_to?(:call) |
|
129 | 131 | raise "Invalid option :html for menu item '#{name}'" if options[:html] && !options[:html].is_a?(Hash) |
|
130 | 132 | @name = name |
|
131 | 133 | @url = url |
|
132 | 134 | @condition = options[:if] |
|
133 | 135 | @param = options[:param] || :id |
|
134 | 136 | @caption_key = options[:caption] |
|
135 | 137 | @html_options = options[:html] || {} |
|
136 | 138 | end |
|
137 | 139 | |
|
138 | 140 | def caption |
|
139 | 141 | # check if localized string exists on first render (after GLoc strings are loaded) |
|
140 | 142 | @caption ||= (@caption_key || (l_has_string?("label_#{@name}".to_sym) ? "label_#{@name}".to_sym : @name.to_s.humanize)) |
|
141 | 143 | end |
|
142 | 144 | end |
|
143 | 145 | end |
|
144 | 146 | end |
General Comments 0
You need to be logged in to leave comments.
Login now