removing passive finish when required field is empty
This commit is contained in:
@@ -175,7 +175,10 @@
|
||||
</label>
|
||||
</div>
|
||||
<div class="mt-3">
|
||||
<button type="button" class="btn btn-primary" form="wf-termination-<?=$term->id?>" onclick="document.getElementById(this.getAttribute('form')).submit()">Speichern</button>
|
||||
<button type="button" class="btn btn-primary" form="wf-termination-<?=$term->id?>" onclick="validateAndSubmit(<?=$term->id?>)">Speichern</button>
|
||||
</div>
|
||||
<div class="text-danger hidden mt-2" id="wf-submit-error-<?=$term->id?>">
|
||||
Nicht fertiggestellt.
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
@@ -208,7 +211,7 @@
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<form method="post" name="wf-termination-<?=$term->id?>" id="wf-termination-<?=$term->id?>" action="<?=self::getUrl("Linework","save", ["filter" => $filter, "s" => $pagination['start']])?>" enctype="multipart/form-data" >
|
||||
<form method="post" name="wf-termination-<?=$term->id?>" id="wf-termination-<?=$term->id?>" action="<?=self::getUrl("Linework","save", ["filter" => $filter, "s" => $pagination['start']])?>" enctype="multipart/form-data">
|
||||
<input type="hidden" name="id" value="<?=$term->id?>" />
|
||||
<table class="table workflow-table">
|
||||
<?php $i = 0; foreach($term->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;
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user