annotate app/helpers/settings_helper.rb @ 1452:d6b9fd02bb89 feature_36_js_refactoring

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