I have multiple controller actions like adminbedroomtypesort, adminbookingstatussort, communicationtypesort, countrysort, currencysort , durationsort, featuressort, floorsort, furnishedsort, includedbillssort
and one js file
My js file:
$(document).ready(function() {
var data = {};
$( "#sortable" ).sortable({
update: function(event, ui) {
var update = ui.item.index();
update = update+1;
data['update'] = update;
console.log('update sortorder: '+update);
},
start: function(event, ui) {
var start = ui.item.index();
start = start+1;
data['start'] = start;
console.log('start: ' +start);
},
stop: function (event, ui) {
$('#loader').show();
$.ajax({
type: 'POST',
url: Routing.generate('adminbedroomtypesort'),
contentType: 'application/x-www-form-urlencoded',
data: {data: data},
success: function(result,status,xhr){
var res = JSON.parse(result);
if(res){
$('#loader').hide();
}
},
error: function(xhr, status, error) {
console.log(status);
}
});
}
});
$( "#sortable" ).disableSelection();
});
Controller action:
/**
* @Route("/bookingstatus/sort", name="adminbookingstatussort", options = { "expose" = true })
*/
public function sortbookingstatusAction(Request $request) {
if ($request->isXmlHttpRequest()) {
$em = $this->getDoctrine()->getManager();
//retrieve sort order from bedroomtypelistpage
$data = $request->request->get('data');
//Retrieve the start position and end position(updateorder) for the sorted field
$start = $data['start'];
$updateorder = empty($data['update']) ? NULL : $data['update'];
if(empty($updateorder)){
return new Response(json_encode('success'));
}
$bedroomtype = $em->getRepository('EpitaHousingBundle:Bookingstatus')->findOneBy(array('sortorder' => $start));
// flag -1 drag order is top to bottom
// flag 1 drag order is bottom to top
$flag = ($start < $updateorder) ? -1 : 1;
$btwelements = $this->getDoctrine()
->getRepository(Bookingstatus::class)
->findBedroom($start, $updateorder, $flag);
foreach ($btwelements as $betweenvalues) {
$order = $betweenvalues->getSortorder();
$betweenvalues->setSortorder($order + $flag);
}
$bedroomtype->setSortorder($updateorder);
$em->flush();
return new Response(json_encode('success'));
}
return new Response('Success');
}
like multiple controller actions have,
here i did one controller action to one separate js file it's working fine but here i am using same js file doing multiple times change url's only.
Is there any way to pass url: Routing.generate('adminbedroomtypesort'),
multiple url's to one js file corresponding controller actions help me any one.
Thanks for advance...