Integrated Contractconfig Hooks in Contractconfig/Save with restore on

error
This commit is contained in:
Frank Schubert
2023-03-21 22:04:57 +01:00
parent a27d7a7418
commit 61e84f085d
14 changed files with 5956 additions and 86 deletions
+132 -20
View File
@@ -57,30 +57,73 @@
<div class="card-body">
<h4 class="text-center mb-3">Konfiguration bearbeiten</h4>
<?php if(is_array($groups) && count($groups)): ?>
<form method="post" action="<?=self::getUrl("Contractconfig", "Save")?>">
<form id="contract-config-form" method="post" action="<?=self::getUrl("Contractconfig", "Save")?>">
<input type="hidden" name="contract_id" value="<?=$contract->id?>" />
<table class="table table-sm table-borderless view-table">
<?php foreach($groups as $group): ?>
<tr class="bg-light">
<th><h4><u><?=$group->name?></u></h4></td>
<td></td>
</tr>
<?php foreach($group->items as $item): ?>
<tr>
<th style="max-width: 50vw;"><?=$item->displayname?>:</th>
<td style="width: 50vw;">
<?php if($item->type == "enum"): ?>
<select class="form-control" name="itemvalues[<?=$item->id?>]">
<?php foreach($item->getTypedataArray() as $option): ?>
<option value="<?=htmlentities($option)?>" <?=($item->getValue() == $option) ? "selected='selected'" : ""?>><?=htmlentities($option)?></option>
<?php endforeach; ?>
</select>
<?php else: ?>
<input type="text" class="form-control <?=(is_array($error_items) && in_array($item->id, $error_items)) ? "invalid" : ""?>" name="itemvalues[<?=$item->id?>]" value="<?=(isset($request)) ? htmlentities($request->itemvalues[$item->id]) : htmlentities($item->getValue())?>" />
<?php endif; ?>
<small><?=$item->description?></small>
</td>
<tr class="bg-light">
<th><h4><u><?=$group->name?></u></h4></td>
<td></td>
</tr>
<?php foreach($group->items as $item): ?>
<?php
$inputname = "itemvalues[".$item->id."]";
if($item->multiple) {
$inputname .= "[]";
}
$inputid = "itemvalues_".$item->id;
$array_count = 0;
?>
<?php if($item->multiple): ?>
<?php foreach($item->getValue() as $item_value): ?>
<tr id="tr-<?=$inputid?>_<?=$array_count?>">
<th style="max-width: 50vw;"><?=$item->displayname?><span class="array_counter"> (<?=$array_count + 1?>)</span>:</th>
<td style="width: 50vw;">
<input type="text"
class="form-control <?=(is_array($error_items) && in_array($item->id, $error_items)) ? "invalid" : ""?>"
name="<?=$inputname?>"
id="<?=$inputid?>_<?=$array_count?>"
value="<?=(isset($request)) ? htmlentities($request->itemvalues[$item->id][$array_count]) : htmlentities($item_value)?>"
<?=($item->multiple) ? "data-item-multiple='true'" : ""?> />
<small><?=$item->description?></small>
</td>
</tr>
<?php $array_count++; ?>
<?php endforeach; ?>
<tr id="tr-<?=$inputid?>_<?=$array_count?>">
<th style="max-width: 50vw;"><?=$item->displayname?><span class="array_counter"> (<?=$array_count + 1?>)</span>:</th>
<td style="width: 50vw;">
<input type="text"
class="form-control <?=(is_array($error_items) && in_array($item->id, $error_items)) ? "invalid" : ""?>"
name="<?=$inputname?>"
id="<?=$inputid?>_<?=$array_count?>"
value="<?=(isset($request)) ? htmlentities($request->itemvalues[$item->id][$array_count]) : ""?>"
<?=($item->multiple) ? "data-item-multiple='true'" : ""?> />
<small><?=$item->description?></small>
</td>
</tr>
<?php else: ?>
<tr id="tr-<?=$inputid?>_0">
<th style="max-width: 50vw;"><?=$item->displayname?>:</th>
<td style="width: 50vw;">
<?php if($item->type == "enum"): ?>
<select class="form-control" name="<?=$inputname?>" id="<?=$inputid?>" <?=($item->multiple) ? "data-item-multiple='true'" : ""?>>
<?php foreach($item->getTypedataArray() as $option): ?>
<option value="<?=htmlentities($option)?>" <?=($item->getValue() == $option) ? "selected='selected'" : ""?>><?=htmlentities($option)?></option>
<?php endforeach; ?>
</select>
<?php else: ?>
<input type="text"
class="form-control <?=(is_array($error_items) && in_array($item->id, $error_items)) ? "invalid" : ""?>"
name="<?=$inputname?>"
id="<?=$inputid?>_0"
value="<?=(isset($request)) ? htmlentities($request->itemvalues[$item->id]) : htmlentities($item->getValue())?>"
<?=($item->multiple) ? "data-item-multiple='true'" : ""?> />
<?php endif; ?>
<small><?=$item->description?></small>
</td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach; ?>
</table>
@@ -105,4 +148,73 @@
</div>
</div>
<script>
$(document).ready(function() {
$("#contract-config-form input").each(function() {
var input = this;
if(!$(input).attr("name")) return;
//console.log(this);
console.log($(input).attr("name"));
if($(input).data("item-multiple")) {
$(input).change(function() {
addMultipleValueField($(this).prop("id"));
});
}
});
});
function addMultipleValueField(id) {
console.log(id);
var id_match = id.match(/^itemvalues_(\d+)_(\d+)$/);
var elem_id = id_match[1];
var last_elem_count = 0;
var stop = false;
// find last input
$("input[id^=itemvalues_" + elem_id + "_").each(function() {
console.log("input id: " + this.id)
console.log("value: " + $(this).val());
if(!$(this).val()) {
stop = true;
return false;
}
var this_count_match = this.id.match(/^itemvalues_\d+_(\d+)$/);
var this_count = this_count_match[1]
if(this_count.length) {
console.log("last_elem_count: " + last_elem_count);
console.log("this count: " + this_count)
last_elem_count = Math.max(this_count, last_elem_count);
}
});
if(stop) {
return;
}
if(!elem_id.length && !last_elem_count.length) {
return;
}
var new_tr = $("#tr-" + id).clone();
console.log(new_tr);
var new_count = parseInt(last_elem_count) + 1;
new_tr.prop("id", "tr-itemvalues_" + elem_id + "_" + new_count);
new_tr.find("td input[type=text]").prop("id", "itemvalues_" + elem_id + "_" + new_count);
new_tr.find("td input[type=text]").val("");
new_tr.find("td input[type=text]").change(function() {
addMultipleValueField($(this).prop("id"));
});
new_tr.find("span.array_counter").text(" (" + (parseInt(new_count) + 1) + ")");
$(new_tr).insertAfter($("#tr-" + id));
}
</script>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>