Owen Leonard
c9b4abac0f
This patch adds DataTables options to the tables on the search engine configuration pages. The table on the "Search fields" tab will be sortable, all tables will be searchable, and all tables will have floating headers. To test you should have the SearchEngine preference set to "Elasticsearch." - Apply the patch and go to Administration -> Search engine configuration (Elasticsearch) - Test the tables under each tab, "Search fields," "Bibliographic records," and "Authorities," the table has a search filter and the header row "sticks" to the top of the browser window as you scroll down. - The "Search fields" table should be sortable, but the other two should not--they have drag-and-drop row reordering. Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
83 lines
2.6 KiB
JavaScript
83 lines
2.6 KiB
JavaScript
/* global __ */
|
|
|
|
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 ) {
|
|
|
|
var oldTableId = $("#" + oldtabid + "_table");
|
|
var newTableId = $("#" + newtabid + "_table");
|
|
|
|
oldTableId.DataTable().destroy();
|
|
newTableId.DataTable(
|
|
$.extend(true, {}, dataTablesDefaults, {
|
|
"columnDefs": [
|
|
{ "orderable": false, "searchable": false, 'targets': ['NoSort'] },
|
|
],
|
|
"paging": false,
|
|
"autoWidth": false
|
|
}));
|
|
}
|
|
|
|
$(document).ready(function () {
|
|
|
|
tableInit( "", "search_fields");
|
|
|
|
$("#tabs").tabs({
|
|
activate: function( event, ui ){
|
|
tableInit( ui.oldPanel.attr('id'), ui.newPanel.attr('id') );
|
|
},
|
|
});
|
|
|
|
$('.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",
|
|
});
|
|
|
|
$('.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",
|
|
});
|
|
}
|
|
});
|
|
$("#facet_biblios > table").tableDnD({
|
|
onDragClass: "dragClass",
|
|
});
|
|
});
|