mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-12-31 23:39:32 +00:00
Use stimulus collection controller for parts orderdetails
This commit is contained in:
parent
66b7b2e9bf
commit
4847fe2fa3
8 changed files with 108 additions and 75 deletions
|
|
@ -1,17 +1,21 @@
|
|||
{% form_theme form with ['Parts/edit/edit_form_styles.html.twig', "bootstrap_4_layout.html.twig"] %}
|
||||
{# Leave this template at bootstrap 4 for now, as it otherwise destroys our layout #}
|
||||
{% form_theme form.orderdetails with ['Parts/edit/edit_form_styles.html.twig', "bootstrap_4_layout.html.twig"] %}
|
||||
{% import 'components/collection_type.macro.html.twig' as collection %}
|
||||
|
||||
<table class="table table-striped table-sm table-responsive-md" id="orderdetails_table" data-prototype="{% if form.orderdetails.vars.prototype is defined %}{{ form_widget(form.orderdetails.vars.prototype)|e('html_attr') }}{% endif %}">
|
||||
<tbody>
|
||||
{% for detail in form.orderdetails %}
|
||||
{{ form_widget(detail, {'disable_delete' : not is_granted('orderdetails.delete', part)}) }}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<div {{ collection.controller(form.orderdetails, 'orderdetails.edit.delete.confirm') }}>
|
||||
<table class="table table-striped table-sm table-responsive-md" id="orderdetails_table" {{ collection.target() }}>
|
||||
<tbody>
|
||||
{% for detail in form.orderdetails %}
|
||||
{{ form_widget(detail, {'disable_delete' : not is_granted('orderdetails.delete', part)}) }}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<button type="button" class="btn btn-success" onclick="create_orderdetail_entry(this)" {% if not is_granted('orderdetails.create', part) %}disabled{% endif %}>
|
||||
<i class="fas fa-plus-square fa-fw"></i>
|
||||
{% trans %}orderdetail.create{% endtrans %}
|
||||
</button>
|
||||
<button type="button" class="btn btn-success" {{ collection.create_btn() }} {% if not is_granted('orderdetails.create', part) %}disabled{% endif %}>
|
||||
<i class="fas fa-plus-square fa-fw"></i>
|
||||
{% trans %}orderdetail.create{% endtrans %}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function delete_pricedetail_entry(btn) {
|
||||
|
|
@ -40,7 +44,7 @@
|
|||
var new_min_amount = $("input[id$='min_discount_quantity_value']" , $holder).last().val();
|
||||
//Assign a valid value, if no price are existing yet
|
||||
if (typeof new_min_amount == "undefined") {
|
||||
new_min_amount = 0;
|
||||
new_min_amount = 0;
|
||||
}
|
||||
new_min_amount = parseInt(new_min_amount) + 1;
|
||||
//Determine the next exponent, 10 -> 100 -> 1000
|
||||
|
|
@ -53,25 +57,4 @@
|
|||
$("#" + price_related_id).val("1");
|
||||
|
||||
}
|
||||
|
||||
function delete_orderdetail_entry(btn) {
|
||||
window.bootbox.confirm('{% trans %}orderdetails.edit.delete.confirm{% endtrans %}', function (result) {
|
||||
if(result) {
|
||||
$(btn).parents("tr").remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function create_orderdetail_entry(btn) {
|
||||
//Determine the table, so we can determine, how many entries there are already.
|
||||
$holder = $("#orderdetails_table");
|
||||
|
||||
var index = $holder.children("tbody").children("tr").length;
|
||||
var newForm = $holder.data("prototype");
|
||||
|
||||
//Increase the index
|
||||
newForm = newForm.replace(/__name__/g, index);
|
||||
|
||||
$holder.children("tbody").append(newForm);
|
||||
}
|
||||
</script>
|
||||
Loading…
Add table
Add a link
Reference in a new issue