diff options
| author | Thibault Delavallée <tde@openerp.com> | 2013-07-25 15:50:01 +0200 |
|---|---|---|
| committer | Thibault Delavallée <tde@openerp.com> | 2013-07-25 15:50:01 +0200 |
| commit | 0810ff005cd4937f33d50d8feb4b5a90547fa5ed (patch) | |
| tree | 479de0f44196cb3841e710b186aa139173098c68 /addons/web/static/src | |
| parent | 0a1db46398d830c66c1d2eb6cc2e1c9941b3a449 (diff) | |
[IMP] Better implementation of header hook check
- list_view: propagate a deselected flag when (un)checking a row
- list_view: define a get_active_domain method that returns an active domain
when having header hook selected
bzr revid: tde@openerp.com-20130725135001-zt8x1leexf7ion4z
Diffstat (limited to 'addons/web/static/src')
| -rw-r--r-- | addons/web/static/src/js/view_list.js | 43 | ||||
| -rw-r--r-- | addons/web/static/src/js/views.js | 19 |
2 files changed, 44 insertions, 18 deletions
diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index 4f58b002328..bc2d0c0b0bf 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -132,8 +132,8 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi 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 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi * @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,27 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi 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(); + var active_domain_done = instance.web.pyeval.eval_domains_and_contexts({ + domains: search_data.domains, + contexts: search_data.contexts, + group_by_seq: search_data.groupbys || [] + }).done(function (results) { + return results.domain; + }); + return active_domain_done; + } + else { + return $.Deferred().resolve(); + } + }, + /** * Adds padding columns at the start or end of all table rows (including * field names row) * @@ -951,8 +977,13 @@ instance.web.ListView.List = instance.web.Class.extend( /** @lends instance.web. .delegate('th.oe_list_record_selector', 'click', function (e) { e.stopPropagation(); var selection = self.get_selection(); + var checked = $(e.currentTarget).find('input').prop('checked'); + // console.log(checked); + // if (! checked) { + // $(self).find('.oe_list_record_selector').prop('checked', false); + // } $(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 +1429,10 @@ instance.web.ListView.Groups = instance.web.Class.extend( /** @lends instance.we 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 diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 67490a4652d..e043715f67b 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -1176,6 +1176,7 @@ instance.web.Sidebar = instance.web.Widget.extend({ 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; @@ -1184,19 +1185,13 @@ instance.web.Sidebar = instance.web.Widget.extend({ active_id: ids[0], active_ids: ids, active_model: self.getParent().dataset.model, - }; - - var search_view = self.getParent().ViewManager.searchview; - var search_data = search_view.build_search_data(); - var active_domain_done = instance.web.pyeval.eval_domains_and_contexts({ - domains: search_data.domains, - contexts: search_data.contexts, - group_by_seq: search_data.groupbys || [] - }).done(function (results) { - active_ids_context['active_domain'] = results.domain; - }); + }; - $.when(active_domain_done).done(function () { + $.when(domain).done(function (results) { + if (results !== undefined) { + console.log(results); + active_ids_context.active_domain = results.domain; + } var c = instance.web.pyeval.eval('context', new instance.web.CompoundContext( sidebar_eval_context, active_ids_context)); |
