diff options
Diffstat (limited to 'addons/web/static/src/js/fields')
| -rw-r--r-- | addons/web/static/src/js/fields/abstract_field.js | 18 | ||||
| -rw-r--r-- | addons/web/static/src/js/fields/basic_fields.js | 4 | ||||
| -rw-r--r-- | addons/web/static/src/js/fields/relational_fields.js | 31 |
3 files changed, 36 insertions, 17 deletions
diff --git a/addons/web/static/src/js/fields/abstract_field.js b/addons/web/static/src/js/fields/abstract_field.js index 36a9f0cb258..735e12a3861 100644 --- a/addons/web/static/src/js/fields/abstract_field.js +++ b/addons/web/static/src/js/fields/abstract_field.js @@ -314,12 +314,12 @@ var AbstractField = Widget.extend({ }, /** - * Update the modifiers with the newest value. - * Now this.attrs.modifiersValue can be used consistantly even with - * conditional modifiers inside field widgets, and without needing new + * Update the modifiers with the newest value. + * Now this.attrs.modifiersValue can be used consistantly even with + * conditional modifiers inside field widgets, and without needing new * events or synchronization between the widgets, renderer and controller - * - * @param {Object || null} modifiers the updated modifiers + * + * @param {Object | null} modifiers the updated modifiers * @override */ updateModifiersValue: function(modifiers) { @@ -487,11 +487,13 @@ var AbstractField = Widget.extend({ _onKeydown: function (ev) { switch (ev.which) { case $.ui.keyCode.TAB: - ev.preventDefault(); - ev.stopPropagation(); - this.trigger_up('navigation_move', { + var event = this.trigger_up('navigation_move', { direction: ev.shiftKey ? 'previous' : 'next', }); + if (event.is_stopped()) { + ev.preventDefault(); + ev.stopPropagation(); + } break; case $.ui.keyCode.ENTER: ev.stopPropagation(); diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index ae0da5427ad..0f426dedd3b 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -319,7 +319,9 @@ var InputField = DebouncedField.extend({ || (ev.data.direction === "right" && (selecting || input.selectionStart !== input.value.length))) { ev.stopPropagation(); } - if (ev.data.direction ==='next' && this.attrs.modifiersValue.required) { + if (ev.data.direction ==='next' && + this.attrs.modifiersValue && + this.attrs.modifiersValue.required) { if (!this.$input.val()){ this.setInvalidClass(); ev.stopPropagation(); diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index 93c924fad4c..c3df03fcff9 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -1059,7 +1059,7 @@ var FieldX2Many = AbstractField.extend({ */ _onEditLine: function (ev) { ev.stopPropagation(); - this.trigger_up('freeze_order', {id: this.value.id}); + this.trigger_up('edited_list', { id: this.value.id }); var editedRecord = this.value.data[ev.data.index]; this.renderer.setRowMode(editedRecord.id, 'edit') .done(ev.data.onSuccess); @@ -1147,7 +1147,7 @@ var FieldX2Many = AbstractField.extend({ _onResequence: function (event) { event.stopPropagation(); var self = this; - this.trigger_up('freeze_order', {id: this.value.id}); + this.trigger_up('edited_list', { id: this.value.id }); var rowIDs = event.data.rowIDs.slice(); var rowID = rowIDs.pop(); var defs = _.map(rowIDs, function (rowID, index) { @@ -1300,7 +1300,7 @@ var FieldOne2Many = FieldX2Many.extend({ } } else if (!this.creatingRecord) { this.creatingRecord = true; - this.trigger_up('freeze_order', {id: this.value.id}); + this.trigger_up('edited_list', { id: this.value.id }); this._setValue({ operation: 'CREATE', position: this.editable, @@ -1330,12 +1330,27 @@ var FieldOne2Many = FieldX2Many.extend({ // we don't want interference with the components upstream. ev.stopPropagation(); + var self = this; var id = ev.data.id; - // trigger an empty 'UPDATE' operation when the user clicks on 'Save' in - // the dialog, to notify the main record that a subrecord of this - // relational field has changed (those changes will be already stored on - // that subrecord, thanks to the 'Save'). - var onSaved = this._setValue.bind(this, { operation: 'UPDATE', id: id }, {}); + var onSaved = function (record, hasChanged) { + if (!hasChanged) { + return; + } + if (_.some(self.value.data, {id: record.id})) { + // the record already exists in the relation, so trigger an + // empty 'UPDATE' operation when the user clicks on 'Save' in + // the dialog, to notify the main record that a subrecord of + // this relational field has changed (those changes will be + // already stored on that subrecord, thanks to the 'Save'). + self._setValue({ operation: 'UPDATE', id: record.id }); + } else { + // the record isn't in the relation yet, so add it ; this can + // happen if the user clicks on 'Save & New' in the dialog (the + // opened record will be updated, and other records will be + // created) + self._setValue({ operation: 'ADD', id: record.id }); + } + }; this._openFormDialog({ id: id, on_saved: onSaved, |
