diff --git a/web_widget_one2many_tags/README.rst b/web_widget_one2many_tags/README.rst new file mode 100644 index 00000000..1bd30efc --- /dev/null +++ b/web_widget_one2many_tags/README.rst @@ -0,0 +1,53 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +=============================== +Tags widget for one2many fields +=============================== + +This module add a widget ``one2many_tags`` that looks and behaves like ``many2many_tags``, but works for one2many fields. + +Usage +===== + +To use this module, use ``widget="one2many_tags"`` on your field element. + +* go to ... +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/162/8.0 + +For further information, please visit: + +* https://www.odoo.com/forum/help-1 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback +`here `_. + +Credits +======= + +Contributors +------------ + +* Holger Brunn + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/web_widget_one2many_tags/__init__.py b/web_widget_one2many_tags/__init__.py new file mode 100644 index 00000000..fa85807b --- /dev/null +++ b/web_widget_one2many_tags/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +# © 2016 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). diff --git a/web_widget_one2many_tags/__openerp__.py b/web_widget_one2many_tags/__openerp__.py new file mode 100644 index 00000000..80105d76 --- /dev/null +++ b/web_widget_one2many_tags/__openerp__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# © 2016 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Tags widget for one2many fields", + "version": "8.0.1.0.0", + "author": "Therp BV,Odoo Community Association (OCA)", + "license": "AGPL-3", + "category": "Hidden/Dependency", + "summary": "Provides a widget similar to many2many_tags for one2many " + "fields", + "depends": [ + 'web', + ], + "data": [ + 'views/templates.xml', + ], +} diff --git a/web_widget_one2many_tags/static/description/icon.png b/web_widget_one2many_tags/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/web_widget_one2many_tags/static/description/icon.png differ diff --git a/web_widget_one2many_tags/static/src/js/web_widget_one2many_tags.js b/web_widget_one2many_tags/static/src/js/web_widget_one2many_tags.js new file mode 100644 index 00000000..002110a7 --- /dev/null +++ b/web_widget_one2many_tags/static/src/js/web_widget_one2many_tags.js @@ -0,0 +1,79 @@ +//-*- coding: utf-8 -*- +//© 2016 Therp BV +//License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +openerp.web_widget_one2many_tags = function(instance) +{ + openerp.web_widget_one2many_tags.FieldOne2ManyTags = + instance.web.form.FieldMany2ManyTags.extend({ + initialize_texttext: function() + { + var self = this, + result = this._super.apply(this, arguments), + removeTag = result.ext.tags.removeTag; + result.plugins = 'tags arrow filter'; + result.ext.core.onSetInputData = function(e, data) + { + this.input().val(data); + }; + result.filter = { + items: [] + }; + result.ext.arrow = { + onArrowClick: function(e) + { + var context = {}, + key = _.str.sprintf( + 'default_%s', self.field.relation_field) + context[key] = self.field_manager.datarecord.id; + self._search_create_popup('form', undefined, context); + }, + } + result.ext.tags.removeTag = function(tag) + { + var id = tag.data("id"), + dataset = new instance.web.DataSet( + self, self.field.relation, self.build_context()); + dataset.unlink([id]); + return removeTag(tag); + }; + return result; + }, + initialize_content: function() + { + var self = this, + result = this._super.apply(this, arguments); + if(!this.$text) + { + return result; + } + this.$text.bind('tagClick', function(e, tag, value, callback) + { + var popup = new instance.web.form.FormOpenPopup(self); + popup.show_element( + self.field.relation, value.id, self.build_context(), + { + title: instance.web._t("Open: ") + value.name, + readonly: self.get("effective_readonly"), + }); + popup.on('write_completed', self, function() + { + popup.dataset.name_get(popup.dataset.ids) + .then(function(names) + { + _(names).each(function(name) + { + value.name = name[1]; + callback(value, true); + }) + }); + }); + }); + return result; + }, + }); + instance.web.form.widgets.add( + 'one2many_tags', + 'instance.web_widget_one2many_tags.FieldOne2ManyTags' + ); +} diff --git a/web_widget_one2many_tags/views/templates.xml b/web_widget_one2many_tags/views/templates.xml new file mode 100644 index 00000000..cb10f7f8 --- /dev/null +++ b/web_widget_one2many_tags/views/templates.xml @@ -0,0 +1,10 @@ + + + + + +