ro5840-integrate_dups_js_by_dustin_lambert-trunk_r7885.patch

Patch created against trunk @ r7885. - Mischa The Evil, 2011-11-24 22:20

Download (2.9 KB)

View differences:

app/views/issues/new.html.erb (working copy)
23 23

  
24 24
<% content_for :header_tags do %>
25 25
    <%= stylesheet_link_tag 'scm' %>
26
    <%= javascript_include_tag "dups.js" %>
26 27
    <%= robot_exclusion_tag %>
27 28
<% end %>
public/javascripts/dups.js (revision 0)
1
var timSearchSimilar = null;
2
var simelement = null;
3
var lastquery = "";
4

  
5
function updateSimilarIssues(element, response)
6
{
7
	var pat = new RegExp(/<a href=\"(\/[a-z]+)?\/issues\/(\d+)\">(.*?) #(\d+) \(([^\)]+)\)\: (.+?)<\/a>/gi);
8

  
9
	var result;
10
        var similarhtml = '';
11
        while ((result = pat.exec(response)) != null) 
12
        {
13
		similarhtml = similarhtml+ "<tr><td><a target=\"_blank\" href=\"" + result[1] + "/issues/" + result[2] + "\">" + result[3] + " #" + result[2]+"</a></td><td>"+result[6]+"</td><td>"+result[5]+"</td></tr>";
14
	}
15

  
16
	// NOTE: IE seems to have issues updating elements with HTML and prototype, so this is the only way I could make it work
17
	if (simelement !== null)
18
	{
19
		simelement.remove();
20
	}
21
	
22
	simelement = new Element("div")
23
	element.insert({after:simelement });
24
	
25
		
26
	if (similarhtml) 
27
	{
28
		var divhtml = "<div id='similarissues' style='padding: 5px 0 8px 180px;'><label>Did you mean?<br><span style='font-size:10px; line-height: normal; font-weight: normal'>These issues already exist</span></label><table style='line-height: 1em'>"+similarhtml+"</table></div>";
29
		simelement.insert(divhtml);
30
	}
31
}
32

  
33
function scheduleDupIssueSearch(element)
34
{
35
	var thisquery = element.getValue();
36
	
37
	if (thisquery == null || thisquery == undefined || lastquery == thisquery)
38
	{
39
		return;
40
	}
41
	
42
	lastquery = thisquery;
43
	
44
	clearTimeout(timSearchSimilar);
45
	timSearchSimilar = setTimeout(function() { searchDupIssues(element); }, 400);
46
}
47

  
48
function searchDupIssues(element)
49
{
50
    var proj = location.href.replace(/^.*\/projects\/([^\/]+)\/issues.*$/, '$1');
51
    var url = "../../../search/index/"+proj+"?issues=1&q="+escape(element.getValue());
52
    new Ajax.Request(url, {
53
    	method: 'get',
54
    	onSuccess: function(transport)
55
    	{
56
    		updateSimilarIssues(element, transport.responseText);
57
    	}    	
58
    });
59

  
60
}
61

  
62
function findDupIssues()
63
{
64

  
65
	$$(".new-issue-form #issue_subject").each(function(element)
66
	{
67
		element.setAttribute("autocomplete", "off");
68
		element.observe('keyup', function() {
69
			scheduleDupIssueSearch(element);
70
        	});
71
        	
72

  
73
                element.observe('change', function() {
74
                     scheduleDupIssueSearch(element);
75
                });        	
76
		
77
	});
78
	
79
}
80

  
81
document.observe('dom:loaded', function(){
82
	findDupIssues();
83
});
84

  
85

  
86