marionette-rails 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
|
|
1
|
-
// Backbone.Marionette v0.9.
|
1
|
+
// Backbone.Marionette v0.9.1
|
2
2
|
//
|
3
3
|
// Copyright (C)2012 Derick Bailey, Muted Solutions, LLC
|
4
4
|
// Distributed Under MIT License
|
@@ -264,6 +264,7 @@ Marionette.CollectionView = Marionette.View.extend({
|
|
264
264
|
|
265
265
|
// Handle a child item added to the collection
|
266
266
|
addChildView: function(item, collection, options){
|
267
|
+
this.closeEmptyView();
|
267
268
|
var ItemView = this.getItemView();
|
268
269
|
return this.addItemView(item, ItemView, options.index);
|
269
270
|
},
|
@@ -274,30 +275,66 @@ Marionette.CollectionView = Marionette.View.extend({
|
|
274
275
|
this.onShowCallbacks.run();
|
275
276
|
},
|
276
277
|
|
277
|
-
//
|
278
|
-
//
|
279
|
-
|
280
|
-
var that = this;
|
281
|
-
var ItemView = this.getItemView();
|
282
|
-
var EmptyView = this.options.emptyView || this.emptyView;
|
283
|
-
|
278
|
+
// Internal method to trigger the before render callbacks
|
279
|
+
// and events
|
280
|
+
triggerBeforeRender: function(){
|
284
281
|
if (this.beforeRender) { this.beforeRender(); }
|
285
282
|
this.trigger("collection:before:render", this);
|
283
|
+
},
|
286
284
|
|
285
|
+
// Internal method to trigger the rendered callbacks and
|
286
|
+
// events
|
287
|
+
triggerRendered: function(){
|
288
|
+
if (this.onRender) { this.onRender(); }
|
289
|
+
this.trigger("collection:rendered", this);
|
290
|
+
},
|
291
|
+
|
292
|
+
// Render the collection of items. Override this method to
|
293
|
+
// provide your own implementation of a render function for
|
294
|
+
// the collection view.
|
295
|
+
render: function(){
|
296
|
+
this.triggerBeforeRender();
|
287
297
|
this.closeChildren();
|
288
298
|
|
289
|
-
if (this.collection) {
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
this.collection.each(function(item, index){
|
294
|
-
that.addItemView(item, ItemView, index);
|
295
|
-
});
|
296
|
-
}
|
299
|
+
if (this.collection && this.collection.length > 0) {
|
300
|
+
this.showCollection();
|
301
|
+
} else {
|
302
|
+
this.showEmptyView();
|
297
303
|
}
|
298
304
|
|
299
|
-
|
300
|
-
|
305
|
+
this.triggerRendered();
|
306
|
+
},
|
307
|
+
|
308
|
+
// Internal method to loop through each item in the
|
309
|
+
// collection view and show it
|
310
|
+
showCollection: function(){
|
311
|
+
var that = this;
|
312
|
+
var ItemView = this.getItemView();
|
313
|
+
this.collection.each(function(item, index){
|
314
|
+
that.addItemView(item, ItemView, index);
|
315
|
+
});
|
316
|
+
},
|
317
|
+
|
318
|
+
// Internal method to show an empty view in place of
|
319
|
+
// a collection of item views, when the collection is
|
320
|
+
// empty
|
321
|
+
showEmptyView: function(){
|
322
|
+
var EmptyView = this.options.emptyView || this.emptyView;
|
323
|
+
if (EmptyView){
|
324
|
+
this.showingEmptyView = true;
|
325
|
+
var model = new Backbone.Model();
|
326
|
+
this.addItemView(model, EmptyView, 0);
|
327
|
+
}
|
328
|
+
},
|
329
|
+
|
330
|
+
// Internal method to close an existing emptyView instance
|
331
|
+
// if one exists. Called when a collection view has been
|
332
|
+
// rendered empty, and then an item is added to the collection.
|
333
|
+
closeEmptyView: function(){
|
334
|
+
if (this.showingEmptyView){
|
335
|
+
this.closeChildren();
|
336
|
+
delete this.showingEmptyView;
|
337
|
+
}
|
301
338
|
},
|
302
339
|
|
303
340
|
// Retrieve the itemView type, either from `this.options.itemView`
|
@@ -380,6 +417,11 @@ Marionette.CollectionView = Marionette.View.extend({
|
|
380
417
|
view.close();
|
381
418
|
delete this.children[item.cid];
|
382
419
|
}
|
420
|
+
|
421
|
+
if (this.collection.length === 0){
|
422
|
+
this.showEmptyView();
|
423
|
+
}
|
424
|
+
|
383
425
|
this.trigger("item:removed", view);
|
384
426
|
},
|
385
427
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marionette-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|