Add initial outlet screens and other menu and acl entries
This commit is contained in:
parent
1fefaf4b09
commit
180a2d4bf9
8 changed files with 893 additions and 7 deletions
|
|
@ -128,3 +128,50 @@ access_keys:
|
||||||
label: Update
|
label: Update
|
||||||
- id: customer.delete
|
- id: customer.delete
|
||||||
label: Delete
|
label: Delete
|
||||||
|
|
||||||
|
|
||||||
|
- id: location
|
||||||
|
label: Location Access
|
||||||
|
acls:
|
||||||
|
- id: location.menu
|
||||||
|
label: Menu
|
||||||
|
- id: outlet
|
||||||
|
label: Outlet Access
|
||||||
|
acls:
|
||||||
|
- id: outlet.menu
|
||||||
|
label: Menu
|
||||||
|
- id: outlet.list
|
||||||
|
label: List
|
||||||
|
- id: outlet.add
|
||||||
|
label: Add
|
||||||
|
- id: outlet.update
|
||||||
|
label: Update
|
||||||
|
- id: outlet.delete
|
||||||
|
label: Delete
|
||||||
|
- id: hub
|
||||||
|
label: Hub Access
|
||||||
|
acls:
|
||||||
|
- id: hub.menu
|
||||||
|
label: Menu
|
||||||
|
- id: hub.list
|
||||||
|
label: List
|
||||||
|
- id: hub.add
|
||||||
|
label: Add
|
||||||
|
- id: hub.update
|
||||||
|
label: Update
|
||||||
|
- id: hub.delete
|
||||||
|
label: Delete
|
||||||
|
|
||||||
|
- id: rider
|
||||||
|
label: Rider Access
|
||||||
|
acls:
|
||||||
|
- id: rider.menu
|
||||||
|
label: Menu
|
||||||
|
- id: rider.list
|
||||||
|
label: List
|
||||||
|
- id: rider.add
|
||||||
|
label: Add
|
||||||
|
- id: rider.update
|
||||||
|
label: Update
|
||||||
|
- id: rider.delete
|
||||||
|
label: Delete
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,15 @@ main_menu:
|
||||||
- id: database
|
- id: database
|
||||||
acl: database.menu
|
acl: database.menu
|
||||||
label: Database
|
label: Database
|
||||||
icon: flaticon-tabs
|
icon: fa fa-database
|
||||||
|
- id: customer_list
|
||||||
|
acl: customer.list
|
||||||
|
label: Customers
|
||||||
|
parent: database
|
||||||
|
- id: rider_list
|
||||||
|
acl: rider.list
|
||||||
|
label: Riders
|
||||||
|
parent: database
|
||||||
|
|
||||||
- id: battery
|
- id: battery
|
||||||
acl: battery.menu
|
acl: battery.menu
|
||||||
|
|
@ -55,7 +63,15 @@ main_menu:
|
||||||
label: Manufacturers
|
label: Manufacturers
|
||||||
parent: vehicle
|
parent: vehicle
|
||||||
|
|
||||||
- id: customer_list
|
- id: location
|
||||||
acl: customer.list
|
acl: location.menu
|
||||||
label: Customers
|
label: Location
|
||||||
parent: database
|
icon: fa fa-home
|
||||||
|
- id: outlet_list
|
||||||
|
acl: outlet.menu
|
||||||
|
label: Outlet
|
||||||
|
parent: location
|
||||||
|
- id: hub_list
|
||||||
|
acl: hub.menu
|
||||||
|
label: Hub
|
||||||
|
parent: location
|
||||||
|
|
|
||||||
36
config/routes/outlet.yaml
Normal file
36
config/routes/outlet.yaml
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
# outlet
|
||||||
|
|
||||||
|
outlet_list:
|
||||||
|
path: /outlets
|
||||||
|
controller: App\Controller\OutletController::index
|
||||||
|
|
||||||
|
outlet_rows:
|
||||||
|
path: /outlets/rows
|
||||||
|
controller: App\Controller\OutletController::rows
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
outlet_create:
|
||||||
|
path: /outlets/create
|
||||||
|
controller: App\Controller\OutletController::create
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
outlet_create_submit:
|
||||||
|
path: /outlets/create
|
||||||
|
controller: App\Controller\OutletController::createSubmit
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
outlet_update:
|
||||||
|
path: /outlets/{id}
|
||||||
|
controller: App\Controller\OutletController::update
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
outlet_update_submit:
|
||||||
|
path: /outlets/{id}
|
||||||
|
controller: App\Controller\OutletController::updateSubmit
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
outlet_delete:
|
||||||
|
path: /outlets/{id}
|
||||||
|
controller: App\Controller\OutletController::destroy
|
||||||
|
methods: [DELETE]
|
||||||
|
|
||||||
353
src/Controller/OutletController.php
Normal file
353
src/Controller/OutletController.php
Normal file
|
|
@ -0,0 +1,353 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Ramcar\BaseController;
|
||||||
|
use App\Entity\Outlet;
|
||||||
|
|
||||||
|
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 OutletController extends BaseController
|
||||||
|
{
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('outlet.list', null, 'No access.');
|
||||||
|
|
||||||
|
$params = $this->initParameters('outlet_list');
|
||||||
|
|
||||||
|
return $this->render('outlet/list.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rows(Request $req)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('outlet.list', null, 'No access.');
|
||||||
|
|
||||||
|
// get query builder
|
||||||
|
$qb = $this->getDoctrine()
|
||||||
|
->getRepository(Outlet::class)
|
||||||
|
->createQueryBuilder('q');
|
||||||
|
|
||||||
|
// count total records
|
||||||
|
$total = $qb->select('COUNT(q)')
|
||||||
|
->getQuery()
|
||||||
|
->getSingleScalarResult();
|
||||||
|
|
||||||
|
// get datatable params
|
||||||
|
$datatable = $req->request->get('datatable');
|
||||||
|
|
||||||
|
// get current page number
|
||||||
|
$page = $datatable['pagination']['page'] ?? 1;
|
||||||
|
|
||||||
|
$perpage = $datatable['pagination']['perpage'];
|
||||||
|
$offset = ($page - 1) * $perpage;
|
||||||
|
|
||||||
|
// add metadata
|
||||||
|
$meta = [
|
||||||
|
'page' => $page,
|
||||||
|
'perpage' => $perpage,
|
||||||
|
'pages' => ceil($total / $perpage),
|
||||||
|
'total' => $total,
|
||||||
|
'sort' => 'asc',
|
||||||
|
'field' => 'id'
|
||||||
|
];
|
||||||
|
|
||||||
|
// build query
|
||||||
|
$query = $qb->select('q');
|
||||||
|
|
||||||
|
// check if filter is present
|
||||||
|
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
|
||||||
|
$query->where('q.outletname LIKE :filter')
|
||||||
|
->orWhere('q.first_name LIKE :filter')
|
||||||
|
->orWhere('q.last_name LIKE :filter')
|
||||||
|
->orWhere('q.email LIKE :filter')
|
||||||
|
->orWhere('q.contact_num LIKE :filter')
|
||||||
|
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if sorting is present, otherwise use default
|
||||||
|
if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) {
|
||||||
|
$order = $datatable['sort']['sort'] ?? 'asc';
|
||||||
|
$query->orderBy('q.' . $datatable['sort']['field'], $order);
|
||||||
|
} else {
|
||||||
|
$query->orderBy('q.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->getID();
|
||||||
|
$row['outletname'] = $orow->getOutletname();
|
||||||
|
$row['first_name'] = $orow->getFirstName();
|
||||||
|
$row['last_name'] = $orow->getLastName();
|
||||||
|
$row['email'] = $orow->getEmail();
|
||||||
|
$row['contact_num'] = $orow->getContactNumber();
|
||||||
|
$row['enabled'] = $orow->isEnabled();
|
||||||
|
|
||||||
|
|
||||||
|
// add row metadata
|
||||||
|
$row['meta'] = [
|
||||||
|
'update_url' => '',
|
||||||
|
'delete_url' => ''
|
||||||
|
];
|
||||||
|
|
||||||
|
// check if they have access to super admin outlets
|
||||||
|
if (!$this->isGranted('outlet.role.sadmin') && $orow->isSuperAdmin())
|
||||||
|
{
|
||||||
|
$rows[] = $row;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add crud urls
|
||||||
|
if ($this->isGranted('outlet.update'))
|
||||||
|
$row['meta']['update_url'] = $this->generateUrl('outlet_update', ['id' => $row['id']]);
|
||||||
|
if ($this->isGranted('outlet.delete'))
|
||||||
|
$row['meta']['delete_url'] = $this->generateUrl('outlet_delete', ['id' => $row['id']]);
|
||||||
|
|
||||||
|
$rows[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->json([
|
||||||
|
'meta' => $meta,
|
||||||
|
'data' => $rows
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('outlet.add', null, 'No access.');
|
||||||
|
|
||||||
|
$params = $this->initParameters('outlet_list');
|
||||||
|
|
||||||
|
// get roles
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$params['roles'] = $em->getRepository(Role::class)->findAll();
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('outlet/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('outlet.add', null, 'No access.');
|
||||||
|
|
||||||
|
// create new row
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$row = new Outlet();
|
||||||
|
|
||||||
|
// set and save values
|
||||||
|
$row->setOutletname($req->request->get('outletname'))
|
||||||
|
->setFirstName($req->request->get('first_name'))
|
||||||
|
->setLastName($req->request->get('last_name'))
|
||||||
|
->setEmail($req->request->get('email'))
|
||||||
|
->setContactNumber($req->request->get('contact_no'))
|
||||||
|
->setEnabled($req->request->get('enabled') ? true : false)
|
||||||
|
->clearRoles();
|
||||||
|
|
||||||
|
// set roles
|
||||||
|
$roles = $req->request->get('roles');
|
||||||
|
|
||||||
|
if (!empty($roles)) {
|
||||||
|
foreach ($roles as $role_id) {
|
||||||
|
// check if role exists
|
||||||
|
$role = $em->getRepository(Role::class)->find($role_id);
|
||||||
|
if (!empty($role))
|
||||||
|
{
|
||||||
|
// check access to super outlet roles
|
||||||
|
if ($role->isSuperAdmin() && !$this->isGranted('outlet.role.sadmin'))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$row->addRole($role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate
|
||||||
|
$errors = $validator->validate($row);
|
||||||
|
|
||||||
|
// initialize error list
|
||||||
|
$error_array = [];
|
||||||
|
|
||||||
|
// add errors to list
|
||||||
|
foreach ($errors as $error) {
|
||||||
|
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// get password inputs
|
||||||
|
$password = $req->request->get('password');
|
||||||
|
$confirm_password = $req->request->get('confirm_password');
|
||||||
|
|
||||||
|
// custom validation for password fields
|
||||||
|
if (!$password) {
|
||||||
|
$error_array['password'] = 'This value should not be blank.';
|
||||||
|
} else if ($password != $confirm_password) {
|
||||||
|
$error_array['confirm_password'] = 'Passwords do not match.';
|
||||||
|
} else {
|
||||||
|
// encode password
|
||||||
|
$enc = $ef->getEncoder($row);
|
||||||
|
$encoded_password = $enc->encodePassword($req->request->get('password'), $row->getSalt());
|
||||||
|
|
||||||
|
// set password
|
||||||
|
$row->setPassword($encoded_password);
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if any errors were found
|
||||||
|
if (!empty($error_array)) {
|
||||||
|
// return validation failure response
|
||||||
|
return $this->json([
|
||||||
|
'success' => false,
|
||||||
|
'errors' => $error_array
|
||||||
|
], 422);
|
||||||
|
} else {
|
||||||
|
// validated! save the entity
|
||||||
|
$em->persist($row);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
// return successful response
|
||||||
|
return $this->json([
|
||||||
|
'success' => 'Changes have been saved!'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('outlet.update', null, 'No access.');
|
||||||
|
|
||||||
|
$params = $this->initParameters('outlet_list');
|
||||||
|
|
||||||
|
// get row data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$row = $em->getRepository(Outlet::class)->find($id);
|
||||||
|
|
||||||
|
// make sure this row exists
|
||||||
|
if (empty($row))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
|
// get roles
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$params['roles'] = $em->getRepository(Role::class)->findAll();
|
||||||
|
|
||||||
|
$params['row'] = $row;
|
||||||
|
$params['values'] = [];
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('outlet/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator, $id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('outlet.update', null, 'No access.');
|
||||||
|
|
||||||
|
// get row data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$row = $em->getRepository(Outlet::class)->find($id);
|
||||||
|
|
||||||
|
// make sure this row exists
|
||||||
|
if (empty($row))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
|
// set and save values
|
||||||
|
$row->setOutletname($req->request->get('outletname'))
|
||||||
|
->setFirstName($req->request->get('first_name'))
|
||||||
|
->setLastName($req->request->get('last_name'))
|
||||||
|
->setEmail($req->request->get('email'))
|
||||||
|
->setContactNumber($req->request->get('contact_no'))
|
||||||
|
->setEnabled($req->request->get('enabled') ? true : false)
|
||||||
|
->clearRoles();
|
||||||
|
|
||||||
|
// set roles
|
||||||
|
$roles = $req->request->get('roles');
|
||||||
|
|
||||||
|
if (!empty($roles)) {
|
||||||
|
foreach ($roles as $role_id) {
|
||||||
|
// check if role exists
|
||||||
|
$role = $em->getRepository(Role::class)->find($role_id);
|
||||||
|
|
||||||
|
if (!empty($role))
|
||||||
|
$row->addRole($role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate
|
||||||
|
$errors = $validator->validate($row);
|
||||||
|
|
||||||
|
// initialize error list
|
||||||
|
$error_array = [];
|
||||||
|
|
||||||
|
// add errors to list
|
||||||
|
foreach ($errors as $error) {
|
||||||
|
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// get password inputs
|
||||||
|
$password = $req->request->get('password');
|
||||||
|
$confirm_password = $req->request->get('confirm_password');
|
||||||
|
|
||||||
|
// custom validation for password fields
|
||||||
|
if ($password || $confirm_password) {
|
||||||
|
if ($password != $confirm_password) {
|
||||||
|
$error_array['confirm_password'] = 'Passwords do not match.';
|
||||||
|
} else {
|
||||||
|
// encode password
|
||||||
|
$enc = $ef->getEncoder($row);
|
||||||
|
$encoded_password = $enc->encodePassword($req->request->get('password'), $row->getSalt());
|
||||||
|
|
||||||
|
// set password
|
||||||
|
$row->setPassword($encoded_password);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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('outlet.delete', null, 'No access.');
|
||||||
|
|
||||||
|
$params = $this->initParameters('outlet_list');
|
||||||
|
|
||||||
|
// get row data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$row = $em->getRepository(Outlet::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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,9 +8,9 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
* @ORM\Table(name="hub")
|
* @ORM\Table(name="job_order")
|
||||||
*/
|
*/
|
||||||
class Hub
|
class JobOrder
|
||||||
{
|
{
|
||||||
// unique id
|
// unique id
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,41 @@ class Outlet
|
||||||
*/
|
*/
|
||||||
protected $id;
|
protected $id;
|
||||||
|
|
||||||
|
// name of enrollee
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=80)
|
||||||
|
*/
|
||||||
|
protected $name;
|
||||||
|
|
||||||
|
// address
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=80)
|
||||||
|
*/
|
||||||
|
protected $address;
|
||||||
|
|
||||||
|
// address coordinates
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="point")
|
||||||
|
*/
|
||||||
|
protected $coordinates;
|
||||||
|
|
||||||
|
// contact numbers
|
||||||
|
// this is displayed in a textarea
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=200)
|
||||||
|
*/
|
||||||
|
protected $contact_numbers;
|
||||||
|
|
||||||
|
// opening time
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="time")
|
||||||
|
*/
|
||||||
|
protected $time_open;
|
||||||
|
|
||||||
|
// closing time
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="time")
|
||||||
|
*/
|
||||||
|
protected $time_close;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
219
templates/outlet/form.html.twig
Normal file
219
templates/outlet/form.html.twig
Normal file
|
|
@ -0,0 +1,219 @@
|
||||||
|
{% 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">Users</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 row is defined %}
|
||||||
|
Edit User
|
||||||
|
<small>{{ row.getUsername() }}</small>
|
||||||
|
{% else %}
|
||||||
|
New User
|
||||||
|
{% endif %}
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<form id="row-form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ row is defined ? url('user_update_submit', {'id': row.getId()}) : url('user_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="username">
|
||||||
|
Username:
|
||||||
|
</label>
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<input type="text" name="username" class="form-control m-input" value="{{ values.username is defined ? values.username : (row is defined ? row.getUsername()) }}">
|
||||||
|
<div class="form-control-feedback hide" data-field="username"></div>
|
||||||
|
<span class="m-form__help">Unique alias for this user</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group m-form__group row">
|
||||||
|
<label class="col-lg-2 col-form-label" data-field="password">
|
||||||
|
Password:
|
||||||
|
</label>
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<input type="password" name="password" class="form-control m-input">
|
||||||
|
<div class="form-control-feedback hide" data-field="password"></div>
|
||||||
|
{% if row is defined %}
|
||||||
|
<span class="m-form__help">Leave both fields blank for unchanged</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<label class="col-lg-2 col-form-label" data-field="confirm_password">
|
||||||
|
Confirm Password:
|
||||||
|
</label>
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<input type="password" name="confirm_password" class="form-control m-input">
|
||||||
|
<div class="form-control-feedback hide" data-field="confirm_password"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<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="{{ values.first_name is defined ? values.first_name : (row is defined ? row.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="{{ values.last_name is defined ? values.last_name : (row is defined ? row.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="email">
|
||||||
|
E-mail Address:
|
||||||
|
</label>
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<input type="email" name="email" class="form-control m-input" value="{{ values.email is defined ? values.email : (row is defined ? row.getEmail()) }}">
|
||||||
|
<div class="form-control-feedback hide" data-field="email"></div>
|
||||||
|
</div>
|
||||||
|
<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="{{ values.contact_no is defined ? values.contact_no : (row is defined ? row.getContactNumber()) }}">
|
||||||
|
<div class="form-control-feedback hide" data-field="contact_no"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group m-form__group row">
|
||||||
|
<label class="col-lg-2 col-form-label" data-field="roles">
|
||||||
|
Roles:
|
||||||
|
</label>
|
||||||
|
<div class="col-lg-10">
|
||||||
|
<div class="m-checkbox-list">
|
||||||
|
{% for role in roles %}
|
||||||
|
{% if role.isSuperAdmin and not is_granted('user.role.sadmin') %}
|
||||||
|
{% else %}
|
||||||
|
<label class="m-checkbox">
|
||||||
|
<input type="checkbox" name="roles[]" value="{{ role.getID() }}"{{ (values.roles is defined and role.getID() in value.roles) or (row is defined and values.roles is not defined and role.getID() in row.getRoles()) ? ' checked' : '' }}>
|
||||||
|
{{ role.getName() }}
|
||||||
|
<span></span>
|
||||||
|
</label>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
<div class="form-control-feedback hide" data-field="roles"></div>
|
||||||
|
<span class="m-form__help">Check all roles that apply</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group m-form__group row">
|
||||||
|
<label class="col-lg-2 col-form-label" data-field="enabled">
|
||||||
|
Enabled:
|
||||||
|
</label>
|
||||||
|
<div class="col-lg-10">
|
||||||
|
<span class="m-switch m-switch--icon">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="enabled" value="1"{{ (values.enabled is defined and values.enabled) or (row is defined and values.enabled is not defined and row.isEnabled()) or (values.enabled is not defined and row is not defined) ? ' checked' }}>
|
||||||
|
<span></span>
|
||||||
|
</label>
|
||||||
|
</span>
|
||||||
|
<div class="form-control-feedback hide" data-field="enabled"></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('user_list') }}" class="btn btn-secondary">Cancel</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
$("#row-form").submit(function(e) {
|
||||||
|
var form = $(this);
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
method: "POST",
|
||||||
|
url: form.prop('action'),
|
||||||
|
data: form.serialize()
|
||||||
|
}).done(function(response) {
|
||||||
|
// remove all error classes
|
||||||
|
removeErrors();
|
||||||
|
swal({
|
||||||
|
title: 'Done!',
|
||||||
|
text: 'Your changes have been saved!',
|
||||||
|
type: 'success',
|
||||||
|
onClose: function() {
|
||||||
|
window.location.href = "{{ url('user_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 %}
|
||||||
180
templates/outlet/list.html.twig
Normal file
180
templates/outlet/list.html.twig
Normal file
|
|
@ -0,0 +1,180 @@
|
||||||
|
{% 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">
|
||||||
|
Outlets
|
||||||
|
</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('outlet_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 Outlet</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("outlet_rows") }}',
|
||||||
|
method: 'POST',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
saveState: {
|
||||||
|
cookie: false,
|
||||||
|
webstorage: false
|
||||||
|
},
|
||||||
|
pageSize: 10,
|
||||||
|
serverPaging: true,
|
||||||
|
serverFiltering: true,
|
||||||
|
serverSorting: true
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
field: 'id',
|
||||||
|
title: 'ID',
|
||||||
|
width: 30
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'username',
|
||||||
|
title: 'Outletname'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'first_name',
|
||||||
|
title: 'First Name'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'last_name',
|
||||||
|
title: 'Last Name'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'email',
|
||||||
|
title: 'E-mail'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'contact_num',
|
||||||
|
title: 'Contact No.'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'enabled',
|
||||||
|
title: 'Status',
|
||||||
|
template: function (row, index, datatable) {
|
||||||
|
var tag = '';
|
||||||
|
|
||||||
|
if (row.enabled === true) {
|
||||||
|
tag = '<span class="m-badge m-badge--success m-badge--wide">Enabled</span>';
|
||||||
|
} else {
|
||||||
|
tag = '<span class="m-badge m-badge--danger m-badge--wide">Disabled</span>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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.username + '" 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.username + '" title="Delete"><i class="la la-trash"></i></a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return actions;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
search: {
|
||||||
|
onEnter: false,
|
||||||
|
input: $('#data-rows-search'),
|
||||||
|
delay: 400
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var table = $("#data-rows").mDatatable(options);
|
||||||
|
|
||||||
|
$(document).on('click', '.btn-delete', function(e) {
|
||||||
|
var url = $(this).prop('href');
|
||||||
|
var id = $(this).data('id');
|
||||||
|
var btn = $(this);
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
swal({
|
||||||
|
title: 'Confirmation',
|
||||||
|
html: 'Are you sure you want to delete <strong>' + id + '</strong>?',
|
||||||
|
type: 'warning',
|
||||||
|
showCancelButton: true
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.value) {
|
||||||
|
$.ajax({
|
||||||
|
method: "DELETE",
|
||||||
|
url: url
|
||||||
|
}).done(function(response) {
|
||||||
|
table.row(btn.parents('tr')).remove();
|
||||||
|
table.reload();
|
||||||
|
}).fail(function() {
|
||||||
|
swal({
|
||||||
|
title: 'Whoops',
|
||||||
|
text: 'An error occurred while deleting this item. Please contact support.',
|
||||||
|
type: 'error'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
Loading…
Reference in a new issue