model collection factory promise support

This commit is contained in:
yuri
2019-01-30 11:18:59 +02:00
parent c7be90e1ad
commit 68634edc0d
2 changed files with 29 additions and 22 deletions
+20 -18
View File
@@ -40,24 +40,26 @@
modelFactory: null,
create: function (name, callback, context) {
context = context || this;
this.modelFactory.getSeed(name, function (seed) {
var orderBy = this.modelFactory.metadata.get(['entityDefs', name, 'collection', 'orderBy']);
var order = this.modelFactory.metadata.get(['entityDefs', name, 'collection', 'order']);
var className = this.modelFactory.metadata.get(['clientDefs', name, 'collection']) || 'collection';
Espo.loader.require(className, function (collectionClass) {
var collection = new collectionClass(null, {
name: name,
orderBy: orderBy,
order: order
});
collection.model = seed;
collection._user = this.modelFactory.user;
collection.entityType = name;
callback.call(context, collection);
return new Promise(function (resolve) {
context = context || this;
this.modelFactory.getSeed(name, function (seed) {
var orderBy = this.modelFactory.metadata.get(['entityDefs', name, 'collection', 'orderBy']);
var order = this.modelFactory.metadata.get(['entityDefs', name, 'collection', 'order']);
var className = this.modelFactory.metadata.get(['clientDefs', name, 'collection']) || 'collection';
Espo.loader.require(className, function (collectionClass) {
var collection = new collectionClass(null, {
name: name,
orderBy: orderBy,
order: order
});
collection.model = seed;
collection._user = this.modelFactory.user;
collection.entityType = name;
if (callback) {
callback.call(context, collection);
}
resolve(collection);
}.bind(this));
}.bind(this));
}.bind(this));
}
+9 -4
View File
@@ -49,10 +49,15 @@ Espo.define('model-factory', [], function () {
user: null,
create: function (name, callback, context) {
context = context || this;
this.getSeed(name, function (seed) {
var model = new seed();
callback.call(context, model);
return new Promise(function (resolve) {
context = context || this;
this.getSeed(name, function (seed) {
var model = new seed();
if (callback) {
callback.call(context, model);
}
resolve(model);
}.bind(this));
}.bind(this));
},