summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorniv-openerp <nicolas.vanhoren@openerp.com>2013-09-25 16:45:56 +0200
committerniv-openerp <nicolas.vanhoren@openerp.com>2013-09-25 16:45:56 +0200
commit38e3daed00b9bfc7386a0c08debe7bc2f164f165 (patch)
tree90ed13957f686ec058e93e7bb315d1543c353615 /addons/web/static/src
parentbc0d066505a054389525cdf7601b35751ea3efbb (diff)
wip
bzr revid: nicolas.vanhoren@openerp.com-20130925144556-97abdprnibq631sc
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/view_form.js71
-rw-r--r--addons/web/static/src/xml/base.xml13
2 files changed, 84 insertions, 0 deletions
diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js
index 324896112cc..679eee0d361 100644
--- a/addons/web/static/src/js/view_form.js
+++ b/addons/web/static/src/js/view_form.js
@@ -5629,6 +5629,76 @@ instance.web.form.FieldMonetary = instance.web.form.FieldFloat.extend({
},
});
+/*
+
+*/
+instance.web.form.FieldMany2ManyCheckBoxes = instance.web.form.AbstractField.extend(instance.web.form.ReinitializeFieldMixin, {
+ className: "oe_form_many2many_checkboxes",
+ init: function() {
+ this._super.apply(this, arguments);
+ this.set("value", {});
+ this.set("records", []);
+ this.field_manager.on("view_content_has_changed", this, function() {
+ var domain = new openerp.web.CompoundDomain(this.build_domain()).eval();
+ if (! _.isEqual(domain, this.get("domain"))) {
+ this.set("domain", domain);
+ }
+ });
+ this.records_orderer = new instance.web.DropMisordered();
+ },
+ initialize_field: function() {
+ instance.web.form.ReinitializeFieldMixin.initialize_field.call(this)
+ this.on("change:domain", this, this.query_records);
+ this.set("domain", new openerp.web.CompoundDomain(this.build_domain()).eval());
+ this.on("change:records", this, this.render_value);
+ },
+ query_records: function() {
+ var self = this;
+ var model = new openerp.Model(openerp.session, this.field.relation);
+ this.records_orderer.add(model.call("search", [this.get("domain")], {"context": this.build_context()}).then(function(record_ids) {
+ return model.call("name_get", [record_ids] , {"context": self.build_context()});
+ })).then(function(res) {
+ self.set("records", res);
+ });
+ },
+ render_value: function() {
+ this.$().html(QWeb.render("FieldMany2ManyCheckBoxes", {widget: this, selected: this.get("value")}));
+ var inputs = this.$("input");
+ inputs.change(_.bind(this.from_dom, this));
+ if (this.get("effective_readonly"))
+ inputs.attr("disabled", "true");
+ },
+ from_dom: function() {
+ var new_value = {};
+ this.$("input").each(function() {
+ var elem = $(this);
+ new_value[elem.data("record-id")] = elem.attr("checked") ? true : undefined;
+ });
+ if (! _.isEqual(new_value, this.get("value")))
+ this.internal_set_value(new_value);
+ },
+ set_value: function(value) {
+ value = value || [];
+ if (value.length >= 1 && value[0] instanceof Array) {
+ value = value[0][2];
+ }
+ var formatted = {};
+ _.each(value, function(el) {
+ formatted[JSON.stringify(el)] = true;
+ });
+ this._super(formatted);
+ },
+ get_value: function() {
+ var value = _.filter(_.keys(this.get("value")), function(el) {
+ return this.get("value")[el];
+ }, this);
+ value = _.map(value, function(el) {
+ return JSON.parse(el);
+ });
+ return [commands.replace_with(value)];
+ },
+});
+
/**
* Registry of form fields, called by :js:`instance.web.FormView`.
*
@@ -5664,6 +5734,7 @@ instance.web.form.widgets = new instance.web.Registry({
'many2many_binary': 'instance.web.form.FieldMany2ManyBinaryMultiFiles',
'statusbar': 'instance.web.form.FieldStatus',
'monetary': 'instance.web.form.FieldMonetary',
+ 'many2many_checkboxes': 'instance.web.form.FieldMany2ManyCheckBoxes',
});
/**
diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml
index ee87237d045..48c51c4837c 100644
--- a/addons/web/static/src/xml/base.xml
+++ b/addons/web/static/src/xml/base.xml
@@ -1934,4 +1934,17 @@
</t>
</t>
</t>
+<t t-name="FieldMany2ManyCheckBoxes">
+ <t t-foreach="widget.get('records')" t-as="record">
+ <div>
+ <t t-if="selected[record[0]]">
+ <input type="checkbox" t-att-data-record-id="JSON.stringify(record[0])" checked="true"/>
+ </t>
+ <t t-if="! selected[record[0]]">
+ <input type="checkbox" t-att-data-record-id="JSON.stringify(record[0])"/>
+ </t>
+ <t t-esc="record[1]"/>
+ </div>
+ </t>
+</t>
</templates>