Compute next/previous record to set button state

The position is not enough to determine if the button will change the current
record. Also the position can be a list for the tree.

issue11413
review405241002
This commit is contained in:
Cédric Krier
2022-04-25 23:20:57 +02:00
parent a182419aa2
commit d1291774fd
2 changed files with 30 additions and 12 deletions
+28 -10
View File
@@ -1355,10 +1355,8 @@
}
}));
},
display_next: function() {
_get_next_record: function() {
var view = this.current_view;
view.set_value();
this.set_cursor(false, false);
if (~['tree', 'form', 'list-form'].indexOf(view.view_type) &&
this.current_record && this.current_record.group) {
var group = this.current_record.group;
@@ -1377,17 +1375,26 @@
break;
}
}
this.current_record = record;
return record;
} else {
this.current_record = this.group[0];
return this.group[0];
}
this.set_cursor(false, false);
return view.display();
},
display_previous: function() {
has_next: function() {
var next_record = this._get_next_record();
return next_record &&
(next_record !== this.current_record);
},
display_next: function() {
var view = this.current_view;
view.set_value();
this.set_cursor(false, false);
this.current_record = this._get_next_record();
this.set_cursor(false, false);
return view.display();
},
_get_previous_record: function() {
var view = this.current_view;
if (~['tree', 'form', 'list-form'].indexOf(view.view_type) &&
this.current_record && this.current_record.group) {
var group = this.current_record.group;
@@ -1406,10 +1413,21 @@
break;
}
}
this.current_record = record;
return record;
} else {
this.current_record = this.group[0];
return this.group[0];
}
},
has_previous: function() {
var previous_record = this._get_previous_record();
return previous_record &&
(previous_record !== this.current_record);
},
display_previous: function() {
var view = this.current_view;
view.set_value();
this.set_cursor(false, false);
this.current_record = this._get_previous_record();
this.set_cursor(false, false);
return view.display();
},
+2 -2
View File
@@ -1487,8 +1487,8 @@
}
set_sensitive('switch_', this.screen.number_of_views > 1);
set_sensitive('delete_', this.screen.deletable);
set_sensitive('previous', position > (this.screen.offset + 1));
set_sensitive('next', position < size);
set_sensitive('previous', this.screen.has_previous());
set_sensitive('next', this.screen.has_next());
var msg;
if (size < max_size) {