changeset e0fdc0f1451d in sao:default
details: https://hg.tryton.org/sao?cmd=changeset&node=e0fdc0f1451d
description:
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
diffstat:
src/screen.js | 38 ++++++++++++++++++++++++++++----------
src/tab.js | 4 ++--
2 files changed, 30 insertions(+), 12 deletions(-)
diffs (85 lines):
diff -r 89b3eed38e6b -r e0fdc0f1451d src/screen.js
--- a/src/screen.js Mon Apr 25 23:19:07 2022 +0200
+++ b/src/screen.js Mon Apr 25 23:20:57 2022 +0200
@@ -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];
}
+ },
+ 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();
},
- display_previous: function() {
+ _get_previous_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;
@@ -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();
},
diff -r 89b3eed38e6b -r e0fdc0f1451d src/tab.js
--- a/src/tab.js Mon Apr 25 23:19:07 2022 +0200
+++ b/src/tab.js Mon Apr 25 23:20:57 2022 +0200
@@ -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) {