change event action

This commit is contained in:
Yuri Kuznetsov
2025-03-10 13:35:16 +02:00
parent b05b4c78e8
commit 06dc8ef281
3 changed files with 19 additions and 8 deletions

View File

@@ -36,7 +36,7 @@ import _ from 'underscore';
*
* @event Model#change
* @param {Model} model A model.
* @param {Object.<string, *>} o Options.
* @param {Record.<string, *> & {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.<string, *>} [options] Options.
* } & Object.<string, *>} [options] Options. Use `patch` to send a PATCH request. If `wait`, attributes will be
* set only after the request is completed.
* @returns {Promise<Object.<string, *>>}
* @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) {

View File

@@ -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',
});
}

View File

@@ -1601,7 +1601,7 @@ class DetailRecordView extends BaseRecordView {
this.model.set(this.attributes, {
skipReRenderInEditMode: skipReRender,
editCancel: true,
action: 'cancel-edit',
});
}