diff --git a/client/src/ajax.js b/client/src/ajax.js index 02d3f9d9b6..75d66ed26a 100644 --- a/client/src/ajax.js +++ b/client/src/ajax.js @@ -43,6 +43,7 @@ define('ajax', [], function () { * * @property {Number} [timeout] A timeout. * @property {Object.} [headers] A request headers. + * @property {'xml'|'json'|'text'} [dataType] A data type. */ /** diff --git a/client/src/collection.js b/client/src/collection.js index fa67d49096..6a893678a7 100644 --- a/client/src/collection.js +++ b/client/src/collection.js @@ -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) { diff --git a/client/src/metadata.js b/client/src/metadata.js index 421391e6ad..bba3db667f 100644 --- a/client/src/metadata.js +++ b/client/src/metadata.js @@ -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 = []; diff --git a/client/src/model-offline.js b/client/src/model-offline.js index f0e2d8efdc..697af01be8 100644 --- a/client/src/model-offline.js +++ b/client/src/model-offline.js @@ -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; }); diff --git a/client/src/model.js b/client/src/model.js index bf71d4ac92..042ca0739c 100644 --- a/client/src/model.js +++ b/client/src/model.js @@ -156,6 +156,8 @@ define('model', [], function () { defs: null, /** + * Initialize. + * * @protected */ initialize: function () { diff --git a/client/src/multi-collection.js b/client/src/multi-collection.js index e7fa99ecd7..a0f9b73b0e 100644 --- a/client/src/multi-collection.js +++ b/client/src/multi-collection.js @@ -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; }); diff --git a/client/src/namespace.js b/client/src/namespace.js index 1685952293..41522be5c5 100644 --- a/client/src/namespace.js +++ b/client/src/namespace.js @@ -26,4 +26,4 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -var Espo = {}; +let Espo = {}; diff --git a/client/src/number.js b/client/src/number.js index 027faf629c..67347d50ec 100644 --- a/client/src/number.js +++ b/client/src/number.js @@ -151,7 +151,6 @@ define('number', [], function () { return decimalMark; }, - }); return NumberUtil; diff --git a/client/src/page-title.js b/client/src/page-title.js index 8436c6c055..75db96b92e 100644 --- a/client/src/page-title.js +++ b/client/src/page-title.js @@ -66,7 +66,6 @@ define('page-title', [], function () { $('head title').text(value); }, - }); return PageTitle; diff --git a/client/src/session-storage.js b/client/src/session-storage.js index 36d80a47aa..cd1a541016 100644 --- a/client/src/session-storage.js +++ b/client/src/session-storage.js @@ -86,6 +86,5 @@ define('session-storage', ['storage'], function (Dep) { } } }, - }); });