summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/data_import.js
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2011-09-22 14:13:27 +0200
committerXavier Morel <xmo@openerp.com>2011-09-22 14:13:27 +0200
commit2187a3e3ddecbf2b95b9c29d68131472d6395e3a (patch)
tree6d359e2cad12f3fe37223e282e0a0d18b000b589 /addons/web/static/src/js/data_import.js
parentc3a0d98e1353c382df0e30a8afa2ba5ef15a641a (diff)
[IMP] extract duplicate fields discovery routine to its own method, to make the validation process clearer
bzr revid: xmo@openerp.com-20110922121327-zqenx9bisr8pe4kd
Diffstat (limited to 'addons/web/static/src/js/data_import.js')
-rw-r--r--addons/web/static/src/js/data_import.js26
1 files 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<String, Array<String>>} 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 {