From 0eb044ad984d5e22a6610323ef213f66d48046b1 Mon Sep 17 00:00:00 2001 From: Dennis Sluijk Date: Sun, 26 Feb 2017 20:17:14 +0100 Subject: [PATCH] [8.0][MIG][web_x2many_delete_all] Backport 10.0 -> 8.0 (#486) --- web_x2many_delete_all/README.rst | 58 +++++++++++++++++ web_x2many_delete_all/__init__.py | 3 + web_x2many_delete_all/__openerp__.py | 26 ++++++++ .../static/src/css/web_x2many_delete_all.css | 13 ++++ .../static/src/js/web_x2many_delete_all.js | 62 +++++++++++++++++++ .../static/src/xml/web_x2many_delete_all.xml | 16 +++++ web_x2many_delete_all/templates/assets.xml | 16 +++++ 7 files changed, 194 insertions(+) create mode 100644 web_x2many_delete_all/README.rst create mode 100644 web_x2many_delete_all/__init__.py create mode 100644 web_x2many_delete_all/__openerp__.py create mode 100644 web_x2many_delete_all/static/src/css/web_x2many_delete_all.css create mode 100644 web_x2many_delete_all/static/src/js/web_x2many_delete_all.js create mode 100644 web_x2many_delete_all/static/src/xml/web_x2many_delete_all.xml create mode 100644 web_x2many_delete_all/templates/assets.xml diff --git a/web_x2many_delete_all/README.rst b/web_x2many_delete_all/README.rst new file mode 100644 index 00000000..aa9a6c5d --- /dev/null +++ b/web_x2many_delete_all/README.rst @@ -0,0 +1,58 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +======================== +X2many Delete All Button +======================== + +Adds a button to Many2many and One2many fields that removes all linked records. + +Configuration +============= + +No configuration is needed. + +Usage +===== + +To use this module, you need to: + +#. Go to any Many2many or One2many field; +#. click 'Edit'; +#. click the top most trash can button. + +.. 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 + +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. + +Credits +======= + +Contributors +------------ + +* Dennis Sluijk + +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. \ No newline at end of file diff --git a/web_x2many_delete_all/__init__.py b/web_x2many_delete_all/__init__.py new file mode 100644 index 00000000..3bf7ea73 --- /dev/null +++ b/web_x2many_delete_all/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +# © 2016 Onestein () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). diff --git a/web_x2many_delete_all/__openerp__.py b/web_x2many_delete_all/__openerp__.py new file mode 100644 index 00000000..efc2bbe2 --- /dev/null +++ b/web_x2many_delete_all/__openerp__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# © 2016 Onestein () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + 'name': 'X2many Delete All Button', + 'summary': """ + Adds a button to x2many fields that removes all linked records + """, + 'version': '8.0.1.0.0', + 'category': 'Web', + 'author': 'Onestein,Odoo Community Association (OCA)', + 'website': 'http://www.onestein.eu', + 'license': 'AGPL-3', + 'depends': [ + 'web', + ], + 'data': [ + 'templates/assets.xml' + ], + 'qweb': [ + 'static/src/xml/web_x2many_delete_all.xml' + ], + 'installable': True, + 'application': False, +} diff --git a/web_x2many_delete_all/static/src/css/web_x2many_delete_all.css b/web_x2many_delete_all/static/src/css/web_x2many_delete_all.css new file mode 100644 index 00000000..a6e4183d --- /dev/null +++ b/web_x2many_delete_all/static/src/css/web_x2many_delete_all.css @@ -0,0 +1,13 @@ +/* Copyright 2016 Onestein + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ + +div.oe_list th.oe_list_record_delete, +div.oe_list th.oe_list_record_delete > button { + cursor: pointer; +} + +div.oe_list th.oe_list_record_delete > button { + border: none; + background: transparent; + padding: 0; +} diff --git a/web_x2many_delete_all/static/src/js/web_x2many_delete_all.js b/web_x2many_delete_all/static/src/js/web_x2many_delete_all.js new file mode 100644 index 00000000..6f5e7e4c --- /dev/null +++ b/web_x2many_delete_all/static/src/js/web_x2many_delete_all.js @@ -0,0 +1,62 @@ +/* Copyright 2016 Onestein + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ + +openerp.web_x2many_delete_all = function(instance) { +"use strict"; + + instance.web.form.FieldMany2Many.include({ + events: { + 'click th.oe_list_record_delete': 'btn_delete_all_clicked' + }, + initialize_content: function() { + var self = this; + var res = this._super.apply(this, arguments); + this.is_loaded.then(function() { + self.toggle_btn_delete_all(); + }); + return res; + }, + toggle_btn_delete_all: function() { + if(this.get('effective_readonly')) { + this.$('th.oe_list_record_delete > button').addClass('hidden'); + } else { + this.$('th.oe_list_record_delete > button').removeClass('hidden'); + } + }, + btn_delete_all_clicked: function() { + if(this.get('effective_readonly')) return; + this.delete_all(); + }, + delete_all: function() { + this.list_view.do_delete(this.dataset.ids); + } + }); + + instance.web.form.FieldOne2Many.include({ + events: { + 'click th.oe_list_record_delete': 'btn_delete_all_clicked' + }, + reload_current_view: function() { + var self = this; + var res = this._super.apply(this, arguments); + res.then(function() { + self.toggle_btn_delete_all(); + }); + return res; + }, + toggle_btn_delete_all: function() { + if(this.get('effective_readonly')) { + this.$('th.oe_list_record_delete > button').addClass('hidden'); + } else { + this.$('th.oe_list_record_delete > button').removeClass('hidden'); + } + }, + btn_delete_all_clicked: function() { + if(this.get('effective_readonly')) return; + this.delete_all(); + }, + delete_all: function() { + this.viewmanager.views.list.controller.do_delete(this.dataset.ids); + } + }); +} diff --git a/web_x2many_delete_all/static/src/xml/web_x2many_delete_all.xml b/web_x2many_delete_all/static/src/xml/web_x2many_delete_all.xml new file mode 100644 index 00000000..28c5a8d5 --- /dev/null +++ b/web_x2many_delete_all/static/src/xml/web_x2many_delete_all.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + diff --git a/web_x2many_delete_all/templates/assets.xml b/web_x2many_delete_all/templates/assets.xml new file mode 100644 index 00000000..69e305f6 --- /dev/null +++ b/web_x2many_delete_all/templates/assets.xml @@ -0,0 +1,16 @@ + + + + + +