From efd0674429d309cf6a2d18fe783c0421b4741166 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 19 Oct 2011 12:38:22 +0200 Subject: [FIX] always add external ids to the list of importable fields lp bug: https://launchpad.net/bugs/878005 fixed bzr revid: xmo@openerp.com-20111019103822-lx0gldsmxbqb87dr --- addons/web/static/src/js/data_import.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src/js/data_import.js') diff --git a/addons/web/static/src/js/data_import.js b/addons/web/static/src/js/data_import.js index 0864c5e594e..0d7d6eca032 100644 --- a/addons/web/static/src/js/data_import.js +++ b/addons/web/static/src/js/data_import.js @@ -1,5 +1,6 @@ openerp.web.data_import = function(openerp) { -var QWeb = openerp.web.qweb; +var QWeb = openerp.web.qweb, + _t = openerp.web._t; /** * Safari does not deal well at all with raw JSON data being returned. As a * result, we're going to cheat by using a pseudo-jsonp: instead of getting @@ -101,7 +102,16 @@ openerp.web.DataImport = openerp.web.Dialog.extend({ level = level || 0; var self = this; + if (level === 0) { + parent.fields.push({ + id: 'id', + name: 'id', + string: _t('External ID'), + required: false + }); + } _(fields).each(function (field, field_name) { + if (field_name === 'id') { return; } var f = { id: field_name, name: field_name, -- cgit v1.2.3 From c3661c0827601a01b1b79284a0e9167e54f85bec Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 19 Oct 2011 15:49:36 +0200 Subject: [FIX] failure to auto-match 'inner' fields of o2m records when importing lp bug: https://launchpad.net/bugs/878005 fixed bzr revid: xmo@openerp.com-20111019134936-xfo9zt1ivgocbffr --- addons/web/static/src/js/data_import.js | 45 ++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 6 deletions(-) (limited to 'addons/web/static/src/js/data_import.js') diff --git a/addons/web/static/src/js/data_import.js b/addons/web/static/src/js/data_import.js index 0d7d6eca032..711e790dfaa 100644 --- a/addons/web/static/src/js/data_import.js +++ b/addons/web/static/src/js/data_import.js @@ -220,17 +220,50 @@ openerp.web.DataImport = openerp.web.Dialog.extend({ }); // 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); + var field_name = self.match_column_to_field(header); + if (field_name) { + $fields.eq(index).val(field_name); } }); self.on_check_field_values(); }); }, + /** + * Returns the name of the field (nested) matching the provided column name + * + * @param {String} name column name to look for + * @param {Array} [fields] fields to look into for the provided name + * @returns {String|undefined} + */ + match_column_to_field: function (name, fields) { + fields = fields || this.fields; + var f; + f = _(fields).detect(function (field) { + // TODO: levenshtein between header and field.string + return field.name === name + || field.string.toLowerCase() === name.toLowerCase(); + }); + if (f) { return f.name; } + + // if ``name`` is a path (o2m), we need to recurse through its .fields + var index = name.indexOf('/'); + if (index === -1) { return undefined; } + // Get the first path section, try to find the matching field + var column_name = name.substring(0, index); + f = _(fields).detect(function (field) { + // field.name for o2m is $foo/id, so we want to match on id + return field.id === column_name + || field.string.toLowerCase() === column_name.toLowerCase() + }); + if (!f) { return undefined; } + + // if we found a matching field for the first path section, recurse in + // its own .fields to try and get the rest of the path matched + var rest = this.match_column_to_field( + name.substring(index+1), f.fields); + if (!rest) { return undefined; } + return f.id + '/' + rest; + }, /** * Looks through all the field selections, and tries to find if two * (or more) columns were matched to the same model field. -- cgit v1.2.3 From a8b81ed5754ef0f2495b28b517f2a5b7ed9ba749 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 24 Oct 2011 15:55:21 +0200 Subject: [ADD] dropdown arrow next to import autocompletes bzr revid: xmo@openerp.com-20111024135521-aikh791r9j94moal --- addons/web/static/src/js/data_import.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'addons/web/static/src/js/data_import.js') diff --git a/addons/web/static/src/js/data_import.js b/addons/web/static/src/js/data_import.js index 711e790dfaa..025ff8df1c5 100644 --- a/addons/web/static/src/js/data_import.js +++ b/addons/web/static/src/js/data_import.js @@ -205,6 +205,10 @@ openerp.web.DataImport = openerp.web.Dialog.extend({ return; } + this.$element.delegate('.oe-m2o-drop-down-button', 'click', function () { + $(this).prev('input').focus(); + }); + var self = this; this.ready.then(function () { var $fields = self.$element.find('.sel_fields').bind('blur', function () { -- cgit v1.2.3 From b45b7ad22cce753a00fff13981502e2c807cee79 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 24 Oct 2011 16:06:58 +0200 Subject: [IMP] import: only show second step once file has been uploaded bzr revid: xmo@openerp.com-20111024140658-8t9csv9i6gd30luj --- addons/web/static/src/js/data_import.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/static/src/js/data_import.js') diff --git a/addons/web/static/src/js/data_import.js b/addons/web/static/src/js/data_import.js index 025ff8df1c5..42f0cf8d680 100644 --- a/addons/web/static/src/js/data_import.js +++ b/addons/web/static/src/js/data_import.js @@ -80,7 +80,7 @@ openerp.web.DataImport = openerp.web.Dialog.extend({ this.toggle_import_button(false); this.$element.find('#csvfile').change(this.on_autodetect_data); this.$element.find('fieldset').change(this.on_autodetect_data); - this.$element.find('fieldset legend').click(function() { + this.$element.delegate('fieldset legend', 'click', function() { $(this).next().toggle(); }); this.ready.push(new openerp.web.DataSet(this, this.model).call( -- cgit v1.2.3 From cd59e5e6fbf07bb1783dde48ecdafa73000d33c4 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 24 Oct 2011 16:17:37 +0200 Subject: [ADD] open/close arrow next to import options bzr revid: xmo@openerp.com-20111024141737-bk2rg08wvll1hgno --- addons/web/static/src/js/data_import.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/static/src/js/data_import.js') diff --git a/addons/web/static/src/js/data_import.js b/addons/web/static/src/js/data_import.js index 42f0cf8d680..a284669732d 100644 --- a/addons/web/static/src/js/data_import.js +++ b/addons/web/static/src/js/data_import.js @@ -81,7 +81,7 @@ openerp.web.DataImport = openerp.web.Dialog.extend({ this.$element.find('#csvfile').change(this.on_autodetect_data); this.$element.find('fieldset').change(this.on_autodetect_data); this.$element.delegate('fieldset legend', 'click', function() { - $(this).next().toggle(); + $(this).parent().toggleClass('oe-closed'); }); this.ready.push(new openerp.web.DataSet(this, this.model).call( 'fields_get', [], function (fields) { -- cgit v1.2.3 From 06344150ebf2860247929c76f3fc6d9b43ca27b9 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 24 Oct 2011 16:27:44 +0200 Subject: [FIX] automatically open options box if the file fails to parse entirely bzr revid: xmo@openerp.com-20111024142744-zeal912gqf9bvrrp --- addons/web/static/src/js/data_import.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'addons/web/static/src/js/data_import.js') diff --git a/addons/web/static/src/js/data_import.js b/addons/web/static/src/js/data_import.js index a284669732d..355c6c1b493 100644 --- a/addons/web/static/src/js/data_import.js +++ b/addons/web/static/src/js/data_import.js @@ -194,9 +194,11 @@ openerp.web.DataImport = openerp.web.Dialog.extend({ : with_headers ? results.records.slice(1) : results.records })); + this.$element.find('fieldset').addClass('oe-closed'); } else if (results['error']) { result_node.append(QWeb.render('ImportView.error', { 'error': results['error']})); + this.$element.find('fieldset').removeClass('oe-closed'); } else if (results['success']) { if (this.widget_parent.widget_parent.active_view == "list") { this.widget_parent.reload_content(); @@ -204,6 +206,7 @@ openerp.web.DataImport = openerp.web.Dialog.extend({ this.stop(); return; } + this.$element.find('form').removeClass('oe-import-no-result'); this.$element.delegate('.oe-m2o-drop-down-button', 'click', function () { $(this).prev('input').focus(); -- cgit v1.2.3