Add new flag for SAP battery. #526
This commit is contained in:
parent
afc9eb7062
commit
debc3bc8cb
4 changed files with 202 additions and 152 deletions
|
|
@ -105,6 +105,7 @@ class SAPBatteryController extends Controller
|
||||||
$row['id'] = $orow[0]->getID();
|
$row['id'] = $orow[0]->getID();
|
||||||
$row['brand_name'] = $orow['brand_name'];
|
$row['brand_name'] = $orow['brand_name'];
|
||||||
$row['size_name'] = $orow['size_name'];
|
$row['size_name'] = $orow['size_name'];
|
||||||
|
$row['flag_new'] = $orow[0]->isNew();
|
||||||
|
|
||||||
// add row metadata
|
// add row metadata
|
||||||
$row['meta'] = [
|
$row['meta'] = [
|
||||||
|
|
@ -163,8 +164,10 @@ class SAPBatteryController extends Controller
|
||||||
if (empty($id))
|
if (empty($id))
|
||||||
$error_array['id'] = 'SAP code is required.';
|
$error_array['id'] = 'SAP code is required.';
|
||||||
|
|
||||||
|
$flag_new = $req->request->get('flag_new', false);
|
||||||
// set and save values
|
// set and save values
|
||||||
$row->setID($id);
|
$row->setID($id)
|
||||||
|
->setNew($flag_new);
|
||||||
|
|
||||||
// custom validation for battery brand
|
// custom validation for battery brand
|
||||||
$brand = $em->getRepository(SAPBatteryBrand::class)
|
$brand = $em->getRepository(SAPBatteryBrand::class)
|
||||||
|
|
@ -258,8 +261,10 @@ class SAPBatteryController extends Controller
|
||||||
if (empty($id))
|
if (empty($id))
|
||||||
$error_array['id'] = 'SAP code is required.';
|
$error_array['id'] = 'SAP code is required.';
|
||||||
|
|
||||||
|
$flag_new = $req->request->get('flag_new', false);
|
||||||
// set and save values
|
// set and save values
|
||||||
$row->setID($id);
|
$row->setID($id)
|
||||||
|
->setNew($flag_new);
|
||||||
|
|
||||||
// custom validation for battery brand
|
// custom validation for battery brand
|
||||||
$brand = $em->getRepository(SAPBatteryBrand::class)
|
$brand = $em->getRepository(SAPBatteryBrand::class)
|
||||||
|
|
|
||||||
|
|
@ -45,10 +45,16 @@ class SAPBattery
|
||||||
*/
|
*/
|
||||||
protected $size;
|
protected $size;
|
||||||
|
|
||||||
|
// flag/tag to indicate this SAP battery is the latest/newest
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="boolean")
|
||||||
|
*/
|
||||||
|
protected $flag_new;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->date_create = new DateTime();
|
$this->date_create = new DateTime();
|
||||||
|
$this->flag_latest = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setID($id)
|
public function setID($id)
|
||||||
|
|
@ -93,4 +99,15 @@ class SAPBattery
|
||||||
{
|
{
|
||||||
return $this->size;
|
return $this->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setNew($new = false)
|
||||||
|
{
|
||||||
|
$this->flag_new = $new;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isNew()
|
||||||
|
{
|
||||||
|
return $this->flag_new;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{% extends 'base.html.twig' %}
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<!-- BEGIN: Subheader -->
|
<!-- BEGIN: Subheader -->
|
||||||
<div class="m-subheader">
|
<div class="m-subheader">
|
||||||
<div class="d-flex align-items-center">
|
<div class="d-flex align-items-center">
|
||||||
<div class="mr-auto">
|
<div class="mr-auto">
|
||||||
|
|
@ -14,33 +14,33 @@
|
||||||
<!--Begin::Section-->
|
<!--Begin::Section-->
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xl-12">
|
<div class="col-xl-12">
|
||||||
<div class="m-portlet m-portlet--mobile">
|
<div class="m-portlet m-portlet--mobile">
|
||||||
<div class="m-portlet__head">
|
<div class="m-portlet__head">
|
||||||
<div class="m-portlet__head-caption">
|
<div class="m-portlet__head-caption">
|
||||||
<div class="m-portlet__head-title">
|
<div class="m-portlet__head-title">
|
||||||
<span class="m-portlet__head-icon">
|
<span class="m-portlet__head-icon">
|
||||||
<i class="fa fa-battery-3"></i>
|
<i class="fa fa-battery-3"></i>
|
||||||
</span>
|
</span>
|
||||||
<h3 class="m-portlet__head-text">
|
<h3 class="m-portlet__head-text">
|
||||||
{% if mode == 'update' %}
|
{% if mode == 'update' %}
|
||||||
Edit SAP Battery
|
Edit SAP Battery
|
||||||
<small>{{ obj.getID }}</small>
|
<small>{{ obj.getID }}</small>
|
||||||
{% else %}
|
{% else %}
|
||||||
New SAP Battery
|
New SAP Battery
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<form id="row-form" class="m-form m-form--fit m-form--label-align-right" method="post" action="{{ mode == 'update' ? url('sapbattery_update_submit', {'id': obj.getID }) : url('sapbattery_create_submit') }}">
|
<form id="row-form" class="m-form m-form--fit m-form--label-align-right" method="post" action="{{ mode == 'update' ? url('sapbattery_update_submit', {'id': obj.getID }) : url('sapbattery_create_submit') }}">
|
||||||
<div class="m-portlet__body">
|
<div class="m-portlet__body">
|
||||||
<div class="m-form__section m-form__section--first">
|
<div class="m-form__section m-form__section--first">
|
||||||
<div class="m-form__heading">
|
<div class="m-form__heading">
|
||||||
<h3 class="m-form__heading-title">
|
<h3 class="m-form__heading-title">
|
||||||
Product Details
|
Product Details
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group m-form__group row">
|
<div class="form-group m-form__group row">
|
||||||
<div class="col-lg-4">
|
<div class="col-lg-4">
|
||||||
<label data-field="id">
|
<label data-field="id">
|
||||||
SAP Code
|
SAP Code
|
||||||
|
|
@ -64,31 +64,43 @@
|
||||||
<label data-field="size">
|
<label data-field="size">
|
||||||
Size
|
Size
|
||||||
</label>
|
</label>
|
||||||
<select class="form-control m-input" id="size" name="size">
|
<select class="form-control m-input" id="size" name="size">
|
||||||
<option value=""></option>
|
<option value=""></option>
|
||||||
{% for size in sizes %}
|
{% for size in sizes %}
|
||||||
<option value="{{ size.getID }}"{{ obj.getSize.getID|default(0) == size.getID ? ' selected' }}>{{ size.getName }}</option>
|
<option value="{{ size.getID }}"{{ obj.getSize.getID|default(0) == size.getID ? ' selected' }}>{{ size.getName }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
<div class="form-control-feedback hide" data-field="size"></div>
|
<div class="form-control-feedback hide" data-field="size"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="form-group m-form__group row">
|
||||||
<div class="m-portlet__foot m-portlet__foot--fit">
|
<div class="col-lg-4">
|
||||||
<div class="m-form__actions m-form__actions--solid m-form__actions--right">
|
<span class="m-switch m-switch--icon block-switch">
|
||||||
<div class="row">
|
<label>
|
||||||
<div class="col-lg-12">
|
<input type="checkbox" name="flag_new" id="flag_new" value="1"{{ obj.isNew() ? ' checked' }}>
|
||||||
<button type="submit" class="btn btn-success">Submit</button>
|
<label class="switch-label">New</label>
|
||||||
<a href="{{ url('sapbattery_list') }}" class="btn btn-secondary">Back</a>
|
<span></span>
|
||||||
</div>
|
</label>
|
||||||
</div>
|
</span>
|
||||||
</div>
|
<div class="form-control-feedback hide" data-field="flag_new"></div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</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('sapbattery_list') }}" class="btn btn-secondary">Back</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
|
|
|
||||||
|
|
@ -54,110 +54,126 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script>
|
<script>
|
||||||
$(function() {
|
$(function() {
|
||||||
var options = {
|
var options = {
|
||||||
data: {
|
data: {
|
||||||
type: 'remote',
|
type: 'remote',
|
||||||
source: {
|
source: {
|
||||||
read: {
|
read: {
|
||||||
url: '{{ url("sapbattery_rows") }}',
|
url: '{{ url("sapbattery_rows") }}',
|
||||||
method: 'POST'
|
method: 'POST'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
saveState: {
|
saveState: {
|
||||||
cookie: false,
|
cookie: false,
|
||||||
webstorage: false
|
webstorage: false
|
||||||
},
|
},
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
serverPaging: true,
|
serverPaging: true,
|
||||||
serverFiltering: true,
|
serverFiltering: true,
|
||||||
serverSorting: true
|
serverSorting: true
|
||||||
},
|
},
|
||||||
layout: {
|
layout: {
|
||||||
scroll: true
|
scroll: true
|
||||||
},
|
},
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
field: 'id',
|
field: 'id',
|
||||||
title: 'ID',
|
title: 'ID',
|
||||||
width: 150
|
width: 150
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'image_file',
|
field: 'image_file',
|
||||||
title: '',
|
title: '',
|
||||||
sortable: false,
|
sortable: false,
|
||||||
width: 40,
|
width: 40,
|
||||||
template: function (row, index, datatable) {
|
template: function (row, index, datatable) {
|
||||||
var html = '<div class="user-portrait-sm" style="background-image: url(\'' + (row.image_file ? "/uploads/" + row.image_file : "/assets/images/battery.gif") + '\');"></div>';
|
var html = '<div class="user-portrait-sm" style="background-image: url(\'' + (row.image_file ? "/uploads/" + row.image_file : "/assets/images/battery.gif") + '\');"></div>';
|
||||||
|
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'brand_name',
|
field: 'brand_name',
|
||||||
title: 'Brand',
|
title: 'Brand',
|
||||||
width: 150
|
width: 150
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'size_name',
|
field: 'size_name',
|
||||||
title: 'Size',
|
title: 'Size',
|
||||||
width: 180
|
width: 180
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'Actions',
|
field: 'flag_new',
|
||||||
width: 110,
|
title: 'New',
|
||||||
title: 'Actions',
|
template: function (row, index, datatable) {
|
||||||
sortable: false,
|
var tag = '';
|
||||||
overflow: 'visible',
|
|
||||||
template: function (row, index, datatable) {
|
|
||||||
var actions = '';
|
|
||||||
|
|
||||||
if (row.meta.update_url != '') {
|
if (row.flag_new === true) {
|
||||||
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.id + '" title="Edit"><i class="la la-edit"></i></a>';
|
tag = '<span class="m-badge m-badge--success m-badge--wide">Yes</span>';
|
||||||
}
|
} else {
|
||||||
|
tag = '<span class="m-badge m-badge--danger m-badge--wide">No</span>';
|
||||||
|
}
|
||||||
|
|
||||||
if (row.meta.delete_url != '') {
|
return tag;
|
||||||
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.id + '" title="Delete"><i class="la la-trash"></i></a>';
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return actions;
|
},
|
||||||
},
|
{
|
||||||
}
|
field: 'Actions',
|
||||||
],
|
width: 110,
|
||||||
search: {
|
title: 'Actions',
|
||||||
onEnter: false,
|
sortable: false,
|
||||||
input: $('#data-rows-search'),
|
overflow: 'visible',
|
||||||
delay: 400
|
template: function (row, index, datatable) {
|
||||||
}
|
var actions = '';
|
||||||
};
|
|
||||||
|
|
||||||
var table = $("#data-rows").mDatatable(options);
|
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.id + '" title="Edit"><i class="la la-edit"></i></a>';
|
||||||
|
}
|
||||||
|
|
||||||
$(document).on('click', '.btn-delete', function(e) {
|
if (row.meta.delete_url != '') {
|
||||||
var url = $(this).prop('href');
|
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.id + '" title="Delete"><i class="la la-trash"></i></a>';
|
||||||
var id = $(this).data('id');
|
}
|
||||||
var btn = $(this);
|
|
||||||
|
|
||||||
e.preventDefault();
|
return actions;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
search: {
|
||||||
|
onEnter: false,
|
||||||
|
input: $('#data-rows-search'),
|
||||||
|
delay: 400
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
swal({
|
var table = $("#data-rows").mDatatable(options);
|
||||||
title: 'Confirmation',
|
|
||||||
html: 'Are you sure you want to delete <strong>' + id + '</strong>?',
|
$(document).on('click', '.btn-delete', function(e) {
|
||||||
type: 'warning',
|
var url = $(this).prop('href');
|
||||||
showCancelButton: true
|
var id = $(this).data('id');
|
||||||
}).then((result) => {
|
var btn = $(this);
|
||||||
if (result.value) {
|
|
||||||
$.ajax({
|
e.preventDefault();
|
||||||
method: "DELETE",
|
|
||||||
url: url
|
swal({
|
||||||
}).done(function(response) {
|
title: 'Confirmation',
|
||||||
table.row(btn.parents('tr')).remove();
|
html: 'Are you sure you want to delete <strong>' + id + '</strong>?',
|
||||||
table.reload();
|
type: 'warning',
|
||||||
});
|
showCancelButton: true
|
||||||
}
|
}).then((result) => {
|
||||||
});
|
if (result.value) {
|
||||||
});
|
$.ajax({
|
||||||
});
|
method: "DELETE",
|
||||||
</script>
|
url: url
|
||||||
|
}).done(function(response) {
|
||||||
|
table.row(btn.parents('tr')).remove();
|
||||||
|
table.reload();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue