list changes

This commit is contained in:
yuri
2015-07-23 14:50:15 +03:00
parent d947223b9b
commit ce2a2a03a3
3 changed files with 49 additions and 20 deletions
+1 -1
View File
@@ -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';
+20 -2
View File
@@ -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;
+28 -17
View File
@@ -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 () {