diff --git a/assets/controllers/elements/collection_type_controller.js b/assets/controllers/elements/collection_type_controller.js
index f0fd09ba..29d00cb2 100644
--- a/assets/controllers/elements/collection_type_controller.js
+++ b/assets/controllers/elements/collection_type_controller.js
@@ -30,6 +30,7 @@ export default class extends Controller {
return long.slice(0, 6); // 6 characters is enough for our unique IDs here
}
+
/**
* Create a new entry in the target using the given prototype value
*/
@@ -50,6 +51,50 @@ export default class extends Controller {
}
}
+ /**
+ * Similar to createEvent Pricedetails need some special handling to fill min amount
+ * @param event
+ */
+ createPricedetail(event) {
+ //First insert our new element
+ this.createElement(event);
+
+ const extractElementsFromRow = (row) => {
+ const priceRelated = row.querySelector("input[id$='price_related_quantity_value']");
+ const minDiscount = row.querySelector("input[id$='min_discount_quantity_value']");
+
+ return [priceRelated, minDiscount];
+ }
+
+ const targetTable = this.targetTarget;
+ const targetRows = targetTable.tBodies[0].rows;
+ const targetRowsCount = targetRows.length;
+
+ //If we just have one element we dont have to do anything as 1 is already the default
+ if(targetRowsCount <= 1) {
+ return;
+ }
+
+ //Our new element is the last child of the table
+ const newlyCreatedRow = targetRows[targetRowsCount - 1];
+ const [newPriceRelated, newMinDiscount] = extractElementsFromRow(newlyCreatedRow);
+
+ const oldRow = targetRows[targetRowsCount - 2];
+ const [oldPriceRelated, oldMinDiscount] = extractElementsFromRow(oldRow);
+
+ //Use the old PriceRelated value to determine the next 10 decade value for the new row
+ const oldMinAmount = parseInt(oldMinDiscount.value)
+ //The next 10 power can be achieved by creating a string beginning with "1" and adding 0 times the length of the old string
+ const oldMinAmountLength = oldMinAmount.toString().length;
+ const newMinAmountStr = '1' + '0'.repeat(oldMinAmountLength);
+ //Parse the sting back to an integer and we have our new min amount
+ const newMinAmount = parseInt(newMinAmountStr);
+
+
+ //Assign it to our new element
+ newMinDiscount.value = newMinAmount;
+ }
+
deleteElement(event) {
bootbox.confirm(this.deleteMessageValue, (result) => {
if(result) {
diff --git a/assets/controllers/elements/selectpicker_controller.js b/assets/controllers/elements/selectpicker_controller.js
index 13bcde81..182a2e35 100644
--- a/assets/controllers/elements/selectpicker_controller.js
+++ b/assets/controllers/elements/selectpicker_controller.js
@@ -3,6 +3,7 @@ require('bootstrap-select/js/bootstrap-select'); // we have to manually require
import {Controller} from "@hotwired/stimulus";
import "bootstrap-select/dist/css/bootstrap-select.css";
+import "../../css/selectpicker_extensions.css";
export default class extends Controller {
connect() {
diff --git a/assets/css/app.css b/assets/css/app.css
index dc4a8fee..168c9076 100644
--- a/assets/css/app.css
+++ b/assets/css/app.css
@@ -857,17 +857,3 @@ div.dataTables_wrapper div.dataTables_info {
width: 100%;
}
-/***********************************************
- * Special level whitespace characters that only show up when inside a bootstrap-select dropdown
- ***********************************************/
-.dropdown-item span.picker-level::after {
- content: "\00a0\00a0\00a0"; /* 3 spaces */
-}
-
-/** Bootstrap-select Hide on Selected element */
-.picker-hs {
- display: none;
-}
-.dropdown-item .picker-hs {
- display: inherit;
-}
\ No newline at end of file
diff --git a/assets/css/selectpicker_extensions.css b/assets/css/selectpicker_extensions.css
new file mode 100644
index 00000000..925ab592
--- /dev/null
+++ b/assets/css/selectpicker_extensions.css
@@ -0,0 +1,14 @@
+/***********************************************
+ * Special level whitespace characters that only show up when inside a bootstrap-select dropdown
+ ***********************************************/
+.dropdown-item span.picker-level::after {
+ content: "\00a0\00a0\00a0"; /* 3 spaces */
+}
+
+/** Bootstrap-select Hide on Selected element */
+.picker-hs {
+ display: none;
+}
+.dropdown-item .picker-hs {
+ display: inherit;
+}
\ No newline at end of file
diff --git a/templates/Parts/edit/_lots.html.twig b/templates/Parts/edit/_lots.html.twig
index 9ed6602d..1a4b436d 100644
--- a/templates/Parts/edit/_lots.html.twig
+++ b/templates/Parts/edit/_lots.html.twig
@@ -1,7 +1,3 @@
-{% set delete_btn %}
-
-{% endset %}
-
{% form_theme form with ['Parts/edit/edit_form_styles.html.twig'] %}
{% import 'components/collection_type.macro.html.twig' as collection %}
diff --git a/templates/Parts/edit/_orderdetails.html.twig b/templates/Parts/edit/_orderdetails.html.twig
index a2cc8404..bfe09d2c 100644
--- a/templates/Parts/edit/_orderdetails.html.twig
+++ b/templates/Parts/edit/_orderdetails.html.twig
@@ -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 %}
-
-
- {% for detail in form.orderdetails %}
- {{ form_widget(detail, {'disable_delete' : not is_granted('orderdetails.delete', part)}) }}
- {% endfor %}
-
-
+
+
+
+ {% for detail in form.orderdetails %}
+ {{ form_widget(detail, {'disable_delete' : not is_granted('orderdetails.delete', part)}) }}
+ {% endfor %}
+
+
-
+
+
\ No newline at end of file
diff --git a/templates/Parts/edit/edit_form_styles.html.twig b/templates/Parts/edit/edit_form_styles.html.twig
index 55245411..04fe0e5a 100644
--- a/templates/Parts/edit/edit_form_styles.html.twig
+++ b/templates/Parts/edit/edit_form_styles.html.twig
@@ -1,5 +1,6 @@
{% block pricedetail_widget %}
{% form_theme form.currency 'Form/extendedBootstrap4_layout.html.twig' %}
+ {% import 'components/collection_type.macro.html.twig' as collection %}