選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

custom_fields_helper.rb 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # redMine - project management software
  2. # Copyright (C) 2006 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 CustomFieldsHelper
  18. # Return custom field html tag corresponding to its format
  19. def custom_field_tag(custom_value)
  20. custom_field = custom_value.custom_field
  21. field_name = "custom_fields[#{custom_field.id}]"
  22. field_id = "custom_fields_#{custom_field.id}"
  23. case custom_field.field_format
  24. when "string", "int"
  25. text_field 'custom_value', 'value', :name => field_name, :id => field_id
  26. when "date"
  27. text_field('custom_value', 'value', :name => field_name, :id => field_id, :size => 10) +
  28. calendar_for(field_id)
  29. when "text"
  30. text_area 'custom_value', 'value', :name => field_name, :id => field_id, :cols => 60, :rows => 3
  31. when "bool"
  32. check_box 'custom_value', 'value', :name => field_name, :id => field_id
  33. when "list"
  34. select 'custom_value', 'value', custom_field.possible_values.split('|'), { :include_blank => true }, :name => field_name, :id => field_id
  35. end
  36. end
  37. # Return custom field label tag
  38. def custom_field_label_tag(custom_value)
  39. content_tag "label", custom_value.custom_field.name +
  40. (custom_value.custom_field.is_required? ? " <span class=\"required\">*</span>" : ""),
  41. :for => "custom_fields_#{custom_value.custom_field.id}",
  42. :class => (custom_value.errors.empty? ? nil : "error" )
  43. end
  44. # Return custom field tag with its label tag
  45. def custom_field_tag_with_label(custom_value)
  46. custom_field_label_tag(custom_value) + custom_field_tag(custom_value)
  47. end
  48. # Return a string used to display a custom value
  49. def show_value(custom_value)
  50. return "" unless custom_value
  51. format_value(custom_value.value, custom_value.custom_field.field_format)
  52. end
  53. # Return a string used to display a custom value
  54. def format_value(value, field_format)
  55. return "" unless value
  56. case field_format
  57. when "date"
  58. value.empty? ? "" : l_date(value.to_date)
  59. when "bool"
  60. l_YesNo(value == "1")
  61. else
  62. value
  63. end
  64. end
  65. # Return an array of custom field formats which can be used in select_tag
  66. def custom_field_formats_for_select
  67. CustomField::FIELD_FORMATS.keys.collect { |k| [ l(CustomField::FIELD_FORMATS[k]), k ] }
  68. end
  69. end