2013-02-14 21:01:30 +03:00
|
|
|
'use strict';
|
|
|
|
|
2013-04-10 06:17:41 +03:00
|
|
|
define(['app', 'Quality/QualityProfileCollection', 'Series/Index/SeriesItemView', 'Config'], function (app, qualityProfileCollection) {
|
2013-04-18 03:48:52 +03:00
|
|
|
|
|
|
|
NzbDrone.Series.Index.EmptySeriesCollectionView = Backbone.Marionette.CompositeView.extend({
|
|
|
|
template: 'Series/Index/EmptySeriesIndexTemplate',
|
|
|
|
tagName : 'tr'
|
|
|
|
});
|
|
|
|
|
2013-03-04 01:42:26 +03:00
|
|
|
NzbDrone.Series.Index.SeriesIndexCollectionView = Backbone.Marionette.CompositeView.extend({
|
2013-03-30 02:28:58 +03:00
|
|
|
itemView : NzbDrone.Series.Index.SeriesItemView,
|
2013-04-10 06:17:41 +03:00
|
|
|
itemViewContainer : '#x-series',
|
2013-03-30 02:28:58 +03:00
|
|
|
template : 'Series/Index/SeriesIndexTemplate',
|
2013-02-15 05:40:29 +03:00
|
|
|
qualityProfileCollection: qualityProfileCollection,
|
2013-04-18 03:48:52 +03:00
|
|
|
|
|
|
|
emptyView : NzbDrone.Series.Index.EmptySeriesCollectionView,
|
2013-02-14 21:01:30 +03:00
|
|
|
|
2013-04-10 06:17:41 +03:00
|
|
|
getTemplate: function(){
|
|
|
|
if (this.viewStyle === 1){
|
|
|
|
return 'Series/Index/SeriesIndexGridTemplate';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 'Series/Index/SeriesIndexTemplate';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
ui: {
|
|
|
|
table: '.x-series-table'
|
|
|
|
},
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'click .x-series-change-view': 'changeViewTemplate'
|
|
|
|
},
|
|
|
|
|
2013-02-14 21:01:30 +03:00
|
|
|
initialize: function () {
|
2013-04-10 06:17:41 +03:00
|
|
|
this.viewStyle = NzbDrone.Config.SeriesViewStyle();
|
|
|
|
|
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-04-10 06:17:41 +03:00
|
|
|
this.itemViewOptions = { qualityProfiles: this.qualityProfileCollection, viewStyle: this.viewStyle };
|
2013-02-16 02:38:53 +03:00
|
|
|
},
|
|
|
|
|
2013-03-30 02:28:58 +03:00
|
|
|
onItemRemoved: function () {
|
2013-02-16 02:38:53 +03:00
|
|
|
this.ui.table.trigger('update');
|
|
|
|
},
|
|
|
|
|
2013-03-30 02:28:58 +03:00
|
|
|
onCompositeCollectionRendered: function () {
|
2013-02-16 02:38:53 +03:00
|
|
|
this.ui.table.trigger('update');
|
|
|
|
|
2013-03-30 02:28:58 +03:00
|
|
|
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;
|
|
|
|
},
|
2013-03-30 02:28:58 +03:00
|
|
|
sortList : [
|
|
|
|
[1, 0]
|
|
|
|
],
|
|
|
|
headers : {
|
2013-02-17 04:16:37 +03:00
|
|
|
0: {
|
|
|
|
sorter: 'title'
|
|
|
|
},
|
|
|
|
1: {
|
|
|
|
sorter: 'innerHtml'
|
|
|
|
},
|
|
|
|
5: {
|
|
|
|
sorter: 'date'
|
|
|
|
},
|
|
|
|
6: {
|
|
|
|
sorter: false
|
|
|
|
},
|
|
|
|
7: {
|
|
|
|
sorter: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2013-02-16 02:38:53 +03:00
|
|
|
|
2013-03-22 09:43:23 +03:00
|
|
|
this.applySortIcons();
|
2013-02-16 02:38:53 +03:00
|
|
|
|
2013-03-30 02:28:58 +03:00
|
|
|
this.ui.table.bind("sortEnd", function () {
|
2013-03-22 09:43:23 +03:00
|
|
|
this.applySortIcons();
|
2013-02-16 02:38:53 +03:00
|
|
|
});
|
2013-02-17 04:16:37 +03:00
|
|
|
}
|
2013-03-30 02:28:58 +03:00
|
|
|
else {
|
2013-02-16 02:38:53 +03:00
|
|
|
this.ui.table.trigger('update');
|
|
|
|
}
|
2013-03-22 09:43:23 +03:00
|
|
|
},
|
|
|
|
//Todo: Remove this from each view that requires it
|
2013-03-30 02:28:58 +03:00
|
|
|
applySortIcons : function () {
|
|
|
|
$(this.ui.table).find('th.tablesorter-header .tablesorter-header-inner i').each(function () {
|
2013-03-22 09:43:23 +03:00
|
|
|
$(this).remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
$(this.ui.table).find('th.tablesorter-header').each(function () {
|
2013-03-30 02:28:58 +03:00
|
|
|
if ($(this).hasClass('tablesorter-headerDesc')) {
|
2013-03-22 09:43:23 +03:00
|
|
|
$(this).children('.tablesorter-header-inner').append('<i class="icon-sort-up pull-right">');
|
2013-03-30 02:28:58 +03:00
|
|
|
}
|
2013-03-22 09:43:23 +03:00
|
|
|
|
2013-03-30 02:28:58 +03:00
|
|
|
else if ($(this).hasClass('tablesorter-headerAsc')) {
|
2013-03-22 09:43:23 +03:00
|
|
|
$(this).children('.tablesorter-header-inner').append('<i class="icon-sort-down pull-right">');
|
2013-03-30 02:28:58 +03:00
|
|
|
}
|
2013-03-22 09:43:23 +03:00
|
|
|
|
2013-03-30 02:28:58 +03:00
|
|
|
else if (!$(this).hasClass('sorter-false')) {
|
2013-03-22 09:43:23 +03:00
|
|
|
$(this).children('.tablesorter-header-inner').append('<i class="icon-sort pull-right">');
|
2013-03-30 02:28:58 +03:00
|
|
|
}
|
2013-03-22 09:43:23 +03:00
|
|
|
});
|
2013-04-10 06:17:41 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
changeViewTemplate: function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
if ($(event.currentTarget).hasClass('x-series-show-grid')) {
|
|
|
|
NzbDrone.Config.SeriesViewStyle(1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NzbDrone.Config.SeriesViewStyle(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.viewStyle = NzbDrone.Config.SeriesViewStyle();
|
|
|
|
this.itemViewOptions.viewStyle = this.viewStyle;
|
|
|
|
this.render();
|
2013-02-14 21:01:30 +03:00
|
|
|
}
|
|
|
|
});
|
2013-02-16 02:38:53 +03:00
|
|
|
});
|