3 var Marionette = require('backbone.marionette');
4 var Backbone = require('backbone');
5 var loadingTemplate = require('./tmpl/loading.hbs');
7 var LoadingView = Marionette.ItemView.extend({
8 template: loadingTemplate
11 // TODO: move this to a behavior
12 // Mixin for Marionette.CollectionView classes
14 loadingView: LoadingView,
15 initialize: function() {
16 this.showEmptyView = this.showLoadingView;
18 showLoadingView: function() {
19 if (this.collection.loading) {
20 var LoadingView = Marionette.getOption(this, 'loadingView');
22 if (!this.loadingModel) {
23 this.loadingModel = new Backbone.Model();
26 var v = this.children.findByModel(this.loadingModel);
28 if (LoadingView && !v) {
29 this.addChild(this.loadingModel, LoadingView, 0);
30 this.listenToOnce(this.collection, 'loaded', function() {
31 this.removeChildView(this.loadingModel);
33 if (this.collection.length === 0) {
34 this.constructor.prototype.showEmptyView.call(this);
42 this.constructor.prototype.showEmptyView.call(this);