From 15f0d69c86f45fe8f0d8920298ede5fe84f91f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 28 Dec 2019 18:16:28 +0100 Subject: [PATCH] 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 --- CHANGELOG | 1 + src/screen.js | 26 +++++++++++++++++++------- src/view/form.js | 2 ++ src/view/tree.js | 8 ++++---- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2ab980ed54..36d80ab2d3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 --git a/src/screen.js b/src/screen.js index d291417103..b8e390774b 100644 --- a/src/screen.js +++ b/src/screen.js @@ -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; + } + } + } + } + if (this.group.parent) { + return -1; + } else { + return 0; } - return position; }, set_on_write: function(name) { if(name) { diff --git a/src/view/form.js b/src/view/form.js index 7856375643..f45e32a709 100644 --- a/src/view/form.js +++ b/src/view/form.js @@ -2899,6 +2899,7 @@ function eval_pyson(value){ 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 @@ function eval_pyson(value){ mode: ['tree'], view_ids: (attributes.view_ids || '').split(','), views_preload: attributes.views || {}, + order: attributes.order, row_activate: this.activate.bind(this), limit: null }); diff --git a/src/view/tree.js b/src/view/tree.js index 0ca82eaf85..29636cd392 100644 --- a/src/view/tree.js +++ b/src/view/tree.js @@ -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);