@@ -5,6 +5,11 @@ import {
55 Many2ManyTagsFieldColorEditable ,
66} from "@web/views/fields/many2many_tags/many2many_tags_field" ;
77
8+ import {
9+ isMruGlobalOptionEnabled ,
10+ updateMruLocalStorageValues ,
11+ } from "@web_m2x_options/utils/mru.esm" ;
12+
813import { Dialog } from "@web/core/dialog/dialog" ;
914import { FormController } from "@web/views/form/form_controller" ;
1015import { FormViewDialog } from "@web/views/view_dialogs/form_view_dialog" ;
@@ -159,6 +164,7 @@ patch(Many2OneField.prototype, "web_m2x_options.Many2OneField", {
159164 this . _super ( ...arguments ) ;
160165 this . ir_options = Component . env . session . web_m2x_options ;
161166 } ,
167+
162168 /**
163169 * @override
164170 */
@@ -170,6 +176,7 @@ patch(Many2OneField.prototype, "web_m2x_options.Many2OneField", {
170176 searchMore : this . props . searchMore ,
171177 canCreate : this . props . canCreate ,
172178 nodeOptions : this . props . nodeOptions ,
179+ fieldName : this . props . name ,
173180 } ;
174181 } ,
175182
@@ -401,4 +408,66 @@ patch(FormController.prototype, "web_m2x_options.FormController", {
401408 }
402409 }
403410 } ,
411+
412+ async saveButtonClicked ( ) {
413+ const mruChanges = this . getUpdateMruLocalStorageValues ( ) ;
414+ const saved = this . _super ( ...arguments ) ;
415+ updateMruLocalStorageValues ( this . props . resModel , mruChanges ) ;
416+ return saved ;
417+ } ,
418+
419+ async beforeExecuteActionButton ( ) {
420+ const mruChanges = this . getUpdateMruLocalStorageValues ( ) ;
421+ const saved = this . _super ( ...arguments ) ;
422+ updateMruLocalStorageValues ( this . props . resModel , mruChanges ) ;
423+ return saved ;
424+ } ,
425+
426+ async beforeLeave ( ) {
427+ const mruChanges = this . getUpdateMruLocalStorageValues ( ) ;
428+ const saved = this . _super ( ...arguments ) ;
429+ updateMruLocalStorageValues ( this . props . resModel , mruChanges ) ;
430+ return saved ;
431+ } ,
432+
433+ async onPagerUpdate ( ) {
434+ const mruChanges = this . getUpdateMruLocalStorageValues ( ) ;
435+ const saved = this . _super ( ...arguments ) ;
436+ updateMruLocalStorageValues ( this . props . resModel , mruChanges ) ;
437+ return saved ;
438+ } ,
439+
440+ getUpdateMruLocalStorageValues ( ) {
441+ if ( ! this . model . root . isDirty ) {
442+ return { } ;
443+ }
444+ const model = this . model ;
445+ const changes = model . __bm__ . _generateChanges (
446+ model . __bm__ . localData [ model . root . __bm_handle__ ] ,
447+ { changesOnly : true }
448+ ) ;
449+ const mruChanges = { } ;
450+ let enableMru = false ;
451+ let nodeOptions = { } ;
452+ let fieldInfo = { } ;
453+ const activeFields = this . archInfo . activeFields ;
454+ Object . keys ( changes ) . forEach ( function ( key ) {
455+ fieldInfo = activeFields [ key ] ;
456+ if (
457+ Boolean ( fieldInfo ) &&
458+ Boolean ( fieldInfo . FieldComponent ) &&
459+ fieldInfo . FieldComponent . name === "Many2OneField"
460+ ) {
461+ nodeOptions = fieldInfo . options ;
462+ enableMru =
463+ nodeOptions . search_mru !== undefined
464+ ? nodeOptions . search_mru
465+ : isMruGlobalOptionEnabled ( ) ;
466+ if ( enableMru ) {
467+ mruChanges [ key ] = changes [ key ] ;
468+ }
469+ }
470+ } ) ;
471+ return mruChanges ;
472+ } ,
404473} ) ;
0 commit comments