mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR Integrating GridFieldSearch.js in GridField.js (and using entwine for it)
This commit is contained in:
parent
51bae9e4a6
commit
0b4228231c
@ -744,11 +744,14 @@ class GridField_Action extends FormAction {
|
||||
* @return string HTML tag
|
||||
*/
|
||||
public function Field() {
|
||||
Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css');
|
||||
Requirements::css(SAPPHIRE_DIR . '/css/GridField.css');
|
||||
|
||||
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
|
||||
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/jquery-ui.js');
|
||||
Requirements::javascript(THIRDPARTY_DIR . '/json-js/json2.js');
|
||||
Requirements::javascript(SAPPHIRE_DIR . '/javascript/i18n.js');
|
||||
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
|
||||
Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
|
||||
Requirements::javascript(SAPPHIRE_DIR . '/javascript/GridField.js');
|
||||
|
||||
|
@ -53,12 +53,6 @@ class GridFieldRelationAdd implements GridField_HTMLProvider, GridField_ActionPr
|
||||
$searchState = $gridField->State->GridFieldSearchRelation;
|
||||
$dataClass = $gridField->getList()->dataClass();
|
||||
|
||||
Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css');
|
||||
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
|
||||
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
|
||||
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/jquery-ui.js');
|
||||
Requirements::javascript(SAPPHIRE_DIR . "/javascript/GridFieldSearch.js");
|
||||
|
||||
$forTemplate = new ArrayData(array());
|
||||
$forTemplate->Fields = new ArrayList();
|
||||
|
||||
|
@ -207,4 +207,44 @@
|
||||
}
|
||||
});
|
||||
|
||||
$(".ss-gridfield .relation-search").entwine({
|
||||
onfocusin: function (event) {
|
||||
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 ) {
|
||||
return { label: name, value: name, id: id };
|
||||
}));
|
||||
},
|
||||
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) {
|
||||
$(this).closest(".ss-gridfield").find("#action_gridfield_relationfind").replaceWith(
|
||||
'<input type="hidden" name="relationID" value="'+ui.item.id+'" id="relationID"/>'
|
||||
);
|
||||
var addbutton = $(this).closest(".ss-gridfield").find("#action_gridfield_relationadd");
|
||||
if(addbutton.data('button')){
|
||||
addbutton.button('enable');
|
||||
}else{
|
||||
addbutton.removeAttr('disabled');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}(jQuery));
|
||||
|
@ -1,41 +0,0 @@
|
||||
jQuery(function($){
|
||||
|
||||
$(document).delegate(".ss-gridfield .relation-search", "focus", function (event) {
|
||||
$(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 ) {
|
||||
return { label: name, value: name, id: id };
|
||||
}));
|
||||
},
|
||||
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) {
|
||||
$(this).closest(".ss-gridfield").find("#action_gridfield_relationfind").replaceWith(
|
||||
'<input type="hidden" name="relationID" value="'+ui.item.id+'" id="relationID"/>'
|
||||
);
|
||||
var addbutton = $(this).closest(".ss-gridfield").find("#action_gridfield_relationadd");
|
||||
if(addbutton.data('button')){
|
||||
addbutton.button('enable');
|
||||
}else{
|
||||
addbutton.removeAttr('disabled');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user