Added a basic possibility to create/edit/delete specifications for parts.

This commit is contained in:
Jan Böhmer 2020-03-08 22:46:29 +01:00
parent 502febb008
commit a6e0f1738b
15 changed files with 1359 additions and 765 deletions

View file

@ -0,0 +1,53 @@
{% form_theme form with ['Parts/edit/edit_form_styles.html.twig', "bootstrap_4_layout.html.twig"] %}
<table class="table table-striped table-sm table-responsive-md" id="specifications_table" data-prototype="{% if form.specifications.vars.prototype is defined %}{{ form_widget(form.specifications.vars.prototype)|e('html_attr') }}{% endif %}">
<thead>
<tr>
<th>{% trans %}specifications.property{% endtrans %}</th>
<th>{% trans %}specifications.symbol{% endtrans %}</th>
<th>{% trans %}specifications.value_min{% endtrans %}</th>
<th>{% trans %}specifications.value_typ{% endtrans %}</th>
<th>{% trans %}specifications.value_max{% endtrans %}</th>
<th>{% trans %}specifications.unit{% endtrans %}</th>
<th>{% trans %}specifications.text{% endtrans %}</th>
<th></th>
</tr>
</thead>
<tbody>
{% for spec in form.specifications %}
{{ form_widget(spec) }}
{% endfor %}
</tbody>
</table>
<button type="button" class="btn btn-success" onclick="create_specification_entry(this)" {% if not is_granted('orderdetails.create', part) %}disabled{% endif %}>
<i class="fas fa-plus-square fa-fw"></i>
{% trans %}specification.create{% endtrans %}
</button>
<script>
function delete_specification_entry(btn) {
window.bootbox.confirm('{% trans %}pricedetails.edit.delete.confirm{% endtrans %}', function (result) {
if(result) {
$(btn).closest("tr").remove();
}
});
}
function create_specification_entry(btn) {
//Determine the table, so we can determine, how many entries there are already.
$holder = $(btn).siblings("table");
var index = $holder.find(":input").length;
var newForm = $holder.data("prototype");
//Increase the index
newForm = newForm.replace(/__name__/g, index);
$holder.children("tbody").append(newForm);
//Reinit the selectpickers
//$(".selectpicker").selectpicker();
}
</script>

View file

@ -62,4 +62,22 @@
{{ form_errors(form) }}
</td>
</tr>
{% endblock %}
{% block specification_widget %}
<tr>
<td>{{ form_widget(form.name) }}{{ form_errors(form.name) }}</td>
<td>{{ form_widget(form.symbol) }}{{ form_errors(form.symbol) }}</td>
<td>{{ form_widget(form.value_min) }}{{ form_errors(form.value_min) }}</td>
<td>{{ form_widget(form.value_typical) }}{{ form_errors(form.value_typical) }}</td>
<td>{{ form_widget(form.value_max) }}{{ form_errors(form.value_max) }}</td>
<td>{{ form_widget(form.unit) }}{{ form_errors(form.unit) }}</td>
<td>{{ form_widget(form.value_text) }}{{ form_errors(form.value_text) }}</td>
<td>
<button type="button" class="btn btn-danger order_btn_delete" onclick="delete_specification_entry(this);" title="{% trans %}orderdetail.delete{% endtrans %}">
<i class="fas fa-trash-alt fa-fw"></i>
</button>
{{ form_errors(form) }}
</td>
</tr>
{% endblock %}

View file

@ -52,6 +52,12 @@
{% trans %}part.edit.tab.orderdetails{% endtrans %}
</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" role="tab" href="#specifications">
<i class="fas fa-atlas fa-fw"></i>
{% trans %}part.edit.tab.specifications{% endtrans %}
</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" role="tab" href="#comment">
<i class="fas fa-sticky-note fa-fw"></i>
@ -81,6 +87,9 @@
<div class="tab-pane fade p-2" id="orderdetails" role="tabpanel">
{% include "Parts/edit/_orderdetails.html.twig" %}
</div>
<div class="tab-pane fade p-2" id="specifications" role="tabpanel">
{% include "Parts/edit/_specifications.html.twig" %}
</div>
<div class="tab-pane fade p-2" id="comment" role="tabpanel">
{{ form_widget(form.comment)}}
</div>