Koha/koha-tmpl/intranet-tmpl/prog/js/elasticsearch-mappings.js
Owen Leonard ab495c64bd Bug 30000: Replace the use of jQueryUI tabs on the search engine configuration page
This patch replaces jQueryUI tabs on the search engine configuration
page, replacing them with Bootstrap tabs.

To test, apply the patch and go to Administration -> Search engine
configuration.

- The "Search fields" tab should be selected by default, and the table
  should be initialized as a DataTable with sorting and filtering.
- When you switch to the "Bibliographic records" and "Authorities" tabs
  the tables on those tabs should also be initialized, each with
  filtering and drag-and-drop row re-ordering.
- All tables should continue to work correctly after switching back and
  forth between tabs.

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
2022-03-24 14:22:09 -10:00

91 lines
3.1 KiB
JavaScript

/* global __ dataTablesDefaults */
function clean_line(line) {
$(line).find('input[type="text"]').val("");
$(line).find('select').find('option:first').attr("selected", "selected");
}
function clone_line(line) {
var new_line = $(line).clone();
$(new_line).removeClass("nodrag nodrop");
$(new_line).find('td:last-child>a').removeClass("add").addClass("delete").html( __("Delete") );
$(new_line).find('[data-id]').each(function () {
$(this).attr({ name: $(this).attr('data-id') }).removeAttr('data-id');
});
$(new_line).find("select").each(function () {
var attr = $(this).attr('name');
var val = $(line).find('[data-id="' + attr + '"]').val();
$(this).find('option[value="' + val + '"]').attr("selected", "selected");
});
return new_line;
}
function tableInit( oldtabid, newtabid ) {
if ( oldtabid ){
var oldTableId = $("#" + oldtabid + "_table");
oldTableId.DataTable().destroy();
}
var newTableId = $("#" + newtabid + "_table");
newTableId.DataTable(
$.extend(true, {}, dataTablesDefaults, {
"columnDefs": [
{ "orderable": false, "searchable": false, 'targets': ['NoSort'] },
],
"paging": false,
"autoWidth": false
}));
}
$(document).ready(function () {
tableInit( "", "search_fields");
$("a[data-toggle='tab']").on("shown.bs.tab", function (e) {
var oldtabid = $(e.relatedTarget).data("tab");
var newtabid = $(e.target).data("tab");
tableInit( oldtabid, newtabid );
});
$('.delete').click(function () {
if ($(this).hasClass('mandatory') && $(".mandatory[data-field_name=" + $(this).attr('data-field_name') + "]").length < 2) {
alert( __("This field is mandatory and must have at least one mapping") );
return;
} else {
$(this).parents('tr').remove();
}
});
$("table.mappings").tableDnD({
onDragClass: "dragClass highlighted-row",
});
$('.add').click(function () {
var table = $(this).closest('table');
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();
});
clean_line(line);
$(table).tableDnD({
onDragClass: "dragClass highlighted-row",
});
}
});
$("#facet_biblios > table").tableDnD({
onDragClass: "dragClass highlighted-row",
});
$("#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();
return true;
});
});