2016-02-12 23:52:43 +08:00
|
|
|
var previousIndex;
|
|
|
|
var disabledOptions;
|
2017-05-18 15:19:44 +08:00
|
|
|
var loadingSamples = false;
|
|
|
|
$('select').focus(function() {
|
2016-02-12 23:52:43 +08:00
|
|
|
previousIndex = $(this)[0].selectedIndex;
|
2017-05-18 15:19:44 +08:00
|
|
|
}).change(function() {
|
2016-02-12 23:52:43 +08:00
|
|
|
var currSelect = $(this);
|
|
|
|
var currIndex = $(currSelect)[0].selectedIndex;
|
|
|
|
|
2017-05-18 15:19:44 +08:00
|
|
|
$('select').each(function() {
|
2016-02-12 23:52:43 +08:00
|
|
|
if (currSelect !== $(this) && currIndex > 0) {
|
2017-05-18 15:19:44 +08:00
|
|
|
$(this).children().eq(currIndex).attr('disabled', 'disabled');
|
2016-02-12 23:52:43 +08:00
|
|
|
}
|
|
|
|
|
2017-05-18 15:19:44 +08:00
|
|
|
$(this).children().eq(previousIndex).removeAttr('disabled');
|
2016-02-12 23:52:43 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
previousIndex = currIndex;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Create import samples ajax
|
2017-05-18 15:19:44 +08:00
|
|
|
$('form#form-import')
|
2016-02-12 23:52:43 +08:00
|
|
|
.submit(function(e) {
|
2017-05-18 15:19:44 +08:00
|
|
|
// Check if we already uploading samples
|
|
|
|
if (loadingSamples) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-12 23:52:43 +08:00
|
|
|
disabledOptions = $("option[disabled='disabled']");
|
2017-05-18 15:19:44 +08:00
|
|
|
disabledOptions.removeAttr('disabled');
|
|
|
|
loadingSamples = true;
|
|
|
|
animateSpinner();
|
2016-02-12 23:52:43 +08:00
|
|
|
})
|
2017-05-18 15:19:44 +08:00
|
|
|
.on('ajax:success', function(ev, data, status) {
|
2016-02-12 23:52:43 +08:00
|
|
|
// Simply reload page to show flash and updated samples list
|
2017-05-18 15:19:44 +08:00
|
|
|
loadingSamples = false;
|
2016-02-12 23:52:43 +08:00
|
|
|
location.reload();
|
|
|
|
})
|
2017-05-18 15:19:44 +08:00
|
|
|
.on('ajax:error', function(ev, data, status) {
|
|
|
|
loadingSamples = false;
|
2016-02-12 23:52:43 +08:00
|
|
|
if (_.isUndefined(data.responseJSON.html)) {
|
|
|
|
// Simply reload page to show flash
|
2017-05-18 15:19:44 +08:00
|
|
|
location.reload();
|
2016-02-12 23:52:43 +08:00
|
|
|
} else {
|
|
|
|
// Re-disable options
|
2017-05-18 15:19:44 +08:00
|
|
|
disabledOptions.attr('disabled', 'disabled');
|
2016-02-12 23:52:43 +08:00
|
|
|
|
|
|
|
// Populate the errors container
|
2017-05-18 15:19:44 +08:00
|
|
|
$('#import-errors-container').html(data.responseJSON.html);
|
2017-06-26 22:51:58 +08:00
|
|
|
animateSpinner(null, false);
|
2016-02-12 23:52:43 +08:00
|
|
|
}
|
2016-10-13 16:00:36 +08:00
|
|
|
});
|