Merge branch 'master' of gitlab.com:jankstudio/resq
This commit is contained in:
commit
7f6beb2b99
26 changed files with 2819 additions and 29 deletions
|
|
@ -32,3 +32,73 @@ access_keys:
|
||||||
label: Update
|
label: Update
|
||||||
- id: role.delete
|
- id: role.delete
|
||||||
label: Delete
|
label: Delete
|
||||||
|
- id: database
|
||||||
|
label: Database Access
|
||||||
|
acls:
|
||||||
|
- id: database.menu
|
||||||
|
label: Menu
|
||||||
|
- id: bmfg
|
||||||
|
label: Battery Manufacturer Access
|
||||||
|
acls:
|
||||||
|
- id: bmfg.menu
|
||||||
|
label: Menu
|
||||||
|
- id: bmfg.list
|
||||||
|
label: List
|
||||||
|
- id: bmfg.add
|
||||||
|
label: Add
|
||||||
|
- id: bmfg.update
|
||||||
|
label: Update
|
||||||
|
- id: bmfg.delete
|
||||||
|
label: Delete
|
||||||
|
- id: bmodel
|
||||||
|
label: Battery Model Access
|
||||||
|
acls:
|
||||||
|
- id: bmodel.menu
|
||||||
|
label: Menu
|
||||||
|
- id: bmodel.list
|
||||||
|
label: List
|
||||||
|
- id: bmodel.add
|
||||||
|
label: Add
|
||||||
|
- id: bmodel.update
|
||||||
|
label: Update
|
||||||
|
- id: bmodel.delete
|
||||||
|
label: Delete
|
||||||
|
- id: bsize
|
||||||
|
label: Battery Size Access
|
||||||
|
acls:
|
||||||
|
- id: bsize.menu
|
||||||
|
label: Menu
|
||||||
|
- id: bsize.list
|
||||||
|
label: List
|
||||||
|
- id: bsize.add
|
||||||
|
label: Add
|
||||||
|
- id: bsize.update
|
||||||
|
label: Update
|
||||||
|
- id: bsize.delete
|
||||||
|
label: Delete
|
||||||
|
- id: vehicle
|
||||||
|
label: Vehicle Access
|
||||||
|
acls:
|
||||||
|
- id: vehicle.menu
|
||||||
|
label: Menu
|
||||||
|
- id: vehicle.list
|
||||||
|
label: List
|
||||||
|
- id: vehicle.add
|
||||||
|
label: Add
|
||||||
|
- id: vehicle.update
|
||||||
|
label: Update
|
||||||
|
- id: vehicle.delete
|
||||||
|
label: Delete
|
||||||
|
- id: vmfg
|
||||||
|
label: Vehicle Manufacturer Access
|
||||||
|
acls:
|
||||||
|
- id: vmfg.menu
|
||||||
|
label: Menu
|
||||||
|
- id: vmfg.list
|
||||||
|
label: List
|
||||||
|
- id: vmfg.add
|
||||||
|
label: Add
|
||||||
|
- id: vmfg.update
|
||||||
|
label: Update
|
||||||
|
- id: vmfg.delete
|
||||||
|
label: Delete
|
||||||
|
|
@ -15,3 +15,28 @@ main_menu:
|
||||||
acl: role.list
|
acl: role.list
|
||||||
label: Roles
|
label: Roles
|
||||||
parent: user
|
parent: user
|
||||||
|
|
||||||
|
- id: database
|
||||||
|
acl: database.menu
|
||||||
|
label: Database
|
||||||
|
icon: flaticon-tabs
|
||||||
|
- id: bmfg_list
|
||||||
|
acl: bmfg.list
|
||||||
|
label: Battery Manufacturers
|
||||||
|
parent: database
|
||||||
|
- id: bmodel_list
|
||||||
|
acl: bmodel.list
|
||||||
|
label: Battery Models
|
||||||
|
parent: database
|
||||||
|
- id: bsize_list
|
||||||
|
acl: bsize.list
|
||||||
|
label: Battery Sizes
|
||||||
|
parent: database
|
||||||
|
- id: vehicle_list
|
||||||
|
acl: vehicle.list
|
||||||
|
label: Vehicles
|
||||||
|
parent: database
|
||||||
|
- id: vmfg_list
|
||||||
|
acl: vmfg.list
|
||||||
|
label: Vehicle Manufacturers
|
||||||
|
parent: database
|
||||||
|
|
@ -88,6 +88,186 @@ role_delete:
|
||||||
controller: App\Controller\RoleController::destroy
|
controller: App\Controller\RoleController::destroy
|
||||||
methods: [DELETE]
|
methods: [DELETE]
|
||||||
|
|
||||||
|
# battery manufacturers
|
||||||
|
|
||||||
|
bmfg_list:
|
||||||
|
path: /battery-manufacturers
|
||||||
|
controller: App\Controller\BatteryManufacturerController::index
|
||||||
|
|
||||||
|
bmfg_rows:
|
||||||
|
path: /battery-manufacturers/rows
|
||||||
|
controller: App\Controller\BatteryManufacturerController::rows
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
bmfg_create:
|
||||||
|
path: /battery-manufacturers/create
|
||||||
|
controller: App\Controller\BatteryManufacturerController::create
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
bmfg_create_submit:
|
||||||
|
path: /battery-manufacturers/create
|
||||||
|
controller: App\Controller\BatteryManufacturerController::createSubmit
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
bmfg_update:
|
||||||
|
path: /battery-manufacturers/{id}
|
||||||
|
controller: App\Controller\BatteryManufacturerController::update
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
bmfg_update_submit:
|
||||||
|
path: /battery-manufacturers/{id}
|
||||||
|
controller: App\Controller\BatteryManufacturerController::updateSubmit
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
bmfg_delete:
|
||||||
|
path: /battery-manufacturers/{id}
|
||||||
|
controller: App\Controller\BatteryManufacturerController::destroy
|
||||||
|
methods: [DELETE]
|
||||||
|
|
||||||
|
# battery models
|
||||||
|
|
||||||
|
bmodel_list:
|
||||||
|
path: /battery-models
|
||||||
|
controller: App\Controller\BatteryModelController::index
|
||||||
|
|
||||||
|
bmodel_rows:
|
||||||
|
path: /battery-models/rows
|
||||||
|
controller: App\Controller\BatteryModelController::rows
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
bmodel_create:
|
||||||
|
path: /battery-models/create
|
||||||
|
controller: App\Controller\BatteryModelController::create
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
bmodel_create_submit:
|
||||||
|
path: /battery-models/create
|
||||||
|
controller: App\Controller\BatteryModelController::createSubmit
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
bmodel_update:
|
||||||
|
path: /battery-models/{id}
|
||||||
|
controller: App\Controller\BatteryModelController::update
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
bmodel_update_submit:
|
||||||
|
path: /battery-models/{id}
|
||||||
|
controller: App\Controller\BatteryModelController::updateSubmit
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
bmodel_delete:
|
||||||
|
path: /battery-models/{id}
|
||||||
|
controller: App\Controller\BatteryModelController::destroy
|
||||||
|
methods: [DELETE]
|
||||||
|
|
||||||
|
# battery sizes
|
||||||
|
|
||||||
|
bsize_list:
|
||||||
|
path: /battery-sizes
|
||||||
|
controller: App\Controller\BatterySizeController::index
|
||||||
|
|
||||||
|
bsize_rows:
|
||||||
|
path: /battery-sizes/rows
|
||||||
|
controller: App\Controller\BatterySizeController::rows
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
bsize_create:
|
||||||
|
path: /battery-sizes/create
|
||||||
|
controller: App\Controller\BatterySizeController::create
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
bsize_create_submit:
|
||||||
|
path: /battery-sizes/create
|
||||||
|
controller: App\Controller\BatterySizeController::createSubmit
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
bsize_update:
|
||||||
|
path: /battery-sizes/{id}
|
||||||
|
controller: App\Controller\BatterySizeController::update
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
bsize_update_submit:
|
||||||
|
path: /battery-sizes/{id}
|
||||||
|
controller: App\Controller\BatterySizeController::updateSubmit
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
bsize_delete:
|
||||||
|
path: /battery-sizes/{id}
|
||||||
|
controller: App\Controller\BatterySizeController::destroy
|
||||||
|
methods: [DELETE]
|
||||||
|
|
||||||
|
# vehicles
|
||||||
|
|
||||||
|
vehicle_list:
|
||||||
|
path: /vehicle
|
||||||
|
controller: App\Controller\VehicleController::index
|
||||||
|
|
||||||
|
vehicle_rows:
|
||||||
|
path: /vehicle/rows
|
||||||
|
controller: App\Controller\VehicleController::rows
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
vehicle_create:
|
||||||
|
path: /vehicle/create
|
||||||
|
controller: App\Controller\VehicleController::create
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
vehicle_create_submit:
|
||||||
|
path: /vehicle/create
|
||||||
|
controller: App\Controller\VehicleController::createSubmit
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
vehicle_update:
|
||||||
|
path: /vehicle/{id}
|
||||||
|
controller: App\Controller\VehicleController::update
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
vehicle_update_submit:
|
||||||
|
path: /vehicle/{id}
|
||||||
|
controller: App\Controller\VehicleController::updateSubmit
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
vehicle_delete:
|
||||||
|
path: /vehicle/{id}
|
||||||
|
controller: App\Controller\VehicleController::destroy
|
||||||
|
methods: [DELETE]
|
||||||
|
|
||||||
|
# vehicle manufacturers
|
||||||
|
|
||||||
|
vmfg_list:
|
||||||
|
path: /vehicle-manufacturers
|
||||||
|
controller: App\Controller\VehicleManufacturerController::index
|
||||||
|
|
||||||
|
vmfg_rows:
|
||||||
|
path: /vehicle-manufacturers/rows
|
||||||
|
controller: App\Controller\VehicleManufacturerController::rows
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
vmfg_create:
|
||||||
|
path: /vehicle-manufacturers/create
|
||||||
|
controller: App\Controller\VehicleManufacturerController::create
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
vmfg_create_submit:
|
||||||
|
path: /vehicle-manufacturers/create
|
||||||
|
controller: App\Controller\VehicleManufacturerController::createSubmit
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
vmfg_update:
|
||||||
|
path: /vehicle-manufacturers/{id}
|
||||||
|
controller: App\Controller\VehicleManufacturerController::update
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
vmfg_update_submit:
|
||||||
|
path: /vehicle-manufacturers/{id}
|
||||||
|
controller: App\Controller\VehicleManufacturerController::updateSubmit
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
vmfg_delete:
|
||||||
|
path: /vehicle-manufacturers/{id}
|
||||||
|
controller: App\Controller\VehicleManufacturerController::destroy
|
||||||
|
methods: [DELETE]
|
||||||
|
|
||||||
# test
|
# test
|
||||||
|
|
||||||
test_acl:
|
test_acl:
|
||||||
|
|
|
||||||
|
|
@ -16,4 +16,14 @@ label.has-danger,
|
||||||
|
|
||||||
.no-border {
|
.no-border {
|
||||||
border: 0 !important;
|
border: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.flex-row {
|
||||||
|
display: flex;
|
||||||
|
flex-flow: row;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.flex-row > * + * {
|
||||||
|
margin-left: 10px;
|
||||||
}
|
}
|
||||||
259
src/Controller/BatteryManufacturerController.php
Normal file
259
src/Controller/BatteryManufacturerController.php
Normal file
|
|
@ -0,0 +1,259 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Ramcar\BaseController;
|
||||||
|
use App\Entity\BatteryManufacturer;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Query;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
|
|
||||||
|
use App\Menu\Generator as MenuGenerator;
|
||||||
|
use App\Access\Generator as ACLGenerator;
|
||||||
|
|
||||||
|
class BatteryManufacturerController extends BaseController
|
||||||
|
{
|
||||||
|
protected $acl_gen;
|
||||||
|
|
||||||
|
public function __construct(MenuGenerator $menu_gen, ACLGenerator $acl_gen)
|
||||||
|
{
|
||||||
|
$this->acl_gen = $acl_gen;
|
||||||
|
parent::__construct($menu_gen);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('bmfg.list', null, 'No access.');
|
||||||
|
|
||||||
|
$params = $this->initParameters('bmfg_list');
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('battery-manufacturer/list.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rows(Request $req)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('bmfg.list', null, 'No access.');
|
||||||
|
|
||||||
|
// build query
|
||||||
|
$qb = $this->getDoctrine()
|
||||||
|
->getRepository(BatteryManufacturer::class)
|
||||||
|
->createQueryBuilder('q');
|
||||||
|
|
||||||
|
// count total records
|
||||||
|
$total = $qb->select('COUNT(q)')
|
||||||
|
->getQuery()
|
||||||
|
->getSingleScalarResult();
|
||||||
|
|
||||||
|
// get datatable params
|
||||||
|
$datatable = $req->request->get('datatable');
|
||||||
|
|
||||||
|
// get current page number
|
||||||
|
$page = $datatable['pagination']['page'] ?? 1;
|
||||||
|
|
||||||
|
$perpage = $datatable['pagination']['perpage'];
|
||||||
|
$offset = ($page - 1) * $perpage;
|
||||||
|
|
||||||
|
// add metadata
|
||||||
|
$meta = [
|
||||||
|
'page' => $page,
|
||||||
|
'perpage' => $perpage,
|
||||||
|
'pages' => ceil($total / $perpage),
|
||||||
|
'total' => $total,
|
||||||
|
'sort' => 'asc',
|
||||||
|
'field' => 'id'
|
||||||
|
];
|
||||||
|
|
||||||
|
// build query
|
||||||
|
$query = $qb->select('q');
|
||||||
|
|
||||||
|
// check if filter is present
|
||||||
|
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
|
||||||
|
$query->where('q.name LIKE :filter')
|
||||||
|
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if sorting is present, otherwise use default
|
||||||
|
if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) {
|
||||||
|
$order = $datatable['sort']['sort'] ?? 'asc';
|
||||||
|
$query->orderBy('q.' . $datatable['sort']['field'], $order);
|
||||||
|
} else {
|
||||||
|
$query->orderBy('q.name', 'asc');
|
||||||
|
}
|
||||||
|
|
||||||
|
// get rows for this page
|
||||||
|
$obj_rows = $query->setFirstResult($offset)
|
||||||
|
->setMaxResults($perpage)
|
||||||
|
->getQuery()
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
// process rows
|
||||||
|
$rows = [];
|
||||||
|
foreach ($obj_rows as $orow) {
|
||||||
|
// add row data
|
||||||
|
$row['id'] = $orow->getID();
|
||||||
|
$row['name'] = $orow->getName();
|
||||||
|
|
||||||
|
// add row metadata
|
||||||
|
$row['meta'] = [
|
||||||
|
'update_url' => '',
|
||||||
|
'delete_url' => ''
|
||||||
|
];
|
||||||
|
|
||||||
|
// add crud urls
|
||||||
|
if ($this->isGranted('user.update'))
|
||||||
|
$row['meta']['update_url'] = $this->generateUrl('bmfg_update', ['id' => $row['id']]);
|
||||||
|
if ($this->isGranted('user.delete'))
|
||||||
|
$row['meta']['delete_url'] = $this->generateUrl('bmfg_delete', ['id' => $row['id']]);
|
||||||
|
|
||||||
|
$rows[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->json([
|
||||||
|
'meta' => $meta,
|
||||||
|
'data' => $rows
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('bmfg.add', null, 'No access.');
|
||||||
|
|
||||||
|
$params = $this->initParameters('bmfg_list');
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('battery-manufacturer/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createSubmit(Request $req, ValidatorInterface $validator)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('bmfg.add', null, 'No access.');
|
||||||
|
|
||||||
|
// create new row
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$row = new BatteryManufacturer();
|
||||||
|
|
||||||
|
// set and save values
|
||||||
|
$row->setName($req->request->get('name'));
|
||||||
|
|
||||||
|
// validate
|
||||||
|
$errors = $validator->validate($row);
|
||||||
|
|
||||||
|
// initialize error list
|
||||||
|
$error_array = [];
|
||||||
|
|
||||||
|
// add errors to list
|
||||||
|
foreach ($errors as $error) {
|
||||||
|
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if any errors were found
|
||||||
|
if (!empty($error_array)) {
|
||||||
|
// return validation failure response
|
||||||
|
return $this->json([
|
||||||
|
'success' => false,
|
||||||
|
'errors' => $error_array
|
||||||
|
], 422);
|
||||||
|
} else {
|
||||||
|
// validated! save the entity
|
||||||
|
$em->persist($row);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
// return successful response
|
||||||
|
return $this->json([
|
||||||
|
'success' => 'Changes have been saved!'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('bmfg.update', null, 'No access.');
|
||||||
|
|
||||||
|
$params = $this->initParameters('bmfg_list');
|
||||||
|
|
||||||
|
// get row data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$row = $em->getRepository(BatteryManufacturer::class)->find($id);
|
||||||
|
|
||||||
|
// make sure this row exists
|
||||||
|
if (empty($row))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
|
$params['row'] = $row;
|
||||||
|
$params['values'] = [];
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('battery-manufacturer/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateSubmit(Request $req, ValidatorInterface $validator, $id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('bmfg.update', null, 'No access.');
|
||||||
|
|
||||||
|
// get row data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$row = $em->getRepository(BatteryManufacturer::class)->find($id);
|
||||||
|
|
||||||
|
// make sure this row exists
|
||||||
|
if (empty($row))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
|
// set and save values
|
||||||
|
$row->setName($req->request->get('name'));
|
||||||
|
|
||||||
|
// validate
|
||||||
|
$errors = $validator->validate($row);
|
||||||
|
|
||||||
|
// initialize error list
|
||||||
|
$error_array = [];
|
||||||
|
|
||||||
|
// add errors to list
|
||||||
|
foreach ($errors as $error) {
|
||||||
|
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if any errors were found
|
||||||
|
if (!empty($error_array)) {
|
||||||
|
// return validation failure response
|
||||||
|
return $this->json([
|
||||||
|
'success' => false,
|
||||||
|
'errors' => $error_array
|
||||||
|
], 422);
|
||||||
|
} else {
|
||||||
|
// validated! save the entity
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
// return successful response
|
||||||
|
return $this->json([
|
||||||
|
'success' => 'Changes have been saved!'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy($id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('bmfg.delete', null, 'No access.');
|
||||||
|
|
||||||
|
$params = $this->initParameters('bmfg_list');
|
||||||
|
|
||||||
|
// get row data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$row = $em->getRepository(BatteryManufacturer::class)->find($id);
|
||||||
|
|
||||||
|
if (empty($row))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
|
// delete this row
|
||||||
|
$em->remove($row);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
// response
|
||||||
|
$response = new Response();
|
||||||
|
$response->setStatusCode(Response::HTTP_OK);
|
||||||
|
$response->send();
|
||||||
|
}
|
||||||
|
}
|
||||||
259
src/Controller/BatteryModelController.php
Normal file
259
src/Controller/BatteryModelController.php
Normal file
|
|
@ -0,0 +1,259 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Ramcar\BaseController;
|
||||||
|
use App\Entity\BatteryModel;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Query;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
|
|
||||||
|
use App\Menu\Generator as MenuGenerator;
|
||||||
|
use App\Access\Generator as ACLGenerator;
|
||||||
|
|
||||||
|
class BatteryModelController extends BaseController
|
||||||
|
{
|
||||||
|
protected $acl_gen;
|
||||||
|
|
||||||
|
public function __construct(MenuGenerator $menu_gen, ACLGenerator $acl_gen)
|
||||||
|
{
|
||||||
|
$this->acl_gen = $acl_gen;
|
||||||
|
parent::__construct($menu_gen);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('bmodel.list', null, 'No access.');
|
||||||
|
|
||||||
|
$params = $this->initParameters('bmodel_list');
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('battery-model/list.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rows(Request $req)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('bmodel.list', null, 'No access.');
|
||||||
|
|
||||||
|
// build query
|
||||||
|
$qb = $this->getDoctrine()
|
||||||
|
->getRepository(BatteryModel::class)
|
||||||
|
->createQueryBuilder('q');
|
||||||
|
|
||||||
|
// count total records
|
||||||
|
$total = $qb->select('COUNT(q)')
|
||||||
|
->getQuery()
|
||||||
|
->getSingleScalarResult();
|
||||||
|
|
||||||
|
// get datatable params
|
||||||
|
$datatable = $req->request->get('datatable');
|
||||||
|
|
||||||
|
// get current page number
|
||||||
|
$page = $datatable['pagination']['page'] ?? 1;
|
||||||
|
|
||||||
|
$perpage = $datatable['pagination']['perpage'];
|
||||||
|
$offset = ($page - 1) * $perpage;
|
||||||
|
|
||||||
|
// add metadata
|
||||||
|
$meta = [
|
||||||
|
'page' => $page,
|
||||||
|
'perpage' => $perpage,
|
||||||
|
'pages' => ceil($total / $perpage),
|
||||||
|
'total' => $total,
|
||||||
|
'sort' => 'asc',
|
||||||
|
'field' => 'id'
|
||||||
|
];
|
||||||
|
|
||||||
|
// build query
|
||||||
|
$query = $qb->select('q');
|
||||||
|
|
||||||
|
// check if filter is present
|
||||||
|
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
|
||||||
|
$query->where('q.name LIKE :filter')
|
||||||
|
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if sorting is present, otherwise use default
|
||||||
|
if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) {
|
||||||
|
$order = $datatable['sort']['sort'] ?? 'asc';
|
||||||
|
$query->orderBy('q.' . $datatable['sort']['field'], $order);
|
||||||
|
} else {
|
||||||
|
$query->orderBy('q.name', 'asc');
|
||||||
|
}
|
||||||
|
|
||||||
|
// get rows for this page
|
||||||
|
$obj_rows = $query->setFirstResult($offset)
|
||||||
|
->setMaxResults($perpage)
|
||||||
|
->getQuery()
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
// process rows
|
||||||
|
$rows = [];
|
||||||
|
foreach ($obj_rows as $orow) {
|
||||||
|
// add row data
|
||||||
|
$row['id'] = $orow->getID();
|
||||||
|
$row['name'] = $orow->getName();
|
||||||
|
|
||||||
|
// add row metadata
|
||||||
|
$row['meta'] = [
|
||||||
|
'update_url' => '',
|
||||||
|
'delete_url' => ''
|
||||||
|
];
|
||||||
|
|
||||||
|
// add crud urls
|
||||||
|
if ($this->isGranted('user.update'))
|
||||||
|
$row['meta']['update_url'] = $this->generateUrl('bmodel_update', ['id' => $row['id']]);
|
||||||
|
if ($this->isGranted('user.delete'))
|
||||||
|
$row['meta']['delete_url'] = $this->generateUrl('bmodel_delete', ['id' => $row['id']]);
|
||||||
|
|
||||||
|
$rows[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->json([
|
||||||
|
'meta' => $meta,
|
||||||
|
'data' => $rows
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('bmodel.add', null, 'No access.');
|
||||||
|
|
||||||
|
$params = $this->initParameters('bmodel_list');
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('battery-model/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createSubmit(Request $req, ValidatorInterface $validator)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('bmodel.add', null, 'No access.');
|
||||||
|
|
||||||
|
// create new row
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$row = new BatteryModel();
|
||||||
|
|
||||||
|
// set and save values
|
||||||
|
$row->setName($req->request->get('name'));
|
||||||
|
|
||||||
|
// validate
|
||||||
|
$errors = $validator->validate($row);
|
||||||
|
|
||||||
|
// initialize error list
|
||||||
|
$error_array = [];
|
||||||
|
|
||||||
|
// add errors to list
|
||||||
|
foreach ($errors as $error) {
|
||||||
|
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if any errors were found
|
||||||
|
if (!empty($error_array)) {
|
||||||
|
// return validation failure response
|
||||||
|
return $this->json([
|
||||||
|
'success' => false,
|
||||||
|
'errors' => $error_array
|
||||||
|
], 422);
|
||||||
|
} else {
|
||||||
|
// validated! save the entity
|
||||||
|
$em->persist($row);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
// return successful response
|
||||||
|
return $this->json([
|
||||||
|
'success' => 'Changes have been saved!'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('bmodel.update', null, 'No access.');
|
||||||
|
|
||||||
|
$params = $this->initParameters('bmodel_list');
|
||||||
|
|
||||||
|
// get row data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$row = $em->getRepository(BatteryModel::class)->find($id);
|
||||||
|
|
||||||
|
// make sure this row exists
|
||||||
|
if (empty($row))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
|
$params['row'] = $row;
|
||||||
|
$params['values'] = [];
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('battery-model/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateSubmit(Request $req, ValidatorInterface $validator, $id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('bmodel.update', null, 'No access.');
|
||||||
|
|
||||||
|
// get row data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$row = $em->getRepository(BatteryModel::class)->find($id);
|
||||||
|
|
||||||
|
// make sure this row exists
|
||||||
|
if (empty($row))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
|
// set and save values
|
||||||
|
$row->setName($req->request->get('name'));
|
||||||
|
|
||||||
|
// validate
|
||||||
|
$errors = $validator->validate($row);
|
||||||
|
|
||||||
|
// initialize error list
|
||||||
|
$error_array = [];
|
||||||
|
|
||||||
|
// add errors to list
|
||||||
|
foreach ($errors as $error) {
|
||||||
|
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if any errors were found
|
||||||
|
if (!empty($error_array)) {
|
||||||
|
// return validation failure response
|
||||||
|
return $this->json([
|
||||||
|
'success' => false,
|
||||||
|
'errors' => $error_array
|
||||||
|
], 422);
|
||||||
|
} else {
|
||||||
|
// validated! save the entity
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
// return successful response
|
||||||
|
return $this->json([
|
||||||
|
'success' => 'Changes have been saved!'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy($id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('bmodel.delete', null, 'No access.');
|
||||||
|
|
||||||
|
$params = $this->initParameters('bmodel_list');
|
||||||
|
|
||||||
|
// get row data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$row = $em->getRepository(BatteryModel::class)->find($id);
|
||||||
|
|
||||||
|
if (empty($row))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
|
// delete this row
|
||||||
|
$em->remove($row);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
// response
|
||||||
|
$response = new Response();
|
||||||
|
$response->setStatusCode(Response::HTTP_OK);
|
||||||
|
$response->send();
|
||||||
|
}
|
||||||
|
}
|
||||||
259
src/Controller/BatterySizeController.php
Normal file
259
src/Controller/BatterySizeController.php
Normal file
|
|
@ -0,0 +1,259 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Ramcar\BaseController;
|
||||||
|
use App\Entity\BatterySize;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Query;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
|
|
||||||
|
use App\Menu\Generator as MenuGenerator;
|
||||||
|
use App\Access\Generator as ACLGenerator;
|
||||||
|
|
||||||
|
class BatterySizeController extends BaseController
|
||||||
|
{
|
||||||
|
protected $acl_gen;
|
||||||
|
|
||||||
|
public function __construct(MenuGenerator $menu_gen, ACLGenerator $acl_gen)
|
||||||
|
{
|
||||||
|
$this->acl_gen = $acl_gen;
|
||||||
|
parent::__construct($menu_gen);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('bsize.list', null, 'No access.');
|
||||||
|
|
||||||
|
$params = $this->initParameters('bsize_list');
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('battery-size/list.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rows(Request $req)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('bsize.list', null, 'No access.');
|
||||||
|
|
||||||
|
// build query
|
||||||
|
$qb = $this->getDoctrine()
|
||||||
|
->getRepository(BatterySize::class)
|
||||||
|
->createQueryBuilder('q');
|
||||||
|
|
||||||
|
// count total records
|
||||||
|
$total = $qb->select('COUNT(q)')
|
||||||
|
->getQuery()
|
||||||
|
->getSingleScalarResult();
|
||||||
|
|
||||||
|
// get datatable params
|
||||||
|
$datatable = $req->request->get('datatable');
|
||||||
|
|
||||||
|
// get current page number
|
||||||
|
$page = $datatable['pagination']['page'] ?? 1;
|
||||||
|
|
||||||
|
$perpage = $datatable['pagination']['perpage'];
|
||||||
|
$offset = ($page - 1) * $perpage;
|
||||||
|
|
||||||
|
// add metadata
|
||||||
|
$meta = [
|
||||||
|
'page' => $page,
|
||||||
|
'perpage' => $perpage,
|
||||||
|
'pages' => ceil($total / $perpage),
|
||||||
|
'total' => $total,
|
||||||
|
'sort' => 'asc',
|
||||||
|
'field' => 'id'
|
||||||
|
];
|
||||||
|
|
||||||
|
// build query
|
||||||
|
$query = $qb->select('q');
|
||||||
|
|
||||||
|
// check if filter is present
|
||||||
|
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
|
||||||
|
$query->where('q.name LIKE :filter')
|
||||||
|
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if sorting is present, otherwise use default
|
||||||
|
if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) {
|
||||||
|
$order = $datatable['sort']['sort'] ?? 'asc';
|
||||||
|
$query->orderBy('q.' . $datatable['sort']['field'], $order);
|
||||||
|
} else {
|
||||||
|
$query->orderBy('q.name', 'asc');
|
||||||
|
}
|
||||||
|
|
||||||
|
// get rows for this page
|
||||||
|
$obj_rows = $query->setFirstResult($offset)
|
||||||
|
->setMaxResults($perpage)
|
||||||
|
->getQuery()
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
// process rows
|
||||||
|
$rows = [];
|
||||||
|
foreach ($obj_rows as $orow) {
|
||||||
|
// add row data
|
||||||
|
$row['id'] = $orow->getID();
|
||||||
|
$row['name'] = $orow->getName();
|
||||||
|
|
||||||
|
// add row metadata
|
||||||
|
$row['meta'] = [
|
||||||
|
'update_url' => '',
|
||||||
|
'delete_url' => ''
|
||||||
|
];
|
||||||
|
|
||||||
|
// add crud urls
|
||||||
|
if ($this->isGranted('user.update'))
|
||||||
|
$row['meta']['update_url'] = $this->generateUrl('bsize_update', ['id' => $row['id']]);
|
||||||
|
if ($this->isGranted('user.delete'))
|
||||||
|
$row['meta']['delete_url'] = $this->generateUrl('bsize_delete', ['id' => $row['id']]);
|
||||||
|
|
||||||
|
$rows[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->json([
|
||||||
|
'meta' => $meta,
|
||||||
|
'data' => $rows
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('bsize.add', null, 'No access.');
|
||||||
|
|
||||||
|
$params = $this->initParameters('bsize_list');
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('battery-size/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createSubmit(Request $req, ValidatorInterface $validator)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('bsize.add', null, 'No access.');
|
||||||
|
|
||||||
|
// create new row
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$row = new BatterySize();
|
||||||
|
|
||||||
|
// set and save values
|
||||||
|
$row->setName($req->request->get('name'));
|
||||||
|
|
||||||
|
// validate
|
||||||
|
$errors = $validator->validate($row);
|
||||||
|
|
||||||
|
// initialize error list
|
||||||
|
$error_array = [];
|
||||||
|
|
||||||
|
// add errors to list
|
||||||
|
foreach ($errors as $error) {
|
||||||
|
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if any errors were found
|
||||||
|
if (!empty($error_array)) {
|
||||||
|
// return validation failure response
|
||||||
|
return $this->json([
|
||||||
|
'success' => false,
|
||||||
|
'errors' => $error_array
|
||||||
|
], 422);
|
||||||
|
} else {
|
||||||
|
// validated! save the entity
|
||||||
|
$em->persist($row);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
// return successful response
|
||||||
|
return $this->json([
|
||||||
|
'success' => 'Changes have been saved!'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('bsize.update', null, 'No access.');
|
||||||
|
|
||||||
|
$params = $this->initParameters('bsize_list');
|
||||||
|
|
||||||
|
// get row data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$row = $em->getRepository(BatterySize::class)->find($id);
|
||||||
|
|
||||||
|
// make sure this row exists
|
||||||
|
if (empty($row))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
|
$params['row'] = $row;
|
||||||
|
$params['values'] = [];
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('battery-size/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateSubmit(Request $req, ValidatorInterface $validator, $id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('bsize.update', null, 'No access.');
|
||||||
|
|
||||||
|
// get row data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$row = $em->getRepository(BatterySize::class)->find($id);
|
||||||
|
|
||||||
|
// make sure this row exists
|
||||||
|
if (empty($row))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
|
// set and save values
|
||||||
|
$row->setName($req->request->get('name'));
|
||||||
|
|
||||||
|
// validate
|
||||||
|
$errors = $validator->validate($row);
|
||||||
|
|
||||||
|
// initialize error list
|
||||||
|
$error_array = [];
|
||||||
|
|
||||||
|
// add errors to list
|
||||||
|
foreach ($errors as $error) {
|
||||||
|
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if any errors were found
|
||||||
|
if (!empty($error_array)) {
|
||||||
|
// return validation failure response
|
||||||
|
return $this->json([
|
||||||
|
'success' => false,
|
||||||
|
'errors' => $error_array
|
||||||
|
], 422);
|
||||||
|
} else {
|
||||||
|
// validated! save the entity
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
// return successful response
|
||||||
|
return $this->json([
|
||||||
|
'success' => 'Changes have been saved!'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy($id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('bsize.delete', null, 'No access.');
|
||||||
|
|
||||||
|
$params = $this->initParameters('bsize_list');
|
||||||
|
|
||||||
|
// get row data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$row = $em->getRepository(BatterySize::class)->find($id);
|
||||||
|
|
||||||
|
if (empty($row))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
|
// delete this row
|
||||||
|
$em->remove($row);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
// response
|
||||||
|
$response = new Response();
|
||||||
|
$response->setStatusCode(Response::HTTP_OK);
|
||||||
|
$response->send();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -25,22 +25,18 @@ class RoleController extends BaseController
|
||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
|
$this->denyAccessUnlessGranted('role.list', null, 'No access.');
|
||||||
|
|
||||||
$params = $this->initParameters('role_list');
|
$params = $this->initParameters('role_list');
|
||||||
|
|
||||||
$qb = $this->getDoctrine()
|
|
||||||
->getRepository(Role::class)
|
|
||||||
->createQueryBuilder('q')
|
|
||||||
->getQuery();
|
|
||||||
|
|
||||||
// get all rows
|
|
||||||
$rows = $qb->getResult(Query::HYDRATE_ARRAY);
|
|
||||||
|
|
||||||
// response
|
// response
|
||||||
return $this->render('role/list.html.twig', $params);
|
return $this->render('role/list.html.twig', $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function rows(Request $req)
|
public function rows(Request $req)
|
||||||
{
|
{
|
||||||
|
$this->denyAccessUnlessGranted('role.list', null, 'No access.');
|
||||||
|
|
||||||
// build query
|
// build query
|
||||||
$qb = $this->getDoctrine()
|
$qb = $this->getDoctrine()
|
||||||
->getRepository(Role::class)
|
->getRepository(Role::class)
|
||||||
|
|
@ -89,15 +85,38 @@ class RoleController extends BaseController
|
||||||
}
|
}
|
||||||
|
|
||||||
// get rows for this page
|
// get rows for this page
|
||||||
$rows = $query->setFirstResult($offset)
|
$obj_rows = $query->setFirstResult($offset)
|
||||||
->setMaxResults($perpage)
|
->setMaxResults($perpage)
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult(Query::HYDRATE_ARRAY);
|
->getResult();
|
||||||
|
|
||||||
// add crud urls
|
// process rows
|
||||||
foreach ($rows as $index => $row) {
|
$rows = [];
|
||||||
$rows[$index]['update_url'] = $this->generateUrl('role_update', ['id' => $row['id']]);
|
foreach ($obj_rows as $orow) {
|
||||||
$rows[$index]['delete_url'] = $this->generateUrl('role_delete', ['id' => $row['id']]);
|
// add row data
|
||||||
|
$row['id'] = $orow->getID();
|
||||||
|
$row['name'] = $orow->getName();
|
||||||
|
|
||||||
|
// add row metadata
|
||||||
|
$row['meta'] = [
|
||||||
|
'update_url' => '',
|
||||||
|
'delete_url' => ''
|
||||||
|
];
|
||||||
|
|
||||||
|
// check if they have access to super admin users
|
||||||
|
if (!$this->isGranted('user.role.sadmin') && $orow->isSuperAdmin())
|
||||||
|
{
|
||||||
|
$rows[] = $row;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add crud urls
|
||||||
|
if ($this->isGranted('user.update'))
|
||||||
|
$row['meta']['update_url'] = $this->generateUrl('role_update', ['id' => $row['id']]);
|
||||||
|
if ($this->isGranted('user.delete'))
|
||||||
|
$row['meta']['delete_url'] = $this->generateUrl('role_delete', ['id' => $row['id']]);
|
||||||
|
|
||||||
|
$rows[] = $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
// response
|
// response
|
||||||
|
|
@ -116,6 +135,8 @@ class RoleController extends BaseController
|
||||||
|
|
||||||
public function create()
|
public function create()
|
||||||
{
|
{
|
||||||
|
$this->denyAccessUnlessGranted('role.add', null, 'No access.');
|
||||||
|
|
||||||
$params = $this->initParameters('role_list');
|
$params = $this->initParameters('role_list');
|
||||||
$this->padACLHierarchy($params);
|
$this->padACLHierarchy($params);
|
||||||
|
|
||||||
|
|
@ -126,6 +147,8 @@ class RoleController extends BaseController
|
||||||
|
|
||||||
public function createSubmit(Request $req, ValidatorInterface $validator)
|
public function createSubmit(Request $req, ValidatorInterface $validator)
|
||||||
{
|
{
|
||||||
|
$this->denyAccessUnlessGranted('role.add', null, 'No access.');
|
||||||
|
|
||||||
// create new row
|
// create new row
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
$row = new Role();
|
$row = new Role();
|
||||||
|
|
@ -173,6 +196,8 @@ class RoleController extends BaseController
|
||||||
|
|
||||||
public function update($id)
|
public function update($id)
|
||||||
{
|
{
|
||||||
|
$this->denyAccessUnlessGranted('role.update', null, 'No access.');
|
||||||
|
|
||||||
$params = $this->initParameters('role_list');
|
$params = $this->initParameters('role_list');
|
||||||
$this->padACLHierarchy($params);
|
$this->padACLHierarchy($params);
|
||||||
|
|
||||||
|
|
@ -193,6 +218,8 @@ class RoleController extends BaseController
|
||||||
|
|
||||||
public function updateSubmit(Request $req, ValidatorInterface $validator, $id)
|
public function updateSubmit(Request $req, ValidatorInterface $validator, $id)
|
||||||
{
|
{
|
||||||
|
$this->denyAccessUnlessGranted('role.update', null, 'No access.');
|
||||||
|
|
||||||
// get row data
|
// get row data
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
$row = $em->getRepository(Role::class)->find($id);
|
$row = $em->getRepository(Role::class)->find($id);
|
||||||
|
|
@ -250,6 +277,8 @@ class RoleController extends BaseController
|
||||||
|
|
||||||
public function destroy($id)
|
public function destroy($id)
|
||||||
{
|
{
|
||||||
|
$this->denyAccessUnlessGranted('role.delete', null, 'No access.');
|
||||||
|
|
||||||
$params = $this->initParameters('role_list');
|
$params = $this->initParameters('role_list');
|
||||||
|
|
||||||
// get row data
|
// get row data
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace App\Entity;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
|
|
@ -22,6 +23,7 @@ class BatteryManufacturer
|
||||||
// name
|
// name
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=80)
|
* @ORM\Column(type="string", length=80)
|
||||||
|
* @Assert\NotBlank()
|
||||||
*/
|
*/
|
||||||
protected $name;
|
protected $name;
|
||||||
|
|
||||||
|
|
@ -35,4 +37,42 @@ class BatteryManufacturer
|
||||||
{
|
{
|
||||||
$this->batteries = new ArrayCollection();
|
$this->batteries = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName($name)
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addBattery(Battery $battery)
|
||||||
|
{
|
||||||
|
$this->batteries->add($battery);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clearBatteries()
|
||||||
|
{
|
||||||
|
$this->batteries->clear();
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBatteries()
|
||||||
|
{
|
||||||
|
// has to return set of strings because symfony is trying to move away from role objects
|
||||||
|
$str_batteries = [];
|
||||||
|
foreach ($this->batteries as $battery)
|
||||||
|
$str_batteries[] = $this->getName() . " " . $battery->getModel()->getName() . " " . $battery->getSize()->getName();
|
||||||
|
|
||||||
|
return $str_batteries;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
|
|
@ -21,12 +23,13 @@ class BatteryModel
|
||||||
// name
|
// name
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=80)
|
* @ORM\Column(type="string", length=80)
|
||||||
|
* @Assert\NotBlank()
|
||||||
*/
|
*/
|
||||||
protected $name;
|
protected $name;
|
||||||
|
|
||||||
// battery
|
// battery
|
||||||
/**
|
/**
|
||||||
* @ORM\OneToMany(targetEntity="Battery", mappedBy="manufacturer")
|
* @ORM\OneToMany(targetEntity="Battery", mappedBy="model")
|
||||||
*/
|
*/
|
||||||
protected $batteries;
|
protected $batteries;
|
||||||
|
|
||||||
|
|
@ -34,4 +37,42 @@ class BatteryModel
|
||||||
{
|
{
|
||||||
$this->batteries = new ArrayCollection();
|
$this->batteries = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName($name)
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addBattery(Battery $battery)
|
||||||
|
{
|
||||||
|
$this->batteries->add($battery);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clearBatteries()
|
||||||
|
{
|
||||||
|
$this->batteries->clear();
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBatteries()
|
||||||
|
{
|
||||||
|
// has to return set of strings because symfony is trying to move away from role objects
|
||||||
|
$str_batteries = [];
|
||||||
|
foreach ($this->batteries as $battery)
|
||||||
|
$str_batteries[] = $battery->getManufacturer()->getName() . " " . $battery->getModel()->getName() . " " . $this->getName();
|
||||||
|
|
||||||
|
return $str_batteries;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace App\Entity;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
|
|
@ -22,12 +23,13 @@ class BatterySize
|
||||||
// name
|
// name
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=80)
|
* @ORM\Column(type="string", length=80)
|
||||||
|
* @Assert\NotBlank()
|
||||||
*/
|
*/
|
||||||
protected $name;
|
protected $name;
|
||||||
|
|
||||||
// battery
|
// battery
|
||||||
/**
|
/**
|
||||||
* @ORM\OneToMany(targetEntity="Battery", mappedBy="manufacturer")
|
* @ORM\OneToMany(targetEntity="Battery", mappedBy="size")
|
||||||
*/
|
*/
|
||||||
protected $batteries;
|
protected $batteries;
|
||||||
|
|
||||||
|
|
@ -35,4 +37,42 @@ class BatterySize
|
||||||
{
|
{
|
||||||
$this->batteries = new ArrayCollection();
|
$this->batteries = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName($name)
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addBattery(Battery $battery)
|
||||||
|
{
|
||||||
|
$this->batteries->add($battery);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clearBatteries()
|
||||||
|
{
|
||||||
|
$this->batteries->clear();
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBatteries()
|
||||||
|
{
|
||||||
|
// has to return set of strings because symfony is trying to move away from role objects
|
||||||
|
$str_batteries = [];
|
||||||
|
foreach ($this->batteries as $battery)
|
||||||
|
$str_batteries[] = $battery->getManufacturer()->getName() . " " . $battery->getModel()->getName() . " " . $this->getName();
|
||||||
|
|
||||||
|
return $str_batteries;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace App\Entity;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
|
|
@ -21,7 +22,7 @@ class Vehicle
|
||||||
|
|
||||||
// customer vehicles
|
// customer vehicles
|
||||||
/**
|
/**
|
||||||
* @ORM\OneToMany(targetEntity="CustomerVehicle", mappedBy="customer")
|
* @ORM\OneToMany(targetEntity="CustomerVehicle", mappedBy="vehicle")
|
||||||
*/
|
*/
|
||||||
protected $customers;
|
protected $customers;
|
||||||
|
|
||||||
|
|
@ -29,30 +30,34 @@ class Vehicle
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity="VehicleManufacturer", inversedBy="vehicles")
|
* @ORM\ManyToOne(targetEntity="VehicleManufacturer", inversedBy="vehicles")
|
||||||
* @ORM\JoinColumn(name="manufacturer_id", referencedColumnName="id")
|
* @ORM\JoinColumn(name="manufacturer_id", referencedColumnName="id")
|
||||||
|
* @Assert\NotBlank()
|
||||||
*/
|
*/
|
||||||
protected $manufacturer;
|
protected $manufacturer;
|
||||||
|
|
||||||
// make
|
// make
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=80)
|
* @ORM\Column(type="string", length=80)
|
||||||
|
* @Assert\NotBlank()
|
||||||
*/
|
*/
|
||||||
protected $make;
|
protected $make;
|
||||||
|
|
||||||
// model year from
|
// model year from
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="smallint")
|
* @ORM\Column(type="smallint")
|
||||||
|
* @Assert\NotBlank()
|
||||||
*/
|
*/
|
||||||
protected $model_year_from;
|
protected $model_year_from;
|
||||||
|
|
||||||
// model year to
|
// model year to
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="smallint")
|
* @ORM\Column(type="smallint")
|
||||||
|
* @Assert\NotBlank()
|
||||||
*/
|
*/
|
||||||
protected $model_year_to;
|
protected $model_year_to;
|
||||||
|
|
||||||
// link to batteries compatible with this vehicle
|
// link to batteries compatible with this vehicle
|
||||||
/**
|
/**
|
||||||
* @ORM\OneToMany(targetEntity="Battery", mappedBy="vehicle")
|
* @ORM\ManyToMany(targetEntity="Battery", mappedBy="vehicles", fetch="EXTRA_LAZY")
|
||||||
*/
|
*/
|
||||||
protected $batteries;
|
protected $batteries;
|
||||||
|
|
||||||
|
|
@ -61,4 +66,75 @@ class Vehicle
|
||||||
$this->customers = new ArrayCollection();
|
$this->customers = new ArrayCollection();
|
||||||
$this->batteries = new ArrayCollection();
|
$this->batteries = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setManufacturer($manufacturer)
|
||||||
|
{
|
||||||
|
$this->manufacturer = $manufacturer;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getManufacturer()
|
||||||
|
{
|
||||||
|
return $this->manufacturer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMake($make)
|
||||||
|
{
|
||||||
|
$this->make = $make;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMake()
|
||||||
|
{
|
||||||
|
return $this->make;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setModelYearFrom($model_year_from)
|
||||||
|
{
|
||||||
|
$this->model_year_from = $model_year_from;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getModelYearFrom()
|
||||||
|
{
|
||||||
|
return $this->model_year_from;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setModelYearTo($model_year_to)
|
||||||
|
{
|
||||||
|
$this->model_year_to = $model_year_to;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getModelYearTo()
|
||||||
|
{
|
||||||
|
return $this->model_year_to;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addBattery(Battery $battery)
|
||||||
|
{
|
||||||
|
$this->batteries->add($battery);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clearBatteries()
|
||||||
|
{
|
||||||
|
$this->batteries->clear();
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBatteries()
|
||||||
|
{
|
||||||
|
// has to return set of strings because symfony is trying to move away from role objects
|
||||||
|
$str_batteries = [];
|
||||||
|
foreach ($this->batteries as $battery)
|
||||||
|
$str_batteries[] = $battery->getManufacturer()->getName() . " " . $battery->getModel()->getName() . " " . $battery->getSize()->getName();
|
||||||
|
|
||||||
|
return $str_batteries;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace App\Entity;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
|
|
@ -22,6 +23,7 @@ class VehicleManufacturer
|
||||||
// name
|
// name
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=80)
|
* @ORM\Column(type="string", length=80)
|
||||||
|
* @Assert\NotBlank()
|
||||||
*/
|
*/
|
||||||
protected $name;
|
protected $name;
|
||||||
|
|
||||||
|
|
@ -35,4 +37,42 @@ class VehicleManufacturer
|
||||||
{
|
{
|
||||||
$this->vehicles = new ArrayCollection();
|
$this->vehicles = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName($name)
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addVehicle(Vehicle $vehicle)
|
||||||
|
{
|
||||||
|
$this->vehicles->add($vehicle);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clearVehicles()
|
||||||
|
{
|
||||||
|
$this->vehicles->clear();
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getVehicles()
|
||||||
|
{
|
||||||
|
// has to return set of strings because symfony is trying to move away from role objects
|
||||||
|
$str_vehicles = [];
|
||||||
|
foreach ($this->vehicles as $vehicle)
|
||||||
|
$str_vehicles[] = $this->getName() . " " . $vehicle->getMake() . " " . $vehicle->getYearFrom() . "-" . $vehicle->getYearTo();
|
||||||
|
|
||||||
|
return $str_vehicles;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
132
templates/battery-manufacturer/form.html.twig
Normal file
132
templates/battery-manufacturer/form.html.twig
Normal file
|
|
@ -0,0 +1,132 @@
|
||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<!-- BEGIN: Subheader -->
|
||||||
|
<div class="m-subheader">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<div class="mr-auto">
|
||||||
|
<h3 class="m-subheader__title">Battery Manufacturers</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- END: Subheader -->
|
||||||
|
<div class="m-content">
|
||||||
|
<!--Begin::Section-->
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xl-4 offset-xl-4">
|
||||||
|
<div class="m-portlet m-portlet--mobile">
|
||||||
|
<div class="m-portlet__head">
|
||||||
|
<div class="m-portlet__head-caption">
|
||||||
|
<div class="m-portlet__head-title">
|
||||||
|
<span class="m-portlet__head-icon">
|
||||||
|
<i class="la la-industry"></i>
|
||||||
|
</span>
|
||||||
|
<h3 class="m-portlet__head-text">
|
||||||
|
{% if row is defined %}
|
||||||
|
Edit Manufacturer
|
||||||
|
<small>{{ row.getName() }}</small>
|
||||||
|
{% else %}
|
||||||
|
New Manufacturer
|
||||||
|
{% endif %}
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<form id="row-form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ row is defined ? url('bmfg_update_submit', {'id': row.getId()}) : url('bmfg_create_submit') }}">
|
||||||
|
<div class="m-portlet__body">
|
||||||
|
<div class="form-group m-form__group row">
|
||||||
|
<label class="col-lg-3 col-form-label" data-field="name">
|
||||||
|
Name:
|
||||||
|
</label>
|
||||||
|
<div class="col-lg-9">
|
||||||
|
<input type="text" name="name" class="form-control m-input" value="{{ values.name is defined ? values.name : (row is defined ? row.getName()) }}">
|
||||||
|
<div class="form-control-feedback hide" data-field="name"></div>
|
||||||
|
<span class="m-form__help">Display name for this manufacturer</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="m-portlet__foot m-portlet__foot--fit">
|
||||||
|
<div class="m-form__actions m-form__actions--solid m-form__actions--right">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12">
|
||||||
|
<button type="submit" class="btn btn-success">Submit</button>
|
||||||
|
<a href="{{ url('bmfg_list') }}" class="btn btn-secondary">Cancel</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
$("#row-form").submit(function(e) {
|
||||||
|
var form = $(this);
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
method: "POST",
|
||||||
|
url: form.prop('action'),
|
||||||
|
data: form.serialize()
|
||||||
|
}).done(function(response) {
|
||||||
|
// remove all error classes
|
||||||
|
removeErrors();
|
||||||
|
swal({
|
||||||
|
title: 'Done!',
|
||||||
|
text: 'Your changes have been saved!',
|
||||||
|
type: 'success',
|
||||||
|
onClose: function() {
|
||||||
|
window.location.href = "{{ url('bmfg_list') }}";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).fail(function(response) {
|
||||||
|
var errors = response.responseJSON.errors;
|
||||||
|
var firstfield = false;
|
||||||
|
|
||||||
|
// remove all error classes first
|
||||||
|
removeErrors();
|
||||||
|
|
||||||
|
// display errors contextually
|
||||||
|
$.each(errors, function(field, msg) {
|
||||||
|
var formfield = $("[name='" + field + "']");
|
||||||
|
var label = $("label[data-field='" + field + "']");
|
||||||
|
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||||
|
|
||||||
|
// add error classes to bad fields
|
||||||
|
formfield.addClass('form-control-danger');
|
||||||
|
label.addClass('has-danger');
|
||||||
|
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||||
|
|
||||||
|
// check if this field comes first in DOM
|
||||||
|
var domfield = formfield.get(0);
|
||||||
|
|
||||||
|
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||||
|
firstfield = domfield;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// focus on first bad field
|
||||||
|
firstfield.focus();
|
||||||
|
|
||||||
|
// scroll to above that field to make it visible
|
||||||
|
$('html, body').animate({
|
||||||
|
scrollTop: $(firstfield).offset().top - 200
|
||||||
|
}, 100);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// remove all error classes
|
||||||
|
function removeErrors() {
|
||||||
|
$(".form-control-danger").removeClass('form-control-danger');
|
||||||
|
$("[data-field]").removeClass('has-danger');
|
||||||
|
$(".form-control-feedback[data-field]").addClass('hide');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
152
templates/battery-manufacturer/list.html.twig
Normal file
152
templates/battery-manufacturer/list.html.twig
Normal file
|
|
@ -0,0 +1,152 @@
|
||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<!-- BEGIN: Subheader -->
|
||||||
|
<div class="m-subheader">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<div class="mr-auto">
|
||||||
|
<h3 class="m-subheader__title">
|
||||||
|
Battery Manufacturers
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- END: Subheader -->
|
||||||
|
<div class="m-content">
|
||||||
|
<!--Begin::Section-->
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xl-12">
|
||||||
|
<div class="m-portlet m-portlet--mobile">
|
||||||
|
<div class="m-portlet__body">
|
||||||
|
<div class="m-form m-form--label-align-right m--margin-top-20 m--margin-bottom-30">
|
||||||
|
<div class="row align-items-center">
|
||||||
|
<div class="col-xl-8 order-2 order-xl-1">
|
||||||
|
<div class="form-group m-form__group row align-items-center">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="m-input-icon m-input-icon--left">
|
||||||
|
<input type="text" class="form-control m-input m-input--solid" placeholder="Search..." id="data-rows-search">
|
||||||
|
<span class="m-input-icon__icon m-input-icon__icon--left">
|
||||||
|
<span><i class="la la-search"></i></span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-xl-4 order-1 order-xl-2 m--align-right">
|
||||||
|
<a href="{{ url('bmfg_create') }}" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
|
||||||
|
<span>
|
||||||
|
<i class="la la-industry"></i>
|
||||||
|
<span>New Manufacturer</span>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
<div class="m-separator m-separator--dashed d-xl-none"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!--begin: Datatable -->
|
||||||
|
<div id="data-rows"></div>
|
||||||
|
<!--end: Datatable -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
var options = {
|
||||||
|
data: {
|
||||||
|
type: 'remote',
|
||||||
|
source: {
|
||||||
|
read: {
|
||||||
|
url: '{{ url("bmfg_rows") }}',
|
||||||
|
method: 'POST'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
saveState: {
|
||||||
|
cookie: false,
|
||||||
|
webstorage: false
|
||||||
|
},
|
||||||
|
pageSize: 10,
|
||||||
|
serverPaging: true,
|
||||||
|
serverFiltering: true,
|
||||||
|
serverSorting: true
|
||||||
|
},
|
||||||
|
layout: {
|
||||||
|
scroll: true
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
field: 'id',
|
||||||
|
title: 'ID',
|
||||||
|
width: 30
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'name',
|
||||||
|
title: 'Name'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'Actions',
|
||||||
|
width: 110,
|
||||||
|
title: 'Actions',
|
||||||
|
sortable: false,
|
||||||
|
overflow: 'visible',
|
||||||
|
template: function (row, index, datatable) {
|
||||||
|
var actions = '';
|
||||||
|
|
||||||
|
if (row.meta.update_url != '') {
|
||||||
|
actions += '<a href="' + row.meta.update_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit" data-id="' + row.name + '" title="Edit"><i class="la la-edit"></i></a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (row.meta.delete_url != '') {
|
||||||
|
actions += '<a href="' + row.meta.delete_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill btn-delete" data-id="' + row.name + '" title="Delete"><i class="la la-trash"></i></a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return actions;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
search: {
|
||||||
|
onEnter: false,
|
||||||
|
input: $('#data-rows-search'),
|
||||||
|
delay: 400
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var table = $("#data-rows").mDatatable(options);
|
||||||
|
|
||||||
|
$(document).on('click', '.btn-delete', function(e) {
|
||||||
|
var url = $(this).prop('href');
|
||||||
|
var id = $(this).data('id');
|
||||||
|
var btn = $(this);
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
swal({
|
||||||
|
title: 'Confirmation',
|
||||||
|
html: 'Are you sure you want to delete <strong>' + id + '</strong>?',
|
||||||
|
type: 'warning',
|
||||||
|
showCancelButton: true
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.value) {
|
||||||
|
$.ajax({
|
||||||
|
method: "DELETE",
|
||||||
|
url: url
|
||||||
|
}).done(function(response) {
|
||||||
|
table.row(btn.parents('tr')).remove();
|
||||||
|
table.reload();
|
||||||
|
}).fail(function() {
|
||||||
|
swal({
|
||||||
|
title: 'Whoops',
|
||||||
|
text: 'An error occurred while deleting this item. Please contact support.',
|
||||||
|
type: 'error'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
132
templates/battery-model/form.html.twig
Normal file
132
templates/battery-model/form.html.twig
Normal file
|
|
@ -0,0 +1,132 @@
|
||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<!-- BEGIN: Subheader -->
|
||||||
|
<div class="m-subheader">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<div class="mr-auto">
|
||||||
|
<h3 class="m-subheader__title">Battery Models</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- END: Subheader -->
|
||||||
|
<div class="m-content">
|
||||||
|
<!--Begin::Section-->
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xl-4 offset-xl-4">
|
||||||
|
<div class="m-portlet m-portlet--mobile">
|
||||||
|
<div class="m-portlet__head">
|
||||||
|
<div class="m-portlet__head-caption">
|
||||||
|
<div class="m-portlet__head-title">
|
||||||
|
<span class="m-portlet__head-icon">
|
||||||
|
<i class="fa fa-cube"></i>
|
||||||
|
</span>
|
||||||
|
<h3 class="m-portlet__head-text">
|
||||||
|
{% if row is defined %}
|
||||||
|
Edit Model
|
||||||
|
<small>{{ row.getName() }}</small>
|
||||||
|
{% else %}
|
||||||
|
New Model
|
||||||
|
{% endif %}
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<form id="row-form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ row is defined ? url('bmodel_update_submit', {'id': row.getId()}) : url('bmodel_create_submit') }}">
|
||||||
|
<div class="m-portlet__body">
|
||||||
|
<div class="form-group m-form__group row">
|
||||||
|
<label class="col-lg-3 col-form-label" data-field="name">
|
||||||
|
Name:
|
||||||
|
</label>
|
||||||
|
<div class="col-lg-9">
|
||||||
|
<input type="text" name="name" class="form-control m-input" value="{{ values.name is defined ? values.name : (row is defined ? row.getName()) }}">
|
||||||
|
<div class="form-control-feedback hide" data-field="name"></div>
|
||||||
|
<span class="m-form__help">Display name for this model</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="m-portlet__foot m-portlet__foot--fit">
|
||||||
|
<div class="m-form__actions m-form__actions--solid m-form__actions--right">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12">
|
||||||
|
<button type="submit" class="btn btn-success">Submit</button>
|
||||||
|
<a href="{{ url('bmodel_list') }}" class="btn btn-secondary">Cancel</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
$("#row-form").submit(function(e) {
|
||||||
|
var form = $(this);
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
method: "POST",
|
||||||
|
url: form.prop('action'),
|
||||||
|
data: form.serialize()
|
||||||
|
}).done(function(response) {
|
||||||
|
// remove all error classes
|
||||||
|
removeErrors();
|
||||||
|
swal({
|
||||||
|
title: 'Done!',
|
||||||
|
text: 'Your changes have been saved!',
|
||||||
|
type: 'success',
|
||||||
|
onClose: function() {
|
||||||
|
window.location.href = "{{ url('bmodel_list') }}";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).fail(function(response) {
|
||||||
|
var errors = response.responseJSON.errors;
|
||||||
|
var firstfield = false;
|
||||||
|
|
||||||
|
// remove all error classes first
|
||||||
|
removeErrors();
|
||||||
|
|
||||||
|
// display errors contextually
|
||||||
|
$.each(errors, function(field, msg) {
|
||||||
|
var formfield = $("[name='" + field + "']");
|
||||||
|
var label = $("label[data-field='" + field + "']");
|
||||||
|
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||||
|
|
||||||
|
// add error classes to bad fields
|
||||||
|
formfield.addClass('form-control-danger');
|
||||||
|
label.addClass('has-danger');
|
||||||
|
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||||
|
|
||||||
|
// check if this field comes first in DOM
|
||||||
|
var domfield = formfield.get(0);
|
||||||
|
|
||||||
|
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||||
|
firstfield = domfield;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// focus on first bad field
|
||||||
|
firstfield.focus();
|
||||||
|
|
||||||
|
// scroll to above that field to make it visible
|
||||||
|
$('html, body').animate({
|
||||||
|
scrollTop: $(firstfield).offset().top - 200
|
||||||
|
}, 100);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// remove all error classes
|
||||||
|
function removeErrors() {
|
||||||
|
$(".form-control-danger").removeClass('form-control-danger');
|
||||||
|
$("[data-field]").removeClass('has-danger');
|
||||||
|
$(".form-control-feedback[data-field]").addClass('hide');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
152
templates/battery-model/list.html.twig
Normal file
152
templates/battery-model/list.html.twig
Normal file
|
|
@ -0,0 +1,152 @@
|
||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<!-- BEGIN: Subheader -->
|
||||||
|
<div class="m-subheader">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<div class="mr-auto">
|
||||||
|
<h3 class="m-subheader__title">
|
||||||
|
Battery Models
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- END: Subheader -->
|
||||||
|
<div class="m-content">
|
||||||
|
<!--Begin::Section-->
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xl-12">
|
||||||
|
<div class="m-portlet m-portlet--mobile">
|
||||||
|
<div class="m-portlet__body">
|
||||||
|
<div class="m-form m-form--label-align-right m--margin-top-20 m--margin-bottom-30">
|
||||||
|
<div class="row align-items-center">
|
||||||
|
<div class="col-xl-8 order-2 order-xl-1">
|
||||||
|
<div class="form-group m-form__group row align-items-center">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="m-input-icon m-input-icon--left">
|
||||||
|
<input type="text" class="form-control m-input m-input--solid" placeholder="Search..." id="data-rows-search">
|
||||||
|
<span class="m-input-icon__icon m-input-icon__icon--left">
|
||||||
|
<span><i class="la la-search"></i></span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-xl-4 order-1 order-xl-2 m--align-right">
|
||||||
|
<a href="{{ url('bmodel_create') }}" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
|
||||||
|
<span>
|
||||||
|
<i class="fa fa-cube"></i>
|
||||||
|
<span>New Model</span>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
<div class="m-separator m-separator--dashed d-xl-none"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!--begin: Datatable -->
|
||||||
|
<div id="data-rows"></div>
|
||||||
|
<!--end: Datatable -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
var options = {
|
||||||
|
data: {
|
||||||
|
type: 'remote',
|
||||||
|
source: {
|
||||||
|
read: {
|
||||||
|
url: '{{ url("bmodel_rows") }}',
|
||||||
|
method: 'POST'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
saveState: {
|
||||||
|
cookie: false,
|
||||||
|
webstorage: false
|
||||||
|
},
|
||||||
|
pageSize: 10,
|
||||||
|
serverPaging: true,
|
||||||
|
serverFiltering: true,
|
||||||
|
serverSorting: true
|
||||||
|
},
|
||||||
|
layout: {
|
||||||
|
scroll: true
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
field: 'id',
|
||||||
|
title: 'ID',
|
||||||
|
width: 30
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'name',
|
||||||
|
title: 'Name'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'Actions',
|
||||||
|
width: 110,
|
||||||
|
title: 'Actions',
|
||||||
|
sortable: false,
|
||||||
|
overflow: 'visible',
|
||||||
|
template: function (row, index, datatable) {
|
||||||
|
var actions = '';
|
||||||
|
|
||||||
|
if (row.meta.update_url != '') {
|
||||||
|
actions += '<a href="' + row.meta.update_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit" data-id="' + row.name + '" title="Edit"><i class="la la-edit"></i></a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (row.meta.delete_url != '') {
|
||||||
|
actions += '<a href="' + row.meta.delete_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill btn-delete" data-id="' + row.name + '" title="Delete"><i class="la la-trash"></i></a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return actions;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
search: {
|
||||||
|
onEnter: false,
|
||||||
|
input: $('#data-rows-search'),
|
||||||
|
delay: 400
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var table = $("#data-rows").mDatatable(options);
|
||||||
|
|
||||||
|
$(document).on('click', '.btn-delete', function(e) {
|
||||||
|
var url = $(this).prop('href');
|
||||||
|
var id = $(this).data('id');
|
||||||
|
var btn = $(this);
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
swal({
|
||||||
|
title: 'Confirmation',
|
||||||
|
html: 'Are you sure you want to delete <strong>' + id + '</strong>?',
|
||||||
|
type: 'warning',
|
||||||
|
showCancelButton: true
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.value) {
|
||||||
|
$.ajax({
|
||||||
|
method: "DELETE",
|
||||||
|
url: url
|
||||||
|
}).done(function(response) {
|
||||||
|
table.row(btn.parents('tr')).remove();
|
||||||
|
table.reload();
|
||||||
|
}).fail(function() {
|
||||||
|
swal({
|
||||||
|
title: 'Whoops',
|
||||||
|
text: 'An error occurred while deleting this item. Please contact support.',
|
||||||
|
type: 'error'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
132
templates/battery-size/form.html.twig
Normal file
132
templates/battery-size/form.html.twig
Normal file
|
|
@ -0,0 +1,132 @@
|
||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<!-- BEGIN: Subheader -->
|
||||||
|
<div class="m-subheader">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<div class="mr-auto">
|
||||||
|
<h3 class="m-subheader__title">Battery Sizes</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- END: Subheader -->
|
||||||
|
<div class="m-content">
|
||||||
|
<!--Begin::Section-->
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xl-4 offset-xl-4">
|
||||||
|
<div class="m-portlet m-portlet--mobile">
|
||||||
|
<div class="m-portlet__head">
|
||||||
|
<div class="m-portlet__head-caption">
|
||||||
|
<div class="m-portlet__head-title">
|
||||||
|
<span class="m-portlet__head-icon">
|
||||||
|
<i class="flaticon-app"></i>
|
||||||
|
</span>
|
||||||
|
<h3 class="m-portlet__head-text">
|
||||||
|
{% if row is defined %}
|
||||||
|
Edit Size
|
||||||
|
<small>{{ row.getName() }}</small>
|
||||||
|
{% else %}
|
||||||
|
New Size
|
||||||
|
{% endif %}
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<form id="row-form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ row is defined ? url('bsize_update_submit', {'id': row.getId()}) : url('bsize_create_submit') }}">
|
||||||
|
<div class="m-portlet__body">
|
||||||
|
<div class="form-group m-form__group row">
|
||||||
|
<label class="col-lg-3 col-form-label" data-field="name">
|
||||||
|
Name:
|
||||||
|
</label>
|
||||||
|
<div class="col-lg-9">
|
||||||
|
<input type="text" name="name" class="form-control m-input" value="{{ values.name is defined ? values.name : (row is defined ? row.getName()) }}">
|
||||||
|
<div class="form-control-feedback hide" data-field="name"></div>
|
||||||
|
<span class="m-form__help">Display name for this size</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="m-portlet__foot m-portlet__foot--fit">
|
||||||
|
<div class="m-form__actions m-form__actions--solid m-form__actions--right">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12">
|
||||||
|
<button type="submit" class="btn btn-success">Submit</button>
|
||||||
|
<a href="{{ url('bsize_list') }}" class="btn btn-secondary">Cancel</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
$("#row-form").submit(function(e) {
|
||||||
|
var form = $(this);
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
method: "POST",
|
||||||
|
url: form.prop('action'),
|
||||||
|
data: form.serialize()
|
||||||
|
}).done(function(response) {
|
||||||
|
// remove all error classes
|
||||||
|
removeErrors();
|
||||||
|
swal({
|
||||||
|
title: 'Done!',
|
||||||
|
text: 'Your changes have been saved!',
|
||||||
|
type: 'success',
|
||||||
|
onClose: function() {
|
||||||
|
window.location.href = "{{ url('bsize_list') }}";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).fail(function(response) {
|
||||||
|
var errors = response.responseJSON.errors;
|
||||||
|
var firstfield = false;
|
||||||
|
|
||||||
|
// remove all error classes first
|
||||||
|
removeErrors();
|
||||||
|
|
||||||
|
// display errors contextually
|
||||||
|
$.each(errors, function(field, msg) {
|
||||||
|
var formfield = $("[name='" + field + "']");
|
||||||
|
var label = $("label[data-field='" + field + "']");
|
||||||
|
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||||
|
|
||||||
|
// add error classes to bad fields
|
||||||
|
formfield.addClass('form-control-danger');
|
||||||
|
label.addClass('has-danger');
|
||||||
|
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||||
|
|
||||||
|
// check if this field comes first in DOM
|
||||||
|
var domfield = formfield.get(0);
|
||||||
|
|
||||||
|
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||||
|
firstfield = domfield;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// focus on first bad field
|
||||||
|
firstfield.focus();
|
||||||
|
|
||||||
|
// scroll to above that field to make it visible
|
||||||
|
$('html, body').animate({
|
||||||
|
scrollTop: $(firstfield).offset().top - 200
|
||||||
|
}, 100);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// remove all error classes
|
||||||
|
function removeErrors() {
|
||||||
|
$(".form-control-danger").removeClass('form-control-danger');
|
||||||
|
$("[data-field]").removeClass('has-danger');
|
||||||
|
$(".form-control-feedback[data-field]").addClass('hide');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
152
templates/battery-size/list.html.twig
Normal file
152
templates/battery-size/list.html.twig
Normal file
|
|
@ -0,0 +1,152 @@
|
||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<!-- BEGIN: Subheader -->
|
||||||
|
<div class="m-subheader">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<div class="mr-auto">
|
||||||
|
<h3 class="m-subheader__title">
|
||||||
|
Battery Sizes
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- END: Subheader -->
|
||||||
|
<div class="m-content">
|
||||||
|
<!--Begin::Section-->
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xl-12">
|
||||||
|
<div class="m-portlet m-portlet--mobile">
|
||||||
|
<div class="m-portlet__body">
|
||||||
|
<div class="m-form m-form--label-align-right m--margin-top-20 m--margin-bottom-30">
|
||||||
|
<div class="row align-items-center">
|
||||||
|
<div class="col-xl-8 order-2 order-xl-1">
|
||||||
|
<div class="form-group m-form__group row align-items-center">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="m-input-icon m-input-icon--left">
|
||||||
|
<input type="text" class="form-control m-input m-input--solid" placeholder="Search..." id="data-rows-search">
|
||||||
|
<span class="m-input-icon__icon m-input-icon__icon--left">
|
||||||
|
<span><i class="la la-search"></i></span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-xl-4 order-1 order-xl-2 m--align-right">
|
||||||
|
<a href="{{ url('bsize_create') }}" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
|
||||||
|
<span>
|
||||||
|
<i class="flaticon-app"></i>
|
||||||
|
<span>New Size</span>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
<div class="m-separator m-separator--dashed d-xl-none"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!--begin: Datatable -->
|
||||||
|
<div id="data-rows"></div>
|
||||||
|
<!--end: Datatable -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
var options = {
|
||||||
|
data: {
|
||||||
|
type: 'remote',
|
||||||
|
source: {
|
||||||
|
read: {
|
||||||
|
url: '{{ url("bsize_rows") }}',
|
||||||
|
method: 'POST'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
saveState: {
|
||||||
|
cookie: false,
|
||||||
|
webstorage: false
|
||||||
|
},
|
||||||
|
pageSize: 10,
|
||||||
|
serverPaging: true,
|
||||||
|
serverFiltering: true,
|
||||||
|
serverSorting: true
|
||||||
|
},
|
||||||
|
layout: {
|
||||||
|
scroll: true
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
field: 'id',
|
||||||
|
title: 'ID',
|
||||||
|
width: 30
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'name',
|
||||||
|
title: 'Name'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'Actions',
|
||||||
|
width: 110,
|
||||||
|
title: 'Actions',
|
||||||
|
sortable: false,
|
||||||
|
overflow: 'visible',
|
||||||
|
template: function (row, index, datatable) {
|
||||||
|
var actions = '';
|
||||||
|
|
||||||
|
if (row.meta.update_url != '') {
|
||||||
|
actions += '<a href="' + row.meta.update_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit" data-id="' + row.name + '" title="Edit"><i class="la la-edit"></i></a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (row.meta.delete_url != '') {
|
||||||
|
actions += '<a href="' + row.meta.delete_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill btn-delete" data-id="' + row.name + '" title="Delete"><i class="la la-trash"></i></a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return actions;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
search: {
|
||||||
|
onEnter: false,
|
||||||
|
input: $('#data-rows-search'),
|
||||||
|
delay: 400
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var table = $("#data-rows").mDatatable(options);
|
||||||
|
|
||||||
|
$(document).on('click', '.btn-delete', function(e) {
|
||||||
|
var url = $(this).prop('href');
|
||||||
|
var id = $(this).data('id');
|
||||||
|
var btn = $(this);
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
swal({
|
||||||
|
title: 'Confirmation',
|
||||||
|
html: 'Are you sure you want to delete <strong>' + id + '</strong>?',
|
||||||
|
type: 'warning',
|
||||||
|
showCancelButton: true
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.value) {
|
||||||
|
$.ajax({
|
||||||
|
method: "DELETE",
|
||||||
|
url: url
|
||||||
|
}).done(function(response) {
|
||||||
|
table.row(btn.parents('tr')).remove();
|
||||||
|
table.reload();
|
||||||
|
}).fail(function() {
|
||||||
|
swal({
|
||||||
|
title: 'Whoops',
|
||||||
|
text: 'An error occurred while deleting this item. Please contact support.',
|
||||||
|
type: 'error'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|
@ -56,7 +56,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group m-form__group row">
|
<div class="form-group m-form__group row">
|
||||||
<label class="col-lg-3 col-form-label" data-field="name">
|
<label class="col-lg-3 col-form-label" data-field="name">
|
||||||
Acess Levels:
|
Access Levels:
|
||||||
</label>
|
</label>
|
||||||
<div class="col-lg-9">
|
<div class="col-lg-9">
|
||||||
<div class="m-checkbox-list">
|
<div class="m-checkbox-list">
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,6 @@
|
||||||
<div class="col-xl-12">
|
<div class="col-xl-12">
|
||||||
<div class="m-portlet m-portlet--mobile">
|
<div class="m-portlet m-portlet--mobile">
|
||||||
<div class="m-portlet__body">
|
<div class="m-portlet__body">
|
||||||
{% for message in app.flashes('success') %}
|
|
||||||
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
|
||||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close"></button>
|
|
||||||
<strong>Success!</strong> {{ message }}
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
<div class="m-form m-form--label-align-right m--margin-top-20 m--margin-bottom-30">
|
<div class="m-form m-form--label-align-right m--margin-top-20 m--margin-bottom-30">
|
||||||
<div class="row align-items-center">
|
<div class="row align-items-center">
|
||||||
<div class="col-xl-8 order-2 order-xl-1">
|
<div class="col-xl-8 order-2 order-xl-1">
|
||||||
|
|
@ -96,10 +90,14 @@
|
||||||
sortable: false,
|
sortable: false,
|
||||||
overflow: 'visible',
|
overflow: 'visible',
|
||||||
template: function (row, index, datatable) {
|
template: function (row, index, datatable) {
|
||||||
var actions = '<a href="' + row.update_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit" data-id="' + row.id + '" title="Edit"><i class="la la-edit"></i></a>';
|
var actions = '';
|
||||||
|
|
||||||
|
if (row.meta.update_url != '') {
|
||||||
|
actions += '<a href="' + row.meta.update_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit" data-id="' + row.username + '" title="Edit"><i class="la la-edit"></i></a>';
|
||||||
|
}
|
||||||
|
|
||||||
if (row.id != 'ROLE_SUPER_ADMIN') {
|
if (row.meta.delete_url != '') {
|
||||||
actions += '<a href="' + row.delete_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill btn-delete" data-id="' + row.id + '" title="Delete"><i class="la la-trash"></i></a>';
|
actions += '<a href="' + row.meta.delete_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill btn-delete" data-id="' + row.username + '" title="Delete"><i class="la la-trash"></i></a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
return actions;
|
return actions;
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@
|
||||||
<div class="col-xl-4 order-1 order-xl-2 m--align-right">
|
<div class="col-xl-4 order-1 order-xl-2 m--align-right">
|
||||||
<a href="{{ url('user_create') }}" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
|
<a href="{{ url('user_create') }}" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
|
||||||
<span>
|
<span>
|
||||||
<i class="la la-user-plus"></i>
|
<i class="la la-user"></i>
|
||||||
<span>New User</span>
|
<span>New User</span>
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
|
||||||
132
templates/vehicle-manufacturer/form.html.twig
Normal file
132
templates/vehicle-manufacturer/form.html.twig
Normal file
|
|
@ -0,0 +1,132 @@
|
||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<!-- BEGIN: Subheader -->
|
||||||
|
<div class="m-subheader">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<div class="mr-auto">
|
||||||
|
<h3 class="m-subheader__title">Vehicle Manufacturers</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- END: Subheader -->
|
||||||
|
<div class="m-content">
|
||||||
|
<!--Begin::Section-->
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xl-4 offset-xl-4">
|
||||||
|
<div class="m-portlet m-portlet--mobile">
|
||||||
|
<div class="m-portlet__head">
|
||||||
|
<div class="m-portlet__head-caption">
|
||||||
|
<div class="m-portlet__head-title">
|
||||||
|
<span class="m-portlet__head-icon">
|
||||||
|
<i class="la la-industry"></i>
|
||||||
|
</span>
|
||||||
|
<h3 class="m-portlet__head-text">
|
||||||
|
{% if row is defined %}
|
||||||
|
Edit Manufacturer
|
||||||
|
<small>{{ row.getName() }}</small>
|
||||||
|
{% else %}
|
||||||
|
New Manufacturer
|
||||||
|
{% endif %}
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<form id="row-form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ row is defined ? url('vmfg_update_submit', {'id': row.getId()}) : url('vmfg_create_submit') }}">
|
||||||
|
<div class="m-portlet__body">
|
||||||
|
<div class="form-group m-form__group row">
|
||||||
|
<label class="col-lg-3 col-form-label" data-field="name">
|
||||||
|
Name:
|
||||||
|
</label>
|
||||||
|
<div class="col-lg-9">
|
||||||
|
<input type="text" name="name" class="form-control m-input" value="{{ values.name is defined ? values.name : (row is defined ? row.getName()) }}">
|
||||||
|
<div class="form-control-feedback hide" data-field="name"></div>
|
||||||
|
<span class="m-form__help">Display name for this manufacturer</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="m-portlet__foot m-portlet__foot--fit">
|
||||||
|
<div class="m-form__actions m-form__actions--solid m-form__actions--right">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12">
|
||||||
|
<button type="submit" class="btn btn-success">Submit</button>
|
||||||
|
<a href="{{ url('vmfg_list') }}" class="btn btn-secondary">Cancel</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
$("#row-form").submit(function(e) {
|
||||||
|
var form = $(this);
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
method: "POST",
|
||||||
|
url: form.prop('action'),
|
||||||
|
data: form.serialize()
|
||||||
|
}).done(function(response) {
|
||||||
|
// remove all error classes
|
||||||
|
removeErrors();
|
||||||
|
swal({
|
||||||
|
title: 'Done!',
|
||||||
|
text: 'Your changes have been saved!',
|
||||||
|
type: 'success',
|
||||||
|
onClose: function() {
|
||||||
|
window.location.href = "{{ url('vmfg_list') }}";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).fail(function(response) {
|
||||||
|
var errors = response.responseJSON.errors;
|
||||||
|
var firstfield = false;
|
||||||
|
|
||||||
|
// remove all error classes first
|
||||||
|
removeErrors();
|
||||||
|
|
||||||
|
// display errors contextually
|
||||||
|
$.each(errors, function(field, msg) {
|
||||||
|
var formfield = $("[name='" + field + "']");
|
||||||
|
var label = $("label[data-field='" + field + "']");
|
||||||
|
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||||
|
|
||||||
|
// add error classes to bad fields
|
||||||
|
formfield.addClass('form-control-danger');
|
||||||
|
label.addClass('has-danger');
|
||||||
|
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||||
|
|
||||||
|
// check if this field comes first in DOM
|
||||||
|
var domfield = formfield.get(0);
|
||||||
|
|
||||||
|
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||||
|
firstfield = domfield;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// focus on first bad field
|
||||||
|
firstfield.focus();
|
||||||
|
|
||||||
|
// scroll to above that field to make it visible
|
||||||
|
$('html, body').animate({
|
||||||
|
scrollTop: $(firstfield).offset().top - 200
|
||||||
|
}, 100);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// remove all error classes
|
||||||
|
function removeErrors() {
|
||||||
|
$(".form-control-danger").removeClass('form-control-danger');
|
||||||
|
$("[data-field]").removeClass('has-danger');
|
||||||
|
$(".form-control-feedback[data-field]").addClass('hide');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
152
templates/vehicle-manufacturer/list.html.twig
Normal file
152
templates/vehicle-manufacturer/list.html.twig
Normal file
|
|
@ -0,0 +1,152 @@
|
||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<!-- BEGIN: Subheader -->
|
||||||
|
<div class="m-subheader">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<div class="mr-auto">
|
||||||
|
<h3 class="m-subheader__title">
|
||||||
|
Vehicle Manufacturers
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- END: Subheader -->
|
||||||
|
<div class="m-content">
|
||||||
|
<!--Begin::Section-->
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xl-12">
|
||||||
|
<div class="m-portlet m-portlet--mobile">
|
||||||
|
<div class="m-portlet__body">
|
||||||
|
<div class="m-form m-form--label-align-right m--margin-top-20 m--margin-bottom-30">
|
||||||
|
<div class="row align-items-center">
|
||||||
|
<div class="col-xl-8 order-2 order-xl-1">
|
||||||
|
<div class="form-group m-form__group row align-items-center">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="m-input-icon m-input-icon--left">
|
||||||
|
<input type="text" class="form-control m-input m-input--solid" placeholder="Search..." id="data-rows-search">
|
||||||
|
<span class="m-input-icon__icon m-input-icon__icon--left">
|
||||||
|
<span><i class="la la-search"></i></span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-xl-4 order-1 order-xl-2 m--align-right">
|
||||||
|
<a href="{{ url('vmfg_create') }}" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
|
||||||
|
<span>
|
||||||
|
<i class="la la-industry"></i>
|
||||||
|
<span>New Manufacturer</span>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
<div class="m-separator m-separator--dashed d-xl-none"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!--begin: Datatable -->
|
||||||
|
<div id="data-rows"></div>
|
||||||
|
<!--end: Datatable -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
var options = {
|
||||||
|
data: {
|
||||||
|
type: 'remote',
|
||||||
|
source: {
|
||||||
|
read: {
|
||||||
|
url: '{{ url("vmfg_rows") }}',
|
||||||
|
method: 'POST'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
saveState: {
|
||||||
|
cookie: false,
|
||||||
|
webstorage: false
|
||||||
|
},
|
||||||
|
pageSize: 10,
|
||||||
|
serverPaging: true,
|
||||||
|
serverFiltering: true,
|
||||||
|
serverSorting: true
|
||||||
|
},
|
||||||
|
layout: {
|
||||||
|
scroll: true
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
field: 'id',
|
||||||
|
title: 'ID',
|
||||||
|
width: 30
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'name',
|
||||||
|
title: 'Name'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'Actions',
|
||||||
|
width: 110,
|
||||||
|
title: 'Actions',
|
||||||
|
sortable: false,
|
||||||
|
overflow: 'visible',
|
||||||
|
template: function (row, index, datatable) {
|
||||||
|
var actions = '';
|
||||||
|
|
||||||
|
if (row.meta.update_url != '') {
|
||||||
|
actions += '<a href="' + row.meta.update_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit" data-id="' + row.name + '" title="Edit"><i class="la la-edit"></i></a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (row.meta.delete_url != '') {
|
||||||
|
actions += '<a href="' + row.meta.delete_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill btn-delete" data-id="' + row.name + '" title="Delete"><i class="la la-trash"></i></a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return actions;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
search: {
|
||||||
|
onEnter: false,
|
||||||
|
input: $('#data-rows-search'),
|
||||||
|
delay: 400
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var table = $("#data-rows").mDatatable(options);
|
||||||
|
|
||||||
|
$(document).on('click', '.btn-delete', function(e) {
|
||||||
|
var url = $(this).prop('href');
|
||||||
|
var id = $(this).data('id');
|
||||||
|
var btn = $(this);
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
swal({
|
||||||
|
title: 'Confirmation',
|
||||||
|
html: 'Are you sure you want to delete <strong>' + id + '</strong>?',
|
||||||
|
type: 'warning',
|
||||||
|
showCancelButton: true
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.value) {
|
||||||
|
$.ajax({
|
||||||
|
method: "DELETE",
|
||||||
|
url: url
|
||||||
|
}).done(function(response) {
|
||||||
|
table.row(btn.parents('tr')).remove();
|
||||||
|
table.reload();
|
||||||
|
}).fail(function() {
|
||||||
|
swal({
|
||||||
|
title: 'Whoops',
|
||||||
|
text: 'An error occurred while deleting this item. Please contact support.',
|
||||||
|
type: 'error'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
168
templates/vehicle/form.html.twig
Normal file
168
templates/vehicle/form.html.twig
Normal file
|
|
@ -0,0 +1,168 @@
|
||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<!-- BEGIN: Subheader -->
|
||||||
|
<div class="m-subheader">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<div class="mr-auto">
|
||||||
|
<h3 class="m-subheader__title">Vehicles</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- END: Subheader -->
|
||||||
|
<div class="m-content">
|
||||||
|
<!--Begin::Section-->
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xl-4 offset-xl-4">
|
||||||
|
<div class="m-portlet m-portlet--mobile">
|
||||||
|
<div class="m-portlet__head">
|
||||||
|
<div class="m-portlet__head-caption">
|
||||||
|
<div class="m-portlet__head-title">
|
||||||
|
<span class="m-portlet__head-icon">
|
||||||
|
<i class="fa fa-car"></i>
|
||||||
|
</span>
|
||||||
|
<h3 class="m-portlet__head-text">
|
||||||
|
{% if row is defined %}
|
||||||
|
Edit Vehicle
|
||||||
|
<small>{{ row.getManufacturer().getName() ~ ' ' ~ row.getMake() ~ row.getModelYearFrom() ~ '-' ~ row.getModelYearTo() }}</small>
|
||||||
|
{% else %}
|
||||||
|
New Vehicle
|
||||||
|
{% endif %}
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<form id="row-form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ row is defined ? url('vehicle_update_submit', {'id': row.getId()}) : url('vehicle_create_submit') }}">
|
||||||
|
|
||||||
|
<div class="m-portlet__body">
|
||||||
|
<div class="form-group m-form__group row no-border">
|
||||||
|
<label class="col-lg-3 col-form-label" data-field="manufacturer">
|
||||||
|
Manufacturer:
|
||||||
|
</label>
|
||||||
|
<div class="col-lg-9">
|
||||||
|
<select class="form-control m-input" id="manufacturer" name="manufacturer">
|
||||||
|
<option value=""></option>
|
||||||
|
{% for manufacturer in manufacturers %}
|
||||||
|
<option value="{{ manufacturer.getID() }}"{{ row is defined and manufacturer.getID() == row.getManufacturer().getID() ? ' selected' }}>{{ manufacturer.getName() }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
<div class="form-control-feedback hide" data-field="manufacturer"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group m-form__group row no-border">
|
||||||
|
<label class="col-lg-3 col-form-label" data-field="make">
|
||||||
|
Make:
|
||||||
|
</label>
|
||||||
|
<div class="col-lg-9">
|
||||||
|
<input type="text" name="make" class="form-control m-input">
|
||||||
|
<div class="form-control-feedback hide" data-field="make"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group m-form__group row">
|
||||||
|
<label class="col-lg-3 col-form-label" data-field="model_year_from">
|
||||||
|
Year:
|
||||||
|
</label>
|
||||||
|
<div class="col-lg-9 flex-row">
|
||||||
|
<select class="form-control m-input" id="manufacturer" name="model_year_from">
|
||||||
|
<option value=""></option>
|
||||||
|
{% for year in years %}
|
||||||
|
<option value="{{ year }}"{{ row is defined and manufacturer.getModelYearFrom() == year ? ' selected' }}>{{ year }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
<label class="col-form-label text-center">
|
||||||
|
to
|
||||||
|
</label>
|
||||||
|
<select class="form-control m-input" id="manufacturer" name="model_year_to">
|
||||||
|
<option value=""></option>
|
||||||
|
{% for year in years %}
|
||||||
|
<option value="{{ year }}"{{ row is defined and manufacturer.getModelYearTo() == year ? ' selected' }}>{{ year }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="m-portlet__foot m-portlet__foot--fit">
|
||||||
|
<div class="m-form__actions m-form__actions--solid m-form__actions--right">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12">
|
||||||
|
<button type="submit" class="btn btn-success">Submit</button>
|
||||||
|
<a href="{{ url('vehicle_list') }}" class="btn btn-secondary">Cancel</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
$("#row-form").submit(function(e) {
|
||||||
|
var form = $(this);
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
method: "POST",
|
||||||
|
url: form.prop('action'),
|
||||||
|
data: form.serialize()
|
||||||
|
}).done(function(response) {
|
||||||
|
// remove all error classes
|
||||||
|
removeErrors();
|
||||||
|
swal({
|
||||||
|
title: 'Done!',
|
||||||
|
text: 'Your changes have been saved!',
|
||||||
|
type: 'success',
|
||||||
|
onClose: function() {
|
||||||
|
window.location.href = "{{ url('vehicle_list') }}";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).fail(function(response) {
|
||||||
|
var errors = response.responseJSON.errors;
|
||||||
|
var firstfield = false;
|
||||||
|
|
||||||
|
// remove all error classes first
|
||||||
|
removeErrors();
|
||||||
|
|
||||||
|
// display errors contextually
|
||||||
|
$.each(errors, function(field, msg) {
|
||||||
|
var formfield = $("[name='" + field + "']");
|
||||||
|
var label = $("label[data-field='" + field + "']");
|
||||||
|
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||||
|
|
||||||
|
// add error classes to bad fields
|
||||||
|
formfield.addClass('form-control-danger');
|
||||||
|
label.addClass('has-danger');
|
||||||
|
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||||
|
|
||||||
|
// check if this field comes first in DOM
|
||||||
|
var domfield = formfield.get(0);
|
||||||
|
|
||||||
|
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||||
|
firstfield = domfield;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// focus on first bad field
|
||||||
|
firstfield.focus();
|
||||||
|
|
||||||
|
// scroll to above that field to make it visible
|
||||||
|
$('html, body').animate({
|
||||||
|
scrollTop: $(firstfield).offset().top - 200
|
||||||
|
}, 100);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// remove all error classes
|
||||||
|
function removeErrors() {
|
||||||
|
$(".form-control-danger").removeClass('form-control-danger');
|
||||||
|
$("[data-field]").removeClass('has-danger');
|
||||||
|
$(".form-control-feedback[data-field]").addClass('hide');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
160
templates/vehicle/list.html.twig
Normal file
160
templates/vehicle/list.html.twig
Normal file
|
|
@ -0,0 +1,160 @@
|
||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<!-- BEGIN: Subheader -->
|
||||||
|
<div class="m-subheader">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<div class="mr-auto">
|
||||||
|
<h3 class="m-subheader__title">
|
||||||
|
Vehicles
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- END: Subheader -->
|
||||||
|
<div class="m-content">
|
||||||
|
<!--Begin::Section-->
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xl-12">
|
||||||
|
<div class="m-portlet m-portlet--mobile">
|
||||||
|
<div class="m-portlet__body">
|
||||||
|
<div class="m-form m-form--label-align-right m--margin-top-20 m--margin-bottom-30">
|
||||||
|
<div class="row align-items-center">
|
||||||
|
<div class="col-xl-8 order-2 order-xl-1">
|
||||||
|
<div class="form-group m-form__group row align-items-center">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="m-input-icon m-input-icon--left">
|
||||||
|
<input type="text" class="form-control m-input m-input--solid" placeholder="Search..." id="data-rows-search">
|
||||||
|
<span class="m-input-icon__icon m-input-icon__icon--left">
|
||||||
|
<span><i class="la la-search"></i></span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-xl-4 order-1 order-xl-2 m--align-right">
|
||||||
|
<a href="{{ url('vehicle_create') }}" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
|
||||||
|
<span>
|
||||||
|
<i class="fa fa-car"></i>
|
||||||
|
<span>New Vehicle</span>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
<div class="m-separator m-separator--dashed d-xl-none"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!--begin: Datatable -->
|
||||||
|
<div id="data-rows"></div>
|
||||||
|
<!--end: Datatable -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
var options = {
|
||||||
|
data: {
|
||||||
|
type: 'remote',
|
||||||
|
source: {
|
||||||
|
read: {
|
||||||
|
url: '{{ url("vehicle_rows") }}',
|
||||||
|
method: 'POST',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
saveState: {
|
||||||
|
cookie: false,
|
||||||
|
webstorage: false
|
||||||
|
},
|
||||||
|
pageSize: 10,
|
||||||
|
serverPaging: true,
|
||||||
|
serverFiltering: true,
|
||||||
|
serverSorting: true
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
field: 'id',
|
||||||
|
title: 'ID',
|
||||||
|
width: 30
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'mfg_name',
|
||||||
|
title: 'Manufacturer'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'make',
|
||||||
|
title: 'Make'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'model_year_from',
|
||||||
|
title: 'Year',
|
||||||
|
template: function (data) {
|
||||||
|
return data.model_year_from + ' - ' + data.model_year_to;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'Actions',
|
||||||
|
width: 110,
|
||||||
|
title: 'Actions',
|
||||||
|
sortable: false,
|
||||||
|
overflow: 'visible',
|
||||||
|
template: function (row, index, datatable) {
|
||||||
|
var actions = '';
|
||||||
|
|
||||||
|
if (row.meta.update_url != '') {
|
||||||
|
actions += '<a href="' + row.meta.update_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit" data-id="' + row.mfg_name + ' ' + row.make + '" title="Edit"><i class="la la-edit"></i></a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (row.meta.delete_url != '') {
|
||||||
|
actions += '<a href="' + row.meta.delete_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill btn-delete" data-id="' + row.mfg_name + ' ' + row.make + '" title="Delete"><i class="la la-trash"></i></a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return actions;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
search: {
|
||||||
|
onEnter: false,
|
||||||
|
input: $('#data-rows-search'),
|
||||||
|
delay: 400
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var table = $("#data-rows").mDatatable(options);
|
||||||
|
|
||||||
|
$(document).on('click', '.btn-delete', function(e) {
|
||||||
|
var url = $(this).prop('href');
|
||||||
|
var id = $(this).data('id');
|
||||||
|
var btn = $(this);
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
swal({
|
||||||
|
title: 'Confirmation',
|
||||||
|
html: 'Are you sure you want to delete <strong>' + id + '</strong>?',
|
||||||
|
type: 'warning',
|
||||||
|
showCancelButton: true
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.value) {
|
||||||
|
$.ajax({
|
||||||
|
method: "DELETE",
|
||||||
|
url: url
|
||||||
|
}).done(function(response) {
|
||||||
|
table.row(btn.parents('tr')).remove();
|
||||||
|
table.reload();
|
||||||
|
}).fail(function() {
|
||||||
|
swal({
|
||||||
|
title: 'Whoops',
|
||||||
|
text: 'An error occurred while deleting this item. Please contact support.',
|
||||||
|
type: 'error'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
Loading…
Reference in a new issue