← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~acsone-openerp/ocb-web/active_domain-7.0-backport into lp:ocb-web

 

Stéphane Bidoul (Acsone) has proposed merging lp:~acsone-openerp/ocb-web/active_domain-7.0-backport into lp:ocb-web.

Requested reviews:
  OpenERP Community Backports Team (ocb)

For more details, see:
https://code.launchpad.net/~acsone-openerp/ocb-web/active_domain-7.0-backport/+merge/189279

Backport of trunk active_domain mechanism for mass actions.

This allows "more menu" actions to work on a larger set of objects than is possible with active_ids.

The backport includes the improvement of the export dialog to use active_domain: when the header checkbox is selected all records matching the current filter are now exported, and not only the current page, as users expect.

Original openerp-web revisions:
- 3787 revid:tde@xxxxxxxxxxx-20130726123705-vdtzxmmk5tszrwqf
- 3809 revid:tde@xxxxxxxxxxx-20130808104733-gg0vpwxzy631pj0x

I kept the original author (Thibault Delavallée) in the commit.

-sbi
-- 
https://code.launchpad.net/~acsone-openerp/ocb-web/active_domain-7.0-backport/+merge/189279
Your team OpenERP Community Backports Team is requested to review the proposed merge of lp:~acsone-openerp/ocb-web/active_domain-7.0-backport into lp:ocb-web.
=== modified file 'addons/web/static/src/js/data_export.js'
--- addons/web/static/src/js/data_export.js	2013-05-30 10:04:20 +0000
+++ addons/web/static/src/js/data_export.js	2013-10-04 11:53:46 +0000
@@ -378,21 +378,28 @@
         exported_fields.unshift({name: 'id', label: 'External ID'});
 
         var export_format = this.$el.find("#export_format").val();
-        var ids_to_export = this.$('#export_selection_only').prop('checked')
-                ? this.getParent().get_selected_ids()
-                : this.dataset.ids;
 
-        instance.web.blockUI();
-        this.session.get_file({
-            url: '/web/export/' + export_format,
-            data: {data: JSON.stringify({
-                model: this.dataset.model,
-                fields: exported_fields,
-                ids: ids_to_export,
-                domain: this.dataset.domain,
-                import_compat: !!this.$el.find("#import_compat").val(),
-            })},
-            complete: instance.web.unblockUI,
+        this.getParent().get_active_domain().then(function (domain) {
+            if (domain === undefined) {
+                var ids_to_export = self.getParent().get_selected_ids();
+                var domain = self.dataset.domain;
+            }
+            else {
+                var ids_to_export = false;
+                var domain = domain;
+            }
+            instance.web.blockUI();
+            self.session.get_file({
+                url: '/web/export/' + export_format,
+                data: {data: JSON.stringify({
+                    model: self.dataset.model,
+                    fields: exported_fields,
+                    ids: ids_to_export,
+                    domain: domain,
+                    import_compat: !!self.$el.find("#import_compat").val(),
+                })},
+                complete: instance.web.unblockUI,
+            });
         });
     },
     close: function() {

=== modified file 'addons/web/static/src/js/view_list.js'
--- addons/web/static/src/js/view_list.js	2013-06-10 07:10:36 +0000
+++ addons/web/static/src/js/view_list.js	2013-10-04 11:53:46 +0000
@@ -132,8 +132,8 @@
 
         this.groups = groups;
         $(this.groups).bind({
-            'selected': function (e, ids, records) {
-                self.do_select(ids, records);
+            'selected': function (e, ids, records, deselected) {
+                self.do_select(ids, records, deselected);
             },
             'deleted': function (e, ids) {
                 self.do_delete(ids);
@@ -603,7 +603,12 @@
      * @param {Array} ids selected record ids
      * @param {Array} records selected record values
      */
-    do_select: function (ids, records) {
+    do_select: function (ids, records, deselected) {
+        // uncheck header hook if at least one row has been deselected
+        if (deselected) {
+            this.$('.oe_list_record_selector').prop('checked', false);
+        }
+
         if (!ids.length) {
             this.dataset.index = 0;
             if (this.sidebar) {
@@ -791,6 +796,26 @@
         return ids;
     },
     /**
+     * Calculate the active domain of the list view. This should be done only
+     * if the header checkbox has been checked.
+     */
+    get_active_domain: function () {
+        if (this.$('.oe_list_record_selector').prop('checked')) {
+            var search_view = this.getParent().searchview;
+            var search_data = search_view.build_search_data();
+            return instance.web.pyeval.eval_domains_and_contexts({
+                domains: search_data.domains,
+                contexts: search_data.contexts,
+                group_by_seq: search_data.groupbys || []
+            }).then(function (results) {
+                return results.domain;
+            });
+        }
+        else {
+            return $.Deferred().resolve();
+        }
+    },
+    /**
      * Adds padding columns at the start or end of all table rows (including
      * field names row)
      *
@@ -951,8 +976,9 @@
             .delegate('th.oe_list_record_selector', 'click', function (e) {
                 e.stopPropagation();
                 var selection = self.get_selection();
+                var checked = $(e.currentTarget).find('input').prop('checked');
                 $(self).trigger(
-                        'selected', [selection.ids, selection.records]);
+                        'selected', [selection.ids, selection.records, ! checked]);
             })
             .delegate('td.oe_list_record_delete button', 'click', function (e) {
                 e.stopPropagation();
@@ -1398,10 +1424,10 @@
     bind_child_events: function (child) {
         var $this = $(this),
              self = this;
-        $(child).bind('selected', function (e) {
+        $(child).bind('selected', function (e, _0, _1, deselected) {
             // can have selections spanning multiple links
             var selection = self.get_selection();
-            $this.trigger(e, [selection.ids, selection.records]);
+            $this.trigger(e, [selection.ids, selection.records, deselected]);
         }).bind(this.passthrough_events, function (e) {
             // additional positional parameters are provided to trigger as an
             // Array, following the event type or event object, but are

=== modified file 'addons/web/static/src/js/views.js'
--- addons/web/static/src/js/views.js	2013-06-21 12:44:49 +0000
+++ addons/web/static/src/js/views.js	2013-10-04 11:53:46 +0000
@@ -1182,6 +1182,7 @@
         var self = this;
         self.getParent().sidebar_eval_context().done(function (sidebar_eval_context) {
             var ids = self.getParent().get_selected_ids();
+            var domain = self.getParent().get_active_domain();
             if (ids.length == 0) {
                 instance.web.dialog($("<div />").text(_t("You must choose at least one record.")), { title: _t("Warning"), modal: true });
                 return false;
@@ -1189,25 +1190,32 @@
             var active_ids_context = {
                 active_id: ids[0],
                 active_ids: ids,
-                active_model: self.getParent().dataset.model
-            }; 
-            var c = instance.web.pyeval.eval('context',
+                active_model: self.getParent().dataset.model,
+            };
+
+            $.when(domain).done(function (domain) {
+                if (domain !== undefined) {
+                    active_ids_context.active_domain = domain;
+                }
+                var c = instance.web.pyeval.eval('context',
                 new instance.web.CompoundContext(
                     sidebar_eval_context, active_ids_context));
-            self.rpc("/web/action/load", {
-                action_id: item.action.id,
-                context: c
-            }).done(function(result) {
-                result.context = new instance.web.CompoundContext(
-                    result.context || {}, active_ids_context)
-                        .set_eval_context(c);
-                result.flags = result.flags || {};
-                result.flags.new_window = true;
-                self.do_action(result, {
-                    on_close: function() {
-                        // reload view
-                        self.getParent().reload();
-                    },
+
+                self.rpc("/web/action/load", {
+                    action_id: item.action.id,
+                    context: c
+                }).done(function(result) {
+                    result.context = new instance.web.CompoundContext(
+                        result.context || {}, active_ids_context)
+                            .set_eval_context(c);
+                    result.flags = result.flags || {};
+                    result.flags.new_window = true;
+                    self.do_action(result, {
+                        on_close: function() {
+                            // reload view
+                            self.getParent().reload();
+                        },
+                    });
                 });
             });
         });

=== modified file 'addons/web/static/src/xml/base.xml'
--- addons/web/static/src/xml/base.xml	2013-08-29 12:44:48 +0000
+++ addons/web/static/src/xml/base.xml	2013-10-04 11:53:46 +0000
@@ -1701,9 +1701,6 @@
 
             <label for="export_format">Export Formats</label>
             <select id="export_format" name="export_format"></select>
-
-            <label for="export_selection_only">Only export selection:</label>
-            <input type="checkbox" id="export_selection_only"/>
         </td>
     </tr>
 


Follow ups