From 1ba6cc3344d05b899bf87f4e9290d1e2a31d8bfa Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Thu, 16 Sep 2021 22:19:28 +0200 Subject: [PATCH] removing passive finish when required field is empty --- Layout/default/Linework/Index.php | 88 +++++++++++++++++---- application/Workflowvalue/Workflowvalue.php | 8 +- 2 files changed, 77 insertions(+), 19 deletions(-) diff --git a/Layout/default/Linework/Index.php b/Layout/default/Linework/Index.php index fcf65bfc5..29d164cc3 100644 --- a/Layout/default/Linework/Index.php +++ b/Layout/default/Linework/Index.php @@ -175,7 +175,10 @@
- + +
+ @@ -208,7 +211,7 @@ -
$filter, "s" => $pagination['start']])?>" enctype="multipart/form-data" > + $filter, "s" => $pagination['start']])?>" enctype="multipart/form-data"> workflowitems as $item): ?> @@ -339,17 +342,43 @@ $(document).ready(function() { var pos = $('#termination-' + term).offset().top; $(window).scrollTop(pos - 150 ); } + + $('input[name=wfitemplaceholder_customer_passive_finished]').each(function() { + var elem = this; + //console.log(elem); + $(elem).click(function() { + var id_match = $(this).attr("id").match(/wfitemplaceholder_customer_passive_finished_(\d+)$/); + var id = id_match[1]; + //console.log(id); + + validateWorkflowItem(id); + }); + + }); + + $('form[id^="wf-termination-"]').each(function() { + var elem = this; + console.log(elem); + $(elem).submit(function(e) { + + console.log(this); + var id_match = $(this).attr("name").match(/wf-termination-(\d+)$/); + var id = id_match[1]; + if(canSubmit(id)) { + return true; + } else { + e.preventDefault(); + return false; + } + }); + }); + + }); -$('input[name=wfitemplaceholder_customer_passive_finished]').each(function() { - var elem = this; - //console.log(elem); - $(elem).click(function() { - var id_match = $(this).attr("id").match(/wfitemplaceholder_customer_passive_finished_(\d+)$/); - var id = id_match[1]; - //console.log(id); - - required_fields = { + +function validateWorkflowItem(id) { + var required_fields = { pop_id: "int", schrank: "string", baugruppe: "string", @@ -372,14 +401,13 @@ $('input[name=wfitemplaceholder_customer_passive_finished]').each(function() { var missing = false; for(var field1 in required_fields) { - field2 = "ist_" + field1; - type = required_fields[field1]; + var field2 = "ist_" + field1; + var type = required_fields[field1]; var val1 = $("#wfitem_" + field1 + "_" + id).val(); + var val2 = true; if($("#wfitem_" + field2 + "_" + id).length) { var val2 = $("#wfitem_" + field2 + "_" + id).val(); - } else { - val2 = true; } if(type == "bool") { @@ -400,15 +428,41 @@ $('input[name=wfitemplaceholder_customer_passive_finished]').each(function() { if(missing) { $("#wfitemplaceholder_customer_passive_finished_" + id).prop('checked', false); + $("#wfitem_customer_passive_finished_" + id).val(0); $("#wfitemplaceholder_customer_passive_finished_" + id).attr("readonly", true); + } else { $("#wfitemplaceholder_customer_passive_finished_" + id).attr("disabled", false); + $("#wfitem_customer_passive_finished_" + id).val(1); $("#wfitemplaceholder_customer_passive_finished_" + id).prop('readonly', true); + $("#wf-submit-error-" + id).hide(); } + + return !missing; +} - }); -}); + + function canSubmit(id) { + if($("#wfitemplaceholder_customer_passive_finished_" + id).prop('checked')) { + if(!validateWorkflowItem(id)) { + console.log("cant submit"); + $("#wf-submit-error-" + id).show(); + return false; + } + } + console.log("can submit"); + $("#wf-submit-error-" + id).hide(); + return true; + } + + function validateAndSubmit(id) { + //e.preventDefault(); + if(canSubmit(id)) { + $('#wf-termination-' + id).trigger("submit"); + } + return true; + } diff --git a/application/Workflowvalue/Workflowvalue.php b/application/Workflowvalue/Workflowvalue.php index 98f433d74..f0f67580a 100644 --- a/application/Workflowvalue/Workflowvalue.php +++ b/application/Workflowvalue/Workflowvalue.php @@ -72,15 +72,19 @@ class Workflowvalue extends mfBaseModel { } } + /*if($this->item->name == "customer_passive_finished") { + var_dump($value, $this->{"value_".$value_type});exit; + }*/ + if($value === null) { return true; } - if($value_type == "int" && !$value) { + if($value_type == "int" && $this->{"value_".$value_type} == null && !$value) { return true; } - if($this->item->type == "bool" && $this->{"value_".$value_type} = null && $value == 0) { + if($this->item->type == "bool" && $this->{"value_".$value_type} == null && $value == 0) { return true; }