ogcp.js: Fix bug when adding a new partition

Fix a bug that made the 'add a new partition' button unusable if all
partitions (rows) were deleted.

The reason for this bug was that the AddPartition() function would add a
new partition by cloning an already present html row element. This would
fail if no more rows were present in the table.

The solution implemented checks, previous to delete a partition, if it
is the last partition. If it is, then, instead of removing the whole
row, it just empties it.

Html button element needs to contain 'type="button"' attribute for this to
work. Otherwise, default action for the button is submit and it would
redirect after clicking.
master
Javier Hernandez 2023-12-11 11:40:12 +01:00 committed by OpenGnSys Support Team
parent ddfaae0ef6
commit cc5c0105db
2 changed files with 16 additions and 8 deletions

View File

@ -300,15 +300,23 @@ function AddPartition(evt) {
function RemovePartition(evt) {
const target = $(evt).parent().parent();
const table = target.parent();
target.remove();
// Reassign rows ids
table.find('tr').each(function(index) {
$(this).find('.form-control').each(function() {
const id = $(this).attr('id').replace(/(.*)-(\d{1,4})-(.*)/, `$1-${index}-$3`);
$(this).attr('name', id).attr('id', id);
if (table[0].children.length > 1) {
target.remove();
// Reassign rows ids
table.find('tr').each(function(index) {
$(this).find('.form-control').each(function() {
const id = $(this).attr('id').replace(/(.*)-(\d{1,4})-(.*)/, `$1-${index}-$3`);
$(this).attr('name', id).attr('id', id);
});
});
});
} else {
table.find('tr').each(function(index) {
$(this).find('.form-control').each(function() {
$(this).val('').removeAttr("checked");
});
});
}
}
function checkImageServer() {

View File

@ -62,7 +62,7 @@
<td>{{ partition.size(class_="form-control") }}</td>
<td>{{ partition.format_partition(class_="form-control") }}</td>
<td>
<button class="btn btn-danger" onclick="RemovePartition(this)">
<button class="btn btn-danger" type="button" onclick="RemovePartition(this)">
{{ _('Remove') }}
</button>
</td>