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
This commit is contained in:
Jean-Philippe Lang 2009-01-16 21:02:03 +00:00
parent f6282f9600
commit a276926f42
34 changed files with 62 additions and 24 deletions

View File

@ -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.

View File

@ -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);
}
}
//]]>
</script>
@ -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 %><br>(<%=l(:text_min_max_length_info)%>)</p>
<p><%= f.text_field :regexp, :size => 50 %><br>(<%=l(:text_regexp_info)%>)</p>
<p id="custom_field_possible_values"><label><%= l(:field_possible_values) %> <%= image_to_function "add.png", "addValueField();return false" %></label>
<% (@custom_field.possible_values.to_a + [""]).each do |value| %>
<span><%= text_field_tag 'custom_field[possible_values][]', value, :size => 30 %> <%= image_to_function "delete.png", "deleteValueField(this);return false" %><br /></span>
<% end %>
</p>
<p id="custom_field_possible_values"><%= f.text_area :possible_values, :value => @custom_field.possible_values.to_a.join("\n"),
:cols => 20,
:rows => 15 %>
<br /><em><%= l(:text_custom_field_possible_values_info) %></em></p>
<p><%= @custom_field.field_format == 'bool' ? f.check_box(:default_value) : f.text_field(:default_value) %></p>
</div>

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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

View File

@ -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'

View File

@ -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'

View File

@ -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

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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