diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb index 7d130331d..e57b75fcc 100644 --- a/app/helpers/settings_helper.rb +++ b/app/helpers/settings_helper.rb @@ -1,5 +1,5 @@ -# redMine - project management software -# Copyright (C) 2006-2007 Jean-Philippe Lang +# Redmine - project management software +# Copyright (C) 2006-2009 Jean-Philippe Lang # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -27,4 +27,48 @@ module SettingsHelper {:name => 'repositories', :partial => 'settings/repositories', :label => :label_repository_plural} ] end + + def setting_select(setting, choices, options={}) + if blank_text = options.delete(:blank) + choices = [[blank_text.is_a?(Symbol) ? l(blank_text) : blank_text, '']] + choices + end + setting_label(setting, options) + + select_tag("settings[#{setting}]", options_for_select(choices, Setting.send(setting).to_s), options) + end + + def setting_multiselect(setting, choices, options={}) + setting_values = Setting.send(setting) + setting_values = [] unless setting_values.is_a?(Array) + + setting_label(setting, options) + + hidden_field_tag("settings[#{setting}][]", '') + + choices.collect do |choice| + text, value = (choice.is_a?(Array) ? choice : [choice, choice]) + content_tag('label', + check_box_tag("settings[#{setting}][]", value, Setting.send(setting).include?(value)) + text.to_s, + :class => 'block' + ) + end.join + end + + def setting_text_field(setting, options={}) + setting_label(setting, options) + + text_field_tag("settings[#{setting}]", Setting.send(setting), options) + end + + def setting_text_area(setting, options={}) + setting_label(setting, options) + + text_area_tag("settings[#{setting}]", Setting.send(setting), options) + end + + def setting_check_box(setting, options={}) + setting_label(setting, options) + + hidden_field_tag("settings[#{setting}]", 0) + + check_box_tag("settings[#{setting}]", 1, Setting.send("#{setting}?"), options) + end + + def setting_label(setting, options={}) + label = options.delete(:label) + label != false ? content_tag("label", l(label || "setting_#{setting}")) : '' + end end diff --git a/app/views/settings/_authentication.rhtml b/app/views/settings/_authentication.rhtml index f4b8dbf52..0d066f91a 100644 --- a/app/views/settings/_authentication.rhtml +++ b/app/views/settings/_authentication.rhtml @@ -1,34 +1,20 @@ <% form_tag({:action => 'edit', :tab => 'authentication'}) do %>
-

-<%= hidden_field_tag 'settings[login_required]', 0 %> -<%= check_box_tag 'settings[login_required]', 1, Setting.login_required? %> -

+

<%= setting_check_box :login_required %>

-

-<%= select_tag 'settings[autologin]', options_for_select( [[l(:label_disabled), "0"]] + [1, 7, 30, 365].collect{|days| [l('datetime.distance_in_words.x_days', :count => days), days.to_s]}, Setting.autologin) %>

+

<%= setting_select :autologin, [1, 7, 30, 365].collect{|days| [l('datetime.distance_in_words.x_days', :count => days), days.to_s]}, :blank => :label_disabled %>

-

-<%= select_tag 'settings[self_registration]', - options_for_select( [[l(:label_disabled), "0"], - [l(:label_registration_activation_by_email), "1"], - [l(:label_registration_manual_activation), "2"], - [l(:label_registration_automatic_activation), "3"] - ], Setting.self_registration ) %>

+

<%= setting_select :self_registration, [[l(:label_disabled), "0"], + [l(:label_registration_activation_by_email), "1"], + [l(:label_registration_manual_activation), "2"], + [l(:label_registration_automatic_activation), "3"]] %>

-

-<%= text_field_tag 'settings[password_min_length]', Setting.password_min_length, :size => 6 %>

+

<%= setting_text_field :password_min_length, :size => 6 %>

-

-<%= hidden_field_tag 'settings[lost_password]', 0 %> -<%= check_box_tag 'settings[lost_password]', 1, Setting.lost_password? %> -

+

<%= setting_check_box :lost_password, :label => :label_password_lost %>

-

-<%= hidden_field_tag 'settings[openid]', 0 %> -<%= check_box_tag 'settings[openid]', 1, Setting.openid?, :disabled => !Object.const_defined?(:OpenID) %> -

+

<%= setting_check_box :openid, :disabled => !Object.const_defined?(:OpenID) %>

diff --git a/app/views/settings/_display.rhtml b/app/views/settings/_display.rhtml index 10a081935..8e07b4ff6 100644 --- a/app/views/settings/_display.rhtml +++ b/app/views/settings/_display.rhtml @@ -1,32 +1,21 @@ <% form_tag({:action => 'edit', :tab => 'display'}) do %>
-

-<%= select_tag 'settings[ui_theme]', options_for_select( ([[l(:label_default), '']] + Redmine::Themes.themes.collect {|t| [t.name, t.id]}), Setting.ui_theme) %>

+

<%= setting_select :ui_theme, Redmine::Themes.themes.collect {|t| [t.name, t.id]}, :blank => :label_default, :label => :label_theme %>

-

-<%= select_tag 'settings[default_language]', options_for_select( lang_options_for_select(false), Setting.default_language) %>

+

<%= setting_select :default_language, lang_options_for_select(false) %>

-

-<%= select_tag 'settings[start_of_week]', options_for_select( [[l(:label_language_based), ''], [day_name(1),'1'], [day_name(7),'7']] , Setting.start_of_week) %>

+

<%= setting_select :start_of_week, [[day_name(1),'1'], [day_name(7),'7']], :blank => :label_language_based %>

-

-<%= select_tag 'settings[date_format]', options_for_select( [[l(:label_language_based), '']] + Setting::DATE_FORMATS.collect {|f| [Date.today.strftime(f), f]}, Setting.date_format) %>

+

<%= setting_select :date_format, Setting::DATE_FORMATS.collect {|f| [Date.today.strftime(f), f]}, :blank => :label_language_based %>

-

-<%= select_tag 'settings[time_format]', options_for_select( [[l(:label_language_based), '']] + Setting::TIME_FORMATS.collect {|f| [Time.now.strftime(f), f]}, Setting.time_format) %>

+

<%= setting_select :time_format, Setting::TIME_FORMATS.collect {|f| [Time.now.strftime(f), f]}, :blank => :label_language_based %>

-

-<%= select_tag 'settings[user_format]', options_for_select( @options[:user_format], Setting.user_format.to_s ) %>

+

<%= setting_select :user_format, @options[:user_format] %>

-

-<%= hidden_field_tag 'settings[gravatar_enabled]', 0 %> -<%= check_box_tag 'settings[gravatar_enabled]', 1, Setting.gravatar_enabled? %> -

+

<%= setting_check_box :gravatar_enabled %>

-

-<%= select_tag 'settings[gravatar_default]', options_for_select([[l(:label_none), ''], ["Wavatars", 'wavatar'], ["Identicons", 'identicon'], ["Monster ids", 'monsterid']], Setting.gravatar_default) %>

-

+

<%= setting_select :gravatar_default, [["Wavatars", 'wavatar'], ["Identicons", 'identicon'], ["Monster ids", 'monsterid']], :blank => :label_none %>

<%= submit_tag l(:button_save) %> diff --git a/app/views/settings/_general.rhtml b/app/views/settings/_general.rhtml index f34161fc2..f14157301 100644 --- a/app/views/settings/_general.rhtml +++ b/app/views/settings/_general.rhtml @@ -1,43 +1,32 @@ <% form_tag({:action => 'edit'}) do %>
-

-<%= text_field_tag 'settings[app_title]', Setting.app_title, :size => 30 %>

+

<%= setting_text_field :app_title, :size => 30 %>

-

-<%= text_area_tag 'settings[welcome_text]', Setting.welcome_text, :cols => 60, :rows => 5, :class => 'wiki-edit' %>

-<%= wikitoolbar_for 'settings[welcome_text]' %> +

<%= setting_text_area :welcome_text, :cols => 60, :rows => 5, :class => 'wiki-edit' %>

+<%= wikitoolbar_for 'settings_welcome_text' %> -

-<%= text_field_tag 'settings[attachment_max_size]', Setting.attachment_max_size, :size => 6 %> KB

+

<%= setting_text_field :attachment_max_size, :size => 6 %> KB

-

-<%= text_field_tag 'settings[per_page_options]', Setting.per_page_options_array.join(', '), :size => 20 %>
<%= l(:text_comma_separated) %>

+

<%= setting_text_field :per_page_options, :size => 20 %>
+<%= l(:text_comma_separated) %>

-

-<%= text_field_tag 'settings[activity_days_default]', Setting.activity_days_default, :size => 6 %> <%= l(:label_day_plural) %>

+

<%= setting_text_field :activity_days_default, :size => 6 %> <%= l(:label_day_plural) %>

-

-<%= text_field_tag 'settings[host_name]', Setting.host_name, :size => 60 %>
+

<%= setting_text_field :host_name, :size => 60 %>
<%= l(:label_example) %>: <%= @guessed_host_and_path %>

-

-<%= select_tag 'settings[protocol]', options_for_select(['http', 'https'], Setting.protocol) %>

+

<%= setting_select :protocol, [['HTTP', 'http'], ['HTTPS', 'https']] %>

-

-<%= select_tag 'settings[text_formatting]', options_for_select([[l(:label_none), "0"], *Redmine::WikiFormatting.format_names.collect{|name| [name, name]} ], Setting.text_formatting.to_sym) %>

+

<%= setting_select :text_formatting, Redmine::WikiFormatting.format_names.collect{|name| [name, name.to_s]}, :blank => :label_none %>

-

-<%= select_tag 'settings[wiki_compression]', options_for_select( [[l(:label_none), 0], ["gzip", "gzip"]], Setting.wiki_compression) %>

+

<%= setting_select :wiki_compression, [['Gzip', 'gzip']], :blank => :label_none %>

-

-<%= text_field_tag 'settings[feeds_limit]', Setting.feeds_limit, :size => 6 %>

+

<%= setting_text_field :feeds_limit, :size => 6 %>

-

-<%= text_field_tag 'settings[file_max_size_displayed]', Setting.file_max_size_displayed, :size => 6 %> KB

+

<%= setting_text_field :file_max_size_displayed, :size => 6 %> KB

-

-<%= text_field_tag 'settings[diff_max_lines_displayed]', Setting.diff_max_lines_displayed, :size => 6 %>

+

<%= setting_text_field :diff_max_lines_displayed, :size => 6 %>

<%= submit_tag l(:button_save) %> diff --git a/app/views/settings/_issues.rhtml b/app/views/settings/_issues.rhtml index 37b00352d..4280e44b5 100644 --- a/app/views/settings/_issues.rhtml +++ b/app/views/settings/_issues.rhtml @@ -1,30 +1,18 @@ <% form_tag({:action => 'edit', :tab => 'issues'}) do %>
-

-<%= hidden_field_tag 'settings[cross_project_issue_relations]', 0 %> -<%= check_box_tag 'settings[cross_project_issue_relations]', 1, Setting.cross_project_issue_relations? %> -

+

<%= setting_check_box :cross_project_issue_relations %>

-

-<%= hidden_field_tag 'settings[display_subprojects_issues]', 0 %> -<%= check_box_tag 'settings[display_subprojects_issues]', 1, Setting.display_subprojects_issues? %> -

+

<%= setting_check_box :display_subprojects_issues %>

-

-<%= select_tag 'settings[issue_done_ratio]', - options_for_select(Issue::DONE_RATIO_OPTIONS.collect {|i| [l("setting_issue_done_ratio_#{i}"), i]}, Setting.issue_done_ratio) %>

+

<%= setting_select :issue_done_ratio, Issue::DONE_RATIO_OPTIONS.collect {|i| [l("setting_issue_done_ratio_#{i}"), i]} %>

-

-<%= text_field_tag 'settings[issues_export_limit]', Setting.issues_export_limit, :size => 6 %>

+

<%= setting_text_field :issues_export_limit, :size => 6 %>

<%= l(:setting_issue_list_default_columns) %> -<%= hidden_field_tag 'settings[issue_list_default_columns][]', '' %> -<% Query.new.available_columns.each do |column| %> -
-<% end %> +<%= setting_multiselect(:issue_list_default_columns, + Query.new.available_columns.collect {|c| [c.caption, c.name.to_s]}, :label => false) %>
<%= submit_tag l(:button_save) %> diff --git a/app/views/settings/_mail_handler.rhtml b/app/views/settings/_mail_handler.rhtml index 8d83358b7..89ea55c5b 100644 --- a/app/views/settings/_mail_handler.rhtml +++ b/app/views/settings/_mail_handler.rhtml @@ -1,18 +1,14 @@ <% form_tag({:action => 'edit', :tab => 'mail_handler'}) do %>
-

-<%= hidden_field_tag 'settings[mail_handler_api_enabled]', 0 %> -<%= check_box_tag 'settings[mail_handler_api_enabled]', 1, Setting.mail_handler_api_enabled?, - :onclick => "if (this.checked) { Form.Element.enable('settings_mail_handler_api_key'); } else { Form.Element.disable('settings_mail_handler_api_key'); }" %> -

+

<%= setting_check_box :mail_handler_api_enabled, + :onclick => "if (this.checked) { Form.Element.enable('settings_mail_handler_api_key'); } else { Form.Element.disable('settings_mail_handler_api_key'); }"%>

-

-<%= text_field_tag 'settings[mail_handler_api_key]', Setting.mail_handler_api_key, - :size => 30, - :id => 'settings_mail_handler_api_key', - :disabled => !Setting.mail_handler_api_enabled? %> -<%= link_to_function l(:label_generate_key), "if ($('settings_mail_handler_api_key').disabled == false) { $('settings_mail_handler_api_key').value = randomKey(20) }" %>

+

<%= setting_text_field :mail_handler_api_key, :size => 30, + :id => 'settings_mail_handler_api_key', + :disabled => !Setting.mail_handler_api_enabled? %> + <%= link_to_function l(:label_generate_key), "if ($('settings_mail_handler_api_key').disabled == false) { $('settings_mail_handler_api_key').value = randomKey(20) }" %> +

<%= submit_tag l(:button_save) %> diff --git a/app/views/settings/_notifications.rhtml b/app/views/settings/_notifications.rhtml index 1b1b294b2..cb1c1abf1 100644 --- a/app/views/settings/_notifications.rhtml +++ b/app/views/settings/_notifications.rhtml @@ -2,31 +2,22 @@ <% form_tag({:action => 'edit', :tab => 'notifications'}) do %>
-

-<%= text_field_tag 'settings[mail_from]', Setting.mail_from, :size => 60 %>

+

<%= setting_text_field :mail_from, :size => 60 %>

-

-<%= hidden_field_tag 'settings[bcc_recipients]', 0 %> -<%= check_box_tag 'settings[bcc_recipients]', 1, Setting.bcc_recipients? %> -

+

<%= setting_check_box :bcc_recipients %>

-

-<%= hidden_field_tag 'settings[plain_text_mail]', 0 %> -<%= check_box_tag 'settings[plain_text_mail]', 1, Setting.plain_text_mail? %> -

+

<%= setting_check_box :plain_text_mail %>

-
<%=l(:text_select_mail_notifications)%> -<% @notifiables.each do |notifiable| %> -
-<% end %> -<%= hidden_field_tag 'settings[notified_events][]', '' %> -

<%= check_all_links('notified_events') %>

+
<%=l(:text_select_mail_notifications)%> + <%= setting_multiselect(:notified_events, + @notifiables.collect {|notifiable| [l_or_humanize(notifiable, :prefix => 'label_'), notifiable]}, :label => false) %> + +

<%= check_all_links('notified_events') %>

<%= l(:setting_emails_footer) %> -<%= text_area_tag 'settings[emails_footer]', Setting.emails_footer, :class => 'wiki-edit', :rows => 5 %> +<%= setting_text_area :emails_footer, :label => false, :class => 'wiki-edit', :rows => 5 %>
diff --git a/app/views/settings/_projects.rhtml b/app/views/settings/_projects.rhtml index 9e94ed141..c1255bbe3 100644 --- a/app/views/settings/_projects.rhtml +++ b/app/views/settings/_projects.rhtml @@ -1,28 +1,16 @@ <% form_tag({:action => 'edit', :tab => 'projects'}) do %>
-

-<%= hidden_field_tag 'settings[default_projects_public]', 0 %> -<%= check_box_tag 'settings[default_projects_public]', 1, Setting.default_projects_public? %> -

+

<%= setting_check_box :default_projects_public %>

-

-<%= hidden_field_tag 'settings[default_projects_modules][]', '' %> -<% Redmine::AccessControl.available_project_modules.each do |m| %> - -<% end %> -

+

<%= setting_multiselect(:default_projects_modules, + Redmine::AccessControl.available_project_modules.collect {|m| [l_or_humanize(m, :prefix => "project_module_"), m.to_s]}) %>

-

-<%= hidden_field_tag 'settings[sequential_project_identifiers]', 0 %> -<%= check_box_tag 'settings[sequential_project_identifiers]', 1, Setting.sequential_project_identifiers? %> -

+

<%= setting_check_box :sequential_project_identifiers %>

-

-<%= select_tag('settings[new_project_user_role_id]', options_for_select([["--- #{l(:actionview_instancetag_blank_option)} ---", '']] + Role.find_all_givable.collect {|r| [r.name, r.id]}, Setting.new_project_user_role_id.to_i)) %>

+

<%= setting_select :new_project_user_role_id, + Role.find_all_givable.collect {|r| [r.name, r.id.to_s]}, + :blank => "--- #{l(:actionview_instancetag_blank_option)} ---" %>

<%= submit_tag l(:button_save) %> diff --git a/app/views/settings/_repositories.rhtml b/app/views/settings/_repositories.rhtml index 4f07f053a..83a3846ce 100644 --- a/app/views/settings/_repositories.rhtml +++ b/app/views/settings/_repositories.rhtml @@ -1,41 +1,27 @@ <% form_tag({:action => 'edit', :tab => 'repositories'}) do %>
-

-<%= hidden_field_tag 'settings[autofetch_changesets]', 0 %> -<%= check_box_tag 'settings[autofetch_changesets]', 1, Setting.autofetch_changesets? %> -

+

<%= setting_check_box :autofetch_changesets %>

-

-<%= hidden_field_tag 'settings[sys_api_enabled]', 0 %> -<%= check_box_tag 'settings[sys_api_enabled]', 1, Setting.sys_api_enabled? %> -

+

<%= setting_check_box :sys_api_enabled %>

-

-<% REDMINE_SUPPORTED_SCM.each do |scm| -%> -<%= check_box_tag 'settings[enabled_scm][]', scm, Setting.enabled_scm.include?(scm) %> <%= scm %> -<% end -%> -<%= hidden_field_tag 'settings[enabled_scm][]', '' %> -

+

<%= setting_multiselect(:enabled_scm, REDMINE_SUPPORTED_SCM) %>

-

-<%= text_field_tag 'settings[repositories_encodings]', Setting.repositories_encodings, :size => 60 %>
<%= l(:text_comma_separated) %>

+

<%= setting_text_field :repositories_encodings, :size => 60 %>
+<%= l(:text_comma_separated) %>

-

-<%= select_tag 'settings[commit_logs_encoding]', options_for_select(Setting::ENCODINGS, Setting.commit_logs_encoding) %>

+

<%= setting_select :commit_logs_encoding, Setting::ENCODINGS %>

-

-<%= text_field_tag 'settings[repository_log_display_limit]', Setting.repository_log_display_limit, :size => 6 %>

+

<%= setting_text_field :repository_log_display_limit, :size => 6 %>

<%= l(:text_issues_ref_in_commit_messages) %> -

-<%= text_field_tag 'settings[commit_ref_keywords]', Setting.commit_ref_keywords, :size => 30 %>
<%= l(:text_comma_separated) %>

+

<%= setting_text_field :commit_ref_keywords, :size => 30 %>
+<%= l(:text_comma_separated) %>

-

-<%= text_field_tag 'settings[commit_fix_keywords]', Setting.commit_fix_keywords, :size => 30 %> - <%= l(:label_applied_status) %>: <%= select_tag 'settings[commit_fix_status_id]', options_for_select( [["", 0]] + IssueStatus.find(:all).collect{|status| [status.name, status.id.to_s]}, Setting.commit_fix_status_id) %> - <%= l(:field_done_ratio) %>: <%= select_tag 'settings[commit_fix_done_ratio]', options_for_select( [[l(:label_no_change_option), '']] + ((0..10).to_a.collect {|r| ["#{r*10} %", "#{r*10}"] }), Setting.commit_fix_done_ratio) %> +

<%= setting_text_field :commit_fix_keywords, :size => 30 %> + <%= l(:label_applied_status) %>: <%= setting_select :commit_fix_status_id, [["", 0]] + IssueStatus.find(:all).collect{|status| [status.name, status.id.to_s]}, :label => false %> + <%= l(:field_done_ratio) %>: <%= setting_select :commit_fix_done_ratio, (0..10).to_a.collect {|r| ["#{r*10} %", "#{r*10}"] }, :blank => :label_no_change_option, :label => false %>
<%= l(:text_comma_separated) %>

diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 54598f17a..812f800af 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -371,6 +371,8 @@ input#time_entry_comments { width: 90%;} .tabular.settings p{ padding-left: 300px; } .tabular.settings label{ margin-left: -300px; width: 295px; } +fieldset.settings label { display: block; } + .required {color: #bb0000;} .summary {font-style: italic;}