From a276926f420d0369a3f9d0fe69e972d07ef74363 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Fri, 16 Jan 2009 21:02:03 +0000 Subject: [PATCH] Use a textarea for custom fields possible values (#2472). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2267 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/custom_field.rb | 11 +++++++++-- app/views/custom_fields/_form.rhtml | 26 ++++---------------------- lang/bg.yml | 1 + lang/ca.yml | 1 + lang/cs.yml | 1 + lang/da.yml | 1 + lang/de.yml | 1 + lang/en.yml | 1 + lang/es.yml | 1 + lang/fi.yml | 1 + lang/fr.yml | 1 + lang/he.yml | 1 + lang/hu.yml | 1 + lang/it.yml | 1 + lang/ja.yml | 1 + lang/ko.yml | 1 + lang/lt.yml | 1 + lang/nl.yml | 1 + lang/no.yml | 1 + lang/pl.yml | 1 + lang/pt-br.yml | 1 + lang/pt.yml | 1 + lang/ro.yml | 1 + lang/ru.yml | 1 + lang/sk.yml | 1 + lang/sr.yml | 1 + lang/sv.yml | 1 + lang/th.yml | 1 + lang/tr.yml | 1 + lang/uk.yml | 1 + lang/vn.yml | 1 + lang/zh-tw.yml | 1 + lang/zh.yml | 1 + test/unit/custom_field_test.rb | 18 ++++++++++++++++++ 34 files changed, 62 insertions(+), 24 deletions(-) diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index 79d12376..f277dc34 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -41,8 +41,6 @@ class CustomField < ActiveRecord::Base end def before_validation - # remove empty values - self.possible_values = self.possible_values.collect{|v| v unless v.empty?}.compact # make sure these fields are not searchable self.searchable = false if %w(int float date bool).include?(field_format) true @@ -60,6 +58,15 @@ class CustomField < ActiveRecord::Base errors.add(:default_value, :activerecord_error_invalid) unless v.valid? end + # Makes possible_values accept a multiline string + def possible_values=(arg) + if arg.is_a?(Array) + write_attribute(:possible_values, arg.compact.collect(&:strip).select {|v| !v.blank?}) + else + self.possible_values = arg.to_s.split(/[\n\r]+/) + end + end + # Returns a ORDER BY clause that can used to sort customized # objects by their value of the custom field. # Returns false, if the custom field can not be used for sorting. diff --git a/app/views/custom_fields/_form.rhtml b/app/views/custom_fields/_form.rhtml index f4aee687..43ed5feb 100644 --- a/app/views/custom_fields/_form.rhtml +++ b/app/views/custom_fields/_form.rhtml @@ -49,23 +49,6 @@ function toggle_custom_field_format() { } } -function addValueField() { - var f = $$('p#custom_field_possible_values span'); - p = document.getElementById("custom_field_possible_values"); - var v = f[0].cloneNode(true); - v.childNodes[0].value = ""; - p.appendChild(v); -} - -function deleteValueField(e) { - var f = $$('p#custom_field_possible_values span'); - if (f.length == 1) { - e.parentNode.childNodes[0].value = ""; - } else { - Element.remove(e.parentNode); - } -} - //]]> @@ -76,11 +59,10 @@ function deleteValueField(e) { <%= f.text_field :min_length, :size => 5, :no_label => true %> - <%= f.text_field :max_length, :size => 5, :no_label => true %>
(<%=l(:text_min_max_length_info)%>)

<%= f.text_field :regexp, :size => 50 %>
(<%=l(:text_regexp_info)%>)

-

-<% (@custom_field.possible_values.to_a + [""]).each do |value| %> -<%= text_field_tag 'custom_field[possible_values][]', value, :size => 30 %> <%= image_to_function "delete.png", "deleteValueField(this);return false" %>
-<% end %> -

+

<%= f.text_area :possible_values, :value => @custom_field.possible_values.to_a.join("\n"), + :cols => 20, + :rows => 15 %> +
<%= l(:text_custom_field_possible_values_info) %>

<%= @custom_field.field_format == 'bool' ? f.check_box(:default_value) : f.text_field(:default_value) %>

diff --git a/lang/bg.yml b/lang/bg.yml index 61f75209..c73752bd 100644 --- a/lang/bg.yml +++ b/lang/bg.yml @@ -699,3 +699,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/ca.yml b/lang/ca.yml index 0ce265f9..6585617c 100644 --- a/lang/ca.yml +++ b/lang/ca.yml @@ -700,3 +700,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/cs.yml b/lang/cs.yml index 534da679..9e34ab9d 100644 --- a/lang/cs.yml +++ b/lang/cs.yml @@ -704,3 +704,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/da.yml b/lang/da.yml index 2edbc524..e447d4c7 100644 --- a/lang/da.yml +++ b/lang/da.yml @@ -700,3 +700,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/de.yml b/lang/de.yml index c403b481..a0098a12 100644 --- a/lang/de.yml +++ b/lang/de.yml @@ -701,3 +701,4 @@ enumeration_activities: Aktivitäten (Zeiterfassung) text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/en.yml b/lang/en.yml index 01ac078c..7ea1b150 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -676,6 +676,7 @@ text_enumeration_category_reassign_to: 'Reassign them to this value:' text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." text_repository_usernames_mapping: "Select or update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped." text_diff_truncated: '... This diff was truncated because it exceeds the maximum size that can be displayed.' +text_custom_field_possible_values_info: 'One line for each value' default_role_manager: Manager default_role_developper: Developer diff --git a/lang/es.yml b/lang/es.yml index 1729292e..36b1f468 100644 --- a/lang/es.yml +++ b/lang/es.yml @@ -684,3 +684,4 @@ text_workflow_edit: Seleccionar un flujo de trabajo para actualizar text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/fi.yml b/lang/fi.yml index 244f858e..2bae1f84 100644 --- a/lang/fi.yml +++ b/lang/fi.yml @@ -699,3 +699,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/fr.yml b/lang/fr.yml index 374a0d86..6465f9bd 100644 --- a/lang/fr.yml +++ b/lang/fr.yml @@ -676,6 +676,7 @@ text_enumeration_category_reassign_to: 'Réaffecter les objets à cette valeur:' text_email_delivery_not_configured: "L'envoi de mail n'est pas configuré, les notifications sont désactivées.\nConfigurez votre serveur SMTP dans config/email.yml et redémarrez l'application pour les activer." text_repository_usernames_mapping: "Vous pouvez sélectionner ou modifier l'utilisateur Redmine associé à chaque nom d'utilisateur figurant dans l'historique du dépôt.\nLes utilisateurs avec le même identifiant ou la même adresse mail seront automatiquement associés." text_diff_truncated: '... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.' +text_custom_field_possible_values_info: 'Une ligne par valeur' default_role_manager: Manager default_role_developper: Développeur diff --git a/lang/he.yml b/lang/he.yml index b10b7329..f2bdd921 100644 --- a/lang/he.yml +++ b/lang/he.yml @@ -699,3 +699,4 @@ text_plugin_assets_writable: Plugin assets directory writable text_diff_truncated: '... This diff was truncated because it exceeds the maximum size that can be displayed.' warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/hu.yml b/lang/hu.yml index 059b3ee6..be6bb0eb 100644 --- a/lang/hu.yml +++ b/lang/hu.yml @@ -700,3 +700,4 @@ setting_diff_max_lines_displayed: A megjelenítendő sorok száma (maximum) a di text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/it.yml b/lang/it.yml index f3798b47..85c8c6ae 100644 --- a/lang/it.yml +++ b/lang/it.yml @@ -699,3 +699,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/ja.yml b/lang/ja.yml index c1279b3f..b215c011 100644 --- a/lang/ja.yml +++ b/lang/ja.yml @@ -700,3 +700,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/ko.yml b/lang/ko.yml index f7958f97..28564676 100644 --- a/lang/ko.yml +++ b/lang/ko.yml @@ -699,3 +699,4 @@ setting_diff_max_lines_displayed: 차이점보기에 표시할 최대 줄수 text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/lt.yml b/lang/lt.yml index 3cdbcf09..8f530e5e 100644 --- a/lang/lt.yml +++ b/lang/lt.yml @@ -701,3 +701,4 @@ enumeration_activities: Veiklos (laiko sekimas) text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/nl.yml b/lang/nl.yml index ed10b4db..b61829bb 100644 --- a/lang/nl.yml +++ b/lang/nl.yml @@ -701,3 +701,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/no.yml b/lang/no.yml index c8f131ff..3689d8df 100644 --- a/lang/no.yml +++ b/lang/no.yml @@ -700,3 +700,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/pl.yml b/lang/pl.yml index 6b28f0e0..98b2197d 100644 --- a/lang/pl.yml +++ b/lang/pl.yml @@ -718,3 +718,4 @@ setting_diff_max_lines_displayed: Maksymalna liczba linii różnicy do pokazania text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/pt-br.yml b/lang/pt-br.yml index ecbbc0ce..846b4d93 100644 --- a/lang/pt-br.yml +++ b/lang/pt-br.yml @@ -700,3 +700,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/pt.yml b/lang/pt.yml index ec42386d..6ed74158 100644 --- a/lang/pt.yml +++ b/lang/pt.yml @@ -701,3 +701,4 @@ setting_diff_max_lines_displayed: Número máximo de linhas de diff mostradas text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/ro.yml b/lang/ro.yml index b0df48d2..6799b4f1 100644 --- a/lang/ro.yml +++ b/lang/ro.yml @@ -699,3 +699,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/ru.yml b/lang/ru.yml index 4943eea0..6bfc64b6 100644 --- a/lang/ru.yml +++ b/lang/ru.yml @@ -733,3 +733,4 @@ text_workflow_edit: Выберите роль и трекер для редак text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/sk.yml b/lang/sk.yml index ffae2d64..4d4d49e8 100644 --- a/lang/sk.yml +++ b/lang/sk.yml @@ -705,3 +705,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/sr.yml b/lang/sr.yml index 7070c4a2..c045d554 100644 --- a/lang/sr.yml +++ b/lang/sr.yml @@ -700,3 +700,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/sv.yml b/lang/sv.yml index 852c7fe5..a7262356 100644 --- a/lang/sv.yml +++ b/lang/sv.yml @@ -700,3 +700,4 @@ enumeration_activities: Aktiviteter (tidsuppföljning) text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/th.yml b/lang/th.yml index c0a38592..0e6e3646 100644 --- a/lang/th.yml +++ b/lang/th.yml @@ -702,3 +702,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/tr.yml b/lang/tr.yml index 81363678..fe214049 100644 --- a/lang/tr.yml +++ b/lang/tr.yml @@ -700,3 +700,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/uk.yml b/lang/uk.yml index be121cb5..55d642b3 100644 --- a/lang/uk.yml +++ b/lang/uk.yml @@ -701,3 +701,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/vn.yml b/lang/vn.yml index 908e2326..15b62e1d 100644 --- a/lang/vn.yml +++ b/lang/vn.yml @@ -702,3 +702,4 @@ setting_diff_max_lines_displayed: Max number of diff lines displayed text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/zh-tw.yml b/lang/zh-tw.yml index 50eccf43..6f6740b7 100644 --- a/lang/zh-tw.yml +++ b/lang/zh-tw.yml @@ -701,3 +701,4 @@ enumeration_activities: 活動 (時間追蹤) text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/lang/zh.yml b/lang/zh.yml index 989f329c..cceaff0f 100644 --- a/lang/zh.yml +++ b/lang/zh.yml @@ -701,3 +701,4 @@ enumeration_activities: 活动(时间跟踪) text_plugin_assets_writable: Plugin assets directory writable warning_attachments_not_saved: "%d file(s) could not be saved." button_create_and_continue: Create and continue +text_custom_field_possible_values_info: 'One line for each value' diff --git a/test/unit/custom_field_test.rb b/test/unit/custom_field_test.rb index 1b9c9aea..2f17d99c 100644 --- a/test/unit/custom_field_test.rb +++ b/test/unit/custom_field_test.rb @@ -25,6 +25,24 @@ class CustomFieldTest < Test::Unit::TestCase assert field.save end + def test_possible_values_should_accept_an_array + field = CustomField.new + field.possible_values = ["One value", ""] + assert_equal ["One value"], field.possible_values + end + + def test_possible_values_should_accept_a_string + field = CustomField.new + field.possible_values = "One value" + assert_equal ["One value"], field.possible_values + end + + def test_possible_values_should_accept_a_multiline_string + field = CustomField.new + field.possible_values = "One value\nAnd another one \r\n \n" + assert_equal ["One value", "And another one"], field.possible_values + end + def test_destroy field = CustomField.find(1) assert field.destroy