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), }, }, }; @@ -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 */ 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(); }); diff --git a/addons/web/static/src/js/chrome/pager.js b/addons/web/static/src/js/chrome/pager.js index bbe69c6d86a..c7f22a6f2c9 100644 --- a/addons/web/static/src/js/chrome/pager.js +++ b/addons/web/static/src/js/chrome/pager.js @@ -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)); + } }, //--------------------------------------------------------------------------