feature-29712-v3.patch

Mizuki ISHIKAWA, 2018-10-15 06:21

Download (4.59 KB)

View differences:

lib/redmine/field_format.rb
415 415
      end
416 416

  
417 417
      def edit_tag(view, tag_id, tag_name, custom_value, options={})
418
        view.text_area_tag(tag_name, custom_value.value, options.merge(:id => tag_id, :rows => 8))
418
        not_full_width_custom_fields = %w(IssueCustomField UserCustomField TimeEntryActivityCustomField)
419

  
420
        # Display wikitoolbar only if textarea is full width
421
        if custom_value.custom_field.text_formatting == 'full' &&
422
          (not_full_width_custom_fields.exclude?(custom_value.custom_field.type) ||custom_value.custom_field.full_width_layout?)
423

  
424
          if custom_value.custom_field.type == "IssueCustomField"
425
            preview_url = view.preview_issue_url(:project_id => custom_value.customized.project.id, :issue_id => custom_value.customized.id)
426
          else
427
            preview_url = view.preview_text_url
428
          end
429
          view.content_tag('span', :id => "#{tag_id}_and_toolbar") do
430
            view.text_area_tag(tag_name, custom_value.value,
431
                              options.merge(:id => tag_id,
432
                                            :rows => 8,
433
                                            :class => 'wiki-edit'
434
                                            ))
435
          end + view.wikitoolbar_for(tag_id, preview_url)
436
        else
437
          view.text_area_tag(tag_name, custom_value.value, options.merge(:id => tag_id, :rows => 8))
438
        end
419 439
      end
420 440

  
421 441
      def bulk_edit_tag(view, tag_id, tag_name, custom_field, objects, value, options={})
test/unit/lib/redmine/field_format/field_format_test.rb
98 98
    assert_equal "foo bar", field.format.formatted_custom_value(self, custom_value, false)
99 99
    assert_equal '<a class="external" href="http://foo/foo%20bar#anchor">foo bar</a>', field.format.formatted_custom_value(self, custom_value, true)
100 100
  end
101

  
102
  def test_edit_tag_should_display_wikitoolbar_if_text_formatting_enabled
103
    field = ProjectCustomField.new(:field_format => 'text', :text_formatting => 'full')
104
    custom_value = CustomValue.new(:custom_field => field, :customized => Project.first, :value => "foo bar")
105
    edit_tag = field.format.edit_tag(self, "tag_id", "tag_name", custom_value)
106

  
107
    assert_includes edit_tag, "<textarea name=\"tag_name\" id=\"tag_id\" rows=\"8\" class=\"wiki-edit\">\nfoo bar</textarea>"
108
    assert_includes edit_tag, wikitoolbar_for('tag_id', preview_text_url)
109
  end
110

  
111
  def test_edit_tag_should_not_display_wikitoolbar_if_text_formatting_disabled
112
    field = ProjectCustomField.new(:field_format => 'text', :text_formatting => nil)
113
    custom_value = CustomValue.new(:custom_field => field, :customized => Project.first, :value => "foo bar")
114
    edit_tag = field.format.edit_tag(self, "tag_id", "tag_name", custom_value)
115

  
116
    assert_includes edit_tag, "<textarea name=\"tag_name\" id=\"tag_id\" rows=\"8\">\nfoo bar</textarea>"
117
    assert_not_includes edit_tag, wikitoolbar_for('tag_id', preview_text_url)
118
  end
119

  
120
  def test_edit_tag_should_not_display_wikitoolbar_if_the_field_is_not_full_width_layout
121
    field = IssueCustomField.new(:field_format => 'text', :full_width_layout => nil, :text_formatting => 'full')
122
    custom_value = CustomValue.new(:custom_field => field, :customized => Issue.first, :value => "foo bar")
123
    edit_tag = field.format.edit_tag(self, "tag_id", "tag_name", custom_value)
124

  
125
    assert_includes edit_tag, "<textarea name=\"tag_name\" id=\"tag_id\" rows=\"8\">\nfoo bar</textarea>"
126
    assert_not_includes edit_tag, wikitoolbar_for('tag_id', preview_text_url)
127
  end
128

  
129
  def test_edit_tag_should_display_wikitoolbar_if_the_field_is_full_width_layout
130
    field = IssueCustomField.new(:field_format => 'text', :full_width_layout => '1', :text_formatting => 'full')
131
    custom_value = CustomValue.new(:custom_field => field, :customized => Issue.first, :value => "foo bar")
132
    edit_tag = field.format.edit_tag(self, "tag_id", "tag_name", custom_value)
133

  
134
    assert_includes edit_tag, "<textarea name=\"tag_name\" id=\"tag_id\" rows=\"8\" class=\"wiki-edit\">\nfoo bar</textarea>"
135
    assert_includes edit_tag, wikitoolbar_for('tag_id', preview_issue_url(:project_id => Issue.first.project.id, :issue_id => Issue.first.id))
136
  end
101 137
end