[ADD] web_tab_title

This commit is contained in:
Raphaël Valyi
2021-10-26 02:30:21 -03:00
parent 2854d4fdda
commit ce2255623d
5 changed files with 102 additions and 0 deletions

View File

View File

@@ -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"],
}

View File

@@ -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;
});

View File

@@ -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;
});

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template
id="assets_backend"
name="web_timeline assets"
inherit_id="web.assets_backend"
>
<xpath expr="." position="inside">
<script
type="text/javascript"
src="/web_tab_title/static/src/js/form_controller.js"
/>
<script
type="text/javascript"
src="/web_tab_title/static/src/js/abstract_web_client.js"
/>
</xpath>
</template>
</odoo>