Support for separator specification in CSV now in frontend

This commit is contained in:
Pedro Markun 2012-04-14 14:26:26 -03:00
parent e695924149
commit c16fc1204e
3 changed files with 13 additions and 4 deletions

View File

@ -121,6 +121,12 @@
<input type="file" name="source" />
</div>
</div>
<div class="control-group">
<label class="control-label">Separator</label>
<div class="controls">
<input type="text" name="separator" value="," class="spam1"/>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Import &raquo;</button>
</div>

View File

@ -127,9 +127,12 @@ function setupLoader(callback) {
$('.modal.js-import-dialog-file').modal('hide');
var $file = $form.find('input[type="file"]')[0];
var file = $file.files[0];
var options = {
separator : $form.find('input[name="separator"]').val()
};
recline.Backend.loadFromCSVFile(file, function(dataset) {
callback(dataset)
});
}, options);
});
}

View File

@ -10,7 +10,7 @@ this.recline.Backend = this.recline.Backend || {};
var reader = new FileReader();
// TODO
reader.onload = function(e) {
var dataset = my.csvToDataset(e.target.result);
var dataset = my.csvToDataset(e.target.result, options);
callback(dataset);
};
reader.onerror = function (e) {
@ -20,7 +20,7 @@ this.recline.Backend = this.recline.Backend || {};
};
my.csvToDataset = function(csvString, options) {
var out = my.parseCSV(csvString);
var out = my.parseCSV(csvString, options);
fields = _.map(out[0], function(cell) {
return { id: cell, label: cell };
});
@ -91,7 +91,7 @@ this.recline.Backend = this.recline.Backend || {};
// If we are at a EOF or EOR
if (inQuote === false && (cur === separator || cur === "\n")) {
field = processField(field);
field = processField(field);
// Add the current field to the current row
row.push(field);
// If this is EOR append row to output and flush row