Add CRM support for upcoming motolite events #730
This commit is contained in:
parent
059bda9bf6
commit
9afa2dfc6c
10 changed files with 752 additions and 6 deletions
|
|
@ -384,6 +384,20 @@ catalyst_auth:
|
||||||
- id: partner.delete
|
- id: partner.delete
|
||||||
label: Delete
|
label: Delete
|
||||||
|
|
||||||
|
- id: motolite_event
|
||||||
|
label: Motolite Events
|
||||||
|
acls:
|
||||||
|
- id: motolite_event.menu
|
||||||
|
label: Menu
|
||||||
|
- id: motolite_event.list
|
||||||
|
label: List
|
||||||
|
- id: motolite_event.add
|
||||||
|
label: Add
|
||||||
|
- id: motolite_event.update
|
||||||
|
label: Update
|
||||||
|
- id: motolite_event.delete
|
||||||
|
label: Delete
|
||||||
|
|
||||||
- id: review
|
- id: review
|
||||||
label: Reviews
|
label: Reviews
|
||||||
acls:
|
acls:
|
||||||
|
|
|
||||||
|
|
@ -235,11 +235,21 @@ catalyst_menu:
|
||||||
label: '[menu.partner.reviews]'
|
label: '[menu.partner.reviews]'
|
||||||
parent: partner
|
parent: partner
|
||||||
|
|
||||||
|
- id: motolite_event
|
||||||
|
acl: motolite_event.menu
|
||||||
|
label: '[menu.motolite_event]'
|
||||||
|
icon: flaticon-event-calendar-symbol
|
||||||
|
order: 13
|
||||||
|
- id: motolite_event_list
|
||||||
|
acl: motolite_event.list
|
||||||
|
label: '[menu.motolite_event.events]'
|
||||||
|
parent: motolite_event
|
||||||
|
|
||||||
- id: analytics
|
- id: analytics
|
||||||
acl: analytics.menu
|
acl: analytics.menu
|
||||||
label: '[menu.analytics]'
|
label: '[menu.analytics]'
|
||||||
icon: flaticon-graphic
|
icon: flaticon-graphic
|
||||||
order: 13
|
order: 14
|
||||||
- id: analytics_forecast_form
|
- id: analytics_forecast_form
|
||||||
acl: analytics.forecast
|
acl: analytics.forecast
|
||||||
label: '[menu.analytics.forecasting]'
|
label: '[menu.analytics.forecasting]'
|
||||||
|
|
@ -249,7 +259,7 @@ catalyst_menu:
|
||||||
acl: database.menu
|
acl: database.menu
|
||||||
label: '[menu.database]'
|
label: '[menu.database]'
|
||||||
icon: fa fa-database
|
icon: fa fa-database
|
||||||
order: 14
|
order: 15
|
||||||
- id: ticket_type_list
|
- id: ticket_type_list
|
||||||
acl: ticket_type.menu
|
acl: ticket_type.menu
|
||||||
label: '[menu.database.tickettypes]'
|
label: '[menu.database.tickettypes]'
|
||||||
|
|
|
||||||
38
config/routes/motolite_event.yaml
Normal file
38
config/routes/motolite_event.yaml
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
motolite_event_list:
|
||||||
|
path: /motolite_events
|
||||||
|
controller: App\Controller\MotoliteEventController::index
|
||||||
|
|
||||||
|
motolite_event_rows:
|
||||||
|
path: /motolite_events/rows
|
||||||
|
controller: App\Controller\MotoliteEventController::rows
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
motolite_event_create:
|
||||||
|
path: /motolite_events/create
|
||||||
|
controller: App\Controller\MotoliteEventController::addForm
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
motolite_event_create_submit:
|
||||||
|
path: /motolite_events/create
|
||||||
|
controller: App\Controller\MotoliteEventController::addSubmit
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
motolite_event_upload_image:
|
||||||
|
path: /motolite_events/upload
|
||||||
|
controller: App\Controller\MotoliteEventController::uploadImage
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
motolite_event_update:
|
||||||
|
path: /motolite_events/{id}
|
||||||
|
controller: App\Controller\MotoliteEventController::updateForm
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
motolite_event_update_submit:
|
||||||
|
path: /motolite_events/{id}
|
||||||
|
controller: App\Controller\MotoliteEventController::updateSubmit
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
motolite_event_delete:
|
||||||
|
path: /motolite_events/{id}
|
||||||
|
controller: App\Controller\MotoliteEventController::destroy
|
||||||
|
methods: [DELETE]
|
||||||
BIN
public/assets/images/image.gif
Executable file
BIN
public/assets/images/image.gif
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
|
|
@ -37,6 +37,7 @@ class MotoliteEventController extends ApiController
|
||||||
'id' => $result->getID(),
|
'id' => $result->getID(),
|
||||||
'name' => $result->getName(),
|
'name' => $result->getName(),
|
||||||
'event_type' => MotoliteEventType::getName($result->getEventType()),
|
'event_type' => MotoliteEventType::getName($result->getEventType()),
|
||||||
|
'event_time' => $result->getEventTime()->format("d M Y g:i A"),
|
||||||
'url' => $result->getUrl(),
|
'url' => $result->getUrl(),
|
||||||
'image_file' => $result->getImageFile(),
|
'image_file' => $result->getImageFile(),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
304
src/Controller/MotoliteEventController.php
Normal file
304
src/Controller/MotoliteEventController.php
Normal file
|
|
@ -0,0 +1,304 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\MotoliteEvent;
|
||||||
|
use App\Ramcar\MotoliteEventType;
|
||||||
|
use App\Service\FileUploader;
|
||||||
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
use Doctrine\ORM\EntityManager;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
|
||||||
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
|
use DateTime;
|
||||||
|
|
||||||
|
use Catalyst\MenuBundle\Annotation\Menu;
|
||||||
|
|
||||||
|
class MotoliteEventController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Menu(selected="motolite_event_list")
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('motolite_event.list', null, 'No access.');
|
||||||
|
|
||||||
|
return $this->render('motolite-event/list.html.twig');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rows(Request $req)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('motolite_event.list', null, 'No access.');
|
||||||
|
|
||||||
|
// get query builder
|
||||||
|
$qb = $this->getDoctrine()
|
||||||
|
->getRepository(MotoliteEvent::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.event_time', 'asc');
|
||||||
|
}
|
||||||
|
|
||||||
|
// get rows for this page
|
||||||
|
$obj_rows = $query->setFirstResult($offset)
|
||||||
|
->setMaxResults($perpage)
|
||||||
|
->getQuery()
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
// process rows
|
||||||
|
$rows = [];
|
||||||
|
foreach ($obj_rows as $orow) {
|
||||||
|
// add row data
|
||||||
|
$row['id'] = $orow->getID();
|
||||||
|
$row['name'] = $orow->getName();
|
||||||
|
$row['event_type'] = MotoliteEventType::getName($orow->getEventType());
|
||||||
|
$row['event_time'] = $orow->getEventTime()->format("d M Y g:i A");
|
||||||
|
$row['url'] = '<a href="' . $orow->getUrl() . '" target="_blank">Link</a>';
|
||||||
|
$row['image_file'] = $orow->getImageFile();
|
||||||
|
|
||||||
|
// add row metadata
|
||||||
|
$row['meta'] = [
|
||||||
|
'update_url' => '',
|
||||||
|
'delete_url' => ''
|
||||||
|
];
|
||||||
|
|
||||||
|
// add crud urls
|
||||||
|
if ($this->isGranted('motolite_event.update'))
|
||||||
|
$row['meta']['update_url'] = $this->generateUrl('motolite_event_update', ['id' => $row['id']]);
|
||||||
|
if ($this->isGranted('motolite_event.delete'))
|
||||||
|
$row['meta']['delete_url'] = $this->generateUrl('motolite_event_delete', ['id' => $row['id']]);
|
||||||
|
|
||||||
|
$rows[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->json([
|
||||||
|
'meta' => $meta,
|
||||||
|
'data' => $rows
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Menu(selected="motolite_event_list")
|
||||||
|
*/
|
||||||
|
public function addForm()
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('motolite_event.add', null, 'No access.');
|
||||||
|
|
||||||
|
$params = [];
|
||||||
|
$params['obj'] = new MotoliteEvent();
|
||||||
|
$params['mode'] = 'create';
|
||||||
|
|
||||||
|
$params['event_types'] = MotoliteEventType::getCollection();
|
||||||
|
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('motolite-event/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('motolite_event.add', null, 'No access.');
|
||||||
|
|
||||||
|
// create new object
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$obj = new MotoliteEvent();
|
||||||
|
|
||||||
|
$this->setObject($obj, $em, $req);
|
||||||
|
|
||||||
|
// validate
|
||||||
|
$errors = $validator->validate($obj);
|
||||||
|
|
||||||
|
// 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($obj);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
// return successful response
|
||||||
|
return $this->json([
|
||||||
|
'success' => 'Changes have been saved!'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Menu(selected="motolite_event_list")
|
||||||
|
*/
|
||||||
|
public function updateForm($id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('motolite_event.update', null, 'No access.');
|
||||||
|
|
||||||
|
// get row data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$obj = $em->getRepository(MotoliteEvent::class)->find($id);
|
||||||
|
|
||||||
|
// make sure this row exists
|
||||||
|
if (empty($obj))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
|
$params = [];
|
||||||
|
$params['obj'] = $obj;
|
||||||
|
$params['mode'] = 'update';
|
||||||
|
|
||||||
|
$params['event_types'] = MotoliteEventType::getCollection();
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('motolite-event/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator, $id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('motolite_event.update', null, 'No access.');
|
||||||
|
|
||||||
|
// get object data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$obj = $em->getRepository(MotoliteEvent::class)->find($id);
|
||||||
|
|
||||||
|
// make sure this object exists
|
||||||
|
if (empty($obj))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
|
$this->setObject($obj, $em, $req);
|
||||||
|
|
||||||
|
// validate
|
||||||
|
$errors = $validator->validate($obj);
|
||||||
|
|
||||||
|
// 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!'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy($id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('motolite_event.delete', null, 'No access.');
|
||||||
|
|
||||||
|
// get object data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$obj = $em->getRepository(MotoliteEvent::class)->find($id);
|
||||||
|
|
||||||
|
if (empty($obj))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
|
// delete this object
|
||||||
|
$em->remove($obj);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
// response
|
||||||
|
$response = new Response();
|
||||||
|
$response->setStatusCode(Response::HTTP_OK);
|
||||||
|
$response->send();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setQueryFilters($datatable, QueryBuilder $query)
|
||||||
|
{
|
||||||
|
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
|
||||||
|
$query->where('q.name LIKE :filter')
|
||||||
|
->orWhere('q.url LIKE :filter')
|
||||||
|
->orWhere('q.event_type LIKE :filter')
|
||||||
|
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setObject(MotoliteEvent $obj, EntityManager $em, Request $req)
|
||||||
|
{
|
||||||
|
// times
|
||||||
|
$format = "Y-m-d\TH:i";
|
||||||
|
$event_time = DateTime::createFromFormat($format, $req->request->get('event_time'));
|
||||||
|
|
||||||
|
$event_type = $req->request->get('event_type');
|
||||||
|
|
||||||
|
// set and save values
|
||||||
|
$obj->setName($req->request->get('name'))
|
||||||
|
->setEventType($event_type)
|
||||||
|
->setEventTime($event_time)
|
||||||
|
->setUrl($req->request->get('url'))
|
||||||
|
->setImageFile($req->request->get('image_file'));
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,7 +4,6 @@ namespace App\Entity;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
use Symfony\Component\HttpFoundation\File\File;
|
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
|
||||||
|
|
@ -48,13 +47,12 @@ class MotoliteEvent
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string")
|
* @ORM\Column(type="string")
|
||||||
* @Assert\NotBlank()
|
* @Assert\NotBlank()
|
||||||
* @Assert\File(mimeTypes={"image/png", "image/jpeg", "image/gif", "image/webp"})
|
|
||||||
*/
|
*/
|
||||||
protected $image_file;
|
protected $image_file;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->event_time = new DateTime();
|
$this->event_time = new DateTime('today noon');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setName($name)
|
public function setName($name)
|
||||||
|
|
@ -112,7 +110,7 @@ class MotoliteEvent
|
||||||
return $this->event_time;
|
return $this->event_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setImageFile(File $image_file = null)
|
public function setImageFile($image_file = null)
|
||||||
{
|
{
|
||||||
$this->image_file = $image_file;
|
$this->image_file = $image_file;
|
||||||
return $this;
|
return $this;
|
||||||
|
|
|
||||||
223
templates/motolite-event/form.html.twig
Normal file
223
templates/motolite-event/form.html.twig
Normal file
|
|
@ -0,0 +1,223 @@
|
||||||
|
{% 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">Motolite Events</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__head">
|
||||||
|
<div class="m-portlet__head-caption">
|
||||||
|
<div class="m-portlet__head-title">
|
||||||
|
<span class="m-portlet__head-icon">
|
||||||
|
<i class="fa fa-calendar"></i>
|
||||||
|
</span>
|
||||||
|
<h3 class="m-portlet__head-text">
|
||||||
|
{% if mode == 'update' %}
|
||||||
|
Edit Event
|
||||||
|
<small>{{ obj.getName() }}</small>
|
||||||
|
{% else %}
|
||||||
|
New Event
|
||||||
|
{% endif %}
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<form id="row-form" class="m-form m-form--label-align-right" method="post" action="{{ mode == 'update' ? url('motolite_event_update_submit', {'id': obj.getId()}) : url('motolite_event_create_submit') }}">
|
||||||
|
<div class="m-portlet__body">
|
||||||
|
<div class="tab-content">
|
||||||
|
<div class="tab-pane active" id="motolite-event-info" role="tabpanel">
|
||||||
|
<div class="form-group m-form__group row no-border">
|
||||||
|
<div class="col-lg-6">
|
||||||
|
<label for="name" data-field="name">
|
||||||
|
Name
|
||||||
|
</label>
|
||||||
|
<input type="text" name="name" class="form-control m-input" value="{{ obj.getName() }}">
|
||||||
|
<div class="form-control-feedback hide" data-field="name"></div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-6">
|
||||||
|
<label for="branch_code" data-field="event_type">
|
||||||
|
Event Type
|
||||||
|
</label>
|
||||||
|
<select class="form-control m-input" name="event_type">
|
||||||
|
<option value=""></option>
|
||||||
|
{% for key, event_type in event_types %}
|
||||||
|
<option value="{{ key }}"{{ key == obj.getEventType ? ' selected' }}>{{ event_type }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
<div class="form-control-feedback hide" data-field="event_type"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group m-form__group row no-border">
|
||||||
|
<div class="col-lg-6">
|
||||||
|
<label for="name" data-field="event_time">
|
||||||
|
Event Time
|
||||||
|
</label>
|
||||||
|
<input type="datetime-local" name="event_time" class="form-control m-input" value="{{ obj.getEventTime|date("Y-m-d\\TH:i") }}">
|
||||||
|
<div class="form-control-feedback hide" data-field="event_time"></div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-6">
|
||||||
|
<label for="name" data-field="name">
|
||||||
|
URL
|
||||||
|
</label>
|
||||||
|
<input type="text" name="url" class="form-control m-input" value="{{ obj.getUrl() }}">
|
||||||
|
<div class="form-control-feedback hide" data-field="url"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group m-form__group row no-border">
|
||||||
|
<div class="col-lg-6">
|
||||||
|
<label data-field="image_file">
|
||||||
|
{% if mode == 'update' and obj.getImageFile %}
|
||||||
|
Replace Picture
|
||||||
|
{% else %}
|
||||||
|
Picture
|
||||||
|
{% endif %}
|
||||||
|
</label>
|
||||||
|
<div class="m-dropzone dropzone m-dropzone--primary" action="{{ url('motolite_event_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' and obj.getImageFile %}
|
||||||
|
<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-6">
|
||||||
|
<label> </label>
|
||||||
|
<div class="portrait-box" style="background-image: url('{{ obj.getImageFile() ? '/uploads/' ~ obj.getImageFile() : '/assets/images/image.gif' }}');"></div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</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">
|
||||||
|
<input type="hidden" name="image_file" value="{{ obj.getImageFile() }}">
|
||||||
|
<button type="submit" class="btn btn-success">Submit</button>
|
||||||
|
<a href="{{ url('motolite_event_list') }}" class="btn btn-secondary">Back</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);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
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('motolite_event_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 %}
|
||||||
155
templates/motolite-event/list.html.twig
Normal file
155
templates/motolite-event/list.html.twig
Normal file
|
|
@ -0,0 +1,155 @@
|
||||||
|
{% 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">
|
||||||
|
Motolite Events
|
||||||
|
</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('motolite_event_create') }}" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
|
||||||
|
<span>
|
||||||
|
<i class="fa fa-calendar"></i>
|
||||||
|
<span>New Event</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("motolite_event_rows") }}',
|
||||||
|
method: 'POST',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
saveState: {
|
||||||
|
cookie: false,
|
||||||
|
webstorage: false
|
||||||
|
},
|
||||||
|
pageSize: 10,
|
||||||
|
serverPaging: true,
|
||||||
|
serverFiltering: true,
|
||||||
|
serverSorting: true
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
field: 'id',
|
||||||
|
title: 'ID',
|
||||||
|
width: 30
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'name',
|
||||||
|
title: 'Event'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'event_type',
|
||||||
|
title: 'Type'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'event_time',
|
||||||
|
title: 'Date'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'url',
|
||||||
|
title: 'URL'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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 %}
|
||||||
|
|
@ -145,6 +145,9 @@ menu.partner: 'Partners'
|
||||||
menu.partner.partners: 'Partners'
|
menu.partner.partners: 'Partners'
|
||||||
menu.partner.reviews: 'Reviews'
|
menu.partner.reviews: 'Reviews'
|
||||||
|
|
||||||
|
menu.motolite_event: 'Motolite Events'
|
||||||
|
menu.motolite_event.events: 'Events'
|
||||||
|
|
||||||
menu.analytics: 'Analytics'
|
menu.analytics: 'Analytics'
|
||||||
menu.analytics.forecasting: 'Forecasting'
|
menu.analytics.forecasting: 'Forecasting'
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue