2012-01-25 05:31:27 +01:00
|
|
|
jQuery(function($){
|
|
|
|
|
2012-01-24 18:37:00 +01:00
|
|
|
$(document).delegate(".ss-gridfield .relation-search", "focus", function (event) {
|
2012-01-25 05:31:27 +01:00
|
|
|
$(this).autocomplete({
|
|
|
|
source: function(request, response){
|
|
|
|
var searchField = $(this.element);
|
|
|
|
var form = $(this.element).closest("form");
|
|
|
|
// Due to some very weird behaviout of jquery.metadata, the url have to be double quoted
|
|
|
|
var suggestionUrl = $(searchField).attr('data-search-url').substr(1,$(searchField).attr('data-search-url').length-2);
|
|
|
|
$.ajax({
|
|
|
|
headers: {
|
|
|
|
"X-Get-Fragment" : 'Partial'
|
|
|
|
},
|
|
|
|
type: "GET",
|
|
|
|
url: suggestionUrl+'/'+request.term,
|
|
|
|
data: form.serialize()+'&'+escape(searchField.attr('name'))+'='+escape(searchField.val()),
|
|
|
|
success: function(data) {
|
|
|
|
response( $.map(JSON.parse(data), function( name, id ) {
|
2012-02-21 21:30:51 +01:00
|
|
|
return { label: name, value: name, id: id };
|
2012-01-25 05:31:27 +01:00
|
|
|
}));
|
|
|
|
},
|
|
|
|
error: function(e) {
|
|
|
|
alert(ss.i18n._t('GRIDFIELD.ERRORINTRANSACTION', 'An error occured while fetching data from the server\n Please try again later.'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
select: function(event, ui) {
|
2012-02-23 15:17:39 +01:00
|
|
|
$(this).closest(".ss-gridfield").find("#action_gridfield_relationfind").replaceWith(
|
2012-01-25 05:31:27 +01:00
|
|
|
'<input type="hidden" name="relationID" value="'+ui.item.id+'" id="relationID"/>'
|
|
|
|
);
|
2012-02-23 15:17:39 +01:00
|
|
|
$(this).closest(".ss-gridfield").find("#action_gridfield_relationadd").removeAttr('disabled');
|
2012-01-25 05:31:27 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|