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
This commit is contained in:
Cédric Krier
2019-12-28 18:16:28 +01:00
parent 55ef710cd5
commit 15f0d69c86
4 changed files with 26 additions and 11 deletions
+1
View File
@@ -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
+19 -7
View File
@@ -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) {
+2
View File
@@ -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
});
+4 -4
View File
@@ -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);