annotate .svn/pristine/a0/a095e9d6e0c8ebab9680ab7ec866f4186904f2e6.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents dffacf8a6908
children
rev   line source
Chris@1517 1 # encoding: utf-8
Chris@1517 2 #
Chris@1517 3 # Redmine - project management software
Chris@1517 4 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1517 5 #
Chris@1517 6 # This program is free software; you can redistribute it and/or
Chris@1517 7 # modify it under the terms of the GNU General Public License
Chris@1517 8 # as published by the Free Software Foundation; either version 2
Chris@1517 9 # of the License, or (at your option) any later version.
Chris@1517 10 #
Chris@1517 11 # This program is distributed in the hope that it will be useful,
Chris@1517 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1517 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1517 14 # GNU General Public License for more details.
Chris@1517 15 #
Chris@1517 16 # You should have received a copy of the GNU General Public License
Chris@1517 17 # along with this program; if not, write to the Free Software
Chris@1517 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1517 19
Chris@1517 20 module CustomFieldsHelper
Chris@1517 21
Chris@1517 22 CUSTOM_FIELDS_TABS = [
Chris@1517 23 {:name => 'IssueCustomField', :partial => 'custom_fields/index',
Chris@1517 24 :label => :label_issue_plural},
Chris@1517 25 {:name => 'TimeEntryCustomField', :partial => 'custom_fields/index',
Chris@1517 26 :label => :label_spent_time},
Chris@1517 27 {:name => 'ProjectCustomField', :partial => 'custom_fields/index',
Chris@1517 28 :label => :label_project_plural},
Chris@1517 29 {:name => 'VersionCustomField', :partial => 'custom_fields/index',
Chris@1517 30 :label => :label_version_plural},
Chris@1517 31 {:name => 'UserCustomField', :partial => 'custom_fields/index',
Chris@1517 32 :label => :label_user_plural},
Chris@1517 33 {:name => 'GroupCustomField', :partial => 'custom_fields/index',
Chris@1517 34 :label => :label_group_plural},
Chris@1517 35 {:name => 'TimeEntryActivityCustomField', :partial => 'custom_fields/index',
Chris@1517 36 :label => TimeEntryActivity::OptionName},
Chris@1517 37 {:name => 'IssuePriorityCustomField', :partial => 'custom_fields/index',
Chris@1517 38 :label => IssuePriority::OptionName},
Chris@1517 39 {:name => 'DocumentCategoryCustomField', :partial => 'custom_fields/index',
Chris@1517 40 :label => DocumentCategory::OptionName}
Chris@1517 41 ]
Chris@1517 42
Chris@1517 43 def render_custom_fields_tabs(types)
Chris@1517 44 tabs = CUSTOM_FIELDS_TABS.select {|h| types.include?(h[:name]) }
Chris@1517 45 render_tabs tabs
Chris@1517 46 end
Chris@1517 47
Chris@1517 48 def custom_field_type_options
Chris@1517 49 CUSTOM_FIELDS_TABS.map {|h| [l(h[:label]), h[:name]]}
Chris@1517 50 end
Chris@1517 51
Chris@1517 52 def render_custom_field_format_partial(form, custom_field)
Chris@1517 53 partial = custom_field.format.form_partial
Chris@1517 54 if partial
Chris@1517 55 render :partial => custom_field.format.form_partial, :locals => {:f => form, :custom_field => custom_field}
Chris@1517 56 end
Chris@1517 57 end
Chris@1517 58
Chris@1517 59 def custom_field_tag_name(prefix, custom_field)
Chris@1517 60 name = "#{prefix}[custom_field_values][#{custom_field.id}]"
Chris@1517 61 name << "[]" if custom_field.multiple?
Chris@1517 62 name
Chris@1517 63 end
Chris@1517 64
Chris@1517 65 def custom_field_tag_id(prefix, custom_field)
Chris@1517 66 "#{prefix}_custom_field_values_#{custom_field.id}"
Chris@1517 67 end
Chris@1517 68
Chris@1517 69 # Return custom field html tag corresponding to its format
Chris@1517 70 def custom_field_tag(prefix, custom_value)
Chris@1517 71 custom_value.custom_field.format.edit_tag self,
Chris@1517 72 custom_field_tag_id(prefix, custom_value.custom_field),
Chris@1517 73 custom_field_tag_name(prefix, custom_value.custom_field),
Chris@1517 74 custom_value,
Chris@1517 75 :class => "#{custom_value.custom_field.field_format}_cf"
Chris@1517 76 end
Chris@1517 77
Chris@1517 78 # Return custom field label tag
Chris@1517 79 def custom_field_label_tag(name, custom_value, options={})
Chris@1517 80 required = options[:required] || custom_value.custom_field.is_required?
Chris@1517 81 title = custom_value.custom_field.description.presence
Chris@1517 82 content = content_tag 'span', custom_value.custom_field.name, :title => title
Chris@1517 83
Chris@1517 84 content_tag "label", content +
Chris@1517 85 (required ? " <span class=\"required\">*</span>".html_safe : ""),
Chris@1517 86 :for => "#{name}_custom_field_values_#{custom_value.custom_field.id}"
Chris@1517 87 end
Chris@1517 88
Chris@1517 89 # Return custom field tag with its label tag
Chris@1517 90 def custom_field_tag_with_label(name, custom_value, options={})
Chris@1517 91 custom_field_label_tag(name, custom_value, options) + custom_field_tag(name, custom_value)
Chris@1517 92 end
Chris@1517 93
Chris@1517 94 # Returns the custom field tag for when bulk editing objects
Chris@1517 95 def custom_field_tag_for_bulk_edit(prefix, custom_field, objects=nil, value='')
Chris@1517 96 custom_field.format.bulk_edit_tag self,
Chris@1517 97 custom_field_tag_id(prefix, custom_field),
Chris@1517 98 custom_field_tag_name(prefix, custom_field),
Chris@1517 99 custom_field,
Chris@1517 100 objects,
Chris@1517 101 value,
Chris@1517 102 :class => "#{custom_field.field_format}_cf"
Chris@1517 103 end
Chris@1517 104
Chris@1517 105 # Return a string used to display a custom value
Chris@1517 106 def show_value(custom_value, html=true)
Chris@1517 107 format_object(custom_value, html)
Chris@1517 108 end
Chris@1517 109
Chris@1517 110 # Return a string used to display a custom value
Chris@1517 111 def format_value(value, custom_field)
Chris@1517 112 format_object(custom_field.format.formatted_value(self, custom_field, value, false), false)
Chris@1517 113 end
Chris@1517 114
Chris@1517 115 # Return an array of custom field formats which can be used in select_tag
Chris@1517 116 def custom_field_formats_for_select(custom_field)
Chris@1517 117 Redmine::FieldFormat.as_select(custom_field.class.customized_class.name)
Chris@1517 118 end
Chris@1517 119
Chris@1517 120 # Renders the custom_values in api views
Chris@1517 121 def render_api_custom_values(custom_values, api)
Chris@1517 122 api.array :custom_fields do
Chris@1517 123 custom_values.each do |custom_value|
Chris@1517 124 attrs = {:id => custom_value.custom_field_id, :name => custom_value.custom_field.name}
Chris@1517 125 attrs.merge!(:multiple => true) if custom_value.custom_field.multiple?
Chris@1517 126 api.custom_field attrs do
Chris@1517 127 if custom_value.value.is_a?(Array)
Chris@1517 128 api.array :value do
Chris@1517 129 custom_value.value.each do |value|
Chris@1517 130 api.value value unless value.blank?
Chris@1517 131 end
Chris@1517 132 end
Chris@1517 133 else
Chris@1517 134 api.value custom_value.value
Chris@1517 135 end
Chris@1517 136 end
Chris@1517 137 end
Chris@1517 138 end unless custom_values.empty?
Chris@1517 139 end
Chris@1517 140
Chris@1517 141 def edit_tag_style_tag(form, options={})
Chris@1517 142 select_options = [[l(:label_drop_down_list), ''], [l(:label_checkboxes), 'check_box']]
Chris@1517 143 if options[:include_radio]
Chris@1517 144 select_options << [l(:label_radio_buttons), 'radio']
Chris@1517 145 end
Chris@1517 146 form.select :edit_tag_style, select_options, :label => :label_display
Chris@1517 147 end
Chris@1517 148 end