summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/widgets
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2017-01-10 13:52:44 +0100
committerChristophe Simonis <chs@odoo.com>2017-01-10 13:52:44 +0100
commita2c1df8b9ca731107dd2d67cc0b2dd39d0c7ad64 (patch)
tree5de4c414a1c137c674ca004fbec6a29fc1a10db5 /addons/web/static/src/js/widgets
parentd38e00031f975db4a3d3e80250d5142444a3239b (diff)
parent557feb950cb74656c92e59a62847c9e414c9b41f (diff)
[MERGE] forward port branch saas-14 up to 557feb950cb
Diffstat (limited to 'addons/web/static/src/js/widgets')
-rw-r--r--addons/web/static/src/js/widgets/domain_selector.js17
-rw-r--r--addons/web/static/src/js/widgets/domain_selector_dialog.js48
2 files changed, 55 insertions, 10 deletions
diff --git a/addons/web/static/src/js/widgets/domain_selector.js b/addons/web/static/src/js/widgets/domain_selector.js
index 5f4287a8d8d..15e967ff4d4 100644
--- a/addons/web/static/src/js/widgets/domain_selector.js
+++ b/addons/web/static/src/js/widgets/domain_selector.js
@@ -3,9 +3,9 @@ odoo.define("web.DomainSelector", function (require) {
var core = require("web.core");
var datepicker = require("web.datepicker");
+var domainUtils = require("web.domainUtils");
var formats = require ("web.formats");
var ModelFieldSelector = require("web.ModelFieldSelector");
-var pyeval = require("web.pyeval");
var Widget = require("web.Widget");
var _t = core._t;
@@ -55,7 +55,7 @@ var DomainNode = Widget.extend({
},
/// A DomainNode needs a model and domain to work. It can also receives a set of options
/// @param model - a string with the model name
- /// @param domain - an array of the prefix representation of the domain
+ /// @param domain - an array of the prefix representation of the domain (or a string which represents it)
/// @param options - an object with possible values:
/// - readonly, a boolean to indicate if the widget is readonly or not (default to true)
/// - fs_filters, an object with a series of filters to use for the field selector (see @FieldSelector)
@@ -109,7 +109,7 @@ var DomainTree = DomainNode.extend({
/// @see DomainTree._addFlattenedChildren
init: function (parent, model, domain, options) {
this._super.apply(this, arguments);
- this._initialize(domain);
+ this._initialize(domainUtils.stringToDomain(domain));
},
/// @see DomainTree.init
_initialize: function (domain) {
@@ -265,8 +265,9 @@ var DomainSelector = DomainTree.extend({
/// the widget is re-rendered and notifies the parents. If not, a warning is shown to the
/// user and the input is ignored.
"change .o_domain_debug_input": function (e) {
+ var domain;
try {
- var domain = pyeval.eval("domain", $(e.currentTarget).val() || "[]");
+ domain = domainUtils.stringToDomain($(e.currentTarget).val());
} catch (err) {
this.do_warn(_t("Syntax error"), _t("The domain you entered is not properly formed"));
return;
@@ -292,12 +293,7 @@ var DomainSelector = DomainTree.extend({
// Display technical domain if in debug mode
this.$debugInput = this.$(".o_domain_debug_input");
if (this.$debugInput.length) {
- var strValue = this.getDomain() || "[]";
- if (!_.isString(strValue)) { // TODO there is no "pyuneval" function
- strValue = JSON.stringify(strValue);
- strValue = strValue.replace(/false/g, "False").replace(/true/g, "True");
- }
- this.$debugInput.val(strValue);
+ this.$debugInput.val(domainUtils.domainToString(this.getDomain()));
}
},
});
@@ -328,6 +324,7 @@ var DomainLeaf = DomainNode.extend({
init: function (parent, model, domain, options) {
this._super.apply(this, arguments);
+ domain = domainUtils.stringToDomain(domain);
this.chain = domain[0][0];
this.operator = domain[0][1];
this.value = domain[0][2];
diff --git a/addons/web/static/src/js/widgets/domain_selector_dialog.js b/addons/web/static/src/js/widgets/domain_selector_dialog.js
new file mode 100644
index 00000000000..47bfa4e1359
--- /dev/null
+++ b/addons/web/static/src/js/widgets/domain_selector_dialog.js
@@ -0,0 +1,48 @@
+odoo.define("web.DomainSelectorDialog", function (require) {
+"use strict";
+
+var core = require("web.core");
+var Dialog = require("web.Dialog");
+var DomainSelector = require("web.DomainSelector");
+
+var _t = core._t;
+
+return Dialog.extend({
+ init: function (parent, model, domain, options) {
+ this.model = model;
+ this.options = _.extend({
+ readonly: true,
+ fs_filters: {},
+ debugMode: false,
+ }, options || {});
+
+ var buttons;
+ if (this.options.readonly) {
+ buttons = [
+ {text: _t("Close"), close: true},
+ ];
+ } else {
+ buttons = [
+ {text: _t("Save"), classes: "btn-primary", close: true, click: function () {
+ this.trigger_up("domain_selected", {domain: this.domainSelector.getDomain()});
+ }},
+ {text: _t("Discard"), close: true},
+ ];
+ }
+
+ this._super(parent, _.extend({}, {
+ title: _t("Domain"),
+ buttons: buttons,
+ }, options || {}));
+
+ this.domainSelector = new DomainSelector(this, model, domain, options);
+ },
+ start: function () {
+ this.$el.css("overflow", "visible").closest(".modal-dialog").css("height", "auto"); // This restores default modal height (bootstrap) and allows field selector to overflow
+ return $.when(
+ this._super.apply(this, arguments),
+ this.domainSelector.appendTo(this.$el)
+ );
+ },
+});
+});