From 2187a3e3ddecbf2b95b9c29d68131472d6395e3a Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 22 Sep 2011 14:13:27 +0200 Subject: [PATCH] [IMP] extract duplicate fields discovery routine to its own method, to make the validation process clearer bzr revid: xmo@openerp.com-20110922121327-zqenx9bisr8pe4kd --- addons/web/static/src/js/data_import.js | 26 ++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/addons/web/static/src/js/data_import.js b/addons/web/static/src/js/data_import.js index b2675079ddd..dedcc97df17 100644 --- a/addons/web/static/src/js/data_import.js +++ b/addons/web/static/src/js/data_import.js @@ -103,11 +103,20 @@ openerp.web.DataImport = openerp.web.Dialog.extend({ this.on_check_field_values(results['required_fields']); }, - on_check_field_values: function (required_fields) { - this.$element.find("#message, #msg").remove(); - - var required_valid = this.check_required(required_fields); - + /** + * Looks through all the field selections, and tries to find if two + * (or more) columns were matched to the same model field. + * + * Returns a map of the multiply-mapped fields to an array of offending + * columns (not actually columns, but the inputs containing the same field + * names). + * + * Also has the side-effect of marking the discovered inputs with the class + * ``duplicate_fld``. + * + * @returns {Object>} map of duplicate field matches to same-valued inputs + */ + find_duplicate_fields: function() { // Maps values to DOM nodes, in order to discover duplicates var values = {}, duplicates = {}; this.$element.find(".sel_fields").each(function(index, element) { @@ -127,7 +136,14 @@ openerp.web.DataImport = openerp.web.Dialog.extend({ $element.add(same_valued_field).addClass('duplicate_fld'); } }); + return duplicates; + }, + on_check_field_values: function (required_fields) { + this.$element.find("#message, #msg").remove(); + var required_valid = this.check_required(required_fields); + + var duplicates = this.find_duplicate_fields(); if (_.isEmpty(duplicates)) { this.toggle_import_button(required_valid); } else {