changeset a6fd5e9bb5a0 in sao:default
details: https://hg.tryton.org/sao?cmd=changeset;node=a6fd5e9bb5a0
description:
        Add breadcrumb as title of window form

        issue7167
        review343151002
diffstat:

 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(-)

diffs (268 lines):

diff -r b22e83f9f106 -r a6fd5e9bb5a0 CHANGELOG
--- a/CHANGELOG Sun Feb 14 14:28:55 2021 +0100
+++ b/CHANGELOG Sun Feb 14 15:45:21 2021 +0100
@@ -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 -r b22e83f9f106 -r a6fd5e9bb5a0 src/sao.js
--- a/src/sao.js        Sun Feb 14 14:28:55 2021 +0100
+++ b/src/sao.js        Sun Feb 14 15:45:21 2021 +0100
@@ -870,8 +870,9 @@
         },
         add_title: function(title) {
             this.header.append(jQuery('<h4/>', {
-                'class': 'modal-title'
-            }).text(title));
+                'class': 'modal-title',
+                'title': title,
+            }).text(Sao.common.ellipsize(title, 120)));
         }
     });
 
diff -r b22e83f9f106 -r a6fd5e9bb5a0 src/screen.js
--- a/src/screen.js     Sun Feb 14 14:28:55 2021 +0100
+++ b/src/screen.js     Sun Feb 14 15:45:21 2021 +0100
@@ -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 -r b22e83f9f106 -r a6fd5e9bb5a0 src/tab.js
--- a/src/tab.js        Sun Feb 14 14:28:55 2021 +0100
+++ b/src/tab.js        Sun Feb 14 15:45:21 2021 +0100
@@ -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 -r b22e83f9f106 -r a6fd5e9bb5a0 src/view/form.js
--- a/src/view/form.js  Sun Feb 14 14:28:55 2021 +0100
+++ b/src/view/form.js  Sun Feb 14 15:45:21 2021 +0100
@@ -2315,6 +2315,10 @@
                 // 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 @@
                 'views_preload': this.attributes.views,
                 'readonly': this._readonly,
                 exclude_field: this.attributes.relation_field,
+                breadcrumb: breadcrumb,
             });
         },
         set_text: function(value) {
@@ -2502,7 +2507,6 @@
                     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 @@
                 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 @@
             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 @@
                 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 @@
                 var win = new Sao.Window.Form(this.screen, update_sequence, {
                     new_: true,
                     many: field_size,
-                    title: this.attributes.string
                 });
             }
         },
@@ -3378,8 +3385,7 @@
             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 @@
                 '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 @@
                 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 @@
             }.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 @@
                 new Sao.Window.Form(screen, callback, {
                     'new_': true,
                     'save_current': true,
-                    title: this.attributes.string,
                     rec_name: this.entry.val()
                 });
             }.bind(this));
diff -r b22e83f9f106 -r a6fd5e9bb5a0 src/window.js
--- a/src/window.js     Sun Feb 14 14:28:55 2021 +0100
+++ b/src/window.js     Sun Feb 14 15:45:21 2021 +0100
@@ -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;
             }

Reply via email to