From 137852452e91dbe689b2f2f44dcca5e169099359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 4 Oct 2020 00:35:23 +0200 Subject: [PATCH] Fallback to model name as title issue9596 review300381002 --- CHANGELOG | 1 + src/common.js | 22 ++++++++++++++++++++++ src/sao.js | 1 + src/tab.js | 14 +++++++++++--- src/window.js | 9 ++++++++- 5 files changed, 43 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 6c3b7983e4..7a735c4f52 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Fallback to model name as title * Set treeview footer sticky on bottom * Add get, in_ and contains methods to PYSON * Manage deletable and writable state diff --git a/src/common.js b/src/common.js index 6bcf15d4c4..9bf56c62e9 100644 --- a/src/common.js +++ b/src/common.js @@ -496,6 +496,28 @@ }); Sao.common.MODELHISTORY = new Sao.common.ModelHistory(); + Sao.common.ModelName = Sao.class_(Object, { + init: function() { + this._names = {}; + }, + load_names: function() { + this._names = Sao.rpc({ + 'method':'model.ir.model.get_names', + 'params': [{}], + }, Sao.Session.current_session, false); + }, + get: function(model) { + if (jQuery.isEmptyObject(this._names)) { + this.load_names(); + } + return this._names[model] || ''; + }, + clear: function() { + this._names = {}; + }, + }); + Sao.common.MODELNAME = new Sao.common.ModelName(); + Sao.common.ViewSearch = Sao.class_(Object, { init: function() { this.encoder = new Sao.PYSON.Encoder(); diff --git a/src/sao.js b/src/sao.js index 3d26e9a7fb..8568fd6e6c 100644 --- a/src/sao.js +++ b/src/sao.js @@ -376,6 +376,7 @@ var Sao = {}; }); Sao.i18n.set_direction(preferences.language_direction); Sao.i18n.locale = preferences.locale; + Sao.common.MODELNAME.clear(); return prm; }); }); diff --git a/src/tab.js b/src/tab.js index 9e9e9f9b01..301044ac7b 100644 --- a/src/tab.js +++ b/src/tab.js @@ -465,7 +465,11 @@ this.view_prm = this.screen.switch_view().done(function() { this.screen.count_tab_domain(); - this.set_name(attributes.name || ''); + var name = attributes.name; + if (!name) { + name = Sao.common.MODELNAME.get(model_name); + } + this.set_name(name); this.content.append(screen.screen_container.el); if (attributes.res_id) { if (!jQuery.isArray(attributes.res_id)) { @@ -1370,7 +1374,7 @@ new Sao.Window.Import(this.title.text(), this.screen); }, get_url: function() { - return this.screen.get_url(this.attributes.name); + return this.screen.get_url(this.name); }, }); @@ -1383,7 +1387,11 @@ this.view_id = (attributes.view_ids.length > 0 ? attributes.view_ids[0] : null); this.context = attributes.context; - this.name = attributes.name || ''; + var name = attributes.name; + if (!name) { + name = Sao.common.MODELNAME.get(this.model); + } + this.name = name; this.dialogs = []; this.board = null; UIView = new Sao.Model('ir.ui.view'); diff --git a/src/window.js b/src/window.js index 008d39eee9..342dddb882 100644 --- a/src/window.js +++ b/src/window.js @@ -94,6 +94,9 @@ this.save_current = kwargs.save_current; var title_prm = jQuery.when(kwargs.title || ''); title_prm.then(function(title) { + if (!title) { + title = Sao.common.MODELNAME.get(this.screen.model_name); + } this.title = title; }.bind(this)); @@ -638,7 +641,11 @@ this.views_preload = views_preload; this.sel_multi = kwargs.sel_multi; this.callback = callback; - this.title = kwargs.title || ''; + var title = kwargs.title; + if (!title) { + title = Sao.common.MODELNAME.get(model); + } + this.title = title; this.exclude_field = kwargs.exclude_field || null; var dialog = new Sao.Dialog(Sao.i18n.gettext( 'Search %1', this.title), '', 'lg');