Compare commits

...

3 commits

Author SHA1 Message Date
Korina Cordero
9db833f0b5 Add saving of status. Add Active column for list of battery models. #732 2023-02-02 01:49:30 +00:00
Korina Cordero
57b5fcf7ed Add active flag to create battery model form. #732 2023-02-01 10:41:57 +00:00
Korina Cordero
f5c351b179 Add flag_active to battery model. #732 2023-02-01 10:10:51 +00:00
4 changed files with 84 additions and 33 deletions

View file

@ -88,6 +88,7 @@ class BatteryModelController extends Controller
// add row data
$row['id'] = $orow->getID();
$row['name'] = $orow->getName();
$row['flag_active'] = $orow->isActive();
// add row metadata
$row['meta'] = [
@ -134,7 +135,8 @@ class BatteryModelController extends Controller
$row = new BatteryModel();
// set and save values
$row->setName($req->request->get('name'));
$row->setName($req->request->get('name'))
->setActive($req->request->get('flag_active', false));
// validate
$errors = $validator->validate($row);
@ -202,7 +204,8 @@ class BatteryModelController extends Controller
throw $this->createNotFoundException('The item does not exist');
// set and save values
$row->setName($req->request->get('name'));
$row->setName($req->request->get('name'))
->setActive($req->request->get('flag_active', false));
// validate
$errors = $validator->validate($row);

View file

@ -33,9 +33,17 @@ class BatteryModel
*/
protected $batteries;
// flag if model is active
/**
* @ORM\Column(type="boolean", options={"default": true})
*/
protected $flag_active;
public function __construct()
{
$this->batteries = new ArrayCollection();
$this->flag_active = true;
}
public function getID()
@ -76,4 +84,15 @@ class BatteryModel
return $str_batteries;
}
public function isActive()
{
return $this->flag_active;
}
public function setActive($flag_active = true)
{
$this->flag_active = $flag_active;
return $this;
}
}

View file

@ -14,37 +14,51 @@
<!--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="fa fa-cube"></i>
</span>
<h3 class="m-portlet__head-text">
{% if mode == 'update' %}
Edit Model
<small>{{ obj.getName() }}</small>
{% else %}
New Model
{% 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-cube"></i>
</span>
<h3 class="m-portlet__head-text">
{% if mode == 'update' %}
Edit Model
<small>{{ obj.getName() }}</small>
{% else %}
New Model
{% 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('bmodel_update_submit', {'id': obj.getId()}) : url('bmodel_create_submit') }}">
<div class="m-portlet__body">
<div class="form-group m-form__group row">
<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>
<span class="m-form__help">Display name for this model</span>
</div>
</div>
</div>
<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>
<span class="m-form__help">Display name for this model</span>
</div>
</div>
<div class="form-group m-form__group row">
<div class="col-lg-3">
</div>
<div class="col-lg-9">
<span class="m-switch m-switch--icon block-switch">
<label>
<input type="checkbox" name="flag_active" id="flag_active" value="1"{{ obj.isActive() ? ' checked' }}>
<label class="switch-label">Active</label>
<span></span>
</label>
</span>
<div class="form-control-feedback hide" data-field="flag_active"></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">

View file

@ -87,6 +87,21 @@
field: 'name',
title: 'Name'
},
{
field: 'flag_active',
title: 'Active',
template: function (row, index, datatable) {
var tag = '';
if (row.flag_active === 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,
@ -143,4 +158,4 @@
});
});
</script>
{% endblock %}
{% endblock %}