Browse files

Handle entities with multiple types on reset

1 parent 684e217 commit 2ea2610a6c938b0e170ecd6230c9adc452d4eecf @bergie committed Sep 21, 2012
Showing with 10 additions and 7 deletions.
  1. +5 −3 src/view/CollectionView.js
  2. +1 −1 test/index.html
  3. +4 −3 test/service/rdfa.js
View
8 src/view/CollectionView.js
@@ -57,6 +57,9 @@ VIE.prototype.view.Collection = Backbone.View.extend({
}
var childType = entity.get('@type');
+ if (_.isArray(childType)) {
+ childType = childType[childType.length - 1];
+ }
var childTypeName = childType.id;
if (!this.canAdd(childTypeName)) {
@@ -136,13 +139,12 @@ VIE.prototype.view.Collection = Backbone.View.extend({
},
refreshItems: function(collection) {
- var view = this;
_.each(this.entityViews, function(view, cid) {
jQuery(view.el).remove();
});
this.entityViews = {};
collection.forEach(function(entity) {
- view.addItem(entity, collection);
- });
+ this.addItem(entity, collection);
+ }, this);
}
});
View
2 test/index.html
@@ -117,7 +117,7 @@ <h1 property="dcterms:title"><span>News item title</span></h1>
<div class="rdfa-collection-reset">
<div about="http://example.net/collectionreset">
<ul rel="collection">
- <li about="http://example.net/collectionreset/item"><span property="title">Title</span></li>
+ <li about="http://example.net/collectionreset/item" typeof="sioc:Post"><span property="title">Title</span></li>
</ul>
</div>
</div>
View
7 test/service/rdfa.js
@@ -148,16 +148,17 @@ test("Test collection reset with RDFa", function() {
var collection = entity.get('collection');
ok(collection.isCollection);
equal(collection.length, 1);
+ equal(collection.at(0).get('@type')[1].id, '<http://rdfs.org/sioc/ns#Post>');
equal(jQuery('li[about]', html).length, 1);
entity.set({
- collection: ['<http://example.net/collectionreset/item>']
+ collection: ['<http://example.net/collectionreset/item>', '<http://example.net/collectionreset/item2>']
});
collection = entity.get('collection');
ok(collection.isCollection);
- equal(collection.length, 1);
- equal(jQuery('li[about]', html).length, 1);
+ equal(collection.length, 2);
+ equal(jQuery('li[about]', html).length, 2);
start();
});

0 comments on commit 2ea2610

Please sign in to comment.