EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
onSync onChange methods
Yuriidc13a18f9afb
diff --git a/client/src/collection.js b/client/src/collection.jsindex 092e4a65eb..d60e43a9fc 100644--- a/client/src/collection.js+++ b/client/src/collection.js@@ -31,6 +31,7 @@import Model from 'model';import {Events, View as BullView} from 'bullbone';import _ from 'underscore';+import {onSync} from 'util/event';/*** On sync with backend.@@ -1003,6 +1004,31 @@ class Collection {return this.url;}+ /**+ * Listen to sync.+ *+ * Important. Owner must be specified.+ *+ * @param {{+ * owner: import('view').default | import('model').default | import('collection').default,+ * once?: boolean,+ * callback: function({+ * action: 'fetch'|'save'|'destroy'|null,+ * response: *,+ * }),+ * }} params+ * @return {{stop: function()}}+ * @since 9.4.0+ */+ onSync(params) {+ return onSync({+ owner: params.owner,+ once: params.once,+ target: this,+ callback: params.callback,+ });+ }+/** @private */_isModel(object) {return object instanceof Model;diff --git a/client/src/model.js b/client/src/model.jsindex 5edb3b571e..c252d0844c 100644--- a/client/src/model.js+++ b/client/src/model.js@@ -31,6 +31,7 @@import {Events, View as BullView} from 'bullbone';import _ from 'underscore';import DefaultValueProvider from 'helpers/model/default-value-provider';+import {onModelChange, onSync} from 'util/event';/*** When attributes have changed.@@ -1076,6 +1077,59 @@ class Model {this.lastSyncPromise.abort();}}++ /**+ * Listen to attribute change.+ *+ * Important. Owner must be specified.+ *+ * @param {{+ * owner: import('view').default | import('model').default | import('collection').default,+ * attributes?: string[],+ * once?: boolean,+ * callback: function({+ * ui: boolean|null,+ * action: string|'ui'|'save'|'fetch'|'cancel-edit'|null,+ * }),+ * }} params+ * @return {{stop: function()}}+ * @since 9.4.0+ */+ onChange(params) {+ return onModelChange({+ owner: params.owner,+ once: params.once,+ target: this,+ attributes: params.attributes,+ callback: params.callback,+ });+ }++ // noinspection JSUnusedGlobalSymbols+ /**+ * Listen to sync.+ *+ * Important. Owner must be specified.+ *+ * @param {{+ * owner: import('view').default | import('model').default | import('collection').default,+ * once?: boolean,+ * callback: function({+ * action: 'fetch'|'save'|'destroy'|null,+ * response: *,+ * }),+ * }} params+ * @return {{stop: function()}}+ * @since 9.4.0+ */+ onSync(params) {+ return onSync({+ owner: params.owner,+ once: params.once,+ target: this,+ callback: params.callback,+ });+ }}Object.assign(Model.prototype, Events);diff --git a/client/src/util/event.js b/client/src/util/event.jsindex 2145fe2762..a6306dde42 100644--- a/client/src/util/event.js+++ b/client/src/util/event.js@@ -27,6 +27,7 @@************************************************************************//**+ * @internal* Listen to model attribute change.** @param {{@@ -87,6 +88,7 @@ export function onModelChange(params) {}/**+ * @internal* Listen to sync.** @param {{diff --git a/client/src/views/fields/wysiwyg.js b/client/src/views/fields/wysiwyg.jsindex f4b3bb318f..49610f5721 100644--- a/client/src/views/fields/wysiwyg.js+++ b/client/src/views/fields/wysiwyg.js@@ -30,7 +30,6 @@import TextFieldView from 'views/fields/text';import {init as initSummernoteCustom} from 'helpers/misc/summernote-custom';-import {onModelChange} from 'util/event';/*** A wysiwyg field.@@ -159,9 +158,8 @@ class WysiwygFieldView extends TextFieldView {return;}- onModelChange({+ this.model.onChange({owner: this,- target: this.model,attributes: ['isHtml'],callback: o => {if (o.ui && this.isEditMode()) {@@ -198,7 +196,7 @@ class WysiwygFieldView extends TextFieldView {this.reRender();}},- })+ });}data() {diff --git a/client/src/views/record/kanban.js b/client/src/views/record/kanban.jsindex e5c731c0f7..143ca1b328 100644--- a/client/src/views/record/kanban.js+++ b/client/src/views/record/kanban.js@@ -30,7 +30,6 @@import ListRecordView from 'views/record/list';import RecordModal from 'helpers/record-modal';-import {onSync} from 'util/event';/*** A kanban record view.@@ -328,9 +327,8 @@ class KanbanRecordView extends ListRecordView {throw new Error('Collection has not been injected into Record.List view.');}- onSync({+ this.collection.onSync({owner: this,- target: this.collection,callback: o => {this.subCollectionList = undefined;// noinspection JSUnresolvedReference