You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

settings_helper.rb 3.8KB

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