To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / helpers / custom_fields_helper.rb @ 912:5e80956cc792
History | View | Annotate | Download (5.72 KB)
| 1 | 909:cbb26bc654de | Chris | # encoding: utf-8
|
|---|---|---|---|
| 2 | #
|
||
| 3 | 441:cbce1fd3b1b7 | Chris | # Redmine - project management software
|
| 4 | # Copyright (C) 2006-2011 Jean-Philippe Lang
|
||
| 5 | 0:513646585e45 | Chris | #
|
| 6 | # This program is free software; you can redistribute it and/or
|
||
| 7 | # modify it under the terms of the GNU General Public License
|
||
| 8 | # as published by the Free Software Foundation; either version 2
|
||
| 9 | # of the License, or (at your option) any later version.
|
||
| 10 | 909:cbb26bc654de | Chris | #
|
| 11 | 0:513646585e45 | Chris | # This program is distributed in the hope that it will be useful,
|
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
| 14 | # GNU General Public License for more details.
|
||
| 15 | 909:cbb26bc654de | Chris | #
|
| 16 | 0:513646585e45 | Chris | # You should have received a copy of the GNU General Public License
|
| 17 | # along with this program; if not, write to the Free Software
|
||
| 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
| 19 | |||
| 20 | module CustomFieldsHelper |
||
| 21 | |||
| 22 | def custom_fields_tabs |
||
| 23 | tabs = [{:name => 'IssueCustomField', :partial => 'custom_fields/index', :label => :label_issue_plural},
|
||
| 24 | {:name => 'TimeEntryCustomField', :partial => 'custom_fields/index', :label => :label_spent_time},
|
||
| 25 | {:name => 'ProjectCustomField', :partial => 'custom_fields/index', :label => :label_project_plural},
|
||
| 26 | {:name => 'VersionCustomField', :partial => 'custom_fields/index', :label => :label_version_plural},
|
||
| 27 | {:name => 'UserCustomField', :partial => 'custom_fields/index', :label => :label_user_plural},
|
||
| 28 | {:name => 'GroupCustomField', :partial => 'custom_fields/index', :label => :label_group_plural},
|
||
| 29 | {:name => 'TimeEntryActivityCustomField', :partial => 'custom_fields/index', :label => TimeEntryActivity::OptionName},
|
||
| 30 | {:name => 'IssuePriorityCustomField', :partial => 'custom_fields/index', :label => IssuePriority::OptionName},
|
||
| 31 | {:name => 'DocumentCategoryCustomField', :partial => 'custom_fields/index', :label => DocumentCategory::OptionName}
|
||
| 32 | ] |
||
| 33 | end
|
||
| 34 | 909:cbb26bc654de | Chris | |
| 35 | 0:513646585e45 | Chris | # Return custom field html tag corresponding to its format
|
| 36 | def custom_field_tag(name, custom_value) |
||
| 37 | custom_field = custom_value.custom_field |
||
| 38 | field_name = "#{name}[custom_field_values][#{custom_field.id}]"
|
||
| 39 | field_id = "#{name}_custom_field_values_#{custom_field.id}"
|
||
| 40 | |||
| 41 | field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format) |
||
| 42 | 441:cbce1fd3b1b7 | Chris | case field_format.try(:edit_as) |
| 43 | 0:513646585e45 | Chris | when "date" |
| 44 | 909:cbb26bc654de | Chris | text_field_tag(field_name, custom_value.value, :id => field_id, :size => 10) + |
| 45 | 0:513646585e45 | Chris | calendar_for(field_id) |
| 46 | when "text" |
||
| 47 | text_area_tag(field_name, custom_value.value, :id => field_id, :rows => 3, :style => 'width:90%') |
||
| 48 | when "bool" |
||
| 49 | hidden_field_tag(field_name, '0') + check_box_tag(field_name, '1', custom_value.true?, :id => field_id) |
||
| 50 | when "list" |
||
| 51 | blank_option = custom_field.is_required? ? |
||
| 52 | 909:cbb26bc654de | Chris | (custom_field.default_value.blank? ? "<option value=\"\">--- #{l(:actionview_instancetag_blank_option)} ---</option>" : '') : |
| 53 | 0:513646585e45 | Chris | '<option></option>'
|
| 54 | 441:cbce1fd3b1b7 | Chris | select_tag(field_name, blank_option + options_for_select(custom_field.possible_values_options(custom_value.customized), custom_value.value), :id => field_id)
|
| 55 | 0:513646585e45 | Chris | else
|
| 56 | text_field_tag(field_name, custom_value.value, :id => field_id)
|
||
| 57 | end
|
||
| 58 | end
|
||
| 59 | 909:cbb26bc654de | Chris | |
| 60 | 0:513646585e45 | Chris | # Return custom field label tag
|
| 61 | def custom_field_label_tag(name, custom_value) |
||
| 62 | 909:cbb26bc654de | Chris | content_tag "label", h(custom_value.custom_field.name) +
|
| 63 | (custom_value.custom_field.is_required? ? " <span class=\"required\">*</span>".html_safe : ""), |
||
| 64 | 0:513646585e45 | Chris | :for => "#{name}_custom_field_values_#{custom_value.custom_field.id}", |
| 65 | :class => (custom_value.errors.empty? ? nil : "error" ) |
||
| 66 | end
|
||
| 67 | 909:cbb26bc654de | Chris | |
| 68 | 0:513646585e45 | Chris | # Return custom field tag with its label tag
|
| 69 | def custom_field_tag_with_label(name, custom_value) |
||
| 70 | custom_field_label_tag(name, custom_value) + custom_field_tag(name, custom_value) |
||
| 71 | end
|
||
| 72 | 909:cbb26bc654de | Chris | |
| 73 | 441:cbce1fd3b1b7 | Chris | def custom_field_tag_for_bulk_edit(name, custom_field, projects=nil) |
| 74 | 0:513646585e45 | Chris | field_name = "#{name}[custom_field_values][#{custom_field.id}]"
|
| 75 | field_id = "#{name}_custom_field_values_#{custom_field.id}"
|
||
| 76 | field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format) |
||
| 77 | 441:cbce1fd3b1b7 | Chris | case field_format.try(:edit_as) |
| 78 | 0:513646585e45 | Chris | when "date" |
| 79 | 909:cbb26bc654de | Chris | text_field_tag(field_name, '', :id => field_id, :size => 10) + |
| 80 | 0:513646585e45 | Chris | calendar_for(field_id) |
| 81 | when "text" |
||
| 82 | text_area_tag(field_name, '', :id => field_id, :rows => 3, :style => 'width:90%') |
||
| 83 | when "bool" |
||
| 84 | select_tag(field_name, options_for_select([[l(:label_no_change_option), ''], |
||
| 85 | [l(:general_text_yes), '1'], |
||
| 86 | [l(:general_text_no), '0']]), :id => field_id) |
||
| 87 | when "list" |
||
| 88 | 441:cbce1fd3b1b7 | Chris | select_tag(field_name, options_for_select([[l(:label_no_change_option), '']] + custom_field.possible_values_options(projects)), :id => field_id) |
| 89 | 0:513646585e45 | Chris | else
|
| 90 | text_field_tag(field_name, '', :id => field_id) |
||
| 91 | end
|
||
| 92 | end
|
||
| 93 | |||
| 94 | # Return a string used to display a custom value
|
||
| 95 | def show_value(custom_value) |
||
| 96 | return "" unless custom_value |
||
| 97 | format_value(custom_value.value, custom_value.custom_field.field_format) |
||
| 98 | end
|
||
| 99 | 909:cbb26bc654de | Chris | |
| 100 | 0:513646585e45 | Chris | # Return a string used to display a custom value
|
| 101 | def format_value(value, field_format) |
||
| 102 | Redmine::CustomFieldFormat.format_value(value, field_format) # Proxy |
||
| 103 | end
|
||
| 104 | |||
| 105 | # Return an array of custom field formats which can be used in select_tag
|
||
| 106 | 441:cbce1fd3b1b7 | Chris | def custom_field_formats_for_select(custom_field) |
| 107 | Redmine::CustomFieldFormat.as_select(custom_field.class.customized_class.name) |
||
| 108 | 0:513646585e45 | Chris | end
|
| 109 | 909:cbb26bc654de | Chris | |
| 110 | 119:8661b858af72 | Chris | # Renders the custom_values in api views
|
| 111 | def render_api_custom_values(custom_values, api) |
||
| 112 | api.array :custom_fields do |
||
| 113 | custom_values.each do |custom_value|
|
||
| 114 | api.custom_field :id => custom_value.custom_field_id, :name => custom_value.custom_field.name do |
||
| 115 | api.value custom_value.value |
||
| 116 | end
|
||
| 117 | end
|
||
| 118 | end unless custom_values.empty? |
||
| 119 | end
|
||
| 120 | 0:513646585e45 | Chris | end |