summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/view_form.js
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2015-01-22 11:24:36 +0100
committerGéry Debongnie <ged@odoo.com>2015-01-22 20:45:08 +0100
commit0521c8b83f8ed899f799af6ac3cf157f7dda8b3e (patch)
tree10bf1855759f690a3132ec2b6b543d37c785e951 /addons/web/static/src/js/view_form.js
parent21c1686f060eaf1eb557a6d1fb531c6fef102d0a (diff)
[FIX] web: fix various bugs in FieldCharDomain
now, the FieldCharDomain widget should * correctly display the selected records instead of the whole list * allow the removal of the current selection in edit mode (by adding a facet in the searchview) * allow the selection of a full group when the list view is grouped also, it correctly now uses the ReinitializeFieldMixin instead of reimplementing half of it in a buggy way.
Diffstat (limited to 'addons/web/static/src/js/view_form.js')
-rw-r--r--addons/web/static/src/js/view_form.js105
1 files changed, 61 insertions, 44 deletions
diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js
index aedee94a4ab..bc37736c21f 100644
--- a/addons/web/static/src/js/view_form.js
+++ b/addons/web/static/src/js/view_form.js
@@ -2626,25 +2626,9 @@ instance.web.form.FieldFloat = instance.web.form.FieldChar.extend({
}
});
+
instance.web.form.FieldCharDomain = instance.web.form.AbstractField.extend(instance.web.form.ReinitializeFieldMixin, {
- init: function(field_manager, node) {
- this._super.apply(this, arguments);
- },
- start: function() {
- var self = this;
- this._super.apply(this, arguments);
- this.on("change:effective_readonly", this, function () {
- this.display_field();
- });
- this.display_field();
- return this._super();
- },
- set_value: function(value_) {
- var self = this;
- this.set('value', value_ || false);
- this.display_field();
- },
- display_field: function() {
+ render_value: function() {
var self = this;
this.$el.html(instance.web.qweb.render("FieldCharDomain", {widget: this}));
if (this.get('value')) {
@@ -2671,37 +2655,24 @@ instance.web.form.FieldCharDomain = instance.web.form.AbstractField.extend(insta
var self = this;
var model = this.options.model || this.field_manager.get_field_value(this.options.model_field);
- this.pop = new instance.web.form.SelectCreatePopup(this);
- this.pop.select_element(
- model, {
+ var options = {
title: this.get('effective_readonly') ? 'Selected records' : 'Select records...',
readonly: this.get('effective_readonly'),
disable_multiple_selection: this.get('effective_readonly'),
no_create: this.get('effective_readonly'),
- }, [], this.build_context());
- this.pop.on("elements_selected", self, function(element_ids) {
- if (this.pop.$('input.oe_list_record_selector').prop('checked')) {
- var search_data = this.pop.searchview.build_search_data();
- var domain_done = 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 {
- var domain = [["id", "in", element_ids]];
- var domain_done = $.Deferred().resolve(domain);
+ };
+ var domain = this.get('value');
+ popup = new instance.web.form.DomainEditorPopup(this);
+ popup.select_element(model, options, domain, {});
+ popup.on("elements_selected", self, function(selected_ids) {
+ if (!self.get('effective_readonly')) {
+ self.set_value(popup.get_domain(selected_ids));
}
- $.when(domain_done).then(function (domain) {
- var domain = self.pop.dataset.domain.concat(domain || []);
- self.set_value(domain);
- });
});
},
});
+
instance.web.DateTimeWidget = instance.web.Widget.extend({
template: "web.datepicker",
type_of_date: "datetime",
@@ -5437,6 +5408,11 @@ instance.web.form.SelectCreatePopup = instance.web.form.AbstractFormPopup.extend
self.view_list.appendTo(self.$(".oe_popup_list").show()).then(function() {
self.view_list.do_show();
}).then(function() {
+ if (self.options.initial_facet) {
+ self.searchview.query.reset([self.options.initial_facet], {
+ preventSearch: true,
+ });
+ }
self.searchview.do_search();
});
self.view_list.on("list_view_loaded", self, function() {
@@ -5458,14 +5434,12 @@ instance.web.form.SelectCreatePopup = instance.web.form.AbstractFormPopup.extend
});
},
do_search: function(domains, contexts, groupbys) {
- var self = this;
- instance.web.pyeval.eval_domains_and_contexts({
+ var results = instance.web.pyeval.sync_eval_domains_and_contexts({
domains: domains || [],
contexts: contexts || [],
group_by_seq: groupbys || []
- }).done(function (results) {
- self.view_list.do_search(results.domain, results.context, results.group_by);
});
+ this.view_list.do_search(results.domain, results.context, results.group_by);
},
on_click_element: function(ids) {
var self = this;
@@ -5488,6 +5462,49 @@ instance.web.form.SelectCreatePopup = instance.web.form.AbstractFormPopup.extend
},
});
+instance.web.form.DomainEditorPopup = instance.web.form.SelectCreatePopup.extend({
+ select_element: function (model, options, domain, context) {
+ if (options.readonly) {
+ return this._super(model, options, domain, context);
+ }
+ options.initial_facet = {
+ category: _t("Custom Filter"),
+ icon: 'fa-star',
+ field: {
+ get_context: function () { return context; },
+ get_groupby: function () { return []; },
+ get_domain: function () { return domain; },
+ },
+ values: [{label: _t("Selected domain"), value: null}],
+ };
+ this._super(model, options, [], context);
+ },
+ get_domain: function (selected_ids) {
+ var group_domain = [],
+ domain;
+ if (this.$('input.oe_list_record_selector').prop('checked')) {
+ if (this.view_list.grouped) {
+ var group_domain = _.chain(_.values(this.view_list.groups.children))
+ .filter(function (child) { return child.records.length; })
+ .map(function (c) { return c.datagroup.domain;})
+ .value();
+ group_domain = _.flatten(group_domain, true);
+ group_domain = _.times(group_domain.length - 1, _.constant('|')).concat(group_domain);
+ }
+ var search_data = this.searchview.build_search_data();
+ domain = instance.web.pyeval.sync_eval_domains_and_contexts({
+ domains: search_data.domains,
+ contexts: search_data.contexts,
+ group_by_seq: search_data.groupbys || []
+ }).domain;
+ }
+ else {
+ domain = [["id", "in", selected_ids]];
+ }
+ return this.dataset.domain.concat(group_domain).concat(domain || []);
+ },
+});
+
instance.web.form.SelectCreateListView = instance.web.ListView.extend({
do_add_record: function () {
this.popup.new_object();