0002-Allow-issue-relation-autocomplete-to-select-multiple.patch

Marius BALTEANU, 2020-12-17 00:16

Download (4.18 KB)

View differences:

app/views/issue_relations/_form.html.erb
18 18
<%= link_to_function l(:button_cancel), '$("#new-relation-form").hide();'%>
19 19
</p>
20 20

  
21
<%= javascript_tag "observeAutocompleteField('relation_issue_to_id', '#{escape_javascript auto_complete_issues_path(:project_id => @project, :scope => (Setting.cross_project_issue_relations? ? 'all' : nil), :issue_id => @issue.id)}')" %>
21
<%= javascript_tag "multipleAutocompleteField('relation_issue_to_id', '#{escape_javascript auto_complete_issues_path(:project_id => @project, :scope => (Setting.cross_project_issue_relations? ? 'all' : nil), :issue_id => @issue.id)}')" %>
22 22

  
23 23
<%= javascript_tag "setPredecessorFieldsVisibility();" %>
public/javascripts/application.js
617 617
  });
618 618
}
619 619

  
620
function multipleAutocompleteField(fieldId, url, options) {
621
  function split(val) {
622
    return val.split(/,\s*/);
623
  }
624

  
625
  function extractLast(term) {
626
    return split(term).pop();
627
  }
628

  
629
  $(document).ready(function () {
630
    $('#' + fieldId).autocomplete($.extend({
631
      source: function (request, response) {
632
        $.getJSON(url, {
633
          term: extractLast(request.term)
634
        }, response);
635
      },
636
      minLength: 2,
637
      position: {collision: "flipfit"},
638
      search: function () {
639
        $('#' + fieldId).addClass('ajax-loading');
640
      },
641
      response: function () {
642
        $('#' + fieldId).removeClass('ajax-loading');
643
      },
644
      select: function (event, ui) {
645
        var terms = split(this.value);
646
        // remove the current input
647
        terms.pop();
648
        // add the selected item
649
        terms.push(ui.item.value);
650
        // add placeholder to get the comma-and-space at the end
651
        terms.push("");
652
        this.value = terms.join(", ");
653
        return false;
654
      }
655
    }, options));
656
    $('#' + fieldId).addClass('autocomplete');
657
  });
658
}
659

  
620 660
function observeSearchfield(fieldId, targetId, url) {
621 661
  $('#'+fieldId).each(function() {
622 662
    var $this = $(this);
test/system/issues_test.rb
540 540
    assert !page.has_css?('#trackers_description')
541 541
    assert_equal "2", page.find('select#issue_tracker_id').value
542 542
  end
543

  
544
  def test_edit_should_allow_adding_multiple_relations_from_autocomplete
545
    log_user('admin', 'admin')
546

  
547
    visit '/issues/1'
548
    page.find('#relations .contextual a').click
549
    page.fill_in 'relation[issue_to_id]', :with => 'issue'
550

  
551
    within('ul.ui-autocomplete') do
552
      assert page.has_text? 'Bug #12: Closed issue on a locked version'
553
      assert page.has_text? 'Bug #11: Closed issue on a closed version'
554

  
555
      first('li.ui-menu-item').click
556
    end
557
    assert_equal '12, ', find('#relation_issue_to_id').value
558

  
559
    find('#relation_issue_to_id').click.send_keys('issue due')
560
    within('ul.ui-autocomplete') do
561
      assert page.has_text? 'Bug #7: Issue due today'
562

  
563
      find('li.ui-menu-item').click
564
    end
565
    assert_equal '12, 7, ', find('#relation_issue_to_id').value
566

  
567
    find('#relations').click_button("Add")
568

  
569
    within('#relations table.issues') do
570
      assert page.has_text? "Related to Bug #12"
571
      assert page.has_text? "Related to Bug #7"
572
    end
573
  end
543 574
end
544
-