diff options
| author | Aaron Bohy <aab@odoo.com> | 2017-08-25 14:29:11 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-08-25 15:54:56 +0200 |
| commit | 802dde31f3b58b8f26d6f6c584e5e4f8f392a482 (patch) | |
| tree | 6aab2151a71e402ebde791559f30f020b3e8bcb4 /addons/barcodes/static | |
| parent | 8019eacb4716befcc0affa4f8c9d554be2ec6655 (diff) | |
[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.
Diffstat (limited to 'addons/barcodes/static')
| -rw-r--r-- | addons/barcodes/static/src/js/barcode_form_view.js | 25 | ||||
| -rw-r--r-- | addons/barcodes/static/tests/barcode_tests.js | 8 |
2 files changed, 32 insertions, 1 deletions
diff --git a/addons/barcodes/static/src/js/barcode_form_view.js b/addons/barcodes/static/src/js/barcode_form_view.js index 8f6a3b0a3e2..5b042999bf6 100644 --- a/addons/barcodes/static/src/js/barcode_form_view.js +++ b/addons/barcodes/static/src/js/barcode_form_view.js @@ -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), }, }, }; @@ -259,6 +261,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 + */ _onCommandNext: function () { return this.mutex.exec(function () {}).then(this.pager.next.bind(this.pager)); }, diff --git a/addons/barcodes/static/tests/barcode_tests.js b/addons/barcodes/static/tests/barcode_tests.js index 5f8af60911b..add55ed4d5d 100644 --- a/addons/barcodes/static/tests/barcode_tests.js +++ b/addons/barcodes/static/tests/barcode_tests.js @@ -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(); }); |
