From 06dc8ef281076be697371bcc6f12b72d424de198 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 10 Mar 2025 13:35:16 +0200 Subject: [PATCH] change event action --- client/src/model.js | 22 ++++++++++++++++------ client/src/views/fields/base.js | 3 ++- client/src/views/record/detail.js | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/client/src/model.js b/client/src/model.js index 320d42efe7..24bae72b86 100644 --- a/client/src/model.js +++ b/client/src/model.js @@ -36,7 +36,7 @@ import _ from 'underscore'; * * @event Model#change * @param {Model} model A model. - * @param {Object.} o Options. + * @param {Record. & {action?: string|'ui'|'save'|'fetch'|'cancel-edit'}} o Options. */ /** @@ -290,6 +290,14 @@ class Model { options = options || {}; + if (options.ui && !options.action) { + options.action = 'ui'; + } + + if (!options.ui && options.action === 'ui') { + options.ui = true; + } + const changes = []; const changing = this._changing; @@ -485,6 +493,9 @@ class Model { fetch(options) { options = {...options}; + options.action = 'fetch'; + + // For bc. const success = options.success; options.success = response => { @@ -496,8 +507,6 @@ class Model { success.call(options.context, this, response, options); } - options.action = 'fetch'; - this.trigger('sync', this, response, options); if (this.collection) { @@ -517,7 +526,8 @@ class Model { * @param {{ * patch?: boolean, * wait?: boolean, - * } & Object.} [options] Options. + * } & Object.} [options] Options. Use `patch` to send a PATCH request. If `wait`, attributes will be + * set only after the request is completed. * @returns {Promise>} * @fires Model#sync * @copyright Credits to Backbone.js. @@ -542,6 +552,8 @@ class Model { responseAttributes = {...setAttributes, ...responseAttributes}; } + options.action = 'save'; + if (responseAttributes) { this.setMultiple(responseAttributes, options); } @@ -550,8 +562,6 @@ class Model { success.call(options.context, this, response, options); } - options.action = 'save'; - this.trigger('sync', this, response, options); if (this.collection) { diff --git a/client/src/views/fields/base.js b/client/src/views/fields/base.js index 3ba6f1a265..e2a973ad76 100644 --- a/client/src/views/fields/base.js +++ b/client/src/views/fields/base.js @@ -940,6 +940,7 @@ class BaseFieldView extends View { this.model.set(attributes, { ui: true, fromView: this, + action: 'ui', }); }); } @@ -1375,7 +1376,7 @@ class BaseFieldView extends View { if (!noReset) { this.model.set(this.initialAttributes, { skipReRenderInEditMode: true, - editCancel: true, + action: 'cancel-edit', }); } diff --git a/client/src/views/record/detail.js b/client/src/views/record/detail.js index 3f19a37d82..383fe54daf 100644 --- a/client/src/views/record/detail.js +++ b/client/src/views/record/detail.js @@ -1601,7 +1601,7 @@ class DetailRecordView extends BaseRecordView { this.model.set(this.attributes, { skipReRenderInEditMode: skipReRender, - editCancel: true, + action: 'cancel-edit', }); }