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

41 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-02-12 23:52:43 +08:00
var previousIndex;
var disabledOptions;
$("select").focus(function() {
previousIndex = $(this)[0].selectedIndex;
}).change(function () {
var currSelect = $(this);
var currIndex = $(currSelect)[0].selectedIndex;
$("select").each(function() {
if (currSelect !== $(this) && currIndex > 0) {
$(this).children().eq(currIndex).attr("disabled", "disabled");
}
$(this).children().eq(previousIndex).removeAttr("disabled");
});
previousIndex = currIndex;
});
// Create import samples ajax
$("form#form-import")
.submit(function(e) {
disabledOptions = $("option[disabled='disabled']");
disabledOptions.removeAttr("disabled");
})
.on("ajax:success", function(ev, data, status) {
// Simply reload page to show flash and updated samples list
location.reload();
})
.on("ajax:error", function(ev, data, status) {
if (_.isUndefined(data.responseJSON.html)) {
// Simply reload page to show flash
location.reload();
} else {
// Re-disable options
disabledOptions.attr("disabled", "disabled");
// Populate the errors container
$("#import-errors-container").html(data.responseJSON.html);
}
});