To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / helpers / settings_helper.rb @ 912:5e80956cc792

History | View | Annotate | Download (4.02 KB)

1 909:cbb26bc654de Chris
# encoding: utf-8
2
#
3 0:513646585e45 Chris
# Redmine - project management software
4 441:cbce1fd3b1b7 Chris
# Copyright (C) 2006-2011  Jean-Philippe Lang
5 0:513646585e45 Chris
#
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU General Public License
8
# as published by the Free Software Foundation; either version 2
9
# of the License, or (at your option) any later version.
10 441:cbce1fd3b1b7 Chris
#
11 0:513646585e45 Chris
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15 441:cbce1fd3b1b7 Chris
#
16 0:513646585e45 Chris
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
20
module SettingsHelper
21
  def administration_settings_tabs
22
    tabs = [{:name => 'general', :partial => 'settings/general', :label => :label_general},
23
            {:name => 'display', :partial => 'settings/display', :label => :label_display},
24
            {:name => 'authentication', :partial => 'settings/authentication', :label => :label_authentication},
25
            {:name => 'projects', :partial => 'settings/projects', :label => :label_project_plural},
26
            {:name => 'issues', :partial => 'settings/issues', :label => :label_issue_tracking},
27
            {:name => 'notifications', :partial => 'settings/notifications', :label => :field_mail_notification},
28
            {:name => 'mail_handler', :partial => 'settings/mail_handler', :label => :label_incoming_emails},
29
            {:name => 'repositories', :partial => 'settings/repositories', :label => :label_repository_plural}
30
            ]
31
  end
32 441:cbce1fd3b1b7 Chris
33 0:513646585e45 Chris
  def setting_select(setting, choices, options={})
34
    if blank_text = options.delete(:blank)
35
      choices = [[blank_text.is_a?(Symbol) ? l(blank_text) : blank_text, '']] + choices
36
    end
37 909:cbb26bc654de Chris
    setting_label(setting, options).html_safe +
38 441:cbce1fd3b1b7 Chris
      select_tag("settings[#{setting}]",
39
                 options_for_select(choices, Setting.send(setting).to_s),
40 909:cbb26bc654de Chris
                 options).html_safe
41 0:513646585e45 Chris
  end
42 441:cbce1fd3b1b7 Chris
43 0:513646585e45 Chris
  def setting_multiselect(setting, choices, options={})
44
    setting_values = Setting.send(setting)
45
    setting_values = [] unless setting_values.is_a?(Array)
46 441:cbce1fd3b1b7 Chris
47 909:cbb26bc654de Chris
    setting_label(setting, options).html_safe +
48
      hidden_field_tag("settings[#{setting}][]", '').html_safe +
49 0:513646585e45 Chris
      choices.collect do |choice|
50 441:cbce1fd3b1b7 Chris
        text, value = (choice.is_a?(Array) ? choice : [choice, choice])
51
        content_tag(
52
          'label',
53
          check_box_tag(
54
             "settings[#{setting}][]",
55
             value,
56
             Setting.send(setting).include?(value)
57
           ) + text.to_s,
58 0:513646585e45 Chris
          :class => 'block'
59 441:cbce1fd3b1b7 Chris
         )
60 909:cbb26bc654de Chris
      end.join.html_safe
61 0:513646585e45 Chris
  end
62 441:cbce1fd3b1b7 Chris
63 0:513646585e45 Chris
  def setting_text_field(setting, options={})
64 909:cbb26bc654de Chris
    setting_label(setting, options).html_safe +
65
      text_field_tag("settings[#{setting}]", Setting.send(setting), options).html_safe
66 0:513646585e45 Chris
  end
67 441:cbce1fd3b1b7 Chris
68 0:513646585e45 Chris
  def setting_text_area(setting, options={})
69 909:cbb26bc654de Chris
    setting_label(setting, options).html_safe +
70
      text_area_tag("settings[#{setting}]", Setting.send(setting), options).html_safe
71 0:513646585e45 Chris
  end
72 441:cbce1fd3b1b7 Chris
73 0:513646585e45 Chris
  def setting_check_box(setting, options={})
74 909:cbb26bc654de Chris
    setting_label(setting, options).html_safe +
75
      hidden_field_tag("settings[#{setting}]", 0).html_safe +
76
        check_box_tag("settings[#{setting}]", 1, Setting.send("#{setting}?"), options).html_safe
77 0:513646585e45 Chris
  end
78 441:cbce1fd3b1b7 Chris
79 0:513646585e45 Chris
  def setting_label(setting, options={})
80
    label = options.delete(:label)
81 909:cbb26bc654de Chris
    label != false ? content_tag("label", l(label || "setting_#{setting}")).html_safe : ''
82 0:513646585e45 Chris
  end
83 37:94944d00e43c chris
84
  # Renders a notification field for a Redmine::Notifiable option
85
  def notification_field(notifiable)
86
    return content_tag(:label,
87
                       check_box_tag('settings[notified_events][]',
88
                                     notifiable.name,
89 909:cbb26bc654de Chris
                                     Setting.notified_events.include?(notifiable.name)).html_safe +
90
                         l_or_humanize(notifiable.name, :prefix => 'label_').html_safe,
91
                       :class => notifiable.parent.present? ? "parent" : '').html_safe
92 37:94944d00e43c chris
  end
93 0:513646585e45 Chris
end