Skip to content

Commit

Permalink
Mehrere Instanzen für Event/NewsCollectionView im split.html erlaubt. #…
Browse files Browse the repository at this point in the history
  • Loading branch information
DracoBlue committed Jan 22, 2016
1 parent 836633f commit 324ce9a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 17 deletions.
20 changes: 18 additions & 2 deletions split.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,31 @@
<div class="row js_page jsb_ jsb_views/AdView" id="ad-view" data-jsb="">
</div>

<div class="row js_page jsb_ jsb_views/NewsCollectionView" data-jsb="">
<div class="row js_page jsb_ jsb_views/NewsCollectionView" data-jsb="offset=0">
<strong class="page-headline"><span class="js_news_headline">Neuigkeiten</span></strong>
<table class="js_news table table-striped table-hover">
<tbody class="js_news_tbody">
</tbody>
</table>
</div>

<div class="row js_page jsb_ jsb_views/EventCollectionView" data-jsb="">
<div class="row js_page jsb_ jsb_views/NewsCollectionView" data-jsb="offset=1">
<strong class="page-headline"><span class="js_news_headline">Neuigkeiten</span></strong>
<table class="js_news table table-striped table-hover">
<tbody class="js_news_tbody">
</tbody>
</table>
</div>

<div class="row js_page jsb_ jsb_views/EventCollectionView" data-jsb="offset=0">
<strong class="page-headline"><span class="js_news_headline">Veranstaltungen</span></strong>
<table class="js_news table table-striped table-hover">
<tbody class="js_news_tbody">
</tbody>
</table>
</div>

<div class="row js_page jsb_ jsb_views/EventCollectionView" data-jsb="offset=1">
<strong class="page-headline"><span class="js_news_headline">Veranstaltungen</span></strong>
<table class="js_news table table-striped table-hover">
<tbody class="js_news_tbody">
Expand Down
2 changes: 1 addition & 1 deletion static/js/models/BaseRssCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ define('models/BaseRssCollection', ["Backbone", "jquery", "config", "moment", "m
} else {
var rawEvents = that.parseNewsResponse(xmlResponseString);

that.reset(rawEvents.slice(0, that.getMaxResults()));
that.reset(rawEvents);
that.trigger('update');

if (options.success) {
Expand Down
5 changes: 0 additions & 5 deletions static/js/models/EventCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ define('models/EventCollection', ["Backbone", "jquery", "config", "moment", "mod

initialize: function(models, attributes) {
if (!config.get('events_rss_feed_url')) throw new Error('Missing config.events_rss_feed_url attribute for EventCollection');
if (!config.get('news_per_page')) throw new Error('Missing config.news_per_page attribute for EventCollection');
},

isValid: function(rssItem) {
Expand All @@ -20,10 +19,6 @@ define('models/EventCollection', ["Backbone", "jquery", "config", "moment", "mod
return config.get('events_rss_feed_url');
},

getMaxResults: function() {
return config.get('news_per_page');
},

comparator: function(a, b) {
if (a.get('updatedTimestamp').getTime() == b.get('updatedTimestamp').getTime()) {
return 0;
Expand Down
5 changes: 0 additions & 5 deletions static/js/models/NewsCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ define('models/NewsCollection', ["Backbone", "jquery", "config", "moment", "mode

initialize: function(models, attributes) {
if (!config.get('news_rss_feed_url')) throw new Error('Missing config.news_rss_feed_url attribute for NewsCollection');
if (!config.get('news_per_page')) throw new Error('Missing config.news_per_page attribute for NewsCollection');
},

isValid: function(rssItem) {
Expand All @@ -16,10 +15,6 @@ define('models/NewsCollection', ["Backbone", "jquery", "config", "moment", "mode
return config.get('news_rss_feed_url');
},

getMaxResults: function() {
return config.get('news_per_page');
},

comparator: function(a, b) {
if (a.get('updatedTimestamp').getTime() == b.get('updatedTimestamp').getTime()) {
return 0;
Expand Down
7 changes: 5 additions & 2 deletions static/js/views/EventCollectionView.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ define('views/EventCollectionView', ["Backbone", "config", "jquery", "views/Base

var EventCollectionView = BaseView.extend({

initialize: function() {
initialize: function(options) {
if (!config.get('news_per_page')) throw new Error('Missing config.news_per_page attribute for EventCollectionView');

this.options = options || {};
this.options.offset = parseInt(this.options.offset || "0", 10);

this.listenTo(eventsCollection, "update", this.render);
this.render();
},
Expand All @@ -24,7 +27,7 @@ define('views/EventCollectionView', ["Backbone", "config", "jquery", "views/Base
newsTable.css('margin-bottom', '0');
}

eventsCollection.forEach(function(event) {
eventsCollection.slice(this.options.offset, this.options.offset + config.get('news_per_page')).forEach(function(event) {
var view = new EventView({"model": event, "tagName": "tr"});
newsTableBody.append(view.render().el);
});
Expand Down
7 changes: 5 additions & 2 deletions static/js/views/NewsCollectionView.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ define('views/NewsCollectionView', ["Backbone", "config", "jquery", "views/BaseV

var NewsCollectionView = BaseView.extend({

initialize: function() {
initialize: function(options) {
if (!config.get('news_per_page')) throw new Error('Missing config.news_per_page attribute for EventCollectionView');

this.options = options || {};
this.options.offset = parseInt(this.options.offset || "0", 10);

this.listenTo(newsCollection, "update", this.render);
this.render();
},
Expand All @@ -24,7 +27,7 @@ define('views/NewsCollectionView', ["Backbone", "config", "jquery", "views/BaseV
newsTable.css('margin-bottom', '0');
}

newsCollection.slice(0, config.get('news_per_page')).forEach(function(event) {
newsCollection.slice(this.options.offset, this.options.offset + config.get('news_per_page')).forEach(function(event) {
var view = new NewsView({"model": event, "tagName": "tr"});
newsTableBody.append(view.render().el);
});
Expand Down

0 comments on commit 324ce9a

Please sign in to comment.