2013-02-14 21:01:30 +03:00
|
|
|
'use strict';
|
|
|
|
|
2013-02-15 05:40:29 +03:00
|
|
|
define(['app', 'Quality/QualityProfileCollection', 'Series/SeriesItemView'], function (app, qualityProfileCollection) {
|
2013-02-14 21:01:30 +03:00
|
|
|
NzbDrone.Series.SeriesCollectionView = Backbone.Marionette.CompositeView.extend({
|
|
|
|
itemView: NzbDrone.Series.SeriesItemView,
|
2013-02-16 02:38:53 +03:00
|
|
|
itemViewContainer: 'tbody',
|
2013-02-14 21:01:30 +03:00
|
|
|
template: 'Series/SeriesCollectionTemplate',
|
2013-02-15 05:40:29 +03:00
|
|
|
qualityProfileCollection: qualityProfileCollection,
|
2013-02-18 03:46:13 +03:00
|
|
|
emptyView: NzbDrone.Series.EmptySeriesCollectionView,
|
2013-02-14 21:01:30 +03:00
|
|
|
|
|
|
|
initialize: function () {
|
2013-02-15 05:40:29 +03:00
|
|
|
this.collection = new NzbDrone.Series.SeriesCollection();
|
2013-02-18 03:46:13 +03:00
|
|
|
//Todo: This caused the onRendered event to be trigger twice, which displays two empty collection messages
|
|
|
|
//http://stackoverflow.com/questions/13065176/backbone-marionette-composit-view-onrender-executing-twice
|
2013-02-15 05:40:29 +03:00
|
|
|
this.collection.fetch();
|
2013-02-14 21:01:30 +03:00
|
|
|
this.qualityProfileCollection.fetch();
|
2013-02-15 05:40:29 +03:00
|
|
|
|
2013-02-14 21:01:30 +03:00
|
|
|
this.itemViewOptions = { qualityProfiles: this.qualityProfileCollection };
|
|
|
|
},
|
|
|
|
|
2013-02-16 02:38:53 +03:00
|
|
|
ui:{
|
|
|
|
table : '.x-series-table'
|
|
|
|
},
|
|
|
|
|
|
|
|
onItemRemoved: function()
|
|
|
|
{
|
|
|
|
this.ui.table.trigger('update');
|
|
|
|
},
|
|
|
|
|
|
|
|
onCompositeCollectionRendered: function()
|
|
|
|
{
|
|
|
|
this.ui.table.trigger('update');
|
|
|
|
|
|
|
|
if(!this.tableSorter && this.collection.length > 0)
|
|
|
|
{
|
2013-02-17 04:16:37 +03:00
|
|
|
this.tableSorter = this.ui.table.tablesorter({
|
|
|
|
textExtraction: function (node) {
|
|
|
|
return node.innerHTML;
|
|
|
|
},
|
|
|
|
sortList: [[1,0]],
|
|
|
|
headers: {
|
|
|
|
0: {
|
|
|
|
sorter: 'title'
|
|
|
|
},
|
|
|
|
1: {
|
|
|
|
sorter: 'innerHtml'
|
|
|
|
},
|
|
|
|
5: {
|
|
|
|
sorter: 'date'
|
|
|
|
},
|
|
|
|
6: {
|
|
|
|
sorter: false
|
|
|
|
},
|
|
|
|
7: {
|
|
|
|
sorter: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2013-02-16 02:38:53 +03:00
|
|
|
|
2013-02-17 04:16:37 +03:00
|
|
|
this.ui.table.find('th.header').each(function(){
|
|
|
|
$(this).append('<i class="icon-sort pull-right">');
|
|
|
|
});
|
2013-02-16 02:38:53 +03:00
|
|
|
|
2013-02-17 04:16:37 +03:00
|
|
|
this.ui.table.bind("sortEnd", function() {
|
2013-02-16 02:38:53 +03:00
|
|
|
$(this).find('th.header i').each(function(){
|
|
|
|
$(this).remove();
|
|
|
|
});
|
|
|
|
|
2013-02-17 04:16:37 +03:00
|
|
|
$(this).find('th.header').each(function () {
|
|
|
|
if (!$(this).hasClass('headerSortDown') && !$(this).hasClass('headerSortUp'))
|
|
|
|
$(this).append('<i class="icon-sort pull-right">');
|
|
|
|
});
|
|
|
|
|
2013-02-16 02:38:53 +03:00
|
|
|
$(this).find('th.headerSortDown').each(function(){
|
|
|
|
$(this).append('<i class="icon-sort-down pull-right">');
|
|
|
|
});
|
|
|
|
|
|
|
|
$(this).find('th.headerSortUp').each(function(){
|
|
|
|
$(this).append('<i class="icon-sort-up pull-right">');
|
|
|
|
});
|
|
|
|
});
|
2013-02-17 04:16:37 +03:00
|
|
|
}
|
2013-02-16 02:38:53 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
this.ui.table.trigger('update');
|
|
|
|
}
|
2013-02-14 21:01:30 +03:00
|
|
|
}
|
|
|
|
});
|
2013-02-18 03:46:13 +03:00
|
|
|
});
|
2013-02-14 21:01:30 +03:00
|
|
|
|
2013-02-18 03:46:13 +03:00
|
|
|
NzbDrone.Series.EmptySeriesCollectionView = Backbone.Marionette.CompositeView.extend({
|
|
|
|
template: 'Series/EmptySeriesCollectionTemplate',
|
|
|
|
tagName: 'tr'
|
2013-02-16 02:38:53 +03:00
|
|
|
});
|