diff --git a/web_invalid_tab/README.rst b/web_invalid_tab/README.rst new file mode 100644 index 00000000..a62ff311 --- /dev/null +++ b/web_invalid_tab/README.rst @@ -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 +`_. 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 +------------ + +* Cesar Lage +* Robert Rübner + +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. diff --git a/web_invalid_tab/__init__.py b/web_invalid_tab/__init__.py new file mode 100644 index 00000000..de1a96ac --- /dev/null +++ b/web_invalid_tab/__init__.py @@ -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). diff --git a/web_invalid_tab/__openerp__.py b/web_invalid_tab/__openerp__.py new file mode 100644 index 00000000..ea60ab8d --- /dev/null +++ b/web_invalid_tab/__openerp__.py @@ -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', + ] +} diff --git a/web_invalid_tab/static/src/css/view_form.css b/web_invalid_tab/static/src/css/view_form.css new file mode 100644 index 00000000..e6ba0023 --- /dev/null +++ b/web_invalid_tab/static/src/css/view_form.css @@ -0,0 +1,3 @@ +li > a.oe_form_tab_invalid { + border: 1px solid #D00 !important; +} diff --git a/web_invalid_tab/static/src/js/view_form.js b/web_invalid_tab/static/src/js/view_form.js new file mode 100644 index 00000000..41d9f322 --- /dev/null +++ b/web_invalid_tab/static/src/js/view_form.js @@ -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'); + } + }); + }, + }); + +}; diff --git a/web_invalid_tab/views/assets.xml b/web_invalid_tab/views/assets.xml new file mode 100644 index 00000000..3a2b0bdb --- /dev/null +++ b/web_invalid_tab/views/assets.xml @@ -0,0 +1,12 @@ + + + + + +