Merge branch 'master' of gitlab.com:jankstudio/resq
|
|
@ -55,6 +55,11 @@ bmfg_create_submit:
|
|||
controller: App\Controller\BatteryManufacturerController::addSubmit
|
||||
methods: [POST]
|
||||
|
||||
bmfg_batteries:
|
||||
path: /battery-manufacturers/batteries
|
||||
controller: App\Controller\BatteryManufacturerController::getBatteries
|
||||
methods: [POST]
|
||||
|
||||
bmfg_update:
|
||||
path: /battery-manufacturers/{id}
|
||||
controller: App\Controller\BatteryManufacturerController::updateForm
|
||||
|
|
|
|||
38
config/routes/rider.yaml
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
rider_list:
|
||||
path: /riders
|
||||
controller: App\Controller\RiderController::index
|
||||
|
||||
rider_rows:
|
||||
path: /riders/rows
|
||||
controller: App\Controller\RiderController::rows
|
||||
methods: [POST]
|
||||
|
||||
rider_upload_image:
|
||||
path: /riders/upload
|
||||
controller: App\Controller\RiderController::uploadImage
|
||||
methods: [POST]
|
||||
|
||||
rider_create:
|
||||
path: /riders/create
|
||||
controller: App\Controller\RiderController::addForm
|
||||
methods: [GET]
|
||||
|
||||
rider_create_submit:
|
||||
path: /riders/create
|
||||
controller: App\Controller\RiderController::addSubmit
|
||||
methods: [POST]
|
||||
|
||||
rider_update:
|
||||
path: /riders/{id}
|
||||
controller: App\Controller\RiderController::updateForm
|
||||
methods: [GET]
|
||||
|
||||
rider_update_submit:
|
||||
path: /riders/{id}
|
||||
controller: App\Controller\RiderController::updateSubmit
|
||||
methods: [POST]
|
||||
|
||||
rider_delete:
|
||||
path: /riders/{id}
|
||||
controller: App\Controller\RiderController::destroy
|
||||
methods: [DELETE]
|
||||
|
|
@ -5,6 +5,7 @@ parameters:
|
|||
map_default:
|
||||
latitude: 14.6091
|
||||
longitude: 121.0223
|
||||
image_upload_directory: '%kernel.project_dir%/public/uploads'
|
||||
|
||||
services:
|
||||
# default configuration for services in *this* file
|
||||
|
|
@ -45,3 +46,7 @@ services:
|
|||
arguments:
|
||||
$acl_gen: "@App\\Access\\Generator"
|
||||
tags: ['security.voter']
|
||||
|
||||
App\Service\FileUploader:
|
||||
arguments:
|
||||
$target_dir: '%image_upload_directory%'
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
/* template add-ons */
|
||||
|
||||
label.has-danger,
|
||||
.form-control-feedback.has-danger {
|
||||
.form-control-feedback.has-danger,
|
||||
span.has-danger,
|
||||
.nav-link.has-danger {
|
||||
color: #f4516c !important;
|
||||
}
|
||||
|
||||
|
|
@ -36,4 +38,36 @@ label.has-danger,
|
|||
.normal-font {
|
||||
font-size: inherit !important;
|
||||
font-weight: inherit !important;
|
||||
}
|
||||
|
||||
.block-switch {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.switch-label {
|
||||
margin: 6px 0 0 8px;
|
||||
}
|
||||
|
||||
.portrait-box {
|
||||
border: 2px solid #5867DD;
|
||||
background-size: 100%;
|
||||
background-repeat: no-repeat;
|
||||
background-position: 50% 50%;
|
||||
width: 150px;
|
||||
height: 150px;
|
||||
}
|
||||
|
||||
.user-portrait-sm {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
background-size: 100%;
|
||||
background-repeat: no-repeat;
|
||||
background-position: 50% 50%;
|
||||
border-radius: 100%;
|
||||
}
|
||||
|
||||
@media (min-width: 995px) {
|
||||
.modal-lg {
|
||||
max-width: 1024px;
|
||||
}
|
||||
}
|
||||
14788
public/assets/vendors/base/vendors.bundle.js
vendored
BIN
public/uploads/001d605b59eb78cc390fe46320780d18.jpeg
Normal file
|
After Width: | Height: | Size: 166 KiB |
BIN
public/uploads/4c7be38a53cc678da17351697bd7172a.jpeg
Normal file
|
After Width: | Height: | Size: 166 KiB |
BIN
public/uploads/4dfd6d72550fa434d132a5831266c5ed.jpeg
Normal file
|
After Width: | Height: | Size: 166 KiB |
BIN
public/uploads/572ce4b8597185c9e933b0d2cd7a20f7.jpeg
Normal file
|
After Width: | Height: | Size: 166 KiB |
BIN
public/uploads/75b26b7e0ff5cc8a4922adc9e840ffae.jpeg
Normal file
|
After Width: | Height: | Size: 166 KiB |
BIN
public/uploads/799768940504d863afc2b247f6ab6779.jpeg
Normal file
|
After Width: | Height: | Size: 166 KiB |
BIN
public/uploads/a6e7e76fb1561f0bd07de522814fe84c.jpeg
Normal file
|
After Width: | Height: | Size: 84 KiB |
BIN
public/uploads/e27f722edde2377d36369ef6d301d087.jpeg
Normal file
|
After Width: | Height: | Size: 166 KiB |
BIN
public/uploads/e7a58d489627998a9c749694ee1b30d2.jpeg
Normal file
|
After Width: | Height: | Size: 714 KiB |
BIN
public/uploads/ed311c191ccfa7826b9d4ebfc8250425.jpeg
Normal file
|
After Width: | Height: | Size: 166 KiB |
|
|
@ -266,6 +266,39 @@ class BatteryManufacturerController extends BaseController
|
|||
$response->send();
|
||||
}
|
||||
|
||||
public function getBatteries(Request $req)
|
||||
{
|
||||
if (!$this->isGranted('customer.add') && !$this->isGranted('customer.update')) {
|
||||
$exception = $this->createAccessDeniedException('No access.');
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
// get row data
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$row = $em->getRepository(BatteryManufacturer::class)->find($req->request->get('id'));
|
||||
|
||||
if (empty($row))
|
||||
throw $this->createNotFoundException('The item does not exist');
|
||||
|
||||
// build batteries array
|
||||
$batteries = [];
|
||||
|
||||
foreach ($row->getBatteries() as $battery) {
|
||||
$batteries[] = [
|
||||
'id' => $battery->getID(),
|
||||
'mfg_name' => $battery->getManufacturer()->getName(),
|
||||
'model_name' => $battery->getModel()->getName(),
|
||||
'size_name' => $battery->getSize()->getName(),
|
||||
'prod_code' => $battery->getProductCode()
|
||||
];
|
||||
}
|
||||
|
||||
// response
|
||||
return $this->json([
|
||||
'data' => $batteries
|
||||
]);
|
||||
}
|
||||
|
||||
// check if datatable filter is present and append to query
|
||||
protected function setQueryFilters($datatable, &$query) {
|
||||
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
|
||||
|
|
|
|||
|
|
@ -5,8 +5,11 @@ namespace App\Controller;
|
|||
use App\Ramcar\BaseController;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\CustomerVehicle;
|
||||
use App\Entity\MobileNumber;
|
||||
use App\Entity\Vehicle;
|
||||
use App\Entity\VehicleManufacturer;
|
||||
use App\Entity\Battery;
|
||||
use App\Entity\BatteryManufacturer;
|
||||
|
||||
use Doctrine\ORM\Query;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
|
@ -16,6 +19,8 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
|
|||
use App\Menu\Generator as MenuGenerator;
|
||||
use App\Access\Generator as ACLGenerator;
|
||||
|
||||
use DateTime;
|
||||
|
||||
class CustomerController extends BaseController
|
||||
{
|
||||
protected $acl_gen;
|
||||
|
|
@ -134,8 +139,11 @@ class CustomerController extends BaseController
|
|||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
// get parent associations
|
||||
$params['bmfgs'] = $em->getRepository(BatteryManufacturer::class)->findAll();
|
||||
$params['vmfgs'] = $em->getRepository(VehicleManufacturer::class)->findAll();
|
||||
|
||||
$params['years'] = $this->generateYearOptions();
|
||||
|
||||
// response
|
||||
return $this->render('customer/form.html.twig', $params);
|
||||
}
|
||||
|
|
@ -149,25 +157,121 @@ class CustomerController extends BaseController
|
|||
$row = new Customer();
|
||||
|
||||
// set and save values
|
||||
$row->setName($req->request->get('name'));
|
||||
$row->setFirstName($req->request->get('first_name'))
|
||||
->setLastName($req->request->get('last_name'))
|
||||
->setConfirmed(false);
|
||||
|
||||
// initialize error lists
|
||||
$error_array = [];
|
||||
$nerror_array = [];
|
||||
$verror_array = [];
|
||||
|
||||
// custom validation for mobile numbers
|
||||
$numbers = json_decode($req->request->get('mobile_numbers'));
|
||||
|
||||
if (!empty($numbers)) {
|
||||
foreach ($numbers as $key => $number) {
|
||||
$mobile_number = new MobileNumber();
|
||||
$mobile_number->setID($number->id)
|
||||
->setDateRegistered(DateTime::createFromFormat("d M Y - h:i A", $number->date_registered))
|
||||
->setCustomer($row);
|
||||
|
||||
if (!empty($number->date_confirmed)) {
|
||||
$mobile_number->setDateConfirmed(DateTime::createFromFormat("d M Y - h:i A", $number->date_confirmed))
|
||||
->setConfirmed();
|
||||
} else {
|
||||
$mobile_number->setConfirmed(false);
|
||||
}
|
||||
|
||||
$nerrors = $validator->validate($mobile_number);
|
||||
|
||||
// add errors to list
|
||||
foreach ($nerrors as $error) {
|
||||
if (!isset($nerror_array[$key]))
|
||||
$nerror_array[$key] = [];
|
||||
|
||||
$nerror_array[$key][$error->getPropertyPath()] = $error->getMessage();
|
||||
}
|
||||
|
||||
if (!isset($nerror_array[$key])) {
|
||||
$row->addMobileNumber($mobile_number);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// custom validation for vehicles
|
||||
$vehicles = json_decode($req->request->get('vehicles'));
|
||||
|
||||
if (!empty($vehicles)) {
|
||||
foreach ($vehicles as $vehicle) {
|
||||
// check if vehicle exists
|
||||
$vobj = $em->getRepository(Vehicle::class)->find($vehicle->vehicle);
|
||||
|
||||
if (empty($vobj)) {
|
||||
$verror_array[$vehicle->index]['vehicle'] = 'Invalid vehicle specified.';
|
||||
} else {
|
||||
$cust_vehicle = new CustomerVehicle();
|
||||
$cust_vehicle->setName($vehicle->name)
|
||||
->setVehicle($vobj)
|
||||
->setPlateNumber($vehicle->plate_number)
|
||||
->setModelYear($vehicle->model_year)
|
||||
->setColor($vehicle->color)
|
||||
->setStatusCondition($vehicle->status_condition)
|
||||
->setFuelType($vehicle->fuel_type)
|
||||
->setActive($vehicle->flag_active)
|
||||
->setCustomer($row);
|
||||
|
||||
// if specified, check if battery exists
|
||||
if ($vehicle->battery) {
|
||||
// check if battery exists
|
||||
$bobj = $em->getRepository(Battery::class)->find($vehicle->battery);
|
||||
|
||||
if (empty($bobj)) {
|
||||
$verror_array[$vehicle->index]['battery'] = 'Invalid battery specified.';
|
||||
} else {
|
||||
$cust_vehicle->setHasMotoliteBattery(true)
|
||||
->setCurrentBattery($bobj)
|
||||
->setWarrantyCode($vehicle->warranty_code)
|
||||
->setWarrantyExpiration(DateTime::createFromFormat("d M Y", $vehicle->warranty_expiration));
|
||||
}
|
||||
} else {
|
||||
$cust_vehicle->setHasMotoliteBattery(false);
|
||||
}
|
||||
|
||||
$verrors = $validator->validate($cust_vehicle);
|
||||
|
||||
// add errors to list
|
||||
foreach ($verrors as $error) {
|
||||
if (!isset($verror_array[$vehicle->index]))
|
||||
$verror_array[$vehicle->index] = [];
|
||||
|
||||
$verror_array[$vehicle->index][$error->getPropertyPath()] = $error->getMessage();
|
||||
}
|
||||
|
||||
// add to entity
|
||||
if (!isset($verror_array[$vehicle->index])) {
|
||||
$row->addVehicle($cust_vehicle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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)) {
|
||||
if (!empty($error_array) || !empty($nerror_array) || !empty($verror_array)) {
|
||||
// return validation failure response
|
||||
return $this->json([
|
||||
'success' => false,
|
||||
'errors' => $error_array
|
||||
'errors' => $error_array,
|
||||
'nerrors' => $nerror_array,
|
||||
'verrors' => $verror_array
|
||||
], 422);
|
||||
} else {
|
||||
// validated! save the entity
|
||||
|
|
@ -196,8 +300,13 @@ class CustomerController extends BaseController
|
|||
if (empty($row))
|
||||
throw $this->createNotFoundException('The item does not exist');
|
||||
|
||||
// get parent associations
|
||||
$params['bmfgs'] = $em->getRepository(BatteryManufacturer::class)->findAll();
|
||||
$params['vmfgs'] = $em->getRepository(VehicleManufacturer::class)->findAll();
|
||||
|
||||
$params['years'] = $this->generateYearOptions();
|
||||
|
||||
$params['obj'] = $row;
|
||||
$params['values'] = [];
|
||||
|
||||
// response
|
||||
return $this->render('customer/form.html.twig', $params);
|
||||
|
|
@ -216,28 +325,180 @@ class CustomerController extends BaseController
|
|||
throw $this->createNotFoundException('The item does not exist');
|
||||
|
||||
// set and save values
|
||||
$row->setName($req->request->get('name'));
|
||||
$row->setFirstName($req->request->get('first_name'))
|
||||
->setLastName($req->request->get('last_name'));
|
||||
|
||||
// initialize error lists
|
||||
$error_array = [];
|
||||
$nerror_array = [];
|
||||
$verror_array = [];
|
||||
|
||||
// initialize child id lists
|
||||
$number_ids = [];
|
||||
$vehicle_ids = [];
|
||||
|
||||
// custom validation for mobile numbers
|
||||
$numbers = json_decode($req->request->get('mobile_numbers'));
|
||||
|
||||
if (!empty($numbers)) {
|
||||
foreach ($numbers as $key => $number) {
|
||||
// check if number exists
|
||||
$mobile_number = $em->getRepository(MobileNumber::class)->find($number->id);
|
||||
|
||||
// this is a new number
|
||||
if (empty($mobile_number)) {
|
||||
$mobile_number = new MobileNumber();
|
||||
$mobile_number->setID($number->id)
|
||||
->setDateRegistered(DateTime::createFromFormat("d M Y - h:i A", $number->date_registered))
|
||||
->setCustomer($row);
|
||||
|
||||
if (!empty($number->date_confirmed)) {
|
||||
$mobile_number->setDateConfirmed(DateTime::createFromFormat("d M Y - h:i A", $number->date_confirmed))
|
||||
->setConfirmed();
|
||||
} else {
|
||||
$mobile_number->setConfirmed(false);
|
||||
}
|
||||
|
||||
$nerrors = $validator->validate($mobile_number);
|
||||
|
||||
// add errors to list
|
||||
foreach ($nerrors as $error) {
|
||||
if (!isset($nerror_array[$key]))
|
||||
$nerror_array[$key] = [];
|
||||
|
||||
$nerror_array[$key][$error->getPropertyPath()] = $error->getMessage();
|
||||
}
|
||||
|
||||
if (!isset($nerror_array[$key])) {
|
||||
$row->addMobileNumber($mobile_number);
|
||||
}
|
||||
}
|
||||
|
||||
// add to list of numbers to keep
|
||||
$number_ids[] = $mobile_number->getID();
|
||||
}
|
||||
}
|
||||
|
||||
// delete all numbers not in list
|
||||
$qb = $em->createQueryBuilder();
|
||||
$del_numbers = $qb->select('m')
|
||||
->from(MobileNumber::class, 'm')
|
||||
->where($qb->expr()->notIn('m.id', $number_ids))
|
||||
->getQuery()
|
||||
->getResult();
|
||||
|
||||
if (!empty($del_numbers)) {
|
||||
foreach ($del_numbers as $dn) {
|
||||
$em->remove($dn);
|
||||
}
|
||||
}
|
||||
|
||||
// custom validation for vehicles
|
||||
$vehicles = json_decode($req->request->get('vehicles'));
|
||||
|
||||
if (!empty($vehicles)) {
|
||||
foreach ($vehicles as $vehicle) {
|
||||
$cust_vehicle = false;
|
||||
$is_new_vehicle = false;
|
||||
|
||||
// check if customer vehicle exists
|
||||
if (!empty($vehicle->id)) {
|
||||
$cust_vehicle = $em->getRepository(CustomerVehicle::class)->find($vehicle->id);
|
||||
}
|
||||
|
||||
// this is a new vehicle
|
||||
if (empty($cust_vehicle)) {
|
||||
$cust_vehicle = new CustomerVehicle();
|
||||
$cust_vehicle->setCustomer($row);
|
||||
$is_new_vehicle = true;
|
||||
}
|
||||
|
||||
// check if vehicle exists
|
||||
$vobj = $em->getRepository(Vehicle::class)->find($vehicle->vehicle);
|
||||
|
||||
if (empty($vobj)) {
|
||||
$verror_array[$vehicle->index]['vehicle'] = 'Invalid vehicle specified.';
|
||||
} else {
|
||||
$cust_vehicle->setName($vehicle->name)
|
||||
->setVehicle($vobj)
|
||||
->setPlateNumber($vehicle->plate_number)
|
||||
->setModelYear($vehicle->model_year)
|
||||
->setColor($vehicle->color)
|
||||
->setStatusCondition($vehicle->status_condition)
|
||||
->setFuelType($vehicle->fuel_type)
|
||||
->setActive($vehicle->flag_active);
|
||||
|
||||
// if specified, check if battery exists
|
||||
if ($vehicle->battery) {
|
||||
// check if battery exists
|
||||
$bobj = $em->getRepository(Battery::class)->find($vehicle->battery);
|
||||
|
||||
if (empty($bobj)) {
|
||||
$verror_array[$vehicle->index]['battery'] = 'Invalid battery specified.';
|
||||
} else {
|
||||
$cust_vehicle->setHasMotoliteBattery(true)
|
||||
->setCurrentBattery($bobj)
|
||||
->setWarrantyCode($vehicle->warranty_code)
|
||||
->setWarrantyExpiration(DateTime::createFromFormat("d M Y", $vehicle->warranty_expiration));
|
||||
}
|
||||
} else {
|
||||
$cust_vehicle->setHasMotoliteBattery(false);
|
||||
}
|
||||
|
||||
$verrors = $validator->validate($cust_vehicle);
|
||||
|
||||
// add errors to list
|
||||
foreach ($verrors as $error) {
|
||||
if (!isset($verror_array[$vehicle->index]))
|
||||
$verror_array[$vehicle->index] = [];
|
||||
|
||||
$verror_array[$vehicle->index][$error->getPropertyPath()] = $error->getMessage();
|
||||
}
|
||||
|
||||
if (!isset($verror_array[$vehicle->index]) && $is_new_vehicle) {
|
||||
$row->addVehicle($cust_vehicle);
|
||||
}
|
||||
|
||||
// add to list of vehicles to keep
|
||||
$vehicle_ids[] = $cust_vehicle->getID();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// delete all vehicles not in list
|
||||
$qb = $em->createQueryBuilder();
|
||||
$del_vehicles = $qb->select('cv')
|
||||
->from(CustomerVehicle::class, 'cv')
|
||||
->where($qb->expr()->notIn('cv.id', $vehicle_ids))
|
||||
->getQuery()
|
||||
->getResult();
|
||||
|
||||
if (!empty($del_vehicles)) {
|
||||
foreach ($del_vehicles as $dv) {
|
||||
$em->remove($dv);
|
||||
}
|
||||
}
|
||||
|
||||
// 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)) {
|
||||
if (!empty($error_array) || !empty($nerror_array) || !empty($verror_array)) {
|
||||
// return validation failure response
|
||||
return $this->json([
|
||||
'success' => false,
|
||||
'errors' => $error_array
|
||||
'errors' => $error_array,
|
||||
'nerrors' => $nerror_array,
|
||||
'verrors' => $verror_array
|
||||
], 422);
|
||||
} else {
|
||||
// validated! save the entity
|
||||
// validated! save the entity. do a persist anyway to save child entities
|
||||
$em->persist($row);
|
||||
$em->flush();
|
||||
|
||||
// return successful response
|
||||
|
|
@ -270,6 +531,12 @@ class CustomerController extends BaseController
|
|||
$response->send();
|
||||
}
|
||||
|
||||
protected function generateYearOptions()
|
||||
{
|
||||
$start_year = 1950;
|
||||
return range($start_year, date("Y") + 1);
|
||||
}
|
||||
|
||||
// check if datatable filter is present and append to query
|
||||
protected function setQueryFilters($datatable, &$query) {
|
||||
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
|
||||
|
|
|
|||
336
src/Controller/RiderController.php
Normal file
|
|
@ -0,0 +1,336 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Ramcar\BaseController;
|
||||
use App\Entity\Rider;
|
||||
use App\Entity\Hub;
|
||||
use App\Service\FileUploader;
|
||||
|
||||
use Doctrine\ORM\Query;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
|
||||
class RiderController extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$this->denyAccessUnlessGranted('rider.list', null, 'No access.');
|
||||
|
||||
$params = $this->initParameters('rider_list');
|
||||
|
||||
return $this->render('rider/list.html.twig', $params);
|
||||
}
|
||||
|
||||
public function rows(Request $req)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('rider.list', null, 'No access.');
|
||||
|
||||
// get query builder
|
||||
$qb = $this->getDoctrine()
|
||||
->getRepository(Rider::class)
|
||||
->createQueryBuilder('q');
|
||||
|
||||
// get datatable params
|
||||
$datatable = $req->request->get('datatable');
|
||||
|
||||
// count total records
|
||||
$tquery = $qb->select('COUNT(q)')
|
||||
->leftJoin('q.hub', 'hub');
|
||||
|
||||
// add filters to count query
|
||||
$this->setQueryFilters($datatable, $tquery);
|
||||
|
||||
$total = $tquery->getQuery()
|
||||
->getSingleScalarResult();
|
||||
|
||||
// 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')
|
||||
->addSelect('hub.name as hub_name');
|
||||
|
||||
// add filters to query
|
||||
$this->setQueryFilters($datatable, $query);
|
||||
|
||||
// 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.id', 'asc');
|
||||
}
|
||||
|
||||
// get rows for this page
|
||||
$obj_rows = $query->setFirstResult($offset)
|
||||
->setMaxResults($perpage)
|
||||
->getQuery()
|
||||
->getResult();
|
||||
// Query::HYDRATE_ARRAY);
|
||||
|
||||
// process rows
|
||||
$rows = [];
|
||||
foreach ($obj_rows as $orow) {
|
||||
// add row data
|
||||
$row['id'] = $orow[0]->getID();
|
||||
$row['image_file'] = $orow[0]->getImageFile();
|
||||
$row['first_name'] = $orow[0]->getFirstName();
|
||||
$row['last_name'] = $orow[0]->getLastName();
|
||||
$row['contact_num'] = $orow[0]->getContactNumber();
|
||||
$row['hub'] = $orow['hub_name'];
|
||||
|
||||
// add row metadata
|
||||
$row['meta'] = [
|
||||
'update_url' => '',
|
||||
'delete_url' => ''
|
||||
];
|
||||
|
||||
// add crud urls
|
||||
if ($this->isGranted('rider.update'))
|
||||
$row['meta']['update_url'] = $this->generateUrl('rider_update', ['id' => $row['id']]);
|
||||
if ($this->isGranted('rider.delete'))
|
||||
$row['meta']['delete_url'] = $this->generateUrl('rider_delete', ['id' => $row['id']]);
|
||||
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
// response
|
||||
return $this->json([
|
||||
'meta' => $meta,
|
||||
'data' => $rows
|
||||
]);
|
||||
}
|
||||
|
||||
public function addForm()
|
||||
{
|
||||
$this->denyAccessUnlessGranted('rider.add', null, 'No access.');
|
||||
|
||||
$params = $this->initParameters('rider_list');
|
||||
$params['obj'] = new Rider();
|
||||
$params['mode'] = 'create';
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
// get parent associations
|
||||
$params['hubs'] = $em->getRepository(Hub::class)->findAll();
|
||||
|
||||
// response
|
||||
return $this->render('rider/form.html.twig', $params);
|
||||
}
|
||||
|
||||
public function addSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('rider.add', null, 'No access.');
|
||||
|
||||
// create new row
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$row = new Rider();
|
||||
|
||||
// set and save values
|
||||
$row->setFirstName($req->request->get('first_name'))
|
||||
->setLastName($req->request->get('last_name'))
|
||||
->setContactNumber($req->request->get('contact_no'))
|
||||
->setImageFile($req->request->get('image_file'));
|
||||
|
||||
// initialize error list
|
||||
$error_array = [];
|
||||
|
||||
// custom validation for associations
|
||||
$hub_id = $req->request->get('hub');
|
||||
|
||||
if ($hub_id) {
|
||||
$hub = $em->getRepository(Hub::class)
|
||||
->find($hub_id);
|
||||
|
||||
if (empty($hub))
|
||||
$error_array['hub'] = 'Invalid hub selected.';
|
||||
else
|
||||
$row->setHub($hub);
|
||||
}
|
||||
|
||||
// validate
|
||||
$errors = $validator->validate($row);
|
||||
|
||||
// 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 updateForm(FileUploader $uploader, $id)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('rider.update', null, 'No access.');
|
||||
|
||||
$params = $this->initParameters('rider_list');
|
||||
$params['mode'] = 'update';
|
||||
|
||||
// get row data
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$row = $em->getRepository(Rider::class)->find($id);
|
||||
|
||||
// make sure this row exists
|
||||
if (empty($row))
|
||||
throw $this->createNotFoundException('The item does not exist');
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
// get parent associations
|
||||
$params['hubs'] = $em->getRepository(Hub::class)->findAll();
|
||||
|
||||
$params['obj'] = $row;
|
||||
|
||||
// get file params if present
|
||||
if (!empty($row->getImageFile())) {
|
||||
$file = $uploader->getTargetDir() . '/' . $row->getImageFile();
|
||||
$params['filesize'] = filesize($file);
|
||||
}
|
||||
|
||||
// response
|
||||
return $this->render('rider/form.html.twig', $params);
|
||||
}
|
||||
|
||||
public function updateSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator, $id)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('rider.update', null, 'No access.');
|
||||
|
||||
// get row data
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$row = $em->getRepository(Rider::class)->find($id);
|
||||
|
||||
// make sure this row exists
|
||||
if (empty($row))
|
||||
throw $this->createNotFoundException('The item does not exist');
|
||||
|
||||
// set and save values
|
||||
$row->setFirstName($req->request->get('first_name'))
|
||||
->setLastName($req->request->get('last_name'))
|
||||
->setContactNumber($req->request->get('contact_no'))
|
||||
->setImageFile($req->request->get('image_file'));
|
||||
|
||||
// initialize error list
|
||||
$error_array = [];
|
||||
|
||||
// custom validation for associations
|
||||
$hub_id = $req->request->get('hub');
|
||||
|
||||
if ($hub_id) {
|
||||
$hub = $em->getRepository(Hub::class)
|
||||
->find($hub_id);
|
||||
|
||||
if (empty($hub))
|
||||
$error_array['hub'] = 'Invalid hub selected.';
|
||||
else
|
||||
$row->setHub($hub);
|
||||
} else {
|
||||
$row->clearHub();
|
||||
}
|
||||
|
||||
// validate
|
||||
$errors = $validator->validate($row);
|
||||
|
||||
// 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('rider.delete', null, 'No access.');
|
||||
|
||||
$params = $this->initParameters('rider_list');
|
||||
|
||||
// get row data
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$row = $em->getRepository(Rider::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();
|
||||
}
|
||||
|
||||
public function uploadImage(Request $req, FileUploader $uploader)
|
||||
{
|
||||
// retrieve temporary info for file
|
||||
$file = $req->files->get('image_file');
|
||||
|
||||
// upload the file
|
||||
$filename = $uploader->upload($file);
|
||||
|
||||
// return response
|
||||
return $this->json([
|
||||
'success' => true,
|
||||
'filename' => $filename
|
||||
]);
|
||||
}
|
||||
|
||||
// check if datatable filter is present and append to query
|
||||
protected function setQueryFilters($datatable, &$query) {
|
||||
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
|
||||
$query->where('hub.name LIKE :filter')
|
||||
->orWhere('q.first_name LIKE :filter')
|
||||
->orWhere('q.last_name LIKE :filter')
|
||||
->orWhere('q.contact_num LIKE :filter')
|
||||
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -216,7 +216,6 @@ class RoleController extends BaseController
|
|||
throw $this->createNotFoundException('The item does not exist');
|
||||
|
||||
$params['obj'] = $row;
|
||||
$params['values'] = [];
|
||||
|
||||
// response
|
||||
return $this->render('role/form.html.twig', $params);
|
||||
|
|
|
|||
|
|
@ -242,7 +242,6 @@ class UserController extends BaseController
|
|||
$params['roles'] = $em->getRepository(Role::class)->findAll();
|
||||
|
||||
$params['obj'] = $row;
|
||||
$params['values'] = [];
|
||||
|
||||
// response
|
||||
return $this->render('user/form.html.twig', $params);
|
||||
|
|
|
|||
|
|
@ -296,7 +296,7 @@ class VehicleController extends BaseController
|
|||
protected function generateYearOptions()
|
||||
{
|
||||
$start_year = 1950;
|
||||
return range($start_year, date("Y"));
|
||||
return range($start_year, date("Y") + 1);
|
||||
}
|
||||
|
||||
// check if datatable filter is present and append to query
|
||||
|
|
|
|||
|
|
@ -68,11 +68,6 @@ class BatteryManufacturer
|
|||
|
||||
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->getProductCode();
|
||||
|
||||
return $str_batteries;
|
||||
return $this->batteries;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class Customer
|
|||
|
||||
// mobile numbers linked to this customer
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="MobileNumber", mappedBy="customer")
|
||||
* @ORM\OneToMany(targetEntity="MobileNumber", mappedBy="customer", cascade={"persist"})
|
||||
*/
|
||||
protected $numbers;
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ class Customer
|
|||
|
||||
// vehicles linked to customer
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="CustomerVehicle", mappedBy="customer")
|
||||
* @ORM\OneToMany(targetEntity="CustomerVehicle", mappedBy="customer", cascade={"persist"})
|
||||
*/
|
||||
protected $vehicles;
|
||||
|
||||
|
|
@ -133,7 +133,7 @@ class Customer
|
|||
return $this->sessions;
|
||||
}
|
||||
|
||||
public function addVehicle(Vehicle $vehicle)
|
||||
public function addVehicle(CustomerVehicle $vehicle)
|
||||
{
|
||||
$this->vehicles->add($vehicle);
|
||||
return $this;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ class CustomerVehicle
|
|||
// user-defined name for vehicle
|
||||
/**
|
||||
* @ORM\Column(type="string", length=80)
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
|
|
@ -81,7 +82,6 @@ class CustomerVehicle
|
|||
// TODO: figure out how to check expiration
|
||||
/**
|
||||
* @ORM\Column(type="string", length=20, nullable=true)
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
protected $warranty_code;
|
||||
|
||||
|
|
@ -121,6 +121,17 @@ class CustomerVehicle
|
|||
return $this->id;
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setCustomer(Customer $customer)
|
||||
{
|
||||
$this->customer = $customer;
|
||||
|
|
@ -220,7 +231,7 @@ class CustomerVehicle
|
|||
return $this->warranty_expiration;
|
||||
}
|
||||
|
||||
public function setCurrentBattery($curr_battery)
|
||||
public function setCurrentBattery(Battery $curr_battery)
|
||||
{
|
||||
$this->curr_battery = $curr_battery;
|
||||
return $this;
|
||||
|
|
@ -242,14 +253,14 @@ class CustomerVehicle
|
|||
return $this->flag_motolite_battery;
|
||||
}
|
||||
|
||||
public function setActive($active = true)
|
||||
public function setActive($flag_active = true)
|
||||
{
|
||||
$this->active = $active;
|
||||
$this->flag_active = $flag_active;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isActive()
|
||||
{
|
||||
return $this->active;
|
||||
return $this->flag_active;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,4 +117,15 @@ class MobileNumber
|
|||
{
|
||||
return $this->date_confirmed;
|
||||
}
|
||||
|
||||
public function setConfirmed($flag_confirmed = true)
|
||||
{
|
||||
$this->flag_confirmed = $flag_confirmed;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isConfirmed()
|
||||
{
|
||||
return $this->flag_confirmed;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,6 +50,11 @@ class Rider
|
|||
*/
|
||||
protected $job_orders;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", nullable=true)
|
||||
*/
|
||||
protected $image_file;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->job_orders = new ArrayCollection();
|
||||
|
|
@ -103,4 +108,21 @@ class Rider
|
|||
{
|
||||
return $this->hub;
|
||||
}
|
||||
|
||||
public function clearHub()
|
||||
{
|
||||
$this->hub = null;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setImageFile($image_file)
|
||||
{
|
||||
$this->image_file = $image_file;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getImageFile()
|
||||
{
|
||||
return $this->image_file;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
29
src/Service/FileUploader.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
|
||||
class FileUploader
|
||||
{
|
||||
private $target_dir;
|
||||
|
||||
public function __construct($target_dir)
|
||||
{
|
||||
$this->target_dir = $target_dir;
|
||||
}
|
||||
|
||||
public function upload(UploadedFile $file)
|
||||
{
|
||||
$filename = md5(uniqid()) . '.' . $file->guessExtension();
|
||||
|
||||
$file->move($this->getTargetDir(), $filename);
|
||||
|
||||
return $filename;
|
||||
}
|
||||
|
||||
public function getTargetDir()
|
||||
{
|
||||
return $this->target_dir;
|
||||
}
|
||||
}
|
||||
|
|
@ -195,7 +195,7 @@
|
|||
Add Vehicle:
|
||||
</label>
|
||||
<div class="col-lg-3">
|
||||
<select name="vehicle_list" class="form-control m-input" id="vmfg">
|
||||
<select name="vmfg_list" class="form-control m-input" id="vmfg">
|
||||
<option value="">Select a manufacturer</option>
|
||||
{% for manufacturer in vmfgs %}
|
||||
<option value="{{ manufacturer.getID() }}">{{ manufacturer.getName() }}</option>
|
||||
|
|
@ -328,12 +328,12 @@
|
|||
// update vehicle list when changing manufacturer
|
||||
$("#vmfg").change(function() {
|
||||
var id = $(this).val();
|
||||
var vehiclefield = $("#vehicle");
|
||||
var field = $("#vehicle");
|
||||
var btn = $("#btn-add-vehicle");
|
||||
|
||||
// no id specified
|
||||
if (!id) {
|
||||
vehiclefield.html('<option value="">Select a manufacturer first</option>').prop('disabled', true);
|
||||
field.html('<option value="">Select a manufacturer first</option>').prop('disabled', true);
|
||||
btn.prop('disabled', true);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -346,18 +346,18 @@
|
|||
url: "{{ url('vmfg_vehicles') }}",
|
||||
data: {id: id}
|
||||
}).done(function(response) {
|
||||
if (response.data) {
|
||||
if (response.data.length > 0) {
|
||||
var html = '';
|
||||
|
||||
$.each(response.data, function(index, vehicle) {
|
||||
html += '<option value="' + vehicle.id + '" data-index="' + index + '">' + vehicle.make + ' ' + vehicle.model_year_from + '-' + vehicle.model_year_to + '</option>';
|
||||
html += '<option value="' + vehicle.id + '" data-index="' + index + '">' + vehicle.make + ' (' + vehicle.model_year_from + '-' + vehicle.model_year_to + ')</option>';
|
||||
});
|
||||
|
||||
vehiclefield.html(html).prop('disabled', false);
|
||||
field.html(html).prop('disabled', false);
|
||||
btn.prop('disabled', false);
|
||||
mfgVehicles = response.data;
|
||||
} else {
|
||||
vehiclefield.html('<option value="">No vehicles found</option>').prop('disabled', true);
|
||||
field.html('<option value="">No vehicles found</option>').prop('disabled', true);
|
||||
btn.prop('disabled', true);
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
</div>
|
||||
<form id="row-form" class="m-form m-form--label-align-right" method="post" action="{{ mode == 'update' ? url('customer_update_submit', {'id': obj.getId()}) : url('customer_create_submit') }}">
|
||||
<div class="m-portlet__body">
|
||||
<ul class="nav nav-tabs" role="tablist">
|
||||
<ul id="customer-tabs" class="nav nav-tabs" role="tablist">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" data-toggle="tab" href="#customer-info">Customer Info</a>
|
||||
</li>
|
||||
|
|
@ -52,14 +52,14 @@
|
|||
First Name:
|
||||
</label>
|
||||
<div class="col-lg-3">
|
||||
<input type="text" name="first_name" class="form-control m-input" value="{{ obj.getFirstName() }}">
|
||||
<input type="text" name="first_name" class="form-control m-input" value="{{ obj.getFirstName() }}" data-name="first_name">
|
||||
<div class="form-control-feedback hide" data-field="first_name"></div>
|
||||
</div>
|
||||
<label class="col-lg-2 col-form-label" data-field="last_name">
|
||||
Last Name:
|
||||
</label>
|
||||
<div class="col-lg-3">
|
||||
<input type="text" name="last_name" class="form-control m-input" value="{{ obj.getLastName() }}">
|
||||
<input type="text" name="last_name" class="form-control m-input" value="{{ obj.getLastName() }}" data-name="last_name">
|
||||
<div class="form-control-feedback hide" data-field="last_name"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -77,7 +77,7 @@
|
|||
<span class="m-form__help">Use the format <span class="text-info">63xxxxxxxxxx</span></span>
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<div class="input-group date">
|
||||
<div class="input-group date dtp">
|
||||
<input type="text" id="date-confirmed" class="form-control m-input" readonly placeholder="Date confirmed">
|
||||
<span class="input-group-addon">
|
||||
<i class="la la-calendar glyphicon-th"></i>
|
||||
|
|
@ -95,7 +95,10 @@
|
|||
<div class="m_datatable" id="data-vehicles"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row form-group-inner">
|
||||
<div class="form-group m-form__group row form-group-inner row">
|
||||
<div class="col-lg-12">
|
||||
<button type="button" class="btn btn-primary" id="add-vehicle">Add Vehicle</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -115,6 +118,172 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal fade" id="vehicle-form-modal" tabindex="-1" role="dialog" aria-labelledby="vehicle-form-title" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg" role="document">
|
||||
<div class="modal-content">
|
||||
<form class="m-form" id="vehicle-form" data-mode="create">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="vehicle-form-title">
|
||||
Add Vehicle
|
||||
</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">
|
||||
×
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="m-form__section m-form__section--first">
|
||||
<div class="m-form__heading">
|
||||
<h3 class="m-form__heading-title">
|
||||
Vehicle Info
|
||||
</h3>
|
||||
</div>
|
||||
<div class="form-group m-form__group row">
|
||||
<div class="col-lg-3">
|
||||
<label for="vehicle-name" data-field="name">Vehicle Name</label>
|
||||
<input type="text" name="name" id="vehicle-name" class="form-control m-input" data-required="1">
|
||||
<div class="form-control-feedback hide" data-field="name"></div>
|
||||
<span class="m-form__help">Display name for this vehicle</span>
|
||||
</div>
|
||||
<div class="col-lg-3">
|
||||
<label for="vmfg" data-field="vmfg">Manufacturer</label>
|
||||
<select name="vmfg" class="form-control m-input" id="vmfg" data-required="0">
|
||||
<option value="">Select a manufacturer</option>
|
||||
{% for manufacturer in vmfgs %}
|
||||
<option value="{{ manufacturer.getID() }}">{{ manufacturer.getName() }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<div class="form-control-feedback hide" data-field="vmfg"></div>
|
||||
</div>
|
||||
<div class="col-lg-3">
|
||||
<label for="vehicle" data-field="vehicle">Vehicle</label>
|
||||
<select name="vehicle" class="form-control m-input" id="vehicle" data-value="" data-required="1" disabled>
|
||||
<option value="">Select a manufacturer first</option>
|
||||
</select>
|
||||
<div class="form-control-feedback hide" data-field="vehicle"></div>
|
||||
</div>
|
||||
<div class="col-lg-3">
|
||||
<label for="vehicle-year" data-field="model_year">Year</label>
|
||||
<select class="form-control m-input" id="vehicle-year" name="model_year" data-required="1">
|
||||
<option value=""></option>
|
||||
{% for year in years %}
|
||||
<option value="{{ year }}">{{ year }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<div class="form-control-feedback hide" data-field="model_year"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row">
|
||||
<div class="col-lg-3">
|
||||
<label for="vehicle-plate-number" data-field="plate_number">Plate Number</label>
|
||||
<input type="text" name="plate_number" id="vehicle-plate-number" class="form-control m-input" data-required="1">
|
||||
<div class="form-control-feedback hide" data-field="plate_number"></div>
|
||||
</div>
|
||||
<div class="col-lg-3">
|
||||
<label for="vehicle-color" data-field="color">Color</label>
|
||||
<input type="text" name="color" id="vehicle-color" class="form-control m-input" data-required="1">
|
||||
<div class="form-control-feedback hide" data-field="color"></div>
|
||||
</div>
|
||||
<div class="col-lg-3">
|
||||
<label for="vehicle-status" data-field="status_condition">Status</label>
|
||||
<select name="status_condition" class="form-control m-input" id="vehicle-status" data-required="1">
|
||||
<option value=""></option>
|
||||
<option value="Brand New">Brand New</option>
|
||||
<option value="Second-Hand">Second-Hand</option>
|
||||
</select>
|
||||
<div class="form-control-feedback hide" data-field="status_condition"></div>
|
||||
</div>
|
||||
<div class="col-lg-3">
|
||||
<label for="vehicle-fuel-type" data-field="fuel_type">Fuel Type</label>
|
||||
<select name="fuel_type" class="form-control m-input" id="vehicle-fuel-type" data-required="1">
|
||||
<option value=""></option>
|
||||
<option value="Gas">Gas</option>
|
||||
<option value="Diesel">Diesel</option>
|
||||
</select>
|
||||
<div class="form-control-feedback hide" data-field="fuel_type"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row">
|
||||
<div class="col-lg-12">
|
||||
<span class="m-switch m-switch--icon block-switch">
|
||||
<label>
|
||||
<input type="checkbox" name="flag_active" id="flag-active" value="1" checked>
|
||||
<label class="switch-label">This vehicle is currently active</label>
|
||||
<span></span>
|
||||
</label>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-form__seperator m-form__seperator--dashed"></div>
|
||||
<div class="m-form__section m-form__section--last">
|
||||
<div class="m-form__heading">
|
||||
<h3 class="m-form__heading-title">
|
||||
Battery Info
|
||||
</h3>
|
||||
</div>
|
||||
<div class="form-group m-form__group row">
|
||||
<div class="col-lg-12">
|
||||
<span class="m-switch m-switch--icon block-switch">
|
||||
<label>
|
||||
<input type="checkbox" name="flag_motolite_battery" id="flag-motolite-battery" value="1">
|
||||
<label class="switch-label">This vehicle is using a Motolite battery</label>
|
||||
<span></span>
|
||||
</label>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row curr_battery_row hide">
|
||||
<div class="col-lg-3">
|
||||
<label for="bmfg" data-field="bmfg">Manufacturer</label>
|
||||
<select name="bmfg" class="form-control m-input" id="bmfg" data-required="0">
|
||||
<option value="">Select a manufacturer</option>
|
||||
{% for manufacturer in bmfgs %}
|
||||
<option value="{{ manufacturer.getID() }}">{{ manufacturer.getName() }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<div class="form-control-feedback hide" data-field="bmfg"></div>
|
||||
</div>
|
||||
<div class="col-lg-3">
|
||||
<label for="battery" data-field="battery">Product</label>
|
||||
<select name="battery" class="form-control m-input" id="battery" data-value="" disabled data-required="0">
|
||||
<option value="">Select a manufacturer first</option>
|
||||
</select>
|
||||
<div class="form-control-feedback hide" data-field="battery"></div>
|
||||
</div>
|
||||
<div class="col-lg-3">
|
||||
<label for="battery-warranty-code" data-field="warranty_code">Warranty Code</label>
|
||||
<input type="text" name="warranty_code" id="battery-warranty-code" class="form-control m-input" data-required="0">
|
||||
<div class="form-control-feedback hide" data-field="warranty_code"></div>
|
||||
</div>
|
||||
<div class="col-lg-3">
|
||||
<label for="battery-warranty-expiration" data-field="warranty_expiration">Warranty Expiration</label>
|
||||
<div class="input-group date dp">
|
||||
<input type="text" name="warranty_expiration" id="battery-warranty-expiration" class="form-control m-input" readonly placeholder="Select a date" data-required="0">
|
||||
<span class="input-group-addon">
|
||||
<i class="la la-calendar glyphicon-th"></i>
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-control-feedback hide" data-field="warranty_expiration"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<input type="hidden" name="id" id="cv-id" value="" data-required="0">
|
||||
<input type="hidden" name="index" id="row-index" value="" data-required="0">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">
|
||||
Close
|
||||
</button>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
Save changes
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
|
|
@ -122,13 +291,26 @@
|
|||
$(function() {
|
||||
$("#row-form").submit(function(e) {
|
||||
var form = $(this);
|
||||
var formdata = form.serializeArray();
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
// add mobile number data
|
||||
formdata.push({
|
||||
name: 'mobile_numbers',
|
||||
value: JSON.stringify(numberRows)
|
||||
});
|
||||
|
||||
// add vehicle data
|
||||
formdata.push({
|
||||
name: 'vehicles',
|
||||
value: JSON.stringify(vehicleRows)
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: form.prop('action'),
|
||||
data: form.serialize()
|
||||
data: formdata
|
||||
}).done(function(response) {
|
||||
// remove all error classes
|
||||
removeErrors();
|
||||
|
|
@ -141,7 +323,10 @@
|
|||
}
|
||||
});
|
||||
}).fail(function(response) {
|
||||
var errors = response.responseJSON.errors;
|
||||
var json = response.responseJSON;
|
||||
var errors = json.errors;
|
||||
var nerrors = json.nerrors;
|
||||
var verrors = json.verrors;
|
||||
var firstfield = false;
|
||||
|
||||
// remove all error classes first
|
||||
|
|
@ -149,7 +334,7 @@
|
|||
|
||||
// display errors contextually
|
||||
$.each(errors, function(field, msg) {
|
||||
var formfield = $("[name='" + field + "']");
|
||||
var formfield = $("[data-name='" + field + "']");
|
||||
var label = $("label[data-field='" + field + "']");
|
||||
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||
|
||||
|
|
@ -164,8 +349,66 @@
|
|||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||
firstfield = domfield;
|
||||
}
|
||||
|
||||
// add error class to this tab
|
||||
var tabId = $(formfield).closest('.tab-pane').prop('id');
|
||||
$("#customer-tabs").find("a[href='#" + tabId + "']").addClass('has-danger');
|
||||
});
|
||||
|
||||
// loop through mobile number errors
|
||||
$.each(nerrors, function(rowindex, errorlist) {
|
||||
var row = $("#data-mobile-numbers table").find("[name='index'][value='" + rowindex + "']").closest('tr');
|
||||
|
||||
$.each(errorlist, function(field, msg) {
|
||||
var msgbox = row.find(".form-control-feedback[data-field='" + field + "']");
|
||||
var col = msgbox.closest('span');
|
||||
|
||||
// add error classes to bad fields
|
||||
col.addClass('has-danger');
|
||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||
|
||||
// check if this field comes first in DOM
|
||||
var domfield = col.get(0);
|
||||
|
||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||
firstfield = domfield;
|
||||
}
|
||||
|
||||
// add error class to this tab
|
||||
var tabId = $(col).closest('.tab-pane').prop('id');
|
||||
$("#customer-tabs").find("a[href='#" + tabId + "']").addClass('has-danger');
|
||||
});
|
||||
});
|
||||
|
||||
// loop through vehicle errors
|
||||
$.each(verrors, function(rowindex, errorlist) {
|
||||
var row = $("#data-vehicles table").find("[name='index'][value='" + rowindex + "']").closest('tr');
|
||||
|
||||
$.each(errorlist, function(field, msg) {
|
||||
var msgbox = row.find(".form-control-feedback[data-field='" + field + "']");
|
||||
var col = msgbox.closest('span');
|
||||
|
||||
// add error classes to bad fields
|
||||
col.addClass('has-danger');
|
||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||
|
||||
// check if this field comes first in DOM
|
||||
var domfield = col.get(0);
|
||||
|
||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||
firstfield = domfield;
|
||||
}
|
||||
|
||||
// add error class to this tab
|
||||
var tabId = $(col).closest('.tab-pane').prop('id');
|
||||
$("#customer-tabs").find("a[href='#" + tabId + "']").addClass('has-danger');
|
||||
});
|
||||
});
|
||||
|
||||
// focus on tab containing first field
|
||||
var firstTabId = $(firstfield).closest('.tab-pane').prop('id');
|
||||
$("#customer-tabs").find("a[href='#" + firstTabId + "']").tab('show');
|
||||
|
||||
// focus on first bad field
|
||||
firstfield.focus();
|
||||
|
||||
|
|
@ -179,19 +422,30 @@
|
|||
// remove all error classes
|
||||
function removeErrors() {
|
||||
$(".form-control-danger").removeClass('form-control-danger');
|
||||
$("[data-field]").removeClass('has-danger');
|
||||
$(".has-danger").removeClass('has-danger');
|
||||
$(".form-control-feedback[data-field]").addClass('hide');
|
||||
}
|
||||
|
||||
// datetimepicker
|
||||
$(".date").datetimepicker({
|
||||
$(".dtp").datetimepicker({
|
||||
format: "dd M yyyy - HH:ii P",
|
||||
showMeridian: true,
|
||||
todayHighlight: true,
|
||||
autoclose: true,
|
||||
pickerPosition: 'top-left',
|
||||
bootcssVer: 3,
|
||||
todayBtn: true
|
||||
todayBtn: true,
|
||||
clearBtn: true
|
||||
});
|
||||
|
||||
// datepicker
|
||||
$(".dp").datepicker({
|
||||
format: "dd M yyyy",
|
||||
todayHighlight: true,
|
||||
autoclose: true,
|
||||
pickerPosition: 'top-left',
|
||||
bootcssVer: 3,
|
||||
clearBtn: true
|
||||
});
|
||||
|
||||
// input mask
|
||||
|
|
@ -200,18 +454,22 @@
|
|||
placeholder: ""
|
||||
});
|
||||
|
||||
$("#vehicle-year").inputmask("mask", {
|
||||
mask: "9999",
|
||||
placeholder: ""
|
||||
});
|
||||
|
||||
// initialize arrays
|
||||
var numberRows = [];
|
||||
var numberIds = [];
|
||||
var mfgVehicles = [];
|
||||
var vehicleRows = [];
|
||||
var vehicleIds = [];
|
||||
|
||||
{% for number in obj.getMobileNumbers() %}
|
||||
nrow = {
|
||||
id: "{{ number.getID() }}",
|
||||
date_registered: "{{ number.getDateRegistered() }}",
|
||||
date_confirmed: "{{ number.getDateConfirmed() }}"
|
||||
date_registered: "{{ number.getDateRegistered()|date('d M Y - h:i A') }}",
|
||||
date_confirmed: "{{ number.getDateConfirmed()|date('d M Y - h:i A') }}"
|
||||
};
|
||||
|
||||
numberRows.push(nrow);
|
||||
|
|
@ -224,44 +482,28 @@
|
|||
|
||||
vrow = {
|
||||
id: "{{ cv.getID() }}",
|
||||
mfg_name: "{{ vehicle.getManufacturer().getName() }}",
|
||||
make: "{{ vehicle.getMake() }}",
|
||||
model_year: "{{ cv.getModelYear() }}",
|
||||
name: "{{ cv.getName() }}",
|
||||
index: moment().unix(),
|
||||
battery: "{{ battery ? battery.getID() }}",
|
||||
battery_label: "{{ battery ? battery.getModel().getName() ~ ' ' ~ battery.getSize().getName() ~ ' (' ~ battery.getProductCode() ~ ')' }}",
|
||||
bmfg: "{{ battery ? battery.getManufacturer().getID() }}",
|
||||
color: "{{ cv.getColor() }}",
|
||||
status_condition: "{{ cv.getStatusCondition() }}",
|
||||
flag_active: {{ cv.isActive() ? 'true' : 'false' }},
|
||||
flag_motolite_battery: {{ cv.hasMotoliteBattery() ? 'true' : 'false' }},
|
||||
fuel_type: "{{ cv.getFuelType() }}",
|
||||
model_year: "{{ cv.getModelYear() }}",
|
||||
plate_number: "{{ cv.getPlateNumber() }}",
|
||||
status_condition: "{{ cv.getStatusCondition() }}",
|
||||
vehicle: "{{ vehicle ? vehicle.getID() }}",
|
||||
vehicle_label: "{{ vehicle ? vehicle.getManufacturer().getName() ~ ' ' ~ vehicle.getMake() ~ ' (' ~ vehicle.getModelYearFrom() ~ ' ' ~ vehicle.getModelYearTo() ~ ')' }}",
|
||||
vmfg: "{{ vehicle ? vehicle.getManufacturer().getID() }}",
|
||||
warranty_code: "{{ cv.getWarrantyCode() }}",
|
||||
warranty_expiration: "{{ cv.getWarrantyExpiration() ? cv.getWarrantyExpiration()|date('d M Y') }}",
|
||||
curr_battery_id: "{{ battery.getID() }}",
|
||||
curr_battery_prod_code: "{{ battery.getProductCode() }}",
|
||||
curr_battery_manufacturer: "{{ battery.getManufacturer().getName() }}",
|
||||
flag_motolite_battery: {{ cv.hasMotoliteBattery() }},
|
||||
flag_active: {{ cv.isActive() }}
|
||||
warranty_expiration: "{{ cv.getWarrantyExpiration() ? cv.getWarrantyExpiration()|date('d M Y') }}"
|
||||
};
|
||||
|
||||
vehicleRows.push(vrow);
|
||||
vehicleIds.push("{{ cv.getID() }}");
|
||||
{% endfor %}
|
||||
|
||||
vrow = {
|
||||
id: "123",
|
||||
mfg_name: "Mitsubishi",
|
||||
make: "Lancer",
|
||||
model_year: "1996",
|
||||
color: "Red",
|
||||
status_condition: "New",
|
||||
fuel_type: "Gas",
|
||||
warranty_code: "12345",
|
||||
warranty_expiration: "15 Jan 2018",
|
||||
curr_battery_id: "11",
|
||||
curr_battery_prod_code: "TESTBATT",
|
||||
curr_battery_manufacturer: "Motolite",
|
||||
flag_motolite_battery: 1,
|
||||
flag_active: 1
|
||||
};
|
||||
|
||||
vehicleRows.push(vrow);
|
||||
|
||||
// add a mobile number to the table
|
||||
$("#btn-add-mobile-number").click(function() {
|
||||
var id = $("#mobile-number").val();
|
||||
|
|
@ -311,65 +553,295 @@
|
|||
numberTable.reload();
|
||||
});
|
||||
|
||||
// add a vehicle to the table
|
||||
$("#btn-add-vehicle").click(function() {
|
||||
var id = $("#vehicle").val();
|
||||
var index = $("#vehicle").find(":selected").data('index');
|
||||
// remove mobile number from table
|
||||
$(document).on('click', '.btn-delete-number', function(e) {
|
||||
var btn = $(this);
|
||||
var id = $(this).data('id');
|
||||
var table = $(this).closest('table');
|
||||
|
||||
if (vehicleIds.indexOf(id) !== -1) {
|
||||
swal({
|
||||
title: 'Whoops',
|
||||
text: 'This vehicle is already on the list.',
|
||||
type: 'warning'
|
||||
});
|
||||
// remove from ids
|
||||
numberIds.splice(numberIds.indexOf(id), 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
$.each(numberRows, function(index, row) {
|
||||
if (row.id == id) {
|
||||
numberRows.splice(index, 1);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// reload table
|
||||
numberTable.row(btn.parents('tr')).remove();
|
||||
numberTable.originalDataSet = numberRows;
|
||||
numberTable.reload();
|
||||
});
|
||||
|
||||
// add vehicle to arrays
|
||||
vehicleIds.push(id);
|
||||
vehicleRows.push(mfgVehicles[index]);
|
||||
// remove vehicle from table
|
||||
$(document).on('click', '.btn-delete-vehicle', function(e) {
|
||||
var btn = $(this);
|
||||
var id = $(this).data('index');
|
||||
var table = $(this).closest('table');
|
||||
|
||||
// refresh the data table
|
||||
$.each(vehicleRows, function(index, row) {
|
||||
if (row.index == id) {
|
||||
vehicleRows.splice(index, 1);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// reload table
|
||||
vehicleTable.row(btn.parents('tr')).remove();
|
||||
vehicleTable.originalDataSet = vehicleRows;
|
||||
vehicleTable.reload();
|
||||
});
|
||||
|
||||
// remove mobile number from table
|
||||
$(document).on('click', '.btn-delete', function(e) {
|
||||
var btn = $(this);
|
||||
var id = $(this).data('id');
|
||||
var table = $(this).closest('table');
|
||||
var rowArray;
|
||||
var rowIds;
|
||||
var dt;
|
||||
// display create vehicle form
|
||||
$("#add-vehicle").click(function() {
|
||||
$("#vehicle-form").data('mode', 'create');
|
||||
$("#vehicle-form-title").html("Add Vehicle");
|
||||
$("#vehicle-form-modal").modal('show');
|
||||
});
|
||||
|
||||
if (table.parent().prop('id') == 'data-mobile-numbers') {
|
||||
rowArray = numberRows;
|
||||
rowIds = numberIds;
|
||||
dt = numberTable;
|
||||
} else {
|
||||
rowArray = vehicleRows;
|
||||
rowIds = vehicleIds;
|
||||
dt = vehicleTable;
|
||||
}
|
||||
// find vehicle row by index
|
||||
function findVehicleRow(index) {
|
||||
for (var i = 0, len = vehicleRows.length; i < len; i++) {
|
||||
if (vehicleRows[i].index === index) {
|
||||
return {
|
||||
row: vehicleRows[i],
|
||||
index: i
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
$.each(rowArray, function(index, row) {
|
||||
if (row.id == id) {
|
||||
rowArray.splice(index, 1);
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
// display edit vehicle form
|
||||
$(document).on("click", ".btn-edit-vehicle", function() {
|
||||
var form = $("#vehicle-form");
|
||||
var tr = $(this).closest('tr');
|
||||
var index = parseInt(tr.find("[name='index']").val());
|
||||
var rowData = findVehicleRow(index);
|
||||
|
||||
if (!rowData) {
|
||||
return;
|
||||
}
|
||||
|
||||
row = rowData.row;
|
||||
|
||||
// set form mode
|
||||
form.data('mode', 'update');
|
||||
$("#vehicle-form-title").html("Edit Vehicle");
|
||||
|
||||
// set index
|
||||
$("#row-index").val(row.index);
|
||||
|
||||
// set text/select field values manually
|
||||
form.find("input[type='text'], select").each(function() {
|
||||
var rowval = row[$(this).prop('name')];
|
||||
|
||||
if (typeof rowval !== 'undefined') {
|
||||
$(this).val(rowval);
|
||||
}
|
||||
});
|
||||
|
||||
// remove from ids
|
||||
rowIds.splice(rowIds.indexOf(id), 1);
|
||||
|
||||
// reload table
|
||||
dt.row(btn.parents('tr')).remove();
|
||||
dt.originalDataSet = rowArray;
|
||||
dt.reload();
|
||||
// set entity ids
|
||||
$("#vehicle").data('id', row.vehicle);
|
||||
$("#battery").data('id', row.battery);
|
||||
$("#cv-id").val(row.id);
|
||||
|
||||
// set select box values
|
||||
$("#vmfg").val(row.vmfg).change();
|
||||
|
||||
if (row.battery) {
|
||||
$("#flag-motolite-battery").prop('checked', true).change();
|
||||
$("#bmfg").val(row.bmfg).change();
|
||||
}
|
||||
|
||||
$("#flag-active").prop('checked', row.flag_active);
|
||||
|
||||
// show modal
|
||||
$("#vehicle-form-modal").modal('show');
|
||||
});
|
||||
|
||||
// update vehicle list when changing manufacturer
|
||||
$("#vmfg").change(function() {
|
||||
var id = $(this).val();
|
||||
var field = $("#vehicle");
|
||||
|
||||
// no id specified
|
||||
if (!id) {
|
||||
field.html('<option value="">Select a manufacturer first</option>').prop('disabled', true);
|
||||
return true;
|
||||
}
|
||||
|
||||
// get vehicles for this manufacturer
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "{{ url('vmfg_vehicles') }}",
|
||||
data: {id: id}
|
||||
}).done(function(response) {
|
||||
if (response.data.length > 0) {
|
||||
var html = '';
|
||||
|
||||
$.each(response.data, function(index, vehicle) {
|
||||
html += '<option value="' + vehicle.id + '" data-index="' + index + '">' + vehicle.make + ' (' + vehicle.model_year_from + '-' + vehicle.model_year_to + ')</option>';
|
||||
});
|
||||
|
||||
field.html(html).prop('disabled', false);
|
||||
} else {
|
||||
field.html('<option value="">No vehicles found</option>').prop('disabled', true);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
// update battery list when changing manufacturer
|
||||
$("#bmfg").change(function() {
|
||||
var id = $(this).val();
|
||||
var field = $("#battery");
|
||||
|
||||
// no id specified
|
||||
if (!id) {
|
||||
field.html('<option value="">Select a manufacturer first</option>').prop('disabled', true);
|
||||
return true;
|
||||
}
|
||||
|
||||
// get vehicles for this manufacturer
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "{{ url('bmfg_batteries') }}",
|
||||
data: {id: id}
|
||||
}).done(function(response) {
|
||||
if (response.data.length > 0) {
|
||||
var html = '';
|
||||
|
||||
$.each(response.data, function(index, battery) {
|
||||
html += '<option value="' + battery.id + '" data-index="' + index + '">' + battery.model_name + ' ' + battery.size_name + ' (' + battery.prod_code + ')</option>';
|
||||
});
|
||||
|
||||
field.html(html).prop('disabled', false);
|
||||
} else {
|
||||
field.html('<option value="">No batteries found</option>').prop('disabled', true);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
// toggle motolite battery area
|
||||
$("#flag-motolite-battery").change(function() {
|
||||
var currBatteryRows = $(".curr_battery_row");
|
||||
|
||||
if ($(this).prop('checked') == true) {
|
||||
currBatteryRows.removeClass('hide').find("[name='battery']").data('required', 1);
|
||||
} else {
|
||||
currBatteryRows.addClass('hide').find("[name='battery']").data('required', 0);
|
||||
}
|
||||
});
|
||||
|
||||
// save vehicle form
|
||||
$("#vehicle-form").submit(function(e) {
|
||||
var form = $(this);
|
||||
var mode = form.data('mode');
|
||||
|
||||
// get all fields, including disabled ones
|
||||
var disabled = form.find(":input:disabled").prop('disabled', false);
|
||||
var fields = form.serializeArray().map(function(x){this[x.name] = x.value; return this;}.bind({}))[0];
|
||||
disabled.prop('disabled', true);
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
var errors = 0;
|
||||
var firstfield = false;
|
||||
|
||||
// remove all error classes first
|
||||
removeVehicleErrors();
|
||||
|
||||
// check for required fields
|
||||
$.each(fields, function(field, value) {
|
||||
var formfield = form.find("[name='" + field + "']");
|
||||
var label = form.find("label[data-field='" + field + "']");
|
||||
var msgbox = form.find(".form-control-feedback[data-field='" + field + "']");
|
||||
var required = formfield.data('required');
|
||||
|
||||
if (required === 1 && !value) {
|
||||
errors++;
|
||||
|
||||
// add error classes to bad fields
|
||||
formfield.addClass('form-control-danger');
|
||||
label.addClass('has-danger');
|
||||
msgbox.html("This value should not be blank.").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;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// errors were found
|
||||
if (errors > 0) {
|
||||
// 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);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// build table row
|
||||
var row = fields;
|
||||
row.vehicle_label = $("#vmfg option:selected").text() + " " + $("#vehicle option:selected").text();
|
||||
row.flag_active = row.flag_active == 1 ? true : false;
|
||||
|
||||
// add optional field
|
||||
if (typeof fields.flag_motolite_battery === 'undefined') {
|
||||
row.flag_motolite_battery = false;
|
||||
row.battery_label = "";
|
||||
} else {
|
||||
row.flag_motolite_battery = true;
|
||||
row.battery_label = $("#battery option:selected").text();
|
||||
}
|
||||
|
||||
if (mode == 'create') {
|
||||
// set an index
|
||||
row.index = moment().unix();
|
||||
|
||||
// save to table
|
||||
vehicleRows.push(row);
|
||||
} else {
|
||||
// get vehicle row by index
|
||||
row.index = parseInt(row.index);
|
||||
rowData = findVehicleRow(row.index);
|
||||
vehicleRows[rowData.index] = row;
|
||||
}
|
||||
|
||||
// refresh the data table
|
||||
vehicleTable.originalDataSet = vehicleRows;
|
||||
vehicleTable.reload();
|
||||
|
||||
// close modal
|
||||
$("#vehicle-form-modal").modal('hide');
|
||||
});
|
||||
|
||||
// reset vehicle form status on close
|
||||
$("#vehicle-form-modal").on('hidden.bs.modal', function(e) {
|
||||
$("#flag-motolite-battery").prop('checked', false).change();
|
||||
$("#flag-active").prop('checked', true);
|
||||
$("#vehicle-form").find("input[type='text'], select").val("").change();
|
||||
removeVehicleErrors();
|
||||
});
|
||||
|
||||
// remove all error classes on vehicle form
|
||||
function removeVehicleErrors() {
|
||||
var form = $("#vehicle-form");
|
||||
form.find(".form-control-danger").removeClass('form-control-danger');
|
||||
form.find("[data-field]").removeClass('has-danger');
|
||||
form.find(".form-control-feedback[data-field]").addClass('hide');
|
||||
}
|
||||
|
||||
// mobile numbers data table
|
||||
var numberOptions = {
|
||||
data: {
|
||||
|
|
@ -386,15 +858,24 @@
|
|||
columns: [
|
||||
{
|
||||
field: 'id',
|
||||
title: 'Mobile Number'
|
||||
title: 'Mobile Number',
|
||||
template: function (row, index, datatable) {
|
||||
return row.id + '<div class="form-control-feedback hide" data-field="id"></div>';
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'date_registered',
|
||||
title: 'Date Registered'
|
||||
title: 'Date Registered',
|
||||
template: function (row, index, datatable) {
|
||||
return row.date_registered + '<div class="form-control-feedback hide" data-field="date_registered"></div>';
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'date_confirmed',
|
||||
title: 'Date Confirmed'
|
||||
title: 'Date Confirmed',
|
||||
template: function (row, index, datatable) {
|
||||
return row.date_confirmed + '<div class="form-control-feedback hide" data-field="date_confirmed"></div>';
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'Actions',
|
||||
|
|
@ -403,7 +884,7 @@
|
|||
sortable: false,
|
||||
overflow: 'visible',
|
||||
template: function (row, index, datatable) {
|
||||
return '<button data-id="' + row.id + '" type="button" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill btn-delete" title="Delete"><i class="la la-trash"></i></button>';
|
||||
return '<button data-id="' + row.id + '" type="button" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill btn-delete-number" title="Delete"><i class="la la-trash"></i></button>';
|
||||
},
|
||||
}
|
||||
],
|
||||
|
|
@ -427,79 +908,91 @@
|
|||
},
|
||||
columns: [
|
||||
{
|
||||
field: 'mfg_name',
|
||||
title: 'Manufacturer'
|
||||
field: 'name',
|
||||
title: 'Name',
|
||||
template: function (row, index, datatable) {
|
||||
return row.name + '<div class="form-control-feedback hide" data-field="name"></div>';
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'make',
|
||||
title: 'Make'
|
||||
field: 'vehicle_label',
|
||||
title: 'Vehicle',
|
||||
width: 150,
|
||||
template: function (row, index, datatable) {
|
||||
return row.vehicle_label + '<div class="form-control-feedback hide" data-field="vehicle"></div>';
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'model_year',
|
||||
title: 'Year',
|
||||
template: function (row, index, datatable) {
|
||||
return '<input type="text" class="form-control" value="' + row.model_year + '" name="year_' + index + '">'
|
||||
return row.model_year + '<div class="form-control-feedback hide" data-field="model_year"></div>';
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'plate_number',
|
||||
title: 'Plate No.',
|
||||
template: function (row, index, datatable) {
|
||||
return row.plate_number + '<div class="form-control-feedback hide" data-field="plate_number"></div>';
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'color',
|
||||
title: 'Color',
|
||||
width: 70,
|
||||
template: function (row, index, datatable) {
|
||||
return '<input type="text" class="form-control" value="' + row.color + '" name="color_' + index + '">'
|
||||
return row.color + '<div class="form-control-feedback hide" data-field="color"></div>';
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'status_condition',
|
||||
title: 'Status',
|
||||
width: 50
|
||||
title: 'Cond.',
|
||||
template: function (row, index, datatable) {
|
||||
return row.status_condition + '<div class="form-control-feedback hide" data-field="status_condition"></div>';
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'fuel_type',
|
||||
title: 'Fuel Type'
|
||||
title: 'Fuel Type',
|
||||
template: function (row, index, datatable) {
|
||||
return row.fuel_type + '<div class="form-control-feedback hide" data-field="fuel_type"></div>';
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'warranty_code',
|
||||
title: 'Warranty Code',
|
||||
title: 'Wty. Code',
|
||||
template: function (row, index, datatable) {
|
||||
return '<input type="text" class="form-control" value="' + row.warranty_code + '" name="warranty_code_' + index + '">'
|
||||
return row.warranty_code + '<div class="form-control-feedback hide" data-field="warranty_code"></div>';
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'warranty_expiration',
|
||||
title: 'Warranty Expiration',
|
||||
title: 'Wty. Exp.',
|
||||
width: 80,
|
||||
template: function (row, index, datatable) {
|
||||
return row.warranty_expiration + '<div class="form-control-feedback hide" data-field="warranty_expiration"></div>';
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'battery_label',
|
||||
title: 'Battery',
|
||||
width: 150,
|
||||
template: function (row, index, datatable) {
|
||||
return '<input type="text" class="form-control" value="' + row.warranty_expiration + '" name="warranty_expiration_' + index + '">'
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'curr_battery',
|
||||
title: 'Current Battery',
|
||||
template: function (row, index, datatable) {
|
||||
return row.curr_battery_manufacturer + ' ' + row.curr_battery_prod_code;
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'flag_motolite_battery',
|
||||
title: 'Using Motolite battery?',
|
||||
template: function (row, index, datatable) {
|
||||
html = '<select class="form-control" name="flag_motolite_battery_' + index + '">';
|
||||
$.each(['False', 'True'], function(val, text) {
|
||||
html += '<option value="' + val + '"' + (val == row.flag_motolite_battery ? ' selected' : '') + '>' + text + '</option>';
|
||||
});
|
||||
html += '</select>';
|
||||
return html;
|
||||
return row.battery_label + '<div class="form-control-feedback hide" data-field="battery"></div>';
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'flag_active',
|
||||
title: 'Is the vehicle active?',
|
||||
title: 'Status',
|
||||
template: function (row, index, datatable) {
|
||||
html = '<select class="form-control" name="flag_motolite_battery_' + index + '">';
|
||||
$.each(['False', 'True'], function(val, text) {
|
||||
html += '<option value="' + val + '"' + (val == row.flag_active ? ' selected' : '') + '>' + text + '</option>';
|
||||
});
|
||||
html += '</select>';
|
||||
if (row.flag_active === true) {
|
||||
html = '<span class="m-badge m-badge--success m-badge--wide">Active</span>';
|
||||
} else {
|
||||
html = '<span class="m-badge m-badge--danger m-badge--wide">Inactive</span>';
|
||||
}
|
||||
|
||||
html += '<div class="form-control-feedback hide" data-field="flag_active"></div>';
|
||||
|
||||
return html;
|
||||
}
|
||||
},
|
||||
|
|
@ -510,7 +1003,12 @@
|
|||
sortable: false,
|
||||
overflow: 'visible',
|
||||
template: function (row, index, datatable) {
|
||||
return '<button data-id="' + row.id + '" type="button" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill btn-delete" title="Delete"><i class="la la-trash"></i></button>';
|
||||
html = '<input type="hidden" name="index" value="' + row.index + '">';
|
||||
|
||||
html += '<button type="button" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit-vehicle" title="Edit"><i class="la la-edit"></i></button>' +
|
||||
'<button data-index="' + row.index + '" type="button" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill btn-delete-vehicle" title="Delete"><i class="la la-trash"></i></button>';
|
||||
|
||||
return html;
|
||||
},
|
||||
}
|
||||
],
|
||||
|
|
|
|||
229
templates/rider/form.html.twig
Normal file
|
|
@ -0,0 +1,229 @@
|
|||
{% 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">Riders</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- END: Subheader -->
|
||||
<div class="m-content">
|
||||
<!--Begin::Section-->
|
||||
<div class="row">
|
||||
<div class="col-xl-8 offset-xl-2">
|
||||
<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-user"></i>
|
||||
</span>
|
||||
<h3 class="m-portlet__head-text">
|
||||
{% if mode == 'update' %}
|
||||
Edit Rider
|
||||
<small>{{ obj.getFirstName() ~ ' ' ~ obj.getLastName() }}</small>
|
||||
{% else %}
|
||||
New Rider
|
||||
{% 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="{{ mode == 'update' ? url('rider_update_submit', {'id': obj.getId()}) : url('rider_create_submit') }}">
|
||||
<div class="m-portlet__body">
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<label class="col-lg-2 col-form-label" data-field="first_name">
|
||||
First Name:
|
||||
</label>
|
||||
<div class="col-lg-4">
|
||||
<input type="text" name="first_name" class="form-control m-input" value="{{ obj.getFirstName() }}">
|
||||
<div class="form-control-feedback hide" data-field="first_name"></div>
|
||||
</div>
|
||||
<label class="col-lg-2 col-form-label" data-field="last_name">
|
||||
Last Name:
|
||||
</label>
|
||||
<div class="col-lg-4">
|
||||
<input type="text" name="last_name" class="form-control m-input" value="{{ obj.getLastName() }}">
|
||||
<div class="form-control-feedback hide" data-field="last_name"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row">
|
||||
<label class="col-lg-2 col-form-label" data-field="contact_no">
|
||||
Contact Number:
|
||||
</label>
|
||||
<div class="col-lg-4">
|
||||
<input type="text" name="contact_no" class="form-control m-input" value="{{ obj.getContactNumber() }}">
|
||||
<div class="form-control-feedback hide" data-field="contact_no"></div>
|
||||
</div>
|
||||
<label class="col-lg-2 col-form-label" data-field="hub">
|
||||
Hub:
|
||||
</label>
|
||||
<div class="col-lg-4">
|
||||
<select class="form-control m-input" id="hub" name="hub">
|
||||
<option value=""></option>
|
||||
{% for hub in hubs %}
|
||||
<option value="{{ hub.getID() }}"{{ obj.getHub() and hub.getID() == obj.getHub().getID() ? ' selected' }}>{{ hub.getName() }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<div class="form-control-feedback hide" data-field="hub"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row">
|
||||
<label class="col-lg-2 col-form-label" data-field="image_file">
|
||||
{% if mode == 'update' %}
|
||||
Replace Portrait:
|
||||
{% else %}
|
||||
Portrait:
|
||||
{% endif %}
|
||||
</label>
|
||||
<div class="col-lg-6">
|
||||
<div class="m-dropzone dropzone m-dropzone--primary" action="{{ url('rider_upload_image') }}" id="image-file">
|
||||
<div class="m-dropzone__msg dz-message needsclick">
|
||||
<h3 class="m-dropzone__msg-title">
|
||||
Drop files here or click to upload.
|
||||
</h3>
|
||||
<span class="m-dropzone__msg-desc">
|
||||
Upload only valid PNG, GIF, or JPEG images
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{% if mode == 'update' %}
|
||||
<span class="m-form__help">Leave blank for unchanged</span>
|
||||
{% endif %}
|
||||
<div class="form-control-feedback hide" data-field="image_file"></div>
|
||||
</div>
|
||||
{% if mode == 'update' %}
|
||||
<div class="col-lg-4">
|
||||
<div class="portrait-box" style="background-image: url('{{ obj.getImageFile() ? '/uploads/' ~ obj.getImageFile() : '/assets/images/user.gif' }}');"></div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</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">
|
||||
<input type="hidden" name="image_file" value="{{ obj.getImageFile() }}">
|
||||
<button type="submit" class="btn btn-success">Submit</button>
|
||||
<a href="{{ url('rider_list') }}" class="btn btn-secondary">Cancel</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
// image upload
|
||||
Dropzone.options.imageFile = {
|
||||
paramName: "image_file", // The name that will be used to transfer the file
|
||||
maxFiles: 1,
|
||||
uploadMultiple: false,
|
||||
maxFilesize: 5, // MB
|
||||
addRemoveLinks: true,
|
||||
acceptedFiles: "image/*",
|
||||
accept: function(file, done) {
|
||||
done();
|
||||
},
|
||||
init: function() {
|
||||
this.on("maxfilesexceeded", function(file) {
|
||||
// limit to one file, overwrite old one
|
||||
this.removeAllFiles();
|
||||
this.addFile(file);
|
||||
});
|
||||
|
||||
{% if obj.getImageFile() %}
|
||||
/*
|
||||
dz = this;
|
||||
|
||||
var mockFile = { name: "{{ obj.getImageFile() }}", size: {{ filesize }} };
|
||||
|
||||
dz.emit("addedfile", mockFile);
|
||||
dz.options.thumbnail.call(dz, mockFile, '/uploads/' + mockFile.name);
|
||||
|
||||
// Make sure that there is no progress bar, etc...
|
||||
dz.emit("complete", mockFile);
|
||||
*/
|
||||
{% endif %}
|
||||
},
|
||||
success: function(file, response) {
|
||||
if (response.success) {
|
||||
$("input[name='image_file']").val(response.filename);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$(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('rider_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 %}
|
||||
172
templates/rider/list.html.twig
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
{% 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">
|
||||
Riders
|
||||
</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('rider_create') }}" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
|
||||
<span>
|
||||
<i class="la la-user"></i>
|
||||
<span>New Rider</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("rider_rows") }}',
|
||||
method: 'POST',
|
||||
}
|
||||
},
|
||||
saveState: {
|
||||
cookie: false,
|
||||
webstorage: false
|
||||
},
|
||||
pageSize: 10,
|
||||
serverPaging: true,
|
||||
serverFiltering: true,
|
||||
serverSorting: true
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
field: 'id',
|
||||
title: 'ID',
|
||||
width: 30
|
||||
},
|
||||
{
|
||||
field: 'image_file',
|
||||
title: '',
|
||||
sortable: false,
|
||||
width: 40,
|
||||
template: function (row, index, datatable) {
|
||||
var html = '<div class="user-portrait-sm" style="background-image: url(\'' + (row.image_file ? "/uploads/" + row.image_file : "/assets/images/user.gif") + '\');"></div>';
|
||||
|
||||
return html;
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'first_name',
|
||||
title: 'First Name'
|
||||
},
|
||||
{
|
||||
field: 'last_name',
|
||||
title: 'Last Name'
|
||||
},
|
||||
{
|
||||
field: 'contact_num',
|
||||
title: 'Contact No.'
|
||||
},
|
||||
{
|
||||
field: 'hub',
|
||||
title: 'Hub'
|
||||
},
|
||||
{
|
||||
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.first_name + ' ' + row.last_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.first_name + ' ' + row.last_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 %}
|
||||