Add CRUD for the motor vehicle types for the MV lookup. #727
This commit is contained in:
parent
a9e2d95ab4
commit
f8327f5d59
10 changed files with 812 additions and 0 deletions
|
|
@ -586,3 +586,17 @@ access_keys:
|
|||
label: Update
|
||||
- id: ownership_type.delete
|
||||
label: Delete
|
||||
|
||||
- id: motor_vehicle_type
|
||||
label: Motor Vehicle Type Access
|
||||
acls:
|
||||
- id: motor_vehicle_type.menu
|
||||
label: Menu
|
||||
- id: motor_vehicle_type.list
|
||||
label: List
|
||||
- id: motor_vehicle_type.add
|
||||
label: Add
|
||||
- id: motor_vehicle_type.update
|
||||
label: Update
|
||||
- id: motor_vehicle_type.delete
|
||||
label: Delete
|
||||
|
|
|
|||
|
|
@ -249,3 +249,7 @@ main_menu:
|
|||
acl: ownership_type.menu
|
||||
label: Ownership Types
|
||||
parent: database
|
||||
- id: motor_vehicle_type_list
|
||||
acl: motor_vehicle_type.menu
|
||||
label: Motor Vehicle Types
|
||||
parent: database
|
||||
|
|
|
|||
35
config/routes/motor_vehicle_type.yaml
Normal file
35
config/routes/motor_vehicle_type.yaml
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
motor_vehicle_type_list:
|
||||
path: /motor-vehicle-types
|
||||
controller: App\Controller\MotorVehicleTypeController::index
|
||||
methods: [GET]
|
||||
|
||||
motor_vehicle_type_rows:
|
||||
path: /motor-vehicle-types/rowdata
|
||||
controller: App\Controller\MotorVehicleTypeController::datatableRows
|
||||
methods: [POST]
|
||||
|
||||
motor_vehicle_type_add_form:
|
||||
path: /motor-vehicle-types/newform
|
||||
controller: App\Controller\MotorVehicleTypeController::addForm
|
||||
methods: [GET]
|
||||
|
||||
motor_vehicle_type_add_submit:
|
||||
path: /motor-vehicle-types
|
||||
controller: App\Controller\MotorVehicleTypeController::addSubmit
|
||||
methods: [POST]
|
||||
|
||||
motor_vehicle_type_update_form:
|
||||
path: /motor-vehicle-types/{id}
|
||||
controller: App\Controller\MotorVehicleTypeController::updateForm
|
||||
methods: [GET]
|
||||
|
||||
motor_vehicle_type_update_submit:
|
||||
path: /motor-vehicle-types/{id}
|
||||
controller: App\Controller\MotorVehicleTypeController::updateSubmit
|
||||
methods: [POST]
|
||||
|
||||
motor_vehicle_type_delete:
|
||||
path: /motor-vehicle-types/{id}
|
||||
controller: App\Controller\MotorVehicleTypeController::deleteSubmit
|
||||
methods: [DELETE]
|
||||
|
||||
258
src/Controller/MotorVehicleTypeController.php
Normal file
258
src/Controller/MotorVehicleTypeController.php
Normal file
|
|
@ -0,0 +1,258 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\MotorVehicleType;
|
||||
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
|
||||
|
||||
use Catalyst\MenuBundle\Annotation\Menu;
|
||||
|
||||
class MotorVehicleTypeController extends Controller
|
||||
{
|
||||
/**
|
||||
* @Menu(selected="motor_vehicle_type_list")
|
||||
* @IsGranted("motor_vehicle_type.list")
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->denyAccessUnlessGranted('motor_vehicle_type.list', null, 'No access.');
|
||||
|
||||
return $this->render('motor-vehicle-type/list.html.twig');
|
||||
}
|
||||
|
||||
/**
|
||||
* @IsGranted("motor_vehicle_type.list")
|
||||
*/
|
||||
public function datatableRows(Request $req)
|
||||
{
|
||||
// get query builder
|
||||
$qb = $this->getDoctrine()
|
||||
->getRepository(MotorVehicleType::class)
|
||||
->createQueryBuilder('q');
|
||||
|
||||
// get datatable params
|
||||
$datatable = $req->request->get('datatable');
|
||||
|
||||
// count total records
|
||||
$tquery = $qb->select('COUNT(q)');
|
||||
$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');
|
||||
$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();
|
||||
|
||||
// process rows
|
||||
$rows = [];
|
||||
foreach ($obj_rows as $orow) {
|
||||
// add row data
|
||||
$row['id'] = $orow->getID();
|
||||
$row['mv_type_id'] = $orow->getMvTypeID();
|
||||
$row['lto_mv_type'] = $orow->getLtoMvType();
|
||||
$row['vehicle_type'] = $orow->getVehicleType();
|
||||
|
||||
// add row metadata
|
||||
$row['meta'] = [
|
||||
'update_url' => '',
|
||||
'delete_url' => ''
|
||||
];
|
||||
|
||||
// add crud urls
|
||||
if ($this->isGranted('motor_vehicle_type.update'))
|
||||
$row['meta']['update_url'] = $this->generateUrl('motor_vehicle_type_update_form', ['id' => $row['id']]);
|
||||
if ($this->isGranted('motor_vehicle_type.delete'))
|
||||
$row['meta']['delete_url'] = $this->generateUrl('motor_vehicle_type_delete', ['id' => $row['id']]);
|
||||
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
// response
|
||||
return $this->json([
|
||||
'meta' => $meta,
|
||||
'data' => $rows
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Menu(selected="motor_vehicle_type.list")
|
||||
* @IsGranted("motor_vehicle_type.add")
|
||||
*/
|
||||
public function addForm()
|
||||
{
|
||||
$motor_vehicle_type = new MotorVehicleType();
|
||||
$params = [
|
||||
'motor_vehicle_type' => $motor_vehicle_type,
|
||||
'mode' => 'create',
|
||||
];
|
||||
|
||||
// response
|
||||
return $this->render('motor-vehicle-type/form.html.twig', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @IsGranted("motor_vehicle_type.add")
|
||||
*/
|
||||
public function addSubmit(Request $req, EntityManagerInterface $em, ValidatorInterface $validator)
|
||||
{
|
||||
$motor_vehicle_type = new MotorVehicleType();
|
||||
|
||||
$this->setObject($motor_vehicle_type, $req);
|
||||
|
||||
// validate
|
||||
$errors = $validator->validate($motor_vehicle_type);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// validated! save the entity
|
||||
$em->persist($motor_vehicle_type);
|
||||
$em->flush();
|
||||
|
||||
// return successful response
|
||||
return $this->json([
|
||||
'success' => 'Changes have been saved!'
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Menu(selected="motor_vehicle_type_list")
|
||||
* @ParamConverter("motor_vehicle_type", class="App\Entity\MotorVehicleType")
|
||||
* @IsGranted("motor_vehicle_type.update")
|
||||
*/
|
||||
public function updateForm($id, EntityManagerInterface $em, MotorVehicleType $motor_vehicle_type)
|
||||
{
|
||||
$params = [];
|
||||
$params['motor_vehicle_type'] = $motor_vehicle_type;
|
||||
$params['mode'] = 'update';
|
||||
|
||||
// response
|
||||
return $this->render('motor-vehicle-type/form.html.twig', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ParamConverter("motor_vehicle_type", class="App\Entity\MotorVehicleType")
|
||||
* @IsGranted("motor_vehicle_type.update")
|
||||
*/
|
||||
public function updateSubmit(Request $req, EntityManagerInterface $em, ValidatorInterface $validator, MotorVehicleType $motor_vehicle_type)
|
||||
{
|
||||
$this->setObject($motor_vehicle_type, $req);
|
||||
|
||||
// validate
|
||||
$errors = $validator->validate($motor_vehicle_type);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// validated! save the entity
|
||||
$em->flush();
|
||||
|
||||
// return successful response
|
||||
return $this->json([
|
||||
'success' => 'Changes have been saved!'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ParamConverter("motor_vehicle_type", class="App\Entity\MotorVehicleType")
|
||||
* @IsGranted("motor_vehicle_type.update")
|
||||
*/
|
||||
public function deleteSubmit(EntityManagerInterface $em, MotorVehicleType $motor_vehicle_type)
|
||||
{
|
||||
// delete this object
|
||||
$em->remove($motor_vehicle_type);
|
||||
$em->flush();
|
||||
|
||||
// response
|
||||
$response = new Response();
|
||||
$response->setStatusCode(Response::HTTP_OK);
|
||||
$response->send();
|
||||
}
|
||||
|
||||
|
||||
protected function setObject(MotorVehicleType $obj, Request $req)
|
||||
{
|
||||
// set and save values
|
||||
$obj->setMvTypeID($req->request->get('mv_type_id'))
|
||||
->setLtoMvType($req->request->get('lto_mv_type'))
|
||||
->setVehicleType($req->request->get('vehicle_type'));
|
||||
}
|
||||
|
||||
protected function setQueryFilters($datatable, QueryBuilder $query)
|
||||
{
|
||||
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
|
||||
$query->where('q.lto_mv_type LIKE :filter')
|
||||
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
88
src/Entity/MotorVehicleType.php
Normal file
88
src/Entity/MotorVehicleType.php
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="motor_vehicle_type", indexes={
|
||||
* @ORM\Index(name="motor_vehicle_type_idx", columns={"mv_type_id"}),
|
||||
* })
|
||||
*/
|
||||
class MotorVehicleType
|
||||
{
|
||||
// unique id
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
// this is decided upon by lto
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
protected $mv_type_id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=50)
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
protected $lto_mv_type;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=50)
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
protected $vehicle_type;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->mv_type_id = 0;
|
||||
$this->lto_mv_type = '';
|
||||
$this->vehicle_type = '';
|
||||
}
|
||||
|
||||
public function getID()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setMvTypeID($mv_type_id)
|
||||
{
|
||||
$this->mv_type_id = $mv_type_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMvTypeID()
|
||||
{
|
||||
return $this->mv_type_id;
|
||||
}
|
||||
|
||||
public function setLtoMvType($lto_mv_type)
|
||||
{
|
||||
$this->lto_mv_type = $lto_mv_type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLtoMvType()
|
||||
{
|
||||
return $this->lto_mv_type;
|
||||
}
|
||||
|
||||
public function setVehicleType($vehicle_type)
|
||||
{
|
||||
$this->vehicle_type = $vehicle_type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getVehicleType()
|
||||
{
|
||||
return $this->vehicle_type;
|
||||
}
|
||||
}
|
||||
76
src/Insurance/ClientData.php
Normal file
76
src/Insurance/ClientData.php
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
namespace App\Insurance;
|
||||
|
||||
class ClientData
|
||||
{
|
||||
// client_info
|
||||
protected $client_type; // client type. Mandatory. String. Valid values are 'C' or I'. C for corporate, I for individual
|
||||
protected $first_name; // first name of client. Mandatory. String.
|
||||
protected $middle_name; // middle name of client. Optional. String.
|
||||
protected $surname; // surname of client. Mandatory. String.
|
||||
protected $corporate_name; // corporate name or whole name of client that starts with <surname>, <first name> <middle name>. Mandatory. String.
|
||||
|
||||
// client_contact_info
|
||||
protected $address_number; // client house number address. Mandatory. String.
|
||||
protected $address_street; // client street address. Optional. String.
|
||||
protected $address_building; // client build address. Optional. String.
|
||||
protected $address_barangay; // client barangay address. Mandatory. String.
|
||||
protected $address_city; // client city address. Mandatory. String.
|
||||
protected $address_province; // client province address. Mandatory. String.
|
||||
protected $zipcode; // client zip code. Mandatory. Integer.
|
||||
protected $mobile_number; // client mobile number. Mandatory. String.
|
||||
protected $email_address; // client email address. Mandatory. String.
|
||||
|
||||
// car_info
|
||||
protected $make; // vehicle make. Mandatory. String.
|
||||
protected $model; // vehicle model. Mandatory. String.
|
||||
protected $series; // vehicle seris. Mandatory. String.
|
||||
protected $color; // vehicle color. Mandatory. String.
|
||||
protected $plate_number; // vehicle plate number. Mandatory. String.
|
||||
protected $mv_file_number; // vehicle MV file number. Mandatory. String.
|
||||
protected $motor_number; // vehicle motor number. Mandatory. String.
|
||||
protected $serial_chassis; // vehicle serial or chassis number. Mandatory. String.
|
||||
protected $year_model; // year model of vehicle. Mandatory. Integer.
|
||||
protected $mv_type_id; // LTO mv type. Mandatory. Integer.
|
||||
protected $body_type; // vehicle body type. Mandatory. String.
|
||||
protected $is_public; // public vehicle or not? Mandatory. Boolean.
|
||||
protected $line; // defines where vehicle should be part of. Mandatory. String. Valid values are: PCOC - Private Car, MCOC - Mototcycle/Motorcycle with Sidecar/Tricycle(is_public is false), CCOC - Commercial Vehicle, LCOC - Motorcycle with sidecar/Tricycle(is_public is true)
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->client_type = 'I';
|
||||
$this->first_name = '';
|
||||
$this->middle_name = '';
|
||||
$this->surname = '';
|
||||
$this->corporate_name = '';
|
||||
|
||||
$this->address_number = '';
|
||||
$this->address_street = '';
|
||||
$this->address_bulding = '';
|
||||
$this->address_barangay = '';
|
||||
$this->address_city = '';
|
||||
$this->address_province = '';
|
||||
$this->zipcode = 0;
|
||||
$this->mobile_number = '';
|
||||
$this->email_address = '';
|
||||
|
||||
$this->make = '';
|
||||
$this->model = '';
|
||||
$this->series = '';
|
||||
$this->color = '';
|
||||
$this->plate_number = '';
|
||||
$this->mv_file_number = '';
|
||||
$this->motor_number = '';
|
||||
$this->serial_chassis = '';
|
||||
$this->year_model = 0;
|
||||
$this->mv_type_id = 0;
|
||||
$this->body_type = '';
|
||||
$this->is_public = false;
|
||||
$this->line = '';
|
||||
}
|
||||
|
||||
public function setClientType($client_type)
|
||||
{
|
||||
}
|
||||
}
|
||||
14
src/Insurance/ClientType.php
Normal file
14
src/Insurance/ClientType.php
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace App\Ramcar;
|
||||
|
||||
class ClientType extends NameValue
|
||||
{
|
||||
const CORPORATE = 'C';
|
||||
const INDIVIDUAL = 'I';
|
||||
|
||||
const COLLECTION = [
|
||||
'C' => 'Corporate',
|
||||
'I' => 'Individual',
|
||||
];
|
||||
}
|
||||
18
src/Insurance/LineType.php
Normal file
18
src/Insurance/LineType.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Ramcar;
|
||||
|
||||
class LineType extends NameValue
|
||||
{
|
||||
const PRIVATE_CAR = 'PCOC';
|
||||
const PRIVATE_MOTORCYCLE = 'MCOC';
|
||||
const COMMERCIAL_VEHICLE = 'CCOC';
|
||||
const PUBLIC_MOTORCYCLE = 'LCOC';
|
||||
|
||||
const COLLECTION = [
|
||||
'PCOC' => 'Private Car',
|
||||
'MCOC' => 'Private Motorcycle/Motorcycle with Sidecar/Tricycle',
|
||||
'CCOC' => 'Commercial Vehicle',
|
||||
'LCOC' => 'Public Motorcycle with Sidecar/Tricycle',
|
||||
];
|
||||
}
|
||||
151
templates/motor-vehicle-type/form.html.twig
Normal file
151
templates/motor-vehicle-type/form.html.twig
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
{% 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">Motor Vehicle Types</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- END: Subheader -->
|
||||
<div class="m-content">
|
||||
<!--Begin::Section-->
|
||||
<div class="row">
|
||||
<div class="col-xl-6">
|
||||
<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 mode == 'update' %}
|
||||
Edit Motor Vehicle Type
|
||||
<small>{{ motor_vehicle_type.getLtoMvType() }}</small>
|
||||
{% else %}
|
||||
New Motor Vehicle Type
|
||||
{% 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('motor_vehicle_type_update_submit', {'id': motor_vehicle_type.getId()}) : url('motor_vehicle_type_add_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="mv_type_id">
|
||||
Motor Vehicle Type ID:
|
||||
</label>
|
||||
<div class="col-lg-9">
|
||||
<input type="text" name="mv_type_id" class="form-control m-input" value="{{ motor_vehicle_type.getMvTypeID() }}">
|
||||
<div class="form-control-feedback hide" data-field="mv_type_id"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<label class="col-lg-3 col-form-label" data-field="lto_mv_type">
|
||||
LTO Motor Vehicle Type:
|
||||
</label>
|
||||
<div class="col-lg-9">
|
||||
<input type="text" name="lto_mv_type" class="form-control m-input" value="{{ motor_vehicle_type.getLtoMvType() }}">
|
||||
<div class="form-control-feedback hide" data-field="lto_mv_type"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<label class="col-lg-3 col-form-label" data-field="vehicle_type">
|
||||
Vehicle Type:
|
||||
</label>
|
||||
<div class="col-lg-9">
|
||||
<input type="text" name="vehicle_type" class="form-control m-input" value="{{ motor_vehicle_type.getVehicleType() }}">
|
||||
<div class="form-control-feedback hide" data-field="vehicle_type"></div>
|
||||
</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('motor_vehicle_type_list') }}" class="btn btn-secondary">Back</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('motor_vehicle_type_list') }}";
|
||||
}
|
||||
});
|
||||
}).fail(function(response) {
|
||||
if (response.status == 422) {
|
||||
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 %}
|
||||
154
templates/motor-vehicle-type/list.html.twig
Normal file
154
templates/motor-vehicle-type/list.html.twig
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
{% 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">
|
||||
Motor Vehicle Types
|
||||
</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('motor_vehicle_type_add_form') }}" 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 Motor Vehicle Type</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("motor_vehicle_type_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: 'mv_type_id',
|
||||
title: 'MV Type ID'
|
||||
},
|
||||
{
|
||||
field: 'lto_mv_type',
|
||||
title: 'LTO MV Type'
|
||||
},
|
||||
{
|
||||
field: 'vehicle_type',
|
||||
title: 'Vehicle Type'
|
||||
},
|
||||
{
|
||||
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();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
Loading…
Reference in a new issue