Display the battery to be added to the form. #323
This commit is contained in:
parent
fd2fe4fb6f
commit
6bcdf70902
2 changed files with 35 additions and 10 deletions
|
|
@ -419,7 +419,6 @@ class BatteryController extends Controller
|
|||
{
|
||||
// no access check, grant all for this ajax call
|
||||
|
||||
error_log($req->query->get('id'));
|
||||
// parse the id: model size
|
||||
$batt_specs = explode(" ", $req->query->get('id'));
|
||||
$bmodel_id = $batt_specs[0];
|
||||
|
|
@ -435,10 +434,24 @@ class BatteryController extends Controller
|
|||
|
||||
$result = $query->getResult();
|
||||
|
||||
if (empty($result))
|
||||
throw $this->createNotFoundException('The item does not exist');
|
||||
|
||||
$batteries = [];
|
||||
|
||||
foreach ($result as $row)
|
||||
{
|
||||
error_log('id ' . $row->getID());
|
||||
$batteries[] = [
|
||||
'id' => $row->getID(),
|
||||
'model' => $row->getModel()->getName(),
|
||||
'size' => $row->getSize()->getName(),
|
||||
'price' => $row->getSellingPrice(),
|
||||
];
|
||||
}
|
||||
|
||||
return $this->json([
|
||||
'data' => $batteries
|
||||
]);
|
||||
}
|
||||
|
||||
// check if datatable filter is present and append to query
|
||||
|
|
|
|||
|
|
@ -292,16 +292,28 @@ $(function() {
|
|||
url: "{{ url('battery_get') }}",
|
||||
data: {id: bmodelsize}
|
||||
}).done(function(response) {
|
||||
|
||||
})
|
||||
if (response.data.length > 0) {
|
||||
var batt = response.data[0];
|
||||
|
||||
// add battery to arrays
|
||||
battModelSize.push(bmodelsize);
|
||||
batteryIds.push(batt.id);
|
||||
|
||||
brow = {
|
||||
id: batt.id,
|
||||
model: batt.model,
|
||||
size: batt.size,
|
||||
sell_price: batt.price
|
||||
};
|
||||
|
||||
battRows.push(brow);
|
||||
|
||||
// refresh the data table
|
||||
battTable.originalDataSet = battRows;
|
||||
battTable.reload();
|
||||
|
||||
// add battery to arrays
|
||||
battModelSize.push(bmodelsize);
|
||||
|
||||
// refresh the data table
|
||||
battTable.originalDataSet = battRows;
|
||||
battTable.reload();
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
// battery data table
|
||||
|
|
|
|||
Loading…
Reference in a new issue