-
Notifications
You must be signed in to change notification settings - Fork 0
/
PoolPartyAutoCompleteSetter.js
75 lines (51 loc) · 2.16 KB
/
PoolPartyAutoCompleteSetter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* Created by Daniel Maatary on 4/22/15.
*/
function set_autocomplete ($, select, $input) {
$input.autocomplete({
source: function (request, response) {
$.ajax({
url: "http://thesaurus.iadb.org/extractor/api/suggest",
data: {projectId: "1DCE031A-B429-0001-49B6-15A028B01F5D", language: "en", searchString: request.term},
username: 'superadmin',
password: 'poolparty',
dataType: 'json',
crossDomain: true,
beforeSend: function(req) {
req.setRequestHeader('Authorization', 'Basic ' + btoa('superadmin:poolparty'));
},
xhrFields: {
withCredentials: true
},
error: function( jqXHR, textStatus, errorThrown ) {
response(textStatus)
},
success: function (data) {
var datatable = Array();
for(i = 0; i < data.suggestedConcepts.length; i++) {
datatable[i] = {label: data.suggestedConcepts[i].matchingLabel, value: data.suggestedConcepts[i].prefLabel, mydata: data.suggestedConcepts[i]}
datatable[i].label = datatable[i].label.replace("<em>", "<strong class = \"ac_highlight\">")
datatable[i].label = datatable[i].label.replace("</em>", "</strong>")
//TODO Filter conceptsSchemes table object
}
response(datatable);
}
})
},
minLength: 2,
select: select,
html: true,
open: function () {
$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
},
close: function () {
$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
}
}).autocomplete("instance")._renderMenu = function( ul, items ) {
var that = this;
$.each( items, function( index, item ) {
that._renderItemData( ul, item );
});
$( ul ).find( "li:odd" ).addClass( "ac_odd" );
}
}