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['brand_name'] = $orow['brand_name'];
|
||||
$row['size_name'] = $orow['size_name'];
|
||||
$row['flag_new'] = $orow[0]->isNew();
|
||||
|
||||
// add row metadata
|
||||
$row['meta'] = [
|
||||
|
|
@ -163,8 +164,10 @@ class SAPBatteryController extends Controller
|
|||
if (empty($id))
|
||||
$error_array['id'] = 'SAP code is required.';
|
||||
|
||||
$flag_new = $req->request->get('flag_new', false);
|
||||
// set and save values
|
||||
$row->setID($id);
|
||||
$row->setID($id)
|
||||
->setNew($flag_new);
|
||||
|
||||
// custom validation for battery brand
|
||||
$brand = $em->getRepository(SAPBatteryBrand::class)
|
||||
|
|
@ -258,8 +261,10 @@ class SAPBatteryController extends Controller
|
|||
if (empty($id))
|
||||
$error_array['id'] = 'SAP code is required.';
|
||||
|
||||
$flag_new = $req->request->get('flag_new', false);
|
||||
// set and save values
|
||||
$row->setID($id);
|
||||
$row->setID($id)
|
||||
->setNew($flag_new);
|
||||
|
||||
// custom validation for battery brand
|
||||
$brand = $em->getRepository(SAPBatteryBrand::class)
|
||||
|
|
|
|||
|
|
@ -45,10 +45,16 @@ class SAPBattery
|
|||
*/
|
||||
protected $size;
|
||||
|
||||
// flag/tag to indicate this SAP battery is the latest/newest
|
||||
/**
|
||||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
protected $flag_new;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->date_create = new DateTime();
|
||||
$this->date_create = new DateTime();
|
||||
$this->flag_latest = false;
|
||||
}
|
||||
|
||||
public function setID($id)
|
||||
|
|
@ -93,4 +99,15 @@ class SAPBattery
|
|||
{
|
||||
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' %}
|
||||
|
||||
{% block body %}
|
||||
<!-- BEGIN: Subheader -->
|
||||
<!-- BEGIN: Subheader -->
|
||||
<div class="m-subheader">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="mr-auto">
|
||||
|
|
@ -14,33 +14,33 @@
|
|||
<!--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-battery-3"></i>
|
||||
</span>
|
||||
<h3 class="m-portlet__head-text">
|
||||
{% if mode == 'update' %}
|
||||
Edit SAP Battery
|
||||
<small>{{ obj.getID }}</small>
|
||||
{% else %}
|
||||
New SAP Battery
|
||||
{% endif %}
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<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-battery-3"></i>
|
||||
</span>
|
||||
<h3 class="m-portlet__head-text">
|
||||
{% if mode == 'update' %}
|
||||
Edit SAP Battery
|
||||
<small>{{ obj.getID }}</small>
|
||||
{% else %}
|
||||
New SAP Battery
|
||||
{% endif %}
|
||||
</h3>
|
||||
</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') }}">
|
||||
<div class="m-portlet__body">
|
||||
<div class="m-form__section m-form__section--first">
|
||||
<div class="m-form__heading">
|
||||
<h3 class="m-form__heading-title">
|
||||
Product Details
|
||||
</h3>
|
||||
</div>
|
||||
<div class="form-group m-form__group row">
|
||||
<div class="m-portlet__body">
|
||||
<div class="m-form__section m-form__section--first">
|
||||
<div class="m-form__heading">
|
||||
<h3 class="m-form__heading-title">
|
||||
Product Details
|
||||
</h3>
|
||||
</div>
|
||||
<div class="form-group m-form__group row">
|
||||
<div class="col-lg-4">
|
||||
<label data-field="id">
|
||||
SAP Code
|
||||
|
|
@ -64,31 +64,43 @@
|
|||
<label data-field="size">
|
||||
Size
|
||||
</label>
|
||||
<select class="form-control m-input" id="size" name="size">
|
||||
<option value=""></option>
|
||||
{% for size in sizes %}
|
||||
<option value="{{ size.getID }}"{{ obj.getSize.getID|default(0) == size.getID ? ' selected' }}>{{ size.getName }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<div class="form-control-feedback hide" data-field="size"></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('sapbattery_list') }}" class="btn btn-secondary">Back</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<select class="form-control m-input" id="size" name="size">
|
||||
<option value=""></option>
|
||||
{% for size in sizes %}
|
||||
<option value="{{ size.getID }}"{{ obj.getSize.getID|default(0) == size.getID ? ' selected' }}>{{ size.getName }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<div class="form-control-feedback hide" data-field="size"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row">
|
||||
<div class="col-lg-4">
|
||||
<span class="m-switch m-switch--icon block-switch">
|
||||
<label>
|
||||
<input type="checkbox" name="flag_new" id="flag_new" value="1"{{ obj.isNew() ? ' checked' }}>
|
||||
<label class="switch-label">New</label>
|
||||
<span></span>
|
||||
</label>
|
||||
</span>
|
||||
<div class="form-control-feedback hide" data-field="flag_new"></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('sapbattery_list') }}" class="btn btn-secondary">Back</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
|
|
|
|||
|
|
@ -54,110 +54,126 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
$(function() {
|
||||
var options = {
|
||||
data: {
|
||||
type: 'remote',
|
||||
source: {
|
||||
read: {
|
||||
url: '{{ url("sapbattery_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: 150
|
||||
},
|
||||
{
|
||||
field: 'image_file',
|
||||
title: '',
|
||||
sortable: false,
|
||||
width: 40,
|
||||
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>';
|
||||
<script>
|
||||
$(function() {
|
||||
var options = {
|
||||
data: {
|
||||
type: 'remote',
|
||||
source: {
|
||||
read: {
|
||||
url: '{{ url("sapbattery_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: 150
|
||||
},
|
||||
{
|
||||
field: 'image_file',
|
||||
title: '',
|
||||
sortable: false,
|
||||
width: 40,
|
||||
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>';
|
||||
|
||||
return html;
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'brand_name',
|
||||
title: 'Brand',
|
||||
width: 150
|
||||
},
|
||||
{
|
||||
field: 'size_name',
|
||||
title: 'Size',
|
||||
width: 180
|
||||
},
|
||||
{
|
||||
field: 'Actions',
|
||||
width: 110,
|
||||
title: 'Actions',
|
||||
sortable: false,
|
||||
overflow: 'visible',
|
||||
template: function (row, index, datatable) {
|
||||
var actions = '';
|
||||
return html;
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'brand_name',
|
||||
title: 'Brand',
|
||||
width: 150
|
||||
},
|
||||
{
|
||||
field: 'size_name',
|
||||
title: 'Size',
|
||||
width: 180
|
||||
},
|
||||
{
|
||||
field: 'flag_new',
|
||||
title: 'New',
|
||||
template: function (row, index, datatable) {
|
||||
var tag = '';
|
||||
|
||||
if (row.flag_new === true) {
|
||||
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>';
|
||||
}
|
||||
|
||||
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.id + '" title="Edit"><i class="la la-edit"></i></a>';
|
||||
}
|
||||
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>';
|
||||
}
|
||||
|
||||
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.id + '" title="Delete"><i class="la la-trash"></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.id + '" title="Delete"><i class="la la-trash"></i></a>';
|
||||
}
|
||||
|
||||
return actions;
|
||||
},
|
||||
}
|
||||
],
|
||||
search: {
|
||||
onEnter: false,
|
||||
input: $('#data-rows-search'),
|
||||
delay: 400
|
||||
}
|
||||
};
|
||||
return actions;
|
||||
},
|
||||
}
|
||||
],
|
||||
search: {
|
||||
onEnter: false,
|
||||
input: $('#data-rows-search'),
|
||||
delay: 400
|
||||
}
|
||||
};
|
||||
|
||||
var table = $("#data-rows").mDatatable(options);
|
||||
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);
|
||||
$(document).on('click', '.btn-delete', function(e) {
|
||||
var url = $(this).prop('href');
|
||||
var id = $(this).data('id');
|
||||
var btn = $(this);
|
||||
|
||||
e.preventDefault();
|
||||
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>
|
||||
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