annotate app/helpers/settings_helper.rb @ 929:5f33065ddc4b redmine-1.3

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