Sonarr/src/UI/Activity/Blacklist/BlacklistLayout.js

115 lines
3.1 KiB
JavaScript
Raw Normal View History

2015-02-07 18:30:02 +00:00
var vent = require('vent');
2015-02-03 01:18:45 +00:00
var Marionette = require('marionette');
var Backgrid = require('backgrid');
var BlacklistCollection = require('./BlacklistCollection');
var SeriesTitleCell = require('../../Cells/SeriesTitleCell');
var QualityCell = require('../../Cells/QualityCell');
var RelativeDateCell = require('../../Cells/RelativeDateCell');
var BlacklistActionsCell = require('./BlacklistActionsCell');
var GridPager = require('../../Shared/Grid/Pager');
var LoadingView = require('../../Shared/LoadingView');
var ToolbarLayout = require('../../Shared/Toolbar/ToolbarLayout');
2015-02-03 01:18:45 +00:00
module.exports = Marionette.Layout.extend({
2015-02-13 21:03:50 +00:00
template : 'Activity/Blacklist/BlacklistLayoutTemplate',
regions : {
2015-02-03 01:18:45 +00:00
blacklist : '#x-blacklist',
toolbar : '#x-toolbar',
pager : '#x-pager'
},
2015-02-13 21:03:50 +00:00
columns : [
{
name : 'series',
label : 'Series',
cell : SeriesTitleCell
},
{
name : 'sourceTitle',
label : 'Source Title',
cell : 'string'
},
{
name : 'quality',
label : 'Quality',
cell : QualityCell,
sortable : false
},
{
name : 'date',
label : 'Date',
cell : RelativeDateCell
},
{
name : 'this',
label : '',
cell : BlacklistActionsCell,
sortable : false
}
],
initialize : function() {
this.collection = new BlacklistCollection({ tableName : 'blacklist' });
2015-02-03 01:18:45 +00:00
this.listenTo(this.collection, 'sync', this._showTable);
this.listenTo(vent, vent.Events.CommandComplete, this._commandComplete);
},
2015-02-13 21:03:50 +00:00
onShow : function() {
2015-02-03 01:18:45 +00:00
this.blacklist.show(new LoadingView());
this._showToolbar();
this.collection.fetch();
},
2015-02-13 21:03:50 +00:00
_showTable : function(collection) {
2015-02-03 01:18:45 +00:00
this.blacklist.show(new Backgrid.Grid({
columns : this.columns,
collection : collection,
className : 'table table-hover'
}));
2015-02-13 21:03:50 +00:00
2015-02-03 01:18:45 +00:00
this.pager.show(new GridPager({
columns : this.columns,
collection : collection
}));
},
2015-02-13 21:03:50 +00:00
_showToolbar : function() {
2015-02-03 01:18:45 +00:00
var leftSideButtons = {
type : 'default',
storeState : false,
2015-02-13 21:03:50 +00:00
items : [
{
title : 'Clear Blacklist',
2015-02-21 02:20:31 +00:00
icon : 'icon-sonarr-clear',
2015-02-13 21:03:50 +00:00
command : 'clearBlacklist'
}
]
2015-02-03 01:18:45 +00:00
};
2015-02-13 21:03:50 +00:00
2015-02-03 01:18:45 +00:00
this.toolbar.show(new ToolbarLayout({
2015-02-13 21:03:50 +00:00
left : [
leftSideButtons
],
2015-02-03 01:18:45 +00:00
context : this
}));
},
2015-02-13 21:03:50 +00:00
_refreshTable : function(buttonContext) {
2015-02-03 01:18:45 +00:00
this.collection.state.currentPage = 1;
2015-02-13 21:03:50 +00:00
var promise = this.collection.fetch({ reset : true });
if (buttonContext) {
2015-02-03 01:18:45 +00:00
buttonContext.ui.icon.spinForPromise(promise);
}
},
2015-02-13 21:03:50 +00:00
_commandComplete : function(options) {
if (options.command.get('name') === 'clearblacklist') {
2015-02-03 01:18:45 +00:00
this._refreshTable();
}
}
2015-02-13 21:03:50 +00:00
});