Browse Source

[ADD][web_x2many_add_button_position] Move Add an item button (#578)

pull/641/head
Dennis Sluijk 7 years ago
committed by Pedro M. Baeza
parent
commit
7999843f1b
  1. 59
      web_x2many_add_button_position/README.rst
  2. 3
      web_x2many_add_button_position/__init__.py
  3. 22
      web_x2many_add_button_position/__openerp__.py
  4. 23
      web_x2many_add_button_position/static/src/js/web_x2many_add_button_position.js
  5. 13
      web_x2many_add_button_position/templates/assets.xml

59
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::
<field name="tax_line">
<tree editable="top" string="Taxes">
</tree>
</field>
Usage
=====
This module has no new visible aspect.
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/web/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.

3
web_x2many_add_button_position/__init__.py

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Onestein (<http://www.onestein.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

22
web_x2many_add_button_position/__openerp__.py

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Onestein (<http://www.onestein.eu>)
# 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,
}

23
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);
}
});
}

13
web_x2many_add_button_position/templates/assets.xml

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2017 Onestein
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<openerp>
<data>
<template id="assets_backend" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/web_x2many_add_button_position/static/src/js/web_x2many_add_button_position.js"></script>
</xpath>
</template>
</data>
</openerp>
Loading…
Cancel
Save