2011-12-14 23:56:23 +04:00
|
|
|
# encoding: utf-8
|
|
|
|
#
|
2011-03-24 21:24:30 +03:00
|
|
|
# Redmine - project management software
|
2014-01-30 02:45:39 +04:00
|
|
|
# Copyright (C) 2006-2014 Jean-Philippe Lang
|
2007-03-12 20:59:02 +03:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-08-28 14:10:18 +04:00
|
|
|
#
|
2007-03-12 20:59:02 +03:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2011-08-28 14:10:18 +04:00
|
|
|
#
|
2007-03-12 20:59:02 +03:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
module CustomFieldsHelper
|
|
|
|
|
2013-08-04 14:26:54 +04:00
|
|
|
CUSTOM_FIELDS_TABS = [
|
|
|
|
{:name => 'IssueCustomField', :partial => 'custom_fields/index',
|
|
|
|
:label => :label_issue_plural},
|
|
|
|
{:name => 'TimeEntryCustomField', :partial => 'custom_fields/index',
|
|
|
|
:label => :label_spent_time},
|
|
|
|
{:name => 'ProjectCustomField', :partial => 'custom_fields/index',
|
|
|
|
:label => :label_project_plural},
|
|
|
|
{:name => 'VersionCustomField', :partial => 'custom_fields/index',
|
|
|
|
:label => :label_version_plural},
|
|
|
|
{:name => 'UserCustomField', :partial => 'custom_fields/index',
|
|
|
|
:label => :label_user_plural},
|
|
|
|
{:name => 'GroupCustomField', :partial => 'custom_fields/index',
|
|
|
|
:label => :label_group_plural},
|
|
|
|
{:name => 'TimeEntryActivityCustomField', :partial => 'custom_fields/index',
|
|
|
|
:label => TimeEntryActivity::OptionName},
|
|
|
|
{:name => 'IssuePriorityCustomField', :partial => 'custom_fields/index',
|
|
|
|
:label => IssuePriority::OptionName},
|
|
|
|
{:name => 'DocumentCategoryCustomField', :partial => 'custom_fields/index',
|
|
|
|
:label => DocumentCategory::OptionName}
|
|
|
|
]
|
|
|
|
|
2014-02-07 11:57:59 +04:00
|
|
|
def render_custom_fields_tabs(types)
|
|
|
|
tabs = CUSTOM_FIELDS_TABS.select {|h| types.include?(h[:name]) }
|
|
|
|
render_tabs tabs
|
|
|
|
end
|
|
|
|
|
|
|
|
def custom_field_type_options
|
|
|
|
CUSTOM_FIELDS_TABS.map {|h| [l(h[:label]), h[:name]]}
|
2008-03-26 21:49:12 +03:00
|
|
|
end
|
2011-08-28 14:10:18 +04:00
|
|
|
|
2013-12-14 12:22:43 +04:00
|
|
|
def render_custom_field_format_partial(form, custom_field)
|
|
|
|
partial = custom_field.format.form_partial
|
|
|
|
if partial
|
|
|
|
render :partial => custom_field.format.form_partial, :locals => {:f => form, :custom_field => custom_field}
|
2007-03-12 20:59:02 +03:00
|
|
|
end
|
|
|
|
end
|
2011-08-28 14:10:18 +04:00
|
|
|
|
2013-12-14 12:22:43 +04:00
|
|
|
def custom_field_tag_name(prefix, custom_field)
|
|
|
|
name = "#{prefix}[custom_field_values][#{custom_field.id}]"
|
|
|
|
name << "[]" if custom_field.multiple?
|
|
|
|
name
|
|
|
|
end
|
|
|
|
|
|
|
|
def custom_field_tag_id(prefix, custom_field)
|
|
|
|
"#{prefix}_custom_field_values_#{custom_field.id}"
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return custom field html tag corresponding to its format
|
|
|
|
def custom_field_tag(prefix, custom_value)
|
|
|
|
custom_value.custom_field.format.edit_tag self,
|
|
|
|
custom_field_tag_id(prefix, custom_value.custom_field),
|
|
|
|
custom_field_tag_name(prefix, custom_value.custom_field),
|
|
|
|
custom_value,
|
|
|
|
:class => "#{custom_value.custom_field.field_format}_cf"
|
|
|
|
end
|
|
|
|
|
2007-03-12 20:59:02 +03:00
|
|
|
# Return custom field label tag
|
2012-07-15 18:12:17 +04:00
|
|
|
def custom_field_label_tag(name, custom_value, options={})
|
|
|
|
required = options[:required] || custom_value.custom_field.is_required?
|
2013-12-14 12:22:43 +04:00
|
|
|
title = custom_value.custom_field.description.presence
|
|
|
|
content = content_tag 'span', custom_value.custom_field.name, :title => title
|
2012-07-15 18:12:17 +04:00
|
|
|
|
2013-12-14 12:22:43 +04:00
|
|
|
content_tag "label", content +
|
2012-07-15 18:12:17 +04:00
|
|
|
(required ? " <span class=\"required\">*</span>".html_safe : ""),
|
|
|
|
:for => "#{name}_custom_field_values_#{custom_value.custom_field.id}"
|
2007-03-12 20:59:02 +03:00
|
|
|
end
|
2011-08-28 14:10:18 +04:00
|
|
|
|
2007-03-12 20:59:02 +03:00
|
|
|
# Return custom field tag with its label tag
|
2012-07-15 18:12:17 +04:00
|
|
|
def custom_field_tag_with_label(name, custom_value, options={})
|
|
|
|
custom_field_label_tag(name, custom_value, options) + custom_field_tag(name, custom_value)
|
2007-03-12 20:59:02 +03:00
|
|
|
end
|
2011-08-28 14:10:18 +04:00
|
|
|
|
2013-12-14 12:22:43 +04:00
|
|
|
# Returns the custom field tag for when bulk editing objects
|
|
|
|
def custom_field_tag_for_bulk_edit(prefix, custom_field, objects=nil, value='')
|
|
|
|
custom_field.format.bulk_edit_tag self,
|
|
|
|
custom_field_tag_id(prefix, custom_field),
|
|
|
|
custom_field_tag_name(prefix, custom_field),
|
|
|
|
custom_field,
|
|
|
|
objects,
|
|
|
|
value,
|
|
|
|
:class => "#{custom_field.field_format}_cf"
|
2010-01-03 14:18:09 +03:00
|
|
|
end
|
2007-03-12 20:59:02 +03:00
|
|
|
|
|
|
|
# Return a string used to display a custom value
|
2013-12-14 12:22:43 +04:00
|
|
|
def show_value(custom_value, html=true)
|
|
|
|
format_object(custom_value, html)
|
2007-03-12 20:59:02 +03:00
|
|
|
end
|
2011-08-28 14:10:18 +04:00
|
|
|
|
2007-03-12 20:59:02 +03:00
|
|
|
# Return a string used to display a custom value
|
2013-12-14 12:22:43 +04:00
|
|
|
def format_value(value, custom_field)
|
|
|
|
format_object(custom_field.format.formatted_value(self, custom_field, value, false), false)
|
2007-03-12 20:59:02 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
# Return an array of custom field formats which can be used in select_tag
|
2011-04-01 17:44:58 +04:00
|
|
|
def custom_field_formats_for_select(custom_field)
|
2013-12-14 12:22:43 +04:00
|
|
|
Redmine::FieldFormat.as_select(custom_field.class.customized_class.name)
|
2006-07-29 13:32:58 +04:00
|
|
|
end
|
2011-08-28 14:10:18 +04:00
|
|
|
|
2010-12-10 13:12:19 +03:00
|
|
|
# Renders the custom_values in api views
|
|
|
|
def render_api_custom_values(custom_values, api)
|
|
|
|
api.array :custom_fields do
|
|
|
|
custom_values.each do |custom_value|
|
2012-01-30 00:51:48 +04:00
|
|
|
attrs = {:id => custom_value.custom_field_id, :name => custom_value.custom_field.name}
|
|
|
|
attrs.merge!(:multiple => true) if custom_value.custom_field.multiple?
|
|
|
|
api.custom_field attrs do
|
|
|
|
if custom_value.value.is_a?(Array)
|
|
|
|
api.array :value do
|
|
|
|
custom_value.value.each do |value|
|
|
|
|
api.value value unless value.blank?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
api.value custom_value.value
|
|
|
|
end
|
2010-12-10 13:12:19 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end unless custom_values.empty?
|
|
|
|
end
|
2013-12-14 12:22:43 +04:00
|
|
|
|
|
|
|
def edit_tag_style_tag(form)
|
|
|
|
form.select :edit_tag_style, [[l(:label_drop_down_list), ''], [l(:label_checkboxes), 'check_box']], :label => :label_display
|
|
|
|
end
|
2006-06-28 22:11:03 +04:00
|
|
|
end
|