frontend populate defaults before view
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
/** @module controllers/record */
|
||||
|
||||
import Controller from 'controller';
|
||||
import DefaultsPopulator from 'helpers/model/defaults-populator';
|
||||
|
||||
/**
|
||||
* A record controller.
|
||||
@@ -329,6 +330,8 @@ class RecordController extends Controller {
|
||||
o[k] = optionsOptions[k];
|
||||
}
|
||||
|
||||
await new DefaultsPopulator().populate(model);
|
||||
|
||||
if (options.attributes) {
|
||||
model.set(options.attributes);
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ class DefaultsPopulator {
|
||||
* Populate default values.
|
||||
*
|
||||
* @param {module:model} model A model.
|
||||
* @return {Promise|undefined}
|
||||
* @return {Promise}
|
||||
*/
|
||||
populate(model) {
|
||||
model.populateDefaults();
|
||||
@@ -113,7 +113,7 @@ class DefaultsPopulator {
|
||||
const preparatorClass = this.metadata.get(`clientDefs.${model.entityType}.modelDefaultsPreparator`);
|
||||
|
||||
if (!preparatorClass) {
|
||||
return undefined;
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return Espo.loader.requirePromise(preparatorClass)
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
import ModalView from 'views/modal';
|
||||
import Backbone from 'backbone';
|
||||
import DefaultsPopulator from 'helpers/model/defaults-populator';
|
||||
|
||||
/**
|
||||
* A quick edit modal.
|
||||
@@ -212,7 +213,7 @@ class EditModalView extends ModalView {
|
||||
|
||||
this.waitForView('edit');
|
||||
|
||||
this.getModelFactory().create(this.entityType, model => {
|
||||
this.getModelFactory().create(this.entityType, async model => {
|
||||
if (this.id) {
|
||||
if (this.sourceModel) {
|
||||
model = this.model = this.sourceModel.clone();
|
||||
@@ -234,6 +235,8 @@ class EditModalView extends ModalView {
|
||||
return;
|
||||
}
|
||||
|
||||
await new DefaultsPopulator().populate(model);
|
||||
|
||||
this.model = model;
|
||||
|
||||
if (this.options.relate) {
|
||||
|
||||
@@ -33,7 +33,6 @@ import ViewRecordHelper from 'view-record-helper';
|
||||
import DynamicLogic from 'dynamic-logic';
|
||||
import _ from 'underscore';
|
||||
import $ from 'jquery';
|
||||
import DefaultsPopulator from 'helpers/model/defaults-populator';
|
||||
|
||||
/**
|
||||
* A base record view. To be extended.
|
||||
@@ -686,7 +685,7 @@ class BaseRecordView extends View {
|
||||
}
|
||||
|
||||
this.listenTo(this.model, 'sync', () => {
|
||||
this.attributes = this.model.getClonedAttributes();
|
||||
this.attributes = this.model.getClonedAttributes();
|
||||
});
|
||||
|
||||
this.initDependency();
|
||||
@@ -1303,15 +1302,12 @@ class BaseRecordView extends View {
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate defaults.
|
||||
*
|
||||
* @return {Promise|undefined}
|
||||
*
|
||||
* @deprecated As of v9.3.0.
|
||||
* @todo Remove in v10.0.
|
||||
*/
|
||||
populateDefaults() {
|
||||
const populator = new DefaultsPopulator();
|
||||
|
||||
return populator.populate(this.model);
|
||||
}
|
||||
populateDefaults() {}
|
||||
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
/**
|
||||
|
||||
@@ -144,10 +144,10 @@ class EditRecordView extends DetailRecordView {
|
||||
super.setupBeforeFinal();
|
||||
}
|
||||
|
||||
// @todo To be removed.
|
||||
if (promise) {
|
||||
this.wait(promise);
|
||||
|
||||
// @todo Revise. Possible race condition issues.
|
||||
promise.then(() => {
|
||||
super.setupBeforeFinal();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user