annotate app/helpers/settings_helper.rb @ 1628:9c5f8e24dadc live tip

Quieten this cron script
author Chris Cannam
date Tue, 25 Aug 2020 11:38:49 +0100
parents dffacf8a6908
children
rev   line source
Chris@909 1 # encoding: utf-8
Chris@909 2 #
Chris@0 3 # Redmine - project management software
Chris@1494 4 # Copyright (C) 2006-2014 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@1115 47 content_tag("label", l(options[:label] || "setting_#{setting}")) +
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@1464 56 setting_values.include?(value),
Chris@1115 57 :id => nil
Chris@441 58 ) + text.to_s,
Chris@1115 59 :class => (options[:inline] ? 'inline' : 'block')
Chris@441 60 )
Chris@909 61 end.join.html_safe
Chris@0 62 end
Chris@441 63
Chris@0 64 def setting_text_field(setting, options={})
Chris@909 65 setting_label(setting, options).html_safe +
Chris@909 66 text_field_tag("settings[#{setting}]", Setting.send(setting), options).html_safe
Chris@0 67 end
Chris@441 68
Chris@0 69 def setting_text_area(setting, options={})
Chris@909 70 setting_label(setting, options).html_safe +
Chris@909 71 text_area_tag("settings[#{setting}]", Setting.send(setting), options).html_safe
Chris@0 72 end
Chris@441 73
Chris@0 74 def setting_check_box(setting, options={})
Chris@909 75 setting_label(setting, options).html_safe +
Chris@1115 76 hidden_field_tag("settings[#{setting}]", 0, :id => nil).html_safe +
Chris@909 77 check_box_tag("settings[#{setting}]", 1, Setting.send("#{setting}?"), options).html_safe
Chris@0 78 end
Chris@441 79
Chris@0 80 def setting_label(setting, options={})
Chris@0 81 label = options.delete(:label)
Chris@1517 82 label != false ? label_tag("settings_#{setting}", l(label || "setting_#{setting}"), options[:label_options]).html_safe : ''
Chris@0 83 end
chris@37 84
chris@37 85 # Renders a notification field for a Redmine::Notifiable option
chris@37 86 def notification_field(notifiable)
chris@37 87 return content_tag(:label,
chris@37 88 check_box_tag('settings[notified_events][]',
chris@37 89 notifiable.name,
Chris@1115 90 Setting.notified_events.include?(notifiable.name), :id => nil).html_safe +
Chris@909 91 l_or_humanize(notifiable.name, :prefix => 'label_').html_safe,
Chris@909 92 :class => notifiable.parent.present? ? "parent" : '').html_safe
chris@37 93 end
Chris@1115 94
Chris@1115 95 def cross_project_subtasks_options
Chris@1115 96 options = [
Chris@1115 97 [:label_disabled, ''],
Chris@1115 98 [:label_cross_project_system, 'system'],
Chris@1115 99 [:label_cross_project_tree, 'tree'],
Chris@1115 100 [:label_cross_project_hierarchy, 'hierarchy'],
Chris@1115 101 [:label_cross_project_descendants, 'descendants']
Chris@1115 102 ]
Chris@1115 103
Chris@1115 104 options.map {|label, value| [l(label), value.to_s]}
Chris@1115 105 end
Chris@0 106 end