Browse Source

Merge 68c83bdf27 into 880df8eb7b

pull/852/merge
andreparames 5 years ago
committed by GitHub
parent
commit
cfce08f76b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      setup/web_tab_focus/odoo/__init__.py
  2. 1
      setup/web_tab_focus/odoo/addons/__init__.py
  3. 1
      setup/web_tab_focus/odoo/addons/web_tab_focus
  4. 6
      setup/web_tab_focus/setup.py
  5. 94
      web_tab_focus/README.rst
  6. 0
      web_tab_focus/__init__.py
  7. 17
      web_tab_focus/__manifest__.py
  8. 31
      web_tab_focus/static/src/js/tab_focus.js
  9. 11
      web_tab_focus/views/templates.xml

1
setup/web_tab_focus/odoo/__init__.py

@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)

1
setup/web_tab_focus/odoo/addons/__init__.py

@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)

1
setup/web_tab_focus/odoo/addons/web_tab_focus

@ -0,0 +1 @@
../../../../web_tab_focus

6
setup/web_tab_focus/setup.py

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

94
web_tab_focus/README.rst

@ -0,0 +1,94 @@
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3
=============
web_tab_focus
=============
This module allows a developer to select which page of a notebook should be
automatically focused, depending on the contents of a field.
Usage
=====
This module is used by adding attributes to the <notebook> and <page> tags of
form views.
For example, if you have a field in your model::
vehicle = fields.Selection([
('bicycle', 'Bicycle'),
('motorcycle', 'Motorcycle'),
('car', 'Car'),
])
And you have a <notebook> in the form view for each vehicle, you can focus on
the appropriate tab automatically using the follow code::
<!-- the field must be in the view, but it can be invisible -->
<field name="vehicle"/>
<notebook focus-var="vehicle">
<page focus-val="bicycle">
<!-- bicycle specific stuff goes here -->
</page>
<page focus-val="car">
<!-- car specific stuff goes here -->
</page>
<page focus-val="motorcycle">
<!-- motorcycle specific stuff goes here -->
</page>
</notebook>
When the record is loaded, the module will compare the value of the field
`vehicle` with the value of each page, and focus on the one that is equal.
.. 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/10.0
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
=======
Images
------
* Odoo Community Association: `Icon <https://odoo-community.org/logo.png>`_.
Contributors
------------
* André Paramés (ACSONE) <github@andreparames.com>
Do not contact contributors directly about support or help with technical issues.
Funders
-------
The development of this module has been financially supported by:
* ACSONE SA/NV
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.

0
web_tab_focus/__init__.py

17
web_tab_focus/__manifest__.py

@ -0,0 +1,17 @@
# coding: utf-8
# Copyright 2018 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': "Web Tab Focus",
'author': 'ACSONE SA/NV,Odoo Community Association (OCA)',
'website': "https://github.com/OCA/web",
'category': 'web',
'version': '10.0.1.0.0',
'license': 'AGPL-3',
'depends': [
'web',
],
'data': [
'views/templates.xml',
],
}

31
web_tab_focus/static/src/js/tab_focus.js

@ -0,0 +1,31 @@
odoo.define('web.tab_focus', function (require) {
'use strict';
var FormRenderingEngine = require('web.FormRenderingEngine');
FormRenderingEngine.include({
process_notebook: function($notebook) {
var $new_notebook = this._super.call(this, $notebook);
if(!!$notebook.attr('focus-var')) {
var focus_var = $notebook.attr('focus-var');
this.view.on("load_record", this, function(record) {
var field_value = record[focus_var];
var original_pages = $notebook.find('> page');
var tabs = $new_notebook.find('ul.nav.nav-tabs > li');
var contents = $new_notebook.find('div.tab-content > div.tab-pane');
for(var i=0; i<original_pages.length; i++) {
var original_page = original_pages.eq(i);
var focus_val = original_page.attr('focus-val');
if(focus_val === field_value) {
tabs.removeClass('active');
tabs.eq(i).addClass('active');
contents.removeClass('active');
contents.eq(i).addClass('active');
break;
}
}
});
}
return $new_notebook;
}
});
});

11
web_tab_focus/views/templates.xml

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets_backend" name="abi_after_sale assets"
inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/web_tab_focus/static/src/js/tab_focus.js"/>
</xpath>
</template>
</odoo>
Loading…
Cancel
Save