Skip to content

EspoCRM – Open Source CRM Application

change event action

Yuri Kuznetsov06dc8ef28107
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.<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) {
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',
});
}