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 @ 1533:59e13100ea95
History | View | Annotate | Download (5.59 KB)
| 1 |
# encoding: utf-8
|
|---|---|
| 2 |
#
|
| 3 |
# Redmine - project management software
|
| 4 |
# Copyright (C) 2006-2014 Jean-Philippe Lang
|
| 5 |
#
|
| 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 |
#
|
| 11 |
# 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 |
#
|
| 16 |
# 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 |
CUSTOM_FIELDS_TABS = [
|
| 23 |
{:name => 'IssueCustomField', :partial => 'custom_fields/index',
|
| 24 |
:label => :label_issue_plural}, |
| 25 |
{:name => 'TimeEntryCustomField', :partial => 'custom_fields/index',
|
| 26 |
:label => :label_spent_time}, |
| 27 |
{:name => 'ProjectCustomField', :partial => 'custom_fields/index',
|
| 28 |
:label => :label_project_plural}, |
| 29 |
{:name => 'VersionCustomField', :partial => 'custom_fields/index',
|
| 30 |
:label => :label_version_plural}, |
| 31 |
{:name => 'UserCustomField', :partial => 'custom_fields/index',
|
| 32 |
:label => :label_user_plural}, |
| 33 |
{:name => 'GroupCustomField', :partial => 'custom_fields/index',
|
| 34 |
:label => :label_group_plural}, |
| 35 |
{:name => 'TimeEntryActivityCustomField', :partial => 'custom_fields/index',
|
| 36 |
:label => TimeEntryActivity::OptionName}, |
| 37 |
{:name => 'IssuePriorityCustomField', :partial => 'custom_fields/index',
|
| 38 |
:label => IssuePriority::OptionName}, |
| 39 |
{:name => 'DocumentCategoryCustomField', :partial => 'custom_fields/index',
|
| 40 |
:label => DocumentCategory::OptionName} |
| 41 |
] |
| 42 |
|
| 43 |
def render_custom_fields_tabs(types) |
| 44 |
tabs = CUSTOM_FIELDS_TABS.select {|h| types.include?(h[:name]) } |
| 45 |
render_tabs tabs |
| 46 |
end
|
| 47 |
|
| 48 |
def custom_field_type_options |
| 49 |
CUSTOM_FIELDS_TABS.map {|h| [l(h[:label]), h[:name]]} |
| 50 |
end
|
| 51 |
|
| 52 |
def render_custom_field_format_partial(form, custom_field) |
| 53 |
partial = custom_field.format.form_partial |
| 54 |
if partial
|
| 55 |
render :partial => custom_field.format.form_partial, :locals => {:f => form, :custom_field => custom_field} |
| 56 |
end
|
| 57 |
end
|
| 58 |
|
| 59 |
def custom_field_tag_name(prefix, custom_field) |
| 60 |
name = "#{prefix}[custom_field_values][#{custom_field.id}]"
|
| 61 |
name << "[]" if custom_field.multiple? |
| 62 |
name |
| 63 |
end
|
| 64 |
|
| 65 |
def custom_field_tag_id(prefix, custom_field) |
| 66 |
"#{prefix}_custom_field_values_#{custom_field.id}"
|
| 67 |
end
|
| 68 |
|
| 69 |
# Return custom field html tag corresponding to its format
|
| 70 |
def custom_field_tag(prefix, custom_value) |
| 71 |
custom_value.custom_field.format.edit_tag self,
|
| 72 |
custom_field_tag_id(prefix, custom_value.custom_field), |
| 73 |
custom_field_tag_name(prefix, custom_value.custom_field), |
| 74 |
custom_value, |
| 75 |
:class => "#{custom_value.custom_field.field_format}_cf" |
| 76 |
end
|
| 77 |
|
| 78 |
# Return custom field label tag
|
| 79 |
def custom_field_label_tag(name, custom_value, options={}) |
| 80 |
required = options[:required] || custom_value.custom_field.is_required?
|
| 81 |
title = custom_value.custom_field.description.presence |
| 82 |
content = content_tag 'span', custom_value.custom_field.name, :title => title |
| 83 |
|
| 84 |
content_tag "label", content +
|
| 85 |
(required ? " <span class=\"required\">*</span>".html_safe : ""), |
| 86 |
:for => "#{name}_custom_field_values_#{custom_value.custom_field.id}" |
| 87 |
end
|
| 88 |
|
| 89 |
# Return custom field tag with its label tag
|
| 90 |
def custom_field_tag_with_label(name, custom_value, options={}) |
| 91 |
custom_field_label_tag(name, custom_value, options) + custom_field_tag(name, custom_value) |
| 92 |
end
|
| 93 |
|
| 94 |
# Returns the custom field tag for when bulk editing objects
|
| 95 |
def custom_field_tag_for_bulk_edit(prefix, custom_field, objects=nil, value='') |
| 96 |
custom_field.format.bulk_edit_tag self,
|
| 97 |
custom_field_tag_id(prefix, custom_field), |
| 98 |
custom_field_tag_name(prefix, custom_field), |
| 99 |
custom_field, |
| 100 |
objects, |
| 101 |
value, |
| 102 |
:class => "#{custom_field.field_format}_cf" |
| 103 |
end
|
| 104 |
|
| 105 |
# Return a string used to display a custom value
|
| 106 |
def show_value(custom_value, html=true) |
| 107 |
format_object(custom_value, html) |
| 108 |
end
|
| 109 |
|
| 110 |
# Return a string used to display a custom value
|
| 111 |
def format_value(value, custom_field) |
| 112 |
format_object(custom_field.format.formatted_value(self, custom_field, value, false), false) |
| 113 |
end
|
| 114 |
|
| 115 |
# Return an array of custom field formats which can be used in select_tag
|
| 116 |
def custom_field_formats_for_select(custom_field) |
| 117 |
Redmine::FieldFormat.as_select(custom_field.class.customized_class.name) |
| 118 |
end
|
| 119 |
|
| 120 |
# Renders the custom_values in api views
|
| 121 |
def render_api_custom_values(custom_values, api) |
| 122 |
api.array :custom_fields do |
| 123 |
custom_values.each do |custom_value|
|
| 124 |
attrs = {:id => custom_value.custom_field_id, :name => custom_value.custom_field.name}
|
| 125 |
attrs.merge!(:multiple => true) if custom_value.custom_field.multiple? |
| 126 |
api.custom_field attrs do
|
| 127 |
if custom_value.value.is_a?(Array) |
| 128 |
api.array :value do |
| 129 |
custom_value.value.each do |value|
|
| 130 |
api.value value unless value.blank?
|
| 131 |
end
|
| 132 |
end
|
| 133 |
else
|
| 134 |
api.value custom_value.value |
| 135 |
end
|
| 136 |
end
|
| 137 |
end
|
| 138 |
end unless custom_values.empty? |
| 139 |
end
|
| 140 |
|
| 141 |
def edit_tag_style_tag(form, options={}) |
| 142 |
select_options = [[l(:label_drop_down_list), ''], [l(:label_checkboxes), 'check_box']] |
| 143 |
if options[:include_radio] |
| 144 |
select_options << [l(:label_radio_buttons), 'radio'] |
| 145 |
end
|
| 146 |
form.select :edit_tag_style, select_options, :label => :label_display |
| 147 |
end
|
| 148 |
end
|