Index: app/views/issues/new.html.erb =================================================================== --- app/views/issues/new.html.erb (revision 7885) +++ app/views/issues/new.html.erb (working copy) @@ -23,5 +23,6 @@ <% content_for :header_tags do %> <%= stylesheet_link_tag 'scm' %> + <%= javascript_include_tag "dups.js" %> <%= robot_exclusion_tag %> <% end %> Index: public/javascripts/dups.js =================================================================== --- public/javascripts/dups.js (revision 0) +++ public/javascripts/dups.js (revision 0) @@ -0,0 +1,86 @@ +var timSearchSimilar = null; +var simelement = null; +var lastquery = ""; + +function updateSimilarIssues(element, response) +{ + var pat = new RegExp(/(.*?) #(\d+) \(([^\)]+)\)\: (.+?)<\/a>/gi); + + var result; + var similarhtml = ''; + while ((result = pat.exec(response)) != null) + { + similarhtml = similarhtml+ "" + result[3] + " #" + result[2]+""+result[6]+""+result[5]+""; + } + + // NOTE: IE seems to have issues updating elements with HTML and prototype, so this is the only way I could make it work + if (simelement !== null) + { + simelement.remove(); + } + + simelement = new Element("div") + element.insert({after:simelement }); + + + if (similarhtml) + { + var divhtml = "
"+similarhtml+"
"; + simelement.insert(divhtml); + } +} + +function scheduleDupIssueSearch(element) +{ + var thisquery = element.getValue(); + + if (thisquery == null || thisquery == undefined || lastquery == thisquery) + { + return; + } + + lastquery = thisquery; + + clearTimeout(timSearchSimilar); + timSearchSimilar = setTimeout(function() { searchDupIssues(element); }, 400); +} + +function searchDupIssues(element) +{ + var proj = location.href.replace(/^.*\/projects\/([^\/]+)\/issues.*$/, '$1'); + var url = "../../../search/index/"+proj+"?issues=1&q="+escape(element.getValue()); + new Ajax.Request(url, { + method: 'get', + onSuccess: function(transport) + { + updateSimilarIssues(element, transport.responseText); + } + }); + +} + +function findDupIssues() +{ + + $$(".new-issue-form #issue_subject").each(function(element) + { + element.setAttribute("autocomplete", "off"); + element.observe('keyup', function() { + scheduleDupIssueSearch(element); + }); + + + element.observe('change', function() { + scheduleDupIssueSearch(element); + }); + + }); + +} + +document.observe('dom:loaded', function(){ + findDupIssues(); +}); + + +