Repository records minor JS refactoring. [SCI-1275]

This commit is contained in:
Matej Zrimšek 2017-06-09 19:33:20 +02:00
parent 29b721365a
commit 514aa6214b

View file

@ -222,45 +222,46 @@ $('form#form-export').submit(function(e) {
$('#form-export').find('input[name=row_ids\\[\\]]').remove(); $('#form-export').find('input[name=row_ids\\[\\]]').remove();
$('#form-export').find('input[name=header_ids\\[\\]]').remove(); $('#form-export').find('input[name=header_ids\\[\\]]').remove();
// Append samples
appendSamplesIdToForm(form);
// Append visible column information // Append visible column information
$('.active table#repository-table thead tr').children('th') $('.active table#repository-table thead tr th').each(function() {
.each(function(i) {
var th = $(this); var th = $(this);
var val; var val;
if ($(th).attr('id') === 'checkbox' || $(th).attr('id') === 'assigned') switch ($(th).attr('id')) {
val = -1 case 'checkbox':
else if ($(th).attr('id') === 'row-name') val = -1;
val = -2; break;
else if ($(th).attr('id') === 'added-by') case 'row-name':
val = -3; val = -2;
else if ($(th).attr('id') === 'added-on') break;
val = -4; case 'added-by':
else val = -3;
val = th.attr('id'); break;
case 'added-on':
val = -4;
break;
default:
val = th.attr('id');
}
if (val) if (val) {
$(form).append( appendInput(form, val, 'header_ids[]');
$('<input>') }
.attr('type', 'hidden') });
.attr('name', 'header_ids[]')
.val(val) // Append records
); $.each(rowsSelected, function(index, rowId) {
appendInput(form, rowId, 'row_ids[]');
}); });
} }
}); });
function appendSamplesIdToForm(form) { function appendInput(form, val, name) {
$.each(rowsSelected, function(index, rowId) { $(form).append(
$(form).append( $('<input>')
$('<input>') .attr('type', 'hidden')
.attr('type', 'hidden') .attr('name', name)
.attr('name', 'row_ids[]') .val(val)
.val(rowId) );
);
});
} }
function initRowSelection() { function initRowSelection() {