From 55376dbc901b1b86356d37bf9ca29319bfabbf0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 14 Feb 2021 15:45:21 +0100 Subject: [PATCH] Add breadcrumb as title of window form issue7167 review343151002 --- CHANGELOG | 1 + src/sao.js | 5 ++-- src/screen.js | 1 + src/tab.js | 12 +++++---- src/view/form.js | 31 +++++++++++++++--------- src/window.js | 63 +++++++++++++++++++++++++++++------------------- 6 files changed, 69 insertions(+), 44 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 522d297068..ec2869b4d0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add breadcrumb as title of window form * Manage help for each selection * Display revision on dialog * Support empty value for timedelta converter diff --git a/src/sao.js b/src/sao.js index 83080e4e38..e07d4a641d 100644 --- a/src/sao.js +++ b/src/sao.js @@ -870,8 +870,9 @@ var Sao = {}; }, add_title: function(title) { this.header.append(jQuery('

', { - 'class': 'modal-title' - }).text(title)); + 'class': 'modal-title', + 'title': title, + }).text(Sao.common.ellipsize(title, 120))); } }); diff --git a/src/screen.js b/src/screen.js index b9ea06357c..03b41a836d 100644 --- a/src/screen.js +++ b/src/screen.js @@ -783,6 +783,7 @@ this.search_count = 0; this.screen_container = new Sao.ScreenContainer( attributes.tab_domain); + this.breadcrumb = attributes.breadcrumb || []; this.context_screen = null; if (attributes.context_model) { diff --git a/src/tab.js b/src/tab.js index 1c52d2a31b..e406aaceb9 100644 --- a/src/tab.js +++ b/src/tab.js @@ -450,6 +450,13 @@ class_: 'tab-form', init: function(model_name, attributes) { Sao.Tab.Form._super.init.call(this, attributes); + attributes = jQuery.extend({}, attributes); + var name = attributes.name; + if (!name) { + name = Sao.common.MODELNAME.get(model_name); + } + this.set_name(name); + attributes.breadcrumb = [name]; var screen = new Sao.Screen(model_name, attributes); screen.tab = this; this.screen = screen; @@ -467,11 +474,6 @@ this.view_prm = this.screen.switch_view().done(function() { this.screen.count_tab_domain(); - 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)) { diff --git a/src/view/form.js b/src/view/form.js index a4f6962930..4f9a86ad19 100644 --- a/src/view/form.js +++ b/src/view/form.js @@ -2315,6 +2315,10 @@ function eval_pyson(value){ // Remove the first tree view as mode is form only view_ids.shift(); } + var model = this.get_model(); + var breadcrumb = jQuery.extend([], this.view.screen.breadcrumb); + breadcrumb.push( + this.attributes.string || Sao.common.MODELNAME.get(model)); return new Sao.Screen(this.get_model(), { 'context': context, 'domain': domain, @@ -2323,6 +2327,7 @@ function eval_pyson(value){ 'views_preload': this.attributes.views, 'readonly': this._readonly, exclude_field: this.attributes.relation_field, + breadcrumb: breadcrumb, }); }, set_text: function(value) { @@ -2502,7 +2507,6 @@ function eval_pyson(value){ screen.load([m2o_id]); win = new Sao.Window.Form(screen, callback.bind(this), { save_current: true, - title: this.attributes.string }); }.bind(this)); return; @@ -2560,7 +2564,6 @@ function eval_pyson(value){ var win = new Sao.Window.Form(screen, callback.bind(this), { new_: true, save_current: true, - title: this.attributes.string, rec_name: rec_name }); }.bind(this)); @@ -3028,7 +3031,11 @@ function eval_pyson(value){ this.el.append(this.content); var modes = (attributes.mode || 'tree,form').split(','); - this.screen = new Sao.Screen(attributes.relation, { + var model = attributes.relation; + var breadcrumb = jQuery.extend([], this.view.screen.breadcrumb); + breadcrumb.push( + attributes.string || Sao.common.MODELNAME.get(model)); + this.screen = new Sao.Screen(model, { mode: modes, view_ids: (attributes.view_ids || '').split(','), views_preload: attributes.views || {}, @@ -3036,7 +3043,8 @@ function eval_pyson(value){ row_activate: this.activate.bind(this), exclude_field: attributes.relation_field || null, limit: null, - pre_validate: attributes.pre_validate + pre_validate: attributes.pre_validate, + breadcrumb: breadcrumb, }); this.screen.pre_validate = attributes.pre_validate == 1; @@ -3270,7 +3278,6 @@ function eval_pyson(value){ var win = new Sao.Window.Form(this.screen, update_sequence, { new_: true, many: field_size, - title: this.attributes.string }); } }, @@ -3378,8 +3385,7 @@ function eval_pyson(value){ return this.validate().then(function() { var record = this.screen.current_record; if (record) { - var win = new Sao.Window.Form(this.screen, function() {}, - {title: this.attributes.string}); + var win = new Sao.Window.Form(this.screen, function() {}); } }.bind(this)); }, @@ -3497,7 +3503,9 @@ function eval_pyson(value){ 'class': this.class_ + '-content panel-body' }); this.el.append(this.content); - + var model = attributes.relation; + var breadcrumb = jQuery.extend([], this.view.screen.breadcrumb); + breadcrumb.push(attributes.string || Sao.common.MODELNAME.get(model)); this.screen = new Sao.Screen(attributes.relation, { mode: ['tree'], view_ids: (attributes.view_ids || '').split(','), @@ -3505,7 +3513,8 @@ function eval_pyson(value){ order: attributes.order, row_activate: this.activate.bind(this), readonly: true, - limit: null + limit: null, + breadcrumb: breadcrumb, }); this.screen.message_callback = this.record_label.bind(this); this.prm = this.screen.switch_view('tree').done(function() { @@ -3675,8 +3684,7 @@ function eval_pyson(value){ }.bind(this); screen.switch_view().done(function() { screen.load([this.screen.current_record.id]); - new Sao.Window.Form(screen, callback, - {title: this.attributes.string}); + new Sao.Window.Form(screen, callback); }.bind(this)); }, new_: function() { @@ -3692,7 +3700,6 @@ function eval_pyson(value){ new Sao.Window.Form(screen, callback, { 'new_': true, 'save_current': true, - title: this.attributes.string, rec_name: this.entry.val() }); }.bind(this)); diff --git a/src/window.js b/src/window.js index 9ec38b8a44..70ba68fb3a 100644 --- a/src/window.js +++ b/src/window.js @@ -94,30 +94,43 @@ this.domain = kwargs.domain || null; this.context = kwargs.context || null; this.save_current = kwargs.save_current; - var title_prm = jQuery.when(kwargs.title || ''); - title_prm = title_prm.then(function(title) { - if (!title) { - title = Sao.common.MODELNAME.get(this.screen.model_name); - } - this.title = title; - var revision = this.screen.context._datetime; - var label; - if (revision && - Sao.common.MODELHISTORY.contains(this.screen.model_name)) { - var date_format = Sao.common.date_format( - this.screen.context.date_format); - var time_format = '%H:%M:%S.%f'; - var revision_label = ' @ ' + Sao.common.format_datetime( - date_format, time_format, revision); - label = Sao.common.ellipsize( - this.title, 80 - revision_label.length) + - revision_label; - title = this.title + revision_label; - } else { - label = Sao.common.ellipsize(this.title, 80); - } - return title; - }.bind(this)); + var title_prm = jQuery.when(kwargs.title || '').then( + function(title) { + if (screen.breadcrumb.length) { + var breadcrumb = jQuery.extend([], screen.breadcrumb); + if (title) { + breadcrumb.push(title); + } + this.title = breadcrumb.slice(-3, -1).map(function(x) { + return Sao.common.ellipsize(x, 30); + }).concat(breadcrumb.slice(-1)).join(' › '); + if (breadcrumb.length > 3) { + this.title = '... › ' + this.title; + } + } else { + if (!title) { + title = Sao.common.MODELNAME.get(this.screen.model_name); + } + this.title = title; + } + var revision = this.screen.context._datetime; + var label; + if (revision && + Sao.common.MODELHISTORY.contains(this.screen.model_name)) { + var date_format = Sao.common.date_format( + this.screen.context.date_format); + var time_format = '%H:%M:%S.%f'; + var revision_label = ' @ ' + Sao.common.format_datetime( + date_format, time_format, revision); + label = Sao.common.ellipsize( + this.title, 80 - revision_label.length) + + revision_label; + title = this.title + revision_label; + } else { + label = Sao.common.ellipsize(this.title, 80); + } + return label; + }.bind(this)); this.prev_view = screen.current_view; this.screen.screen_container.alternate_view = true; @@ -713,6 +726,7 @@ views_preload: views_preload, row_activate: this.activate.bind(this), readonly: true, + breadcrumb: [this.title], }); this.screen.load_next_view().done(function() { this.screen.switch_view().done(function() { @@ -775,7 +789,6 @@ new Sao.Window.Form(screen, callback.bind(this), { new_: true, save_current: true, - title: this.title }); return; }