This commit is contained in:
Yuri Kuznetsov
2022-06-16 18:20:22 +03:00
parent c0bb2148c6
commit cd7f060feb
10 changed files with 121 additions and 41 deletions
+1
View File
@@ -43,6 +43,7 @@ define('ajax', [], function () {
*
* @property {Number} [timeout] A timeout.
* @property {Object.<string,string>} [headers] A request headers.
* @property {'xml'|'json'|'text'} [dataType] A data type.
*/
/**
+12 -3
View File
@@ -181,9 +181,11 @@ define('collection', [], function () {
_user: null,
/**
* Initialize.
*
* @protected
* @param {module:model.Class[]} models
* @param {Object} options
* @param {module:model.Class[]} models Models.
* @param {Object} options Options.
*/
initialize: function (models, options) {
options = options || {};
@@ -305,7 +307,14 @@ define('collection', [], function () {
this.fetch();
},
parse: function (response) {
/**
* Parse a response from the backend.
*
* @param {Object} response A response.
* @param {Object} options Options.
* @returns {module:collection.Class[]}
*/
parse: function (response, options) {
this.total = response.total;
if ('additionalData' in response) {
+78 -18
View File
@@ -28,21 +28,43 @@
define('metadata', [], function () {
/**
* Application metadata.
*
* @class
* @name Class
* @memberOf module:metadata
*
* @param {module:cache.Class} [cache] A cache.
*/
let Metadata = function (cache) {
/**
* @private
* @type {module:cache.Class|null}
*/
this.cache = cache || null;
/**
* @private
* @type {Object}
*/
this.data = {};
this.ajax = $.ajax;
};
_.extend(Metadata.prototype, {
cache: null,
data: null,
_.extend(Metadata.prototype, /** @lends module:metadata.Class# */{
/**
* @private
*/
url: 'Metadata',
/**
* Load from cache or the backend (if not yet cached).
*
* @param {Function|null} [callback] Deprecated. Use a promise.
* @param {boolean} [disableCache=false] Bypass cache.
* @returns {Promise}
*/
load: function (callback, disableCache) {
this.off('sync');
@@ -64,25 +86,38 @@ define('metadata', [], function () {
});
},
/**
* Load from the server.
*
* @returns {Promise}
*/
loadSkipCache: function () {
return this.load(null, true);
},
/**
* @private
* @returns {Promise}
*/
fetch: function () {
return this.ajax({
url: this.url,
type: 'GET',
dataType: 'JSON',
success: data => {
this.data = data;
this.storeToCache();
this.trigger('sync');
},
});
return Espo.Ajax
.getRequest(this.url, null, {
dataType: 'json',
success: data => {
this.data = data;
this.storeToCache();
this.trigger('sync');
},
});
},
/**
* Get a value.
*
* @param {string[]|string} path A key path.
* @param {*} [defaultValue] A value to return if not set.
* @returns {*} Null if not set.
*/
get: function (path, defaultValue) {
defaultValue = defaultValue || null;
@@ -117,6 +152,10 @@ define('metadata', [], function () {
return result;
},
/**
* @private
* @returns {boolean} True if success.
*/
loadFromCache: function () {
if (this.cache) {
let cached = this.cache.get('app', 'metadata');
@@ -131,12 +170,18 @@ define('metadata', [], function () {
return null;
},
/**
* @private
*/
storeToCache: function () {
if (this.cache) {
this.cache.set('app', 'metadata', this.data);
}
},
/**
* Clear cache.
*/
clearCache: function () {
if (!this.cache) {
return;
@@ -145,6 +190,11 @@ define('metadata', [], function () {
this.cache.clear('app', 'metadata');
},
/**
* Get a scope list.
*
* @returns {string}
*/
getScopeList: function () {
let scopes = this.get('scopes') || {};
let scopeList = [];
@@ -162,6 +212,11 @@ define('metadata', [], function () {
return scopeList;
},
/**
* Get an object-scope list. An object-scope represents a business entity.
*
* @returns {string[]}
*/
getScopeObjectList: function () {
let scopes = this.get('scopes') || {};
let scopeList = [];
@@ -183,6 +238,11 @@ define('metadata', [], function () {
return scopeList;
},
/**
* Get an entity-scope list. Scopes that represents entities.
*
* @returns {string[]}
*/
getScopeEntityList: function () {
var scopes = this.get('scopes') || {};
var scopeList = [];
+10 -10
View File
@@ -26,14 +26,17 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
/**
* @internal Not used.
*/
define('model-offline', 'model', function (Model) {
define('model-offline', ['model'], function (Model) {
let ModelOffline = Model.extend({
name: null,
/**
* @internal Not used.
*
* @class
* @name Class
* @extends module:model.Class
* @memberOf module:model-offline
*/
return Model.extend(/** @lends module:model-offline.Class# */{
cache: null,
@@ -97,8 +100,5 @@ define('model-offline', 'model', function (Model) {
isNew: function () {
return false;
},
});
return ModelOffline;
});
+2
View File
@@ -156,6 +156,8 @@ define('model', [], function () {
defs: null,
/**
* Initialize.
*
* @protected
*/
initialize: function () {
+17 -6
View File
@@ -28,21 +28,35 @@
define('multi-collection', ['collection'], function (Collection) {
let MultiCollection = Collection.extend({
/**
* A collection that can contain entities of different entity types.
*
* @class
* @name Class
* @extends module:collection.Class
* @memberOf module:multi-collection
*/
return Collection.extend(/** @lends module:multi-collection.Class# */{
/**
* @prop {Object} seeds Hash off model classes.
* @private
*/
seeds: null,
/**
* @inheritDoc
*/
initialize: function (models, options) {
options = options || {};
this.data = {};
Backbone.Collection.prototype.initialize.call(this);
Backbone.Collection.prototype.initialize.call(this, options);
},
/**
* @inheritDoc
*/
parse: function (resp, options) {
this.total = resp.total;
@@ -54,8 +68,5 @@ define('multi-collection', ['collection'], function (Collection) {
return new this.seeds[attributes._scope](a, options);
});
},
});
return MultiCollection;
});
+1 -1
View File
@@ -26,4 +26,4 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
var Espo = {};
let Espo = {};
-1
View File
@@ -151,7 +151,6 @@ define('number', [], function () {
return decimalMark;
},
});
return NumberUtil;
-1
View File
@@ -66,7 +66,6 @@ define('page-title', [], function () {
$('head title').text(value);
},
});
return PageTitle;
-1
View File
@@ -86,6 +86,5 @@ define('session-storage', ['storage'], function (Dep) {
}
}
},
});
});