summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2011-09-26 12:07:44 +0200
committerXavier Morel <xmo@openerp.com>2011-09-26 12:07:44 +0200
commit7fd9078fede491efc51a072384dc69df09ff0b8e (patch)
treeb40fc31282ec3cac61c18a2bb7256871ad668f41 /addons/web/static/src
parent60207baf447c934ab92438186bb4b0339a992ffe (diff)
[ADD] basic auto-matching of imported file columns to model fields
todo: if exact equality with field name and field string fail, a levenshtein distance test with the field string would be pretty cool (mostly for importing stuff) bzr revid: xmo@openerp.com-20110926100744-1mcucy3njp9fd3r5
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/data_import.js22
1 files changed, 17 insertions, 5 deletions
diff --git a/addons/web/static/src/js/data_import.js b/addons/web/static/src/js/data_import.js
index cbcaa10d7e4..9c686846751 100644
--- a/addons/web/static/src/js/data_import.js
+++ b/addons/web/static/src/js/data_import.js
@@ -159,13 +159,15 @@ openerp.web.DataImport = openerp.web.Dialog.extend({
},
on_import_results: function(results) {
this.$element.find('#result').empty();
- var result_node = this.$element.find("#result");
+ var headers, result_node = this.$element.find("#result");
if (results['records']) {
- var lines_to_skip = parseInt(this.$element.find('#csv_skip').val(), 10);
- var with_headers = this.$element.find('#file_has_headers').prop('checked');
+ var lines_to_skip = parseInt(this.$element.find('#csv_skip').val(), 10),
+ with_headers = this.$element.find('#file_has_headers').prop('checked');
+ headers = with_headers ? results.records[0] : null;
+
result_node.append(QWeb.render('ImportView.result', {
- 'headers': with_headers ? results.records[0] : null,
+ 'headers': headers,
'records': lines_to_skip ? results.records.slice(lines_to_skip)
: with_headers ? results.records.slice(1)
: results.records
@@ -183,7 +185,7 @@ openerp.web.DataImport = openerp.web.Dialog.extend({
var self = this;
this.ready.then(function () {
- self.$element.find('.sel_fields').bind('blur', function () {
+ var $fields = self.$element.find('.sel_fields').bind('blur', function () {
if (this.value && !_(self.all_fields).contains(this.value)) {
this.value = '';
}
@@ -194,6 +196,16 @@ openerp.web.DataImport = openerp.web.Dialog.extend({
}).focus(function () {
$(this).autocomplete('search');
});
+ // Column auto-detection
+ _(headers).each(function (header, index) {
+ var f =_(self.fields).detect(function (field) {
+ // TODO: levenshtein between header and field.string
+ return field.name === header || field.string.toLowerCase() === header;
+ });
+ if (f) {
+ $fields.eq(index).val(f.name);
+ }
+ });
self.on_check_field_values();
});
},