Added encoding selecting options

This commit is contained in:
Pedro Markun 2012-04-14 14:39:41 -03:00
parent c16fc1204e
commit 6a352f9c44
3 changed files with 11 additions and 2 deletions

View File

@ -127,6 +127,12 @@
<input type="text" name="separator" value="," class="spam1"/>
</div>
</div>
<div class="control-group">
<label class="control-label">Encoding</label>
<div class="controls">
<input type="text" name="encoding" value="UTF-8" />
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Import &raquo;</button>
</div>

View File

@ -128,7 +128,8 @@ function setupLoader(callback) {
var $file = $form.find('input[type="file"]')[0];
var file = $file.files[0];
var options = {
separator : $form.find('input[name="separator"]').val()
separator : $form.find('input[name="separator"]').val(),
encoding : $form.find('input[name="encoding"]').val()
};
recline.Backend.loadFromCSVFile(file, function(dataset) {
callback(dataset)

View File

@ -3,6 +3,8 @@ this.recline.Backend = this.recline.Backend || {};
(function($, my) {
my.loadFromCSVFile = function(file, callback, options) {
var encoding = options.encoding || 'UTF-8';
var metadata = {
id: file.name,
file: file
@ -16,7 +18,7 @@ this.recline.Backend = this.recline.Backend || {};
reader.onerror = function (e) {
alert('Failed to load file. Code: ' + e.target.error.code);
};
reader.readAsText(file);
reader.readAsText(file, encoding);
};
my.csvToDataset = function(csvString, options) {