[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

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