mirror of https://github.com/OCA/web.git
Merge pull request #370 from kaerdsar/8.0-web-invalid-tab
[ADD] adding module web_invalid_tabpull/458/head
commit
1ac3f8d38d
|
@ -0,0 +1,45 @@
|
|||
.. 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
|
||||
|
||||
===============
|
||||
Web invalid tab
|
||||
===============
|
||||
|
||||
This module highlights a tab when fields inside are invalid. It's useful when you have a form with many tabs.
|
||||
|
||||
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 smashing it by providing a detailed and welcomed `feedback
|
||||
<https://github.com/OCA/
|
||||
web/issues/new?body=module:%20
|
||||
web_invalid_tab%0Aversion:%20
|
||||
8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
* Cesar Lage <kaerdsar@gmail.com>
|
||||
* Robert Rübner <rruebner@bloopark.de>
|
||||
|
||||
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,0 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# © 2016 Cesar Lage (bloopark systems GmbH)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
@ -0,0 +1,19 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# © 2016 Cesar Lage (bloopark systems GmbH)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
{
|
||||
'name': "Web Invalid Tab",
|
||||
'summary': "Highlight tab when fields inside are invalid.",
|
||||
'author': "bloopark systems GmbH & Co. KG, "
|
||||
"Odoo Community Association (OCA)",
|
||||
'website': "http://www.bloopark.de",
|
||||
'category': 'web',
|
||||
'version': '8.0.1.0.0',
|
||||
"license": "AGPL-3",
|
||||
'depends': [
|
||||
'web',
|
||||
],
|
||||
'data': [
|
||||
'views/assets.xml',
|
||||
]
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
li > a.oe_form_tab_invalid {
|
||||
border: 1px solid #D00 !important;
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
openerp.web_invalid_tab = function(instance) {
|
||||
|
||||
var tab_selector = 'div[role="tabpanel"]';
|
||||
|
||||
function tab_link(tab) {
|
||||
return $("a[href='#" + tab.attr('id') + "']");
|
||||
}
|
||||
|
||||
function is_visible(tab, element) {
|
||||
if ($(element).hasClass('oe_form_invisible') || element.style.display == 'none') {
|
||||
return false;
|
||||
}
|
||||
else if (element.parentNode && element.parentNode != tab) {
|
||||
return is_visible(tab, element.parentNode);
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
instance.web.form.AbstractField.include({
|
||||
_check_css_flags: function() {
|
||||
if (this.field.translate) {
|
||||
this.$el.find('.oe_field_translate').toggle(this.field_manager.get('actual_mode') !== "create");
|
||||
}
|
||||
if (!this.disable_utility_classes) {
|
||||
if (this.field_manager.get('display_invalid_fields')) {
|
||||
this.$el.toggleClass('oe_form_invalid', !this.is_valid());
|
||||
this._update_tab_invalid_class();
|
||||
}
|
||||
}
|
||||
},
|
||||
_update_tab_invalid_class: function() {
|
||||
var tab = this.$el.closest(tab_selector);
|
||||
if (tab.attr('id')) {
|
||||
if (this.is_valid()) {
|
||||
if (tab.find('.oe_form_invalid').length == 0) {
|
||||
tab_link(tab).removeClass('oe_form_tab_invalid');
|
||||
}
|
||||
}
|
||||
else if (is_visible(tab.get(0), this.$el.get(0)) === true) {
|
||||
tab_link(tab).addClass('oe_form_tab_invalid');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
instance.web.FormView.include({
|
||||
on_form_changed: function() {
|
||||
this._super();
|
||||
$(tab_selector).each(function(i, tab) {
|
||||
var invalid = _.detect($(tab).find('.oe_form_invalid'), function(x) {
|
||||
return is_visible(tab, x);
|
||||
});
|
||||
if (!invalid) {
|
||||
tab_link($(tab)).removeClass('oe_form_tab_invalid');
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
};
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<template id="assets_backend" name="web_invalid_tab_assets" inherit_id="web.assets_backend">
|
||||
<xpath expr="." position="inside">
|
||||
<link rel="stylesheet" href="/web_invalid_tab/static/src/css/view_form.css"/>
|
||||
|
||||
<script type="text/javascript" src="/web_invalid_tab/static/src/js/view_form.js"></script>
|
||||
</xpath>
|
||||
</template>
|
||||
</data>
|
||||
</openerp>
|
Loading…
Reference in New Issue