[FIX]Fix header problem in preview table and selection of column if duplicate it...
authorKunal Chavda (OpenERP) <kch@tinyerp.com>
Wed, 31 Aug 2011 10:52:32 +0000 (16:22 +0530)
committerKunal Chavda (OpenERP) <kch@tinyerp.com>
Wed, 31 Aug 2011 10:52:32 +0000 (16:22 +0530)
bzr revid: kch@tinyerp.com-20110831105232-2gra1irdwv61aj02

addons/base/controllers/main.py
addons/base/static/src/js/data_import.js
addons/base/static/src/xml/base.xml

index 4b07cac..f01bf18 100644 (file)
@@ -1304,7 +1304,6 @@ class Export(View):
         #TODO: ok now we've got the report, and so what?
         return False
 
-
 class Import(View):
     _cp_path = "/base/import"
 
@@ -1351,6 +1350,7 @@ class Import(View):
         fields.update({'id':{'string':'ID'},'.id':{'string':'Database ID'}})
         model_populate(fields)
         all_fields = fields.keys()
+
         try:
             data = csv.reader(params.get('csvfile').file, quotechar=str(params.get('csvdel')), delimiter=str(params.get('csvsep')))
         except:
@@ -1361,13 +1361,16 @@ class Import(View):
         fields = []
         word=''
         limit = 4
+        count = 0
         try:
             for i, row in enumerate(data):
                 records.append(row)
                 if i == limit:
                     break
 
-            for line in records:
+            for j, line in enumerate(records):
+                if j == 1:
+                    break
                 for word in line:
                     word = str(word.decode(params.get('csvcode')))
                     if word in _fields:
@@ -1375,8 +1378,12 @@ class Import(View):
                     elif word in _fields_invert.keys():
                         fields.append((_fields_invert[word], word))
                     else:
+                        count = count + 1
                         fields.append((word, word))
 #                        error = {'message':("You cannot import the field '%s', because we cannot auto-detect it" % (word,))}
+
+            if len(line) == count:
+                error = {'message':"File has not any column header."}
         except:
             error = {'message':('Error processing the first line of the file. Field "%s" is unknown') % (word,)}
 
@@ -1385,7 +1392,7 @@ class Import(View):
             error=dict(error, preview=params.get('csvfile').file.read(200))
             return simplejson.dumps({'error':error})
 
-        return simplejson.dumps({'records':records[1:],'fields':fields,'all_fields':all_fields})
+        return simplejson.dumps({'records':records[1:],'header':fields,'all_fields':all_fields})
 
     @openerpweb.httprequest
     def import_data(self, req, **params):
@@ -1449,5 +1456,4 @@ class Import(View):
             d+= ('%s: %s' % (str(key),str(val)))
         msg = 'Error trying to import this record:%s. ErrorMessage:%s %s' % (d,res[2],res[3])
         error = {'message':str(msg), 'title':'ImportationError'}
-
         return simplejson.dumps({'error':error})
index a98f387..e09b4dc 100644 (file)
@@ -54,11 +54,11 @@ openerp.base.DataImport = openerp.base.Dialog.extend({
     },
     import_results:function(res){
         $('#result, #success').empty();
-        $(".ui-button-text:contains('Import File')").parent().attr("disabled",false);
+
         var results = $.parseJSON(res);
         var result_node = $("#result");
         if (results['records']){
-            records = {'header':results['fields'],'sel':results['all_fields'],'row':results['records']};
+            records = {'header':results['header'],'sel':results['all_fields'],'row':results['records']};
             result_node.append(QWeb.render('ImportView-result',{'records':records}));
         }else if(results['error']){
             result_node.append(QWeb.render('ImportView-result',{'error': results['error']}));
@@ -66,16 +66,26 @@ openerp.base.DataImport = openerp.base.Dialog.extend({
             var success_node = $("#success");
             success_node.append(QWeb.render('ImportView-result',{'success': results['success']}));
         }
-        $('td #header').each(function(){
-            var head = $(this).text();
-            if (jQuery.inArray(head,results['all_fields']) <= -1){
-                $(".ui-button-text:contains('Import File')").parent().attr("disabled",true);
+        var mm = [];
+        $("td #sel_field").click(function(){
+            mm = [];
+            $("td #sel_field option:selected").each(function(){
+                mm.push($(this).index());
+            });
+        });
+        $("td #sel_field").change(function(){
+            $(this).css('background-color','');
+            var kk = this.selectedIndex;
+            if ($.inArray(kk,mm) > -1){
+                $(this).css('background-color','#FF6666');
+            }else{
+                $(this).css('background-color','');
             }
         });
     },
     stop: function() {
         $(this.$dialog).remove();
         this._super();
-    },
+    }
 });
 };
\ No newline at end of file
index 491495c..2bcef18 100644 (file)
                     <tr>
                         <t t-foreach="records.header" t-as="header">
                             <td>
-                                <select name="fld" id="fld">
+                                <select name="sel_field" id="sel_field">
                                     <option selected="selected" value=""></option>
                                     <t t-foreach="records.sel" t-as="selection">
                                         <option t-att="{'selected': header[0] === selection ? 'selected' : null}"
         </table>
     </t>
 </t>
-</templates>
+</templates>
\ No newline at end of file