From 38e3daed00b9bfc7386a0c08debe7bc2f164f165 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 25 Sep 2013 16:45:56 +0200 Subject: wip bzr revid: nicolas.vanhoren@openerp.com-20130925144556-97abdprnibq631sc --- addons/web/static/src/js/view_form.js | 71 +++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'addons/web/static/src/js/view_form.js') 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', }); /** -- cgit v1.2.3 From fb17860c4110baa50d7d9bbde1afe176c5f7085e Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 1 Oct 2013 18:07:54 +0200 Subject: [IMP] doc bzr revid: nicolas.vanhoren@openerp.com-20131001160754-w47z24xf3wtkqioh --- addons/web/static/src/js/view_form.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src/js/view_form.js') diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 679eee0d361..a00b66cbeda 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -5630,7 +5630,9 @@ instance.web.form.FieldMonetary = instance.web.form.FieldFloat.extend({ }); /* - + This type of field display a list of checkboxes. It works only with m2ms. This field will display one checkbox for each + record existing in the model targeted by the relation, according to the given domain if one is specified. Checked records + will be added to the relation. */ instance.web.form.FieldMany2ManyCheckBoxes = instance.web.form.AbstractField.extend(instance.web.form.ReinitializeFieldMixin, { className: "oe_form_many2many_checkboxes", -- cgit v1.2.3 From 63c0220d3152332e54f118c6affc9fffcacde3dd Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 4 Oct 2013 17:37:34 +0200 Subject: still some problems bzr revid: nicolas.vanhoren@openerp.com-20131004153734-rxdt32qvu3gcxip2 --- addons/web/static/src/js/view_form.js | 75 +++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) (limited to 'addons/web/static/src/js/view_form.js') diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index a00b66cbeda..2069a33ab2a 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -5701,6 +5701,80 @@ instance.web.form.FieldMany2ManyCheckBoxes = instance.web.form.AbstractField.ext }, }); +instance.web.form.X2ManyCounter = instance.web.form.AbstractField.extend(instance.web.form.ReinitializeFieldMixin, { + className: "oe_form_x2many_counter", + init: function() { + this._super.apply(this, arguments); + this.set("value", []); + _.defaults(this.options, { + "views": [[false, "tree"], [false, "form"]], + }); + }, + render_value: function() { + var text = _.str.sprintf("%d %s", this.val().length, this.string); + this.$().html(QWeb.render("X2ManyCounter", {text: text})); + this.$("a").click(_.bind(this.go_to, this)); + }, + go_to: function() { + return this.view.recursive_save().then(_.bind(function() { + var val = this.val(); + var context = {}; + +/* +Object {groups_id: Array[0], domain: false, help: "

Click here to …documents, etc.↵

↵ ", res_model: "project.task", search_view_id: Array[2]…} +auto_refresh: 0 +auto_search: true +context: Class +domain: false +filter: false +flags: Object +groups_id: Array[0] +help: "

Click here to add new tasks

↵ OpenERP's project management allows you to manage the pipeline↵ of tasks in order to get things done efficiently. You can↵ track progress, discuss on tasks, attach documents, etc.↵

↵ " +id: 151 +limit: 80 +multi: false +name: "Tasks" +res_id: 0 +res_model: "project.task" +search_view: "{'name': u'project.task.search.form', 'fields': {'categ_ids': {'domain': [], 'string': 'Tags', 'views': {}, 'm2m_join_columns': ['project_task_id', 'project_category_id'], 'm2m_join_table': 'project_category_project_task_rel', 'relation': 'project.category', 'context': {}, 'selectable': True, 'type': 'many2many'}, 'partner_id': {'domain': [], 'string': 'Customer', 'views': {}, 'relation': 'res.partner', 'context': {}, 'selectable': True, 'type': 'many2one'}, 'user_id': {'domain': [], 'string': 'Assigned to', 'views': {}, 'relation': 'res.users', 'context': {}, 'selectable': True, 'type': 'many2one'}, 'project_id': {'domain': [], 'string': 'Project', 'views': {}, 'relation': 'project.project', 'context': {}, 'selectable': True, 'type': 'many2one', 'select': '1'}, 'stage_id': {'domain': "[('project_ids', '=', project_id)]", 'string': 'Stage', 'views': {}, 'relation': 'project.task.type', 'context': {}, 'selectable': True, 'type': 'many2one'}, 'name': {'string': 'Task Summary', 'views': {}, 'required': True, 'selectable': True, 'type': 'char', 'select': True, 'size': 128}}, 'arch': '\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ', 'model': 'project.task', 'type': u'search', 'view_id': 288, 'field_parent': False}" +search_view_id: Array[2] +src_model: false +target: "current" +type: "ir.actions.act_window" +usage: false +view_id: false +view_ids: Array[0] +view_mode: "kanban,list,form,calendar,gantt,graph" +views: Array[6] +__proto__: Object +*/ + + if (this.field.type === "one2many") { + context["default_" + this.field.relation_field] = this.view.datarecord.id; + } + context["search_default_"+ this.field.relation_field] = [this.view.datarecord.id]; + return this.do_action({ + type: 'ir.actions.act_window', + auto_search: true, + name: this.string, + res_model: this.field.relation, + res_id: val.length >= 1 ? val[0] : false, + res_ids: val, + views: this.options.views, + target: 'current', + context: {}, + }); + }, this)); + }, + val: function() { + var value = this.get("value") || []; + if (value.length >= 1 && value[0] instanceof Array) { + value = value[0][2]; + } + return value; + } +}); + /** * Registry of form fields, called by :js:`instance.web.FormView`. * @@ -5737,6 +5811,7 @@ instance.web.form.widgets = new instance.web.Registry({ 'statusbar': 'instance.web.form.FieldStatus', 'monetary': 'instance.web.form.FieldMonetary', 'many2many_checkboxes': 'instance.web.form.FieldMany2ManyCheckBoxes', + 'x2many_counter': 'instance.web.form.X2ManyCounter', }); /** -- cgit v1.2.3 From dc8f0ca96e5e58341f16c6713a08cbcaf210d9d7 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 4 Oct 2013 17:45:34 +0200 Subject: corrected problems bzr revid: nicolas.vanhoren@openerp.com-20131004154534-b3x46pmbybtza1cs --- addons/web/static/src/js/view_form.js | 35 +++-------------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) (limited to 'addons/web/static/src/js/view_form.js') diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 2069a33ab2a..859c78d7217 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -5719,50 +5719,21 @@ instance.web.form.X2ManyCounter = instance.web.form.AbstractField.extend(instanc return this.view.recursive_save().then(_.bind(function() { var val = this.val(); var context = {}; - -/* -Object {groups_id: Array[0], domain: false, help: "

Click here to …documents, etc.↵

↵ ", res_model: "project.task", search_view_id: Array[2]…} -auto_refresh: 0 -auto_search: true -context: Class -domain: false -filter: false -flags: Object -groups_id: Array[0] -help: "

Click here to add new tasks

↵ OpenERP's project management allows you to manage the pipeline↵ of tasks in order to get things done efficiently. You can↵ track progress, discuss on tasks, attach documents, etc.↵

↵ " -id: 151 -limit: 80 -multi: false -name: "Tasks" -res_id: 0 -res_model: "project.task" -search_view: "{'name': u'project.task.search.form', 'fields': {'categ_ids': {'domain': [], 'string': 'Tags', 'views': {}, 'm2m_join_columns': ['project_task_id', 'project_category_id'], 'm2m_join_table': 'project_category_project_task_rel', 'relation': 'project.category', 'context': {}, 'selectable': True, 'type': 'many2many'}, 'partner_id': {'domain': [], 'string': 'Customer', 'views': {}, 'relation': 'res.partner', 'context': {}, 'selectable': True, 'type': 'many2one'}, 'user_id': {'domain': [], 'string': 'Assigned to', 'views': {}, 'relation': 'res.users', 'context': {}, 'selectable': True, 'type': 'many2one'}, 'project_id': {'domain': [], 'string': 'Project', 'views': {}, 'relation': 'project.project', 'context': {}, 'selectable': True, 'type': 'many2one', 'select': '1'}, 'stage_id': {'domain': "[('project_ids', '=', project_id)]", 'string': 'Stage', 'views': {}, 'relation': 'project.task.type', 'context': {}, 'selectable': True, 'type': 'many2one'}, 'name': {'string': 'Task Summary', 'views': {}, 'required': True, 'selectable': True, 'type': 'char', 'select': True, 'size': 128}}, 'arch': '\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ', 'model': 'project.task', 'type': u'search', 'view_id': 288, 'field_parent': False}" -search_view_id: Array[2] -src_model: false -target: "current" -type: "ir.actions.act_window" -usage: false -view_id: false -view_ids: Array[0] -view_mode: "kanban,list,form,calendar,gantt,graph" -views: Array[6] -__proto__: Object -*/ - if (this.field.type === "one2many") { context["default_" + this.field.relation_field] = this.view.datarecord.id; + } else if (this.field.type === "many2many") { + context["default_" + this.field.relation_field] = [6, 0, [this.view.datarecord.id]]; } context["search_default_"+ this.field.relation_field] = [this.view.datarecord.id]; return this.do_action({ type: 'ir.actions.act_window', - auto_search: true, name: this.string, res_model: this.field.relation, res_id: val.length >= 1 ? val[0] : false, res_ids: val, views: this.options.views, target: 'current', - context: {}, + context: context, }); }, this)); }, -- cgit v1.2.3 From 8d2f37ec8bd42d6e593cdbcaec3028cce1730274 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 7 Oct 2013 13:56:38 +0200 Subject: wip bzr revid: nicolas.vanhoren@openerp.com-20131007115638-9b82rw1azwjtp5fr --- addons/web/static/src/js/view_form.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'addons/web/static/src/js/view_form.js') diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 859c78d7217..06c700eb280 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -5721,19 +5721,16 @@ instance.web.form.X2ManyCounter = instance.web.form.AbstractField.extend(instanc var context = {}; if (this.field.type === "one2many") { context["default_" + this.field.relation_field] = this.view.datarecord.id; - } else if (this.field.type === "many2many") { - context["default_" + this.field.relation_field] = [6, 0, [this.view.datarecord.id]]; } - context["search_default_"+ this.field.relation_field] = [this.view.datarecord.id]; + var domain = [["id", "in", val]]; return this.do_action({ type: 'ir.actions.act_window', name: this.string, res_model: this.field.relation, - res_id: val.length >= 1 ? val[0] : false, - res_ids: val, views: this.options.views, target: 'current', context: context, + domain: domain, }); }, this)); }, -- cgit v1.2.3 From 8b0193a3bc71be75fbfdaf9eff3665ddcfc05a13 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 8 Oct 2013 15:51:43 +0200 Subject: added doc bzr revid: nicolas.vanhoren@openerp.com-20131008135143-8qjqwi3s23ld0wks --- addons/web/static/src/js/view_form.js | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'addons/web/static/src/js/view_form.js') diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 06c700eb280..c096dd884ad 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -5701,6 +5701,17 @@ instance.web.form.FieldMany2ManyCheckBoxes = instance.web.form.AbstractField.ext }, }); +/** + This field can be applied on many2many and one2many. It is a read-only field that will display a single link whose name is + "