From 189c0594c59a0808bb834a0876b48df256a3f939 Mon Sep 17 00:00:00 2001 From: Cesar Lage Date: Fri, 25 Nov 2016 11:09:19 -0500 Subject: [PATCH] [IMP] web_invalid_tab: migrating to version 9 --- web_invalid_tab/README.rst | 45 +++++++++++++ web_invalid_tab/__init__.py | 3 + web_invalid_tab/__openerp__.py | 19 ++++++ web_invalid_tab/static/src/css/view_form.css | 3 + web_invalid_tab/static/src/js/view_form.js | 66 ++++++++++++++++++++ web_invalid_tab/views/assets.xml | 11 ++++ 6 files changed, 147 insertions(+) create mode 100644 web_invalid_tab/README.rst create mode 100644 web_invalid_tab/__init__.py create mode 100644 web_invalid_tab/__openerp__.py create mode 100644 web_invalid_tab/static/src/css/view_form.css create mode 100644 web_invalid_tab/static/src/js/view_form.js create mode 100644 web_invalid_tab/views/assets.xml diff --git a/web_invalid_tab/README.rst b/web_invalid_tab/README.rst new file mode 100644 index 00000000..f3c79932 --- /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. \ No newline at end of file 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..f8bd347d --- /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': '9.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..4a46ad30 --- /dev/null +++ b/web_invalid_tab/static/src/js/view_form.js @@ -0,0 +1,66 @@ +odoo.define('web_invalid_tab.invalid_tab', function(require){ + 'use strict'; + + var FormView = require('web.FormView'); + var form_common = require('web.form_common'); + + 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; + } + } + + form_common.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'); + } + } + } + }); + + 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..62228392 --- /dev/null +++ b/web_invalid_tab/views/assets.xml @@ -0,0 +1,11 @@ + + + + + +