From ce2255623de0b59c41efcec9ef66a832eb88944d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Valyi?= Date: Tue, 26 Oct 2021 02:30:21 -0300 Subject: [PATCH] [ADD] web_tab_title --- web_tab_title/__init__.py | 0 web_tab_title/__manifest__.py | 23 ++++++++++++++ .../static/src/js/abstract_web_client.js | 29 +++++++++++++++++ .../static/src/js/form_controller.js | 31 +++++++++++++++++++ web_tab_title/views/web_tab_title.xml | 19 ++++++++++++ 5 files changed, 102 insertions(+) create mode 100644 web_tab_title/__init__.py create mode 100644 web_tab_title/__manifest__.py create mode 100644 web_tab_title/static/src/js/abstract_web_client.js create mode 100644 web_tab_title/static/src/js/form_controller.js create mode 100644 web_tab_title/views/web_tab_title.xml diff --git a/web_tab_title/__init__.py b/web_tab_title/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/web_tab_title/__manifest__.py b/web_tab_title/__manifest__.py new file mode 100644 index 0000000..1eab5d5 --- /dev/null +++ b/web_tab_title/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright 2021 Akretion +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Web Tab Title', + 'description': """ + Automatically set tab document.title when empty. + Important limitation: the tab will get its title only once you browse it. + """, + 'version': '14.0.1.0.0', + 'license': 'AGPL-3', + 'author': 'Akretion', + 'website': 'akretion.com', + 'depends': [ + 'web', + ], + 'data': [ + ], + 'demo': [ + ], + "data": ["views/web_tab_title.xml"], + "maintainers": ["rvalyi"], +} diff --git a/web_tab_title/static/src/js/abstract_web_client.js b/web_tab_title/static/src/js/abstract_web_client.js new file mode 100644 index 0000000..5a9f699 --- /dev/null +++ b/web_tab_title/static/src/js/abstract_web_client.js @@ -0,0 +1,29 @@ +/* global vis, py */ +odoo.define("web_tab_title.AbstractWebClient", function (require) { + "use strict"; + + var AbstractWebClient = require('web.AbstractWebClient'); + + var TabTitleAbstractWebClient = AbstractWebClient.include({ + + _title_changed: function () { + // like the original except we change the title + // only when it's different from "Odoo" to avoid + // resetting the tab title when switching tabs. + var parts = _.sortBy(_.keys(this.get("title_part")), function (x) { return x; }); + var tmp = ""; + _.each(parts, function (part) { + var str = this.get("title_part")[part]; + if (str) { + tmp = tmp ? tmp + " - " + str : str; + } + }, this); + if (tmp != "Odoo") { + document.title = tmp; + } + }, + + }); + + return TabTitleAbstractWebClient; +}); diff --git a/web_tab_title/static/src/js/form_controller.js b/web_tab_title/static/src/js/form_controller.js new file mode 100644 index 0000000..8b049c3 --- /dev/null +++ b/web_tab_title/static/src/js/form_controller.js @@ -0,0 +1,31 @@ +/* global vis, py */ +odoo.define("web_tab_title.FormController", function (require) { + "use strict"; + + var FormController = require('web.FormController'); + + var TabTitleController = FormController.include({ + + on_attach_callback: function () { + this._super.apply(this, arguments); + + if (document.title == "Odoo") { + var form_name_elem = $("div.oe_title>h1"); + if (form_name_elem.length == 0) { + form_name_elem = $('span.o_field_char[name="name"]') + } + var title = form_name_elem.text(); + if (title !== '') { + // alternatively we could access the record + // in views/basic/basic_model.js + // but we would also we miss the model name + document.title = title + " - Odoo"; + } + } + + }, + + }); + + return TabTitleController; +}); diff --git a/web_tab_title/views/web_tab_title.xml b/web_tab_title/views/web_tab_title.xml new file mode 100644 index 0000000..29f9268 --- /dev/null +++ b/web_tab_title/views/web_tab_title.xml @@ -0,0 +1,19 @@ + + +