scinote-web/app/assets/javascripts/samples/samples_importer.js

52 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-02-12 23:52:43 +08:00
var previousIndex;
var disabledOptions;
var loadingSamples = false;
$('select').focus(function() {
2016-02-12 23:52:43 +08:00
previousIndex = $(this)[0].selectedIndex;
}).change(function() {
2016-02-12 23:52:43 +08:00
var currSelect = $(this);
var currIndex = $(currSelect)[0].selectedIndex;
$('select').each(function() {
2016-02-12 23:52:43 +08:00
if (currSelect !== $(this) && currIndex > 0) {
$(this).children().eq(currIndex).attr('disabled', 'disabled');
2016-02-12 23:52:43 +08:00
}
$(this).children().eq(previousIndex).removeAttr('disabled');
2016-02-12 23:52:43 +08:00
});
previousIndex = currIndex;
});
// Create import samples ajax
$('form#form-import')
2016-02-12 23:52:43 +08:00
.submit(function(e) {
// Check if we already uploading samples
if (loadingSamples) {
return false;
}
2016-02-12 23:52:43 +08:00
disabledOptions = $("option[disabled='disabled']");
disabledOptions.removeAttr('disabled');
loadingSamples = true;
animateSpinner();
2016-02-12 23:52:43 +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
loadingSamples = false;
2016-02-12 23:52:43 +08:00
location.reload();
})
.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
location.reload();
2016-02-12 23:52:43 +08:00
} else {
// Re-disable options
disabledOptions.attr('disabled', 'disabled');
2016-02-12 23:52:43 +08:00
// Populate the errors container
$('#import-errors-container').html(data.responseJSON.html);
animateSpinner(null, false);
2016-02-12 23:52:43 +08:00
}
});