From 7999843f1b6abd2eda9b9d5ebd8a67ecbc8f59db Mon Sep 17 00:00:00 2001 From: Dennis Sluijk Date: Mon, 20 Mar 2017 13:55:44 +0100 Subject: [PATCH] [ADD][web_x2many_add_button_position] Move Add an item button (#578) --- web_x2many_add_button_position/README.rst | 59 +++++++++++++++++++ web_x2many_add_button_position/__init__.py | 3 + web_x2many_add_button_position/__openerp__.py | 22 +++++++ .../src/js/web_x2many_add_button_position.js | 23 ++++++++ .../templates/assets.xml | 13 ++++ 5 files changed, 120 insertions(+) create mode 100644 web_x2many_add_button_position/README.rst create mode 100644 web_x2many_add_button_position/__init__.py create mode 100644 web_x2many_add_button_position/__openerp__.py create mode 100644 web_x2many_add_button_position/static/src/js/web_x2many_add_button_position.js create mode 100644 web_x2many_add_button_position/templates/assets.xml diff --git a/web_x2many_add_button_position/README.rst b/web_x2many_add_button_position/README.rst new file mode 100644 index 00000000..15a3a5e1 --- /dev/null +++ b/web_x2many_add_button_position/README.rst @@ -0,0 +1,59 @@ +.. 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 Add Button Position +========================== + +This module moves the ``Add an item`` button of x2many fields to the top or bottom of the list (depending on the ``editable`` attribute). + +Configuration +============= + +To configure this module, you need to: + +#. Modify or add the ``editable`` attribute of / to the tree element. + +Example:: + + + + + + +Usage +===== + +This module has no new visible aspect. + +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 smash it by providing 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_add_button_position/__init__.py b/web_x2many_add_button_position/__init__.py new file mode 100644 index 00000000..6529c19d --- /dev/null +++ b/web_x2many_add_button_position/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Onestein () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). diff --git a/web_x2many_add_button_position/__openerp__.py b/web_x2many_add_button_position/__openerp__.py new file mode 100644 index 00000000..5621cf11 --- /dev/null +++ b/web_x2many_add_button_position/__openerp__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Onestein () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + 'name': 'X2many Add Button Position', + 'summary': """ + Configurable position for the 'Add an Item' button + """, + 'author': 'Onestein,Odoo Community Association (OCA)', + 'website': 'http://www.onestein.eu', + 'category': 'Web', + 'version': '8.0.1.0.0', + 'depends': [ + 'web' + ], + 'data': [ + 'templates/assets.xml', + ], + 'installable': True, + 'application': False, +} diff --git a/web_x2many_add_button_position/static/src/js/web_x2many_add_button_position.js b/web_x2many_add_button_position/static/src/js/web_x2many_add_button_position.js new file mode 100644 index 00000000..fd266f3b --- /dev/null +++ b/web_x2many_add_button_position/static/src/js/web_x2many_add_button_position.js @@ -0,0 +1,23 @@ +/* Copyright 2017 Onestein + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ + +openerp.web_x2many_add_button_position = function(instance) { + instance.web.form.AddAnItemList.include({ + pad_table_to: function() { + var self = this; + this._super.apply(this, arguments); + if (this.view.fields_view.arch.attrs.editable && + this.view.fields_view.arch.attrs.editable == 'top') { + this.move_add_item_button(); + this.$current.find('.' + this._add_row_class + ' a').click(function() { + self.move_add_item_button(); + }); + } + }, + move_add_item_button: function() { + $btn_row = this.$current.find('.' + this._add_row_class).parent(); + $btn_row.detach(); + this.$current.find('tr:first').before($btn_row); + } + }); +} diff --git a/web_x2many_add_button_position/templates/assets.xml b/web_x2many_add_button_position/templates/assets.xml new file mode 100644 index 00000000..bc488735 --- /dev/null +++ b/web_x2many_add_button_position/templates/assets.xml @@ -0,0 +1,13 @@ + + + + + + + +