diff --git a/frontend/client/src/controller.js b/frontend/client/src/controller.js index 4ef31089be..29c2d48784 100644 --- a/frontend/client/src/controller.js +++ b/frontend/client/src/controller.js @@ -197,7 +197,7 @@ Espo.define('controller', [], function () { * Create main view in master and return it. * @param {String} view Name of view. * @param {Object} options Options for view. - * @return {Espo.View} + * @return {view} */ main: function (view, options, callback) { var view = view || 'Base'; diff --git a/frontend/client/src/controllers/record.js b/frontend/client/src/controllers/record.js index 2ea52ad22e..6266cdd6c5 100644 --- a/frontend/client/src/controllers/record.js +++ b/frontend/client/src/controllers/record.js @@ -39,6 +39,7 @@ Espo.define('controllers/record', 'controller', function (Dep) { initialize: function () { this.viewMap = this.viewMap || {}; this.viewsMap = this.viewsMap || {}; + this.collectionMap = {}; }, getViewName: function (type) { @@ -196,7 +197,7 @@ Espo.define('controllers/record', 'controller', function (Dep) { /** * Get collection for the current controller. - * @param {Espo.Collection}. + * @param {collection}. */ getCollection: function (callback, context) { context = context || this; @@ -205,14 +206,31 @@ Espo.define('controllers/record', 'controller', function (Dep) { throw new Error('No collection for unnamed controller'); } var collectionName = this.name; + /*if (collectionName in this.collectionMap) { + var collection = this.collectionMap[collectionName];// = this.collectionMap[collectionName].clone(); + var maxSize = this.getConfig().get('recordsPerPage'); + if (collection.length > maxSize) { + var k = collection.length - maxSize; + while (k) { + collection.pop(); + k--; + } + } + callback.call(context, collection); + return; + }*/ this.collectionFactory.create(collectionName, function (collection) { + this.collectionMap[collectionName] = collection; + this.listenTo(collection, 'sync', function () { + collection.isFetched = true; + }, this); callback.call(context, collection); }, context); }, /** * Get model for the current controller. - * @param {Espo.Model}. + * @param {model}. */ getModel: function (callback, context) { context = context || this; diff --git a/frontend/client/src/views/list.js b/frontend/client/src/views/list.js index 3fe5aa8a60..87394b9d3e 100644 --- a/frontend/client/src/views/list.js +++ b/frontend/client/src/views/list.js @@ -144,24 +144,35 @@ Espo.define('views/list', ['views/main', 'search-manager'], function (Dep, Searc loadList: function () { this.notify('Loading...'); + if (this.collection.isFetched) { + this.createListRecordView(true); + } else { + this.listenToOnce(this.collection, 'sync', function () { + this.createListRecordView(); + }, this); + this.collection.fetch(); + } + }, + + createListRecordView: function (fetch) { var listViewName = this.getRecordViewName(); - this.listenToOnce(this.collection, 'sync', function () { - this.createView('list', listViewName, { - collection: this.collection, - el: this.options.el + ' .list-container', - }, function (view) { - view.render(); - view.notify(false); - - if (this.searchPanel) { - this.listenTo(this.getView('list'), 'sort', function (obj) { - this.getStorage().set('listSorting', this.collection.name, obj); - }, this); - } - - }.bind(this)); - }, this); - this.collection.fetch(); + this.createView('list', listViewName, { + collection: this.collection, + el: this.options.el + ' .list-container', + }, function (view) { + view.render(); + view.notify(false); + if (this.searchPanel) { + this.listenTo(view, 'sort', function (obj) { + this.getStorage().set('listSorting', this.collection.name, obj); + }, this); + } + if (fetch) { + setTimeout(function () { + this.collection.fetch(); + }.bind(this), 2000); + } + }); }, getHeader: function () {