[FIX] web,barcodes: pager: FIRST and LAST actions

The barcode mechanism is supposed to handle commands PAGER-FIRST
(go to first record referenced in the pager) and PAGER-LAST (go
to last record). Before this rev., it wasn't the case.

We needed to add an option 'notifyChange' to the updateState
function of the pager, to ensure that the form is correctly
reloaded when the pager cursor is manually set (by the barcode
handler) on the first or last element.
This commit is contained in:
Aaron Bohy
2017-08-25 15:54:56 +02:00
parent 8019eacb47
commit 802dde31f3
3 changed files with 39 additions and 2 deletions
@@ -31,6 +31,8 @@ FormController.include({
'O-CMD.SAVE': this._onCommandSave.bind(this),
'O-CMD.PAGER-PREV': this._onCommandPrevious.bind(this),
'O-CMD.PAGER-NEXT': this._onCommandNext.bind(this),
'O-CMD.PAGER-FIRST': this._onCommandFirst.bind(this),
'O-CMD.PAGER-LAST': this._onCommandLast.bind(this),
},
},
};
@@ -256,6 +258,29 @@ FormController.include({
});
});
},
/**
* @private
*/
_onCommandFirst: function () {
var self = this;
return this.mutex.exec(function () {}).then(function () {
self.pager.updateState({
current_min: 1,
}, {notifyChange: true});
});
},
/**
* @private
*/
_onCommandLast: function () {
var self = this;
return this.mutex.exec(function () {}).then(function () {
var state = self.model.get(self.handle, {raw: true});
self.pager.updateState({
current_min: state.count,
}, {notifyChange: true});
});
},
/**
* @private
*/
@@ -128,7 +128,7 @@ QUnit.test('edit, save and cancel buttons', function (assert) {
});
QUnit.test('pager buttons', function (assert) {
assert.expect(3);
assert.expect(5);
var form = createView({
View: FormView,
@@ -149,6 +149,12 @@ QUnit.test('pager buttons', function (assert) {
// O-CMD.PAGER-PREV
_.each(["O","-","C","M","D",".","P","A","G","E","R","-","P","R","E","V","Enter"], triggerKeypressEvent);
assert.strictEqual(form.$('.o_field_widget').text(), 'iPad Mini');
// O-CMD.PAGER-LAST
_.each(["O","-","C","M","D",".","P","A","G","E","R","-","L","A","S","T","Enter"], triggerKeypressEvent);
assert.strictEqual(form.$('.o_field_widget').text(), 'Mouse, Optical');
// O-CMD.PAGER-FIRST
_.each(["O","-","C","M","D",".","P","A","G","E","R","-","F","I","R","S","T","Enter"], triggerKeypressEvent);
assert.strictEqual(form.$('.o_field_widget').text(), 'iPad Mini');
form.destroy();
});
+7 -1
View File
@@ -97,10 +97,16 @@ var Pager = Widget.extend({
/**
* Sets the state of the pager and renders it
* @param {Object} [state] the values to update (size, current_min and limit)
* @param {Object} [options]
* @param {boolean} [options.notifyChange] set to true to make the pager
* notify the environment that its state changed
*/
updateState: function (state) {
updateState: function (state, options) {
_.extend(this.state, state);
this._render();
if (options && options.notifyChange) {
this.trigger('pager_changed', _.clone(this.state));
}
},
//--------------------------------------------------------------------------