Commit 69177b7b authored by Matija Obreza's avatar Matija Obreza
Browse files

Run auto-detect on paste event

parent 914d6774
label.title=Passport data validation
label.run-autodetect=Autodetect
label.run-autodetect=Auto-detect CSV settings
label.run-check=Validate Taxonomic data
label.run-check-country=Validate Country of Origin
label.run-check-land=Classify Land or Water
......
......@@ -30,8 +30,7 @@
}
.btn {
padding: 1em 2em;
margin: 2em 0;
padding: 1em 2em;
}
code {
......@@ -85,7 +84,11 @@
</div>
<h2>2. Configure CSV settings</h2>
<div>
<button class="btn" type="button" value="" id="autodetectCsv">
<spring:message code="label.run-autodetect"/>
</button>
<h3><spring:message code="label.separator"/>:</h3>
<input id="separatorTab" name="separator" value="&#9;" type="radio" checked>
<label for="separatorTab"><spring:message code="label.separator.tab"/> <code>&#09;</code></label>
......@@ -125,10 +128,7 @@
<label for="toCurrentTaxaNo"><spring:message code="label.no"/></label>
</div>
<div>
<button class="btn" type="button" value="" id="autodetectCsv">
<spring:message code="label.run-autodetect"/>
</button>
<div style="margin: 2em 0;">
<button class="btn" type="submit" value="" name="validateType">
<spring:message code="label.run-check"/>
</button>
......@@ -193,7 +193,7 @@
detectedSeparator = separators[i];
}
}
return detectedSeparator.name;
return detectedSeparator === null ? '\t' : detectedSeparator.name;
},
detectQuoteChar: function(lines, separator) {
......@@ -370,17 +370,22 @@
};
document.addEventListener("DOMContentLoaded", function() {
var btn = document.getElementById("autodetectCsv");
btn.addEventListener("click", function() {
var autodetectSettings = function() {
var area = document.getElementById("csvText");
if (area.value.length < 10) {
console.log('Not enough data for auto-detection len=', area.value.length);
return;
}
var lines = area.value.replace(/\r\n/g, "\n").split("\n");
var separator = CSVAutodetector.detectSeparator(lines);
var quote = CSVAutodetector.detectQuoteChar(lines, separator);
var escape = CSVAutodetector.detectEscapeChar(lines, separator, quote);
var decimalMark = CSVAutodetector.detectDecimalMark(lines, separator);
console.log('CSV auto-detected separator=', separator, ' quote=', quote, ' escape=', escape, ' decimal=', decimalMark);
CSVAutodetector.autoSelectOptions(separator, quote, escape, decimalMark);
});
};
document.getElementById("autodetectCsv").addEventListener("click", autodetectSettings);
document.getElementById("csvText").addEventListener("paste", function(e) { setTimeout(autodetectSettings, 10); });
});
</script>
</body>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment