Bug 30584: Fix ES mapping creation

We need to tell DT that we are adding/removing row, not only deal
manually with the DOM.

This patch also fixes the following bug: if you add or remove a row from
the "biblio" tab, then go to another tab and back to "biblio", all
changes were gone (bug existed prior to bug 29893).

Test plan:
Add, edit and remove mappings, switch from tabs and save.
Use the filters, save (29893 regression test)

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Jonathan Druart 2022-04-21 19:23:14 +02:00 committed by Fridolin Somers
parent 83da2adc72
commit d3101bb5dc

View file

@ -52,7 +52,9 @@ $(document).ready(function () {
alert( __("This field is mandatory and must have at least one mapping") );
return;
} else {
$(this).parents('tr').remove();
var table = $(this).closest('table');
let dt = $(table).DataTable();
dt.row( $(this).closest('tr') ).remove().draw();
}
});
@ -62,15 +64,22 @@ $(document).ready(function () {
$('.add').click(function () {
var table = $(this).closest('table');
let table_id = table.attr('id');
var index_name = $(table).attr('data-index_name');
var line = $(this).closest("tr");
var marc_field = $(line).find('input[data-id="mapping_marc_field"]').val();
if (marc_field.length > 0) {
var new_line = clone_line(line);
new_line.appendTo($('table[data-index_name="' + index_name + '"]>tbody'));
$('.delete').click(function () {
$(this).parents('tr').remove();
});
let dt = $('#' + table_id).DataTable();
dt.row.add(new_line).draw();
$(table).on( 'click', '.delete', function () {
var table = $(this).closest('table');
let dt = $(table).DataTable();
dt.row( $(this).closest('tr') ).remove().draw();
} );
clean_line(line);
$(table).tableDnD({
@ -83,9 +92,20 @@ $(document).ready(function () {
});
$("#es_mappings").on("submit", function(e){
$("#search_fields_table").DataTable({ paging: false }).search('').draw();
$("#mapping_biblios_table").DataTable({ paging: false }).search('').draw();
$("#mapping_authorities_table").DataTable({ paging: false }).search('').draw();
let table_ids = ['search_fields_table', 'mapping_biblios_table', 'mapping_authorities_table'];
$(table_ids).each(function(){
let table;
// Remove warning "Cannot reinitialise DataTable"
if ( $.fn.dataTable.isDataTable( '#' + this ) ) {
table = $('#' + this).DataTable();
}
else {
table = $('#' + this).DataTable( {
paging: false
} );
}
table.search('').draw();
});
return true;
});
});