changeset 9ec4af008e52 in sao:default
details: https://hg.tryton.org/sao?cmd=changeset;node=9ec4af008e52
description:
        Position new record based on order

        We sent an order to the client for action and xxx2Many so its screen has
        always a default order set.
        To position a new record on non editable tree, we use the order of the 
'id'
        column if presents.

        issue8880
        review276501003
diffstat:

 CHANGELOG        |   1 +
 src/screen.js    |  26 +++++++++++++++++++-------
 src/view/form.js |   2 ++
 src/view/tree.js |   8 ++++----
 4 files changed, 26 insertions(+), 11 deletions(-)

diffs (104 lines):

diff -r 4496aa6afc97 -r 9ec4af008e52 CHANGELOG
--- a/CHANGELOG Sat Dec 28 18:07:13 2019 +0100
+++ b/CHANGELOG Sat Dec 28 18:16:28 2019 +0100
@@ -1,3 +1,4 @@
+* Position new record based on order
 * Reset display_size of TreeView when group is cleared or changed
 * Allow relation field to be selected in CSV export
 * Hide empty cell on small screen
diff -r 4496aa6afc97 -r 9ec4af008e52 src/screen.js
--- a/src/screen.js     Sat Dec 28 18:07:13 2019 +0100
+++ b/src/screen.js     Sat Dec 28 18:16:28 2019 +0100
@@ -1386,7 +1386,7 @@
                     prm = jQuery.when();
                 }
                 return prm.then(function() {
-                    group.add(record, this.new_model_position());
+                    group.add(record, this.new_position);
                     this.current_record = record;
                     if (previous_view.view_type == 'calendar') {
                         previous_view.set_default_date(record, selected_date);
@@ -1398,13 +1398,25 @@
                 }.bind(this));
             }.bind(this));
         },
-        new_model_position: function() {
-            var position = -1;
-            if (this.current_view && (this.current_view.view_type == 'tree') &&
-                    (this.current_view.attributes.editable == 'top')) {
-                position = 0;
+        get new_position() {
+            if (this.order) {
+                for (var j = 0; j < this.order.length; j++) {
+                    var oexpr = this.order[j][0],
+                        otype = this.order[j][1];
+                    if ((oexpr == 'id') && otype) {
+                        if (otype.startsWith('DESC')) {
+                            return 0;
+                        } else if (otype.startsWith('ASC')) {
+                            return -1;
+                        }
+                    }
+                }
             }
-            return position;
+            if (this.group.parent) {
+                return -1;
+            } else {
+                return 0;
+            }
         },
         set_on_write: function(name) {
             if(name) {
diff -r 4496aa6afc97 -r 9ec4af008e52 src/view/form.js
--- a/src/view/form.js  Sat Dec 28 18:07:13 2019 +0100
+++ b/src/view/form.js  Sat Dec 28 18:16:28 2019 +0100
@@ -2899,6 +2899,7 @@
                 mode: modes,
                 view_ids: (attributes.view_ids || '').split(','),
                 views_preload: attributes.views || {},
+                order: attributes.order,
                 row_activate: this.activate.bind(this),
                 exclude_field: attributes.relation_field || null,
                 limit: null,
@@ -3360,6 +3361,7 @@
                 mode: ['tree'],
                 view_ids: (attributes.view_ids || '').split(','),
                 views_preload: attributes.views || {},
+                order: attributes.order,
                 row_activate: this.activate.bind(this),
                 limit: null
             });
diff -r 4496aa6afc97 -r 9ec4af008e52 src/view/tree.js
--- a/src/view/tree.js  Sat Dec 28 18:07:13 2019 +0100
+++ b/src/view/tree.js  Sat Dec 28 18:16:28 2019 +0100
@@ -217,7 +217,7 @@
             this.display_size = Sao.config.display_size;
         },
         get editable() {
-            return (Boolean(this.attributes.editable) &&
+            return (parseInt(this.attributes.editable || 0, 10) &&
                 !this.screen.attributes.readonly);
         },
         sort_model: function(e){
@@ -1809,7 +1809,7 @@
                                 } else if (event_.which == 
Sao.common.DOWN_KEYCODE) {
                                     next_row = this.el.next('tr');
                                 } else {
-                                    if (this.tree.attributes.editable == 
'bottom') {
+                                    if (this.tree.screen.new_position == -1) {
                                         next_row = this.el.next('tr');
                                     } else {
                                         next_row = this.el.prev('tr');
@@ -1818,9 +1818,9 @@
                                 if (!next_row.length &&
                                     ((event_.which == 
Sao.common.RETURN_KEYCODE) ||
                                         ((event_.which == 
Sao.common.UP_KEYCODE) &&
-                                            (this.tree.attributes.editable == 
'top')) ||
+                                            (this.tree.screen.new_position == 
0)) ||
                                         ((event_.which == 
Sao.common.DOWN_KEYCODE) &&
-                                            (this.tree.attributes.editable == 
'bottom')))) {
+                                            (this.tree.screen.new_position == 
-1)))) {
                                     var model = this.tree.screen.group;
                                     var access = Sao.common.MODELACCESS.get(
                                         this.tree.screen.model_name);

Reply via email to