Add controller for price tier. #780
This commit is contained in:
parent
9447f64312
commit
fa3cf12be1
9 changed files with 713 additions and 18 deletions
|
|
@ -634,6 +634,48 @@ catalyst_auth:
|
|||
- id: service_offering.delete
|
||||
label: Delete
|
||||
|
||||
- id: price_tier
|
||||
label: Price Tier
|
||||
acls:
|
||||
- id: price_tier.menu
|
||||
label: Menu
|
||||
- id: price_tier.list
|
||||
label: List
|
||||
- id: price_tier.add
|
||||
label: Add
|
||||
- id: price_tier.update
|
||||
label: Update
|
||||
- id: price_tier.delete
|
||||
label: Delete
|
||||
|
||||
- id: item_type
|
||||
label: Item Type
|
||||
acls:
|
||||
- id: item.type.menu
|
||||
label: Menu
|
||||
- id: item.type.list
|
||||
label: List
|
||||
- id: item.type.add
|
||||
label: Add
|
||||
- id: item.type.update
|
||||
label: Update
|
||||
- id: item.type.delete
|
||||
label: Delete
|
||||
|
||||
- id: item
|
||||
label: Item
|
||||
acls:
|
||||
- id: item.menu
|
||||
label: Menu
|
||||
- id: item.list
|
||||
label: List
|
||||
- id: item.add
|
||||
label: Add
|
||||
- id: item.update
|
||||
label: Update
|
||||
- id: item.delete
|
||||
label: Delete
|
||||
|
||||
api:
|
||||
user_entity: "App\\Entity\\ApiUser"
|
||||
acl_data:
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ catalyst_menu:
|
|||
acl: support.menu
|
||||
label: '[menu.support]'
|
||||
icon: flaticon-support
|
||||
order: 10
|
||||
order: 11
|
||||
- id: customer_list
|
||||
acl: customer.list
|
||||
label: '[menu.support.customers]'
|
||||
|
|
@ -223,7 +223,7 @@ catalyst_menu:
|
|||
acl: service.menu
|
||||
label: '[menu.service]'
|
||||
icon: flaticon-squares
|
||||
order: 11
|
||||
order: 12
|
||||
- id: service_list
|
||||
acl: service.list
|
||||
label: '[menu.service.services]'
|
||||
|
|
@ -233,7 +233,7 @@ catalyst_menu:
|
|||
acl: partner.menu
|
||||
label: '[menu.partner]'
|
||||
icon: flaticon-network
|
||||
order: 12
|
||||
order: 13
|
||||
- id: partner_list
|
||||
acl: partner.list
|
||||
label: '[menu.partner.partners]'
|
||||
|
|
@ -247,7 +247,7 @@ catalyst_menu:
|
|||
acl: motolite_event.menu
|
||||
label: '[menu.motolite_event]'
|
||||
icon: flaticon-event-calendar-symbol
|
||||
order: 13
|
||||
order: 14
|
||||
- id: motolite_event_list
|
||||
acl: motolite_event.list
|
||||
label: '[menu.motolite_event.events]'
|
||||
|
|
@ -257,7 +257,7 @@ catalyst_menu:
|
|||
acl: analytics.menu
|
||||
label: '[menu.analytics]'
|
||||
icon: flaticon-graphic
|
||||
order: 14
|
||||
order: 15
|
||||
- id: analytics_forecast_form
|
||||
acl: analytics.forecast
|
||||
label: '[menu.analytics.forecasting]'
|
||||
|
|
@ -267,7 +267,7 @@ catalyst_menu:
|
|||
acl: database.menu
|
||||
label: '[menu.database]'
|
||||
icon: fa fa-database
|
||||
order: 15
|
||||
order: 16
|
||||
- id: ticket_type_list
|
||||
acl: ticket_type.menu
|
||||
label: '[menu.database.tickettypes]'
|
||||
|
|
@ -288,3 +288,17 @@ catalyst_menu:
|
|||
acl: service_offering.menu
|
||||
label: '[menu.database.serviceofferings]'
|
||||
parent: database
|
||||
|
||||
- id: item
|
||||
acl: item.menu
|
||||
label: Item Management
|
||||
icon: fa fa-boxes
|
||||
order: 10
|
||||
- id: price_tier_list
|
||||
acl: price_tier.list
|
||||
label: Price Tiers
|
||||
parent: item
|
||||
- id: item_list
|
||||
acl: item.list
|
||||
label: Items
|
||||
parent: item
|
||||
|
|
|
|||
34
config/routes/price_tier.yaml
Normal file
34
config/routes/price_tier.yaml
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
price_tier_list:
|
||||
path: /pricetiers
|
||||
controller: App\Controller\PriceTierController::index
|
||||
methods: [GET]
|
||||
|
||||
price_tier_rows:
|
||||
path: /pricetiers/rows
|
||||
controller: App\Controller\PriceTierController::datatableRows
|
||||
methods: [POST]
|
||||
|
||||
price_tier_add_form:
|
||||
path: /pricetiers/newform
|
||||
controller: App\Controller\PriceTierController::addForm
|
||||
methods: [GET]
|
||||
|
||||
price_tier_add_submit:
|
||||
path: /pricetiers
|
||||
controller: App\Controller\PriceTierController::addSubmit
|
||||
methods: [POST]
|
||||
|
||||
price_tier_update_form:
|
||||
path: /pricetiers/{id}
|
||||
controller: App\Controller\PriceTierController::updateForm
|
||||
methods: [GET]
|
||||
|
||||
price_tier_update_submit:
|
||||
path: /pricetiers/{id}
|
||||
controller: App\Controller\PriceTierController::updateSubmit
|
||||
methods: [POST]
|
||||
|
||||
price_tier_delete:
|
||||
path: /pricetiers/{id}
|
||||
controller: App\Controller\PriceTierController::deleteSubmit
|
||||
methods: [DELETE]
|
||||
244
src/Controller/PriceTierController.php
Normal file
244
src/Controller/PriceTierController.php
Normal file
|
|
@ -0,0 +1,244 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
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\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
|
||||
|
||||
use Catalyst\MenuBundle\Annotation\Menu;
|
||||
|
||||
use App\Entity\PriceTier;
|
||||
use App\Entity\SupportedArea;
|
||||
|
||||
class PriceTierController extends Controller
|
||||
{
|
||||
/**
|
||||
* @Menu(selected="price_tier_list")
|
||||
* @IsGranted("price_tier.list")
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return $this->render('price-tier/list.html.twig');
|
||||
}
|
||||
|
||||
/**
|
||||
* @IsGranted("price_tier.list")
|
||||
*/
|
||||
public function datatableRows(Request $req)
|
||||
{
|
||||
// get query builder
|
||||
$qb = $this->getDoctrine()
|
||||
->getRepository(PriceTier::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['name'] = $orow->getName();
|
||||
|
||||
// add row metadata
|
||||
$row['meta'] = [
|
||||
'update_url' => '',
|
||||
'delete_url' => ''
|
||||
];
|
||||
|
||||
// add crud urls
|
||||
if ($this->isGranted('price_tier.update'))
|
||||
$row['meta']['update_url'] = $this->generateUrl('price_tier_update_form', ['id' => $row['id']]);
|
||||
if ($this->isGranted('service_offering.delete'))
|
||||
$row['meta']['delete_url'] = $this->generateUrl('price_tier_delete', ['id' => $row['id']]);
|
||||
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
// response
|
||||
return $this->json([
|
||||
'meta' => $meta,
|
||||
'data' => $rows
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Menu(selected="price_tier.list")
|
||||
* @IsGranted("price_tier.add")
|
||||
*/
|
||||
public function addForm(EntityManagerInterface $em)
|
||||
{
|
||||
$pt = new PriceTier();
|
||||
|
||||
// get the supported areas
|
||||
$sets = $this->generateFormSets($em);
|
||||
|
||||
$params = [
|
||||
'obj' => $pt,
|
||||
'sets' => $sets,
|
||||
'mode' => 'create',
|
||||
];
|
||||
|
||||
// response
|
||||
return $this->render('price-tier/form.html.twig', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @IsGranted("price_tier.add")
|
||||
*/
|
||||
public function addSubmit(Request $req, EntityManagerInterface $em, ValidatorInterface $validator)
|
||||
{
|
||||
$pt = new PriceTier();
|
||||
|
||||
// TODO: add validation for supported area
|
||||
$this->setObject($pt, $req);
|
||||
|
||||
// validate
|
||||
$errors = $validator->validate($pt);
|
||||
|
||||
// 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($pt);
|
||||
|
||||
// set the price tier id for the selected supported areas
|
||||
$this->updateSupportedAreas($em, $pt, $req);
|
||||
|
||||
$em->flush();
|
||||
|
||||
// return successful response
|
||||
return $this->json([
|
||||
'success' => 'Changes have been saved!'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Menu(selected="price_tier_list")
|
||||
* @ParamConverter("price_tier", class="App\Entity\PriceTier")
|
||||
* @IsGranted("price_tier.update")
|
||||
*/
|
||||
public function updateForm($id, EntityManagerInterface $em, PriceTier $pt)
|
||||
{
|
||||
// get the supported areas
|
||||
$sets = $this->generateFormSets($em);
|
||||
|
||||
$params = [
|
||||
'obj' => $pt,
|
||||
'sets' => $sets,
|
||||
'mode' => 'update',
|
||||
];
|
||||
|
||||
// response
|
||||
return $this->render('price-tier/form.html.twig', $params);
|
||||
}
|
||||
|
||||
protected function setObject(PriceTier $obj, Request $req)
|
||||
{
|
||||
$obj->setName($req->request->get('name'));
|
||||
}
|
||||
|
||||
public function updateSupportedAreas(EntityManagerInterface $em, PriceTier $obj, Request $req)
|
||||
{
|
||||
// get the selected areas
|
||||
$areas = $req->request->get('areas');
|
||||
|
||||
foreach ($areas as $area_id)
|
||||
{
|
||||
// get supported area
|
||||
$supported_area = $em->getRepository(SupportedArea::class)->find($area_id);
|
||||
|
||||
if ($supported_area != null)
|
||||
$supported_area->setPriceTier($obj);
|
||||
}
|
||||
}
|
||||
|
||||
protected function generateFormSets(EntityManagerInterface $em)
|
||||
{
|
||||
// get the supported areas
|
||||
// TODO: filter out the supported areas that already have a price tier id? but if we're editing, we need those price tiers
|
||||
$areas = $em->getRepository(SupportedArea::class)->findAll();
|
||||
$areas_set = [];
|
||||
foreach ($areas as $area)
|
||||
{
|
||||
$areas_set[$area->getID()] = $area->getName();
|
||||
}
|
||||
|
||||
return [
|
||||
'areas' => $areas_set
|
||||
];
|
||||
}
|
||||
|
||||
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')
|
||||
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@ class ItemPrice
|
|||
protected $id;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="PriceTier", inversedBy="items")
|
||||
* @ORM\ManyToOne(targetEntity="PriceTier", inversedBy="item_prices")
|
||||
* @ORM\JoinColumn(name="price_tier_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $price_tier;
|
||||
|
|
@ -44,10 +44,43 @@ class ItemPrice
|
|||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
protected $item_price;
|
||||
protected $price;
|
||||
|
||||
public function getID()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setPriceTier(PriceTier $price_tier)
|
||||
{
|
||||
$this->price_tier = $price_tier;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPriceTier()
|
||||
{
|
||||
return $this->price_tier;
|
||||
}
|
||||
|
||||
public function setItemID($item_id)
|
||||
{
|
||||
$this->item_id = $item_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getItemID()
|
||||
{
|
||||
return $this->item_id;
|
||||
}
|
||||
|
||||
public function setPrice($price)
|
||||
{
|
||||
$this->price = $price;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPrice()
|
||||
{
|
||||
return $this->price;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,21 +28,20 @@ class PriceTier
|
|||
|
||||
// supported areas under price tier
|
||||
/**
|
||||
* @ORM\Column(type="json")
|
||||
* @ORM\OneToMany(targetEntity="SupportedArea", mappedBy="price_tier");
|
||||
*/
|
||||
protected $meta_areas;
|
||||
protected $supported_areas;
|
||||
|
||||
// items under a price tier
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="ItemPrice", mappedBy="price_tier")
|
||||
*/
|
||||
protected $items;
|
||||
protected $item_prices;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->meta_areas = [];
|
||||
|
||||
$this->items = new ArrayCollection();
|
||||
$this->supported_areas = new ArrayCollection();
|
||||
$this->item_prices = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getID()
|
||||
|
|
@ -61,13 +60,23 @@ class PriceTier
|
|||
return $this->name;
|
||||
}
|
||||
|
||||
public function addMetaArea($id, $value)
|
||||
public function getSupportedAreaObjects()
|
||||
{
|
||||
$this->meta_areas[$id] = $value;
|
||||
return $this->supported_areas;
|
||||
}
|
||||
|
||||
public function getAllMetaAreas()
|
||||
public function getSupportedAreas()
|
||||
{
|
||||
return $this->meta_areas;
|
||||
$str_supported_areas = [];
|
||||
foreach ($this->supported_areas as $supported_area)
|
||||
$str_supported_areas[] = $supported_area->getID();
|
||||
|
||||
return $str_supported_areas;
|
||||
}
|
||||
|
||||
public function getItemPrices()
|
||||
{
|
||||
return $this->item_prices;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,9 +39,17 @@ class SupportedArea
|
|||
*/
|
||||
protected $coverage_area;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="PriceTier", inversedBy="supported_areas")
|
||||
* @ORM\JoinColumn(name="price_tier_id", referencedColumnName="id", nullable=true)
|
||||
*/
|
||||
protected $price_tier;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->date_create = new DateTime();
|
||||
|
||||
$this->price_tier = null;
|
||||
}
|
||||
|
||||
public function getID()
|
||||
|
|
@ -82,5 +90,16 @@ class SupportedArea
|
|||
{
|
||||
return $this->coverage_area;
|
||||
}
|
||||
|
||||
public function setPriceTier(PriceTier $price_tier)
|
||||
{
|
||||
$this->price_tier = $price_tier;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPriceTier()
|
||||
{
|
||||
return $this->price_tier;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
154
templates/price-tier/form.html.twig
Normal file
154
templates/price-tier/form.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">Price Tiers</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 Price Tier
|
||||
<small>{{ obj.getName() }}</small>
|
||||
{% else %}
|
||||
New Price Tier
|
||||
{% 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('price_tier_update_submit', {'id': obj.getId()}) : url('price_tier_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="name">
|
||||
Name:
|
||||
</label>
|
||||
<div class="col-lg-9">
|
||||
<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>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<label class="col-lg-3 col-form-label" data-field="areas">
|
||||
Coverage Area:
|
||||
</label>
|
||||
<div class="col-lg-9">
|
||||
{% if sets.areas is empty %}
|
||||
No supported areas.
|
||||
{% else %}
|
||||
<div class="m-checkbox-list">
|
||||
{% for id, label in sets.areas %}
|
||||
<label class="m-checkbox">
|
||||
<input type="checkbox" name="areas[]" value="{{ id }}"{{ id in obj.getSupportedAreas() ? ' checked' : '' }}>
|
||||
{{ label }}
|
||||
<span></span>
|
||||
</label>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="form-control-feedback hide" data-field="areas"></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('price_tier_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('price_tier_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 %}
|
||||
146
templates/price-tier/list.html.twig
Normal file
146
templates/price-tier/list.html.twig
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
{% 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">
|
||||
Price Tiers
|
||||
</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('price_tier_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 Price Tier</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("price_tier_rows") }}',
|
||||
method: 'POST'
|
||||
}
|
||||
},
|
||||
saveState: {
|
||||
cookie: false,
|
||||
webstorage: false
|
||||
},
|
||||
pageSize: 10,
|
||||
serverPaging: true,
|
||||
serverFiltering: true,
|
||||
serverSorting: true
|
||||
},
|
||||
layout: {
|
||||
scroll: true
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
field: 'id',
|
||||
title: 'ID',
|
||||
width: 30
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: 'Name'
|
||||
},
|
||||
{
|
||||
field: 'Actions',
|
||||
width: 110,
|
||||
title: 'Actions',
|
||||
sortable: false,
|
||||
overflow: 'visible',
|
||||
template: function (row, index, datatable) {
|
||||
var actions = '';
|
||||
|
||||
if (row.meta.update_url != '') {
|
||||
actions += '<a href="' + row.meta.update_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit" data-id="' + row.name + '" title="Edit"><i class="la la-edit"></i></a>';
|
||||
}
|
||||
|
||||
if (row.meta.delete_url != '') {
|
||||
actions += '<a href="' + row.meta.delete_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill btn-delete" data-id="' + row.name + '" title="Delete"><i class="la la-trash"></i></a>';
|
||||
}
|
||||
|
||||
return actions;
|
||||
},
|
||||
}
|
||||
],
|
||||
search: {
|
||||
onEnter: false,
|
||||
input: $('#data-rows-search'),
|
||||
delay: 400
|
||||
}
|
||||
};
|
||||
|
||||
var table = $("#data-rows").mDatatable(options);
|
||||
|
||||
$(document).on('click', '.btn-delete', function(e) {
|
||||
var url = $(this).prop('href');
|
||||
var id = $(this).data('id');
|
||||
var btn = $(this);
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
swal({
|
||||
title: 'Confirmation',
|
||||
html: 'Are you sure you want to delete <strong>' + id + '</strong>?',
|
||||
type: 'warning',
|
||||
showCancelButton: true
|
||||
}).then((result) => {
|
||||
if (result.value) {
|
||||
$.ajax({
|
||||
method: "DELETE",
|
||||
url: url
|
||||
}).done(function(response) {
|
||||
table.row(btn.parents('tr')).remove();
|
||||
table.reload();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
Loading…
Reference in a new issue