1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-29 03:05:49 +00:00
Sonarr/UI/Series/Index/SeriesIndexCollectionView.js

95 lines
3.6 KiB
JavaScript
Raw Normal View History

'use strict';
2013-03-03 22:42:26 +00:00
define(['app', 'Quality/QualityProfileCollection', 'Series/Index/SeriesItemView'], function (app, qualityProfileCollection) {
NzbDrone.Series.Index.SeriesIndexCollectionView = Backbone.Marionette.CompositeView.extend({
itemView : NzbDrone.Series.Index.SeriesItemView,
itemViewContainer : 'tbody',
template : 'Series/Index/SeriesIndexTemplate',
qualityProfileCollection: qualityProfileCollection,
//emptyView: NzbDrone.Series.EmptySeriesCollectionView,
initialize: function () {
this.collection = new NzbDrone.Series.SeriesCollection();
//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
this.collection.fetch();
this.qualityProfileCollection.fetch();
this.itemViewOptions = { qualityProfiles: this.qualityProfileCollection };
},
ui: {
table: '.x-series-table'
2013-02-15 23:38:53 +00:00
},
onItemRemoved: function () {
2013-02-15 23:38:53 +00:00
this.ui.table.trigger('update');
},
onCompositeCollectionRendered: function () {
2013-02-15 23:38:53 +00:00
this.ui.table.trigger('update');
if (!this.tableSorter && this.collection.length > 0) {
2013-02-17 01:16:37 +00:00
this.tableSorter = this.ui.table.tablesorter({
textExtraction: function (node) {
return node.innerHTML;
},
sortList : [
[1, 0]
],
headers : {
2013-02-17 01:16:37 +00:00
0: {
sorter: 'title'
},
1: {
sorter: 'innerHtml'
},
5: {
sorter: 'date'
},
6: {
sorter: false
},
7: {
sorter: false
}
}
});
2013-02-15 23:38:53 +00:00
2013-03-22 06:43:23 +00:00
this.applySortIcons();
2013-02-15 23:38:53 +00:00
this.ui.table.bind("sortEnd", function () {
2013-03-22 06:43:23 +00:00
this.applySortIcons();
2013-02-15 23:38:53 +00:00
});
2013-02-17 01:16:37 +00:00
}
else {
2013-02-15 23:38:53 +00:00
this.ui.table.trigger('update');
}
2013-03-22 06:43:23 +00:00
},
//Todo: Remove this from each view that requires it
applySortIcons : function () {
$(this.ui.table).find('th.tablesorter-header .tablesorter-header-inner i').each(function () {
2013-03-22 06:43:23 +00:00
$(this).remove();
});
$(this.ui.table).find('th.tablesorter-header').each(function () {
if ($(this).hasClass('tablesorter-headerDesc')) {
2013-03-22 06:43:23 +00:00
$(this).children('.tablesorter-header-inner').append('<i class="icon-sort-up pull-right">');
}
2013-03-22 06:43:23 +00:00
else if ($(this).hasClass('tablesorter-headerAsc')) {
2013-03-22 06:43:23 +00:00
$(this).children('.tablesorter-header-inner').append('<i class="icon-sort-down pull-right">');
}
2013-03-22 06:43:23 +00:00
else if (!$(this).hasClass('sorter-false')) {
2013-03-22 06:43:23 +00:00
$(this).children('.tablesorter-header-inner').append('<i class="icon-sort pull-right">');
}
2013-03-22 06:43:23 +00:00
});
}
});
});
2013-03-03 22:42:26 +00:00
NzbDrone.Series.Index.EmptySeriesCollectionView = Backbone.Marionette.CompositeView.extend({
template: 'Series/Index/EmptySeriesCollectionTemplate',
tagName : 'tr'
2013-02-15 23:38:53 +00:00
});