[IMP] add a level of nesting to do_fill result so do_fill_table can get the view...
authorXavier Morel <xmo@openerp.com>
Thu, 21 Apr 2011 13:12:39 +0000 (15:12 +0200)
committerXavier Morel <xmo@openerp.com>
Thu, 21 Apr 2011 13:12:39 +0000 (15:12 +0200)
bzr revid: xmo@openerp.com-20110421131239-dbr5cg27qntj0nuu

addons/base/controllers/main.py
addons/base/static/src/js/list.js
addons/base/static/test/list.js

index bdedb85..f51b42f 100644 (file)
@@ -573,19 +573,22 @@ class ListView(View):
         :param int limit: search limit, for pagination
         :returns: hell if I have any idea yet
         """
-        view = self.fields_view_get(request, model, id)
+        view = self.fields_view_get(request, model, id, toolbar=True)
 
         rows = DataSet().do_search_read(request, model,
                                         offset=offset, limit=limit,
                                         domain=domain)
         eval_context = request.session.evaluation_context(
             request.context)
-        return [
-            {'data': dict((key, {'value': value})
-                          for key, value in row.iteritems()),
-             'color': self.process_colors(view, row, eval_context)}
-            for row in rows
-        ]
+        return {
+            'view': view,
+            'records': [
+                {'data': dict((key, {'value': value})
+                              for key, value in row.iteritems()),
+                 'color': self.process_colors(view, row, eval_context)}
+                for row in rows
+            ]
+        }
 
     def process_colors(self, view, row, context):
         colors = view['arch']['attrs'].get('colors')
index 04a97d9..862c9df 100644 (file)
@@ -177,10 +177,13 @@ openerp.base.ListView = openerp.base.Controller.extend(
      *
      * TODO: should also re-load the table itself, as e.g. columns may have changed
      *
-     * @param {Array} records the records to fill the list view with
+     * @param {Object} result filling result
+     * @param {Array} [result.view] the new view (wrapped fields_view_get result)
+     * @param {Array} result.records records the records to fill the list view with
      * @returns {Promise} promise to the end of view rendering (list views are asynchronously filled for improved responsiveness)
      */
-    do_fill_table: function(records) {
+    do_fill_table: function(result) {
+        var records = result.records;
         var $table = this.$element.find('table');
         this.rows = records;
 
index c0a34aa..92d0bdd 100644 (file)
@@ -34,15 +34,15 @@ $(document).ready(function () {
     asyncTest('render selection checkboxes', 2, function () {
         var listview = new openerp.base.ListView(
                 {}, null,
-                'qunit-fixture', {model: null});
+                'qunit-fixture', {model: null, ids: [null, null, null], index: 0});
 
         listview.on_loaded(fvg);
 
-        listview.do_fill_table([
+        listview.do_fill_table({records: [
                 {data: {id: {value: null}}},
                 {data: {id: {value: null}}},
                 {data: {id: {value: null}}}
-        ]).then(function () {
+        ]}).then(function () {
             ok(are(listview.$element.find('tbody th'),
                    '.oe-record-selector'));
             ok(are(listview.$element.find('tbody th input'),
@@ -53,30 +53,30 @@ $(document).ready(function () {
     asyncTest('render no checkbox if selectable=false', 1, function () {
         var listview = new openerp.base.ListView(
                 {}, null,
-                'qunit-fixture', {model: null}, false,
+                'qunit-fixture', {model: null, ids: [null, null, null], index: 0}, false,
                 {selectable: false});
 
         listview.on_loaded(fvg);
 
-        listview.do_fill_table([
+        listview.do_fill_table({records: [
                 {data: {id: {value: null}}},
                 {data: {id: {value: null}}},
                 {data: {id: {value: null}}}
-        ]).then(function () {
+        ]}).then(function () {
             equal(listview.$element.find('tbody th').length, 0);
             start();
         });
     });
     asyncTest('select a bunch of records', 2, function () {
         var listview = new openerp.base.ListView(
-                {}, null, 'qunit-fixture', {model: null});
+                {}, null, 'qunit-fixture', {model: null, ids: [1, 2, 3], index: 0});
         listview.on_loaded(fvg);
 
-        listview.do_fill_table([
+        listview.do_fill_table({records: [
                 {data: {id: {value: 1}}},
                 {data: {id: {value: 2}}},
                 {data: {id: {value: 3}}}
-        ]).then(function () {
+        ]}).then(function () {
             listview.$element.find('tbody th input:eq(2)')
                              .attr('checked', true);
             deepEqual(listview.get_selection(), [3]);
@@ -88,15 +88,15 @@ $(document).ready(function () {
     });
     asyncTest('render deletion button if list is deletable', 1, function () {
         var listview = new openerp.base.ListView(
-                {}, null, 'qunit-fixture', {model: null});
+                {}, null, 'qunit-fixture', {model: null, ids: [null, null, null], index: 0});
 
         listview.on_loaded(fvg);
 
-        listview.do_fill_table([
+        listview.do_fill_table({records: [
                 {data: {id: {value: null}}},
                 {data: {id: {value: null}}},
                 {data: {id: {value: null}}}
-        ]).then(function () {
+        ]}).then(function () {
             equal(
                 listview.$element.find('tbody tr td.oe-record-delete button').length,
                 3);
@@ -109,15 +109,15 @@ $(document).ready(function () {
         var listview = new openerp.base.ListView(
                 {}, null, 'qunit-fixture', {model: null, unlink: function (ids) {
             deleted = ids;
-        }});
+        }, ids: [1, 2, 3], index: 0});
 
         listview.on_loaded(fvg);
 
-        listview.do_fill_table([
+        listview.do_fill_table({records: [
                 {data: {id: {value: 1}}},
                 {data: {id: {value: 2}}},
                 {data: {id: {value: 3}}}
-        ]).then(function () {
+        ]}).then(function () {
             listview.$element.find('tbody td.oe-record-delete:eq(2) button').click();
             deepEqual(deleted, [3]);
             listview.$element.find('tbody td.oe-record-delete:eq(0) button').click();
@@ -130,15 +130,15 @@ $(document).ready(function () {
         var listview = new openerp.base.ListView(
                 {}, null, 'qunit-fixture', {model: null, unlink: function (ids) {
             deleted = ids;
-        }});
+        }, ids: [1, 2, 3], index: 0});
 
         listview.on_loaded(fvg);
 
-        listview.do_fill_table([
+        listview.do_fill_table({records: [
                 {data: {id: {value: 1}}},
                 {data: {id: {value: 2}}},
                 {data: {id: {value: 3}}}
-        ]).then(function () {
+        ]}).then(function () {
             listview.$element.find('tbody th input:eq(2)')
                              .attr('checked', true);
             listview.$element.find('tbody th input:eq(1)')