From 92d913e4acde23cd5621adfe13b2a8bfd1ddd610 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 16 May 2013 20:47:28 -0700 Subject: [PATCH] Better Backgrid.Column defaults, much cleaner --- UI/History/HistoryLayout.js | 100 +++++++++++-------------- UI/Missing/MissingLayout.js | 77 ++++++++----------- UI/Mixins/backbone.Backgrid.mixin.js | 11 +++ UI/Series/Details/SeasonLayout.js | 5 +- UI/Series/Index/SeriesIndexLayout.js | 108 ++++++++++++--------------- 5 files changed, 134 insertions(+), 167 deletions(-) diff --git a/UI/History/HistoryLayout.js b/UI/History/HistoryLayout.js index c8861327b..e8f05d53f 100644 --- a/UI/History/HistoryLayout.js +++ b/UI/History/HistoryLayout.js @@ -15,73 +15,59 @@ define([ pager : '#x-pager' }, - showTable: function () { + columns: [ + { + name : 'indexer', + label : '', + cell : Backgrid.TemplateBackedCell.extend({ template: 'History/IndexerTemplate' }) + }, + { + name : 'Series.Title', + label : 'Series Title', + cell : Backgrid.TemplateBackedCell.extend({ template: 'Missing/SeriesTitleTemplate' }) + }, + { + name : 'episode', + label : 'Episode', + sortable : false, + cell : Backgrid.TemplateBackedCell.extend({ template: 'Missing/EpisodeColumnTemplate' }) + }, + { + name : 'Episode.Title', + label : 'Episode Title', + sortable : false, + cell : Backgrid.TemplateBackedCell.extend({ template: 'History/EpisodeTitleTemplate' }) + }, + { + name : 'quality', + label : 'Quality', + cell : Backgrid.TemplateBackedCell.extend({ template: 'History/QualityTemplate' }) + }, + { + name : 'date', + label : 'Grabbed', + cell : 'airDate' + }, + { + name : 'edit', + label : '', + sortable : false, + cell : Backgrid.TemplateBackedCell.extend({ template: 'History/ControlsColumnTemplate' }) + } + ], - var columns = [ - { - name : 'indexer', - label : '', - editable : false, - cell : Backgrid.TemplateBackedCell.extend({ template: 'History/IndexerTemplate' }), - headerCell: 'nzbDrone' - }, - { - name : 'Series.Title', - label : 'Series Title', - editable : false, - cell : Backgrid.TemplateBackedCell.extend({ template: 'Missing/SeriesTitleTemplate' }), - headerCell: 'nzbDrone' - }, - { - name : 'episode', - label : 'Episode', - editable : false, - sortable : false, - cell : Backgrid.TemplateBackedCell.extend({ template: 'Missing/EpisodeColumnTemplate' }), - headerCell: 'nzbDrone' - }, - { - name : 'Episode.Title', - label : 'Episode Title', - editable : false, - sortable : false, - cell : Backgrid.TemplateBackedCell.extend({ template: 'History/EpisodeTitleTemplate' }), - headerCell: 'nzbDrone' - }, - { - name : 'quality', - label : 'Quality', - editable : false, - cell : Backgrid.TemplateBackedCell.extend({ template: 'History/QualityTemplate' }), - headerCell: 'nzbDrone' - }, - { - name : 'date', - label : 'Grabbed', - editable : false, - cell : 'airDate', - headerCell: 'nzbDrone' - }, - { - name : 'edit', - label : '', - editable : false, - sortable : false, - cell : Backgrid.TemplateBackedCell.extend({ template: 'History/ControlsColumnTemplate' }), - headerCell: 'nzbDrone' - } - ]; + showTable: function () { this.history.show(new Backgrid.Grid( { row : NzbDrone.History.Row, - columns : columns, + columns : this.columns, collection: this.historyCollection, className : 'table table-hover' })); this.pager.show(new Backgrid.NzbDronePaginator({ - columns: columns, + columns: this.columns, collection: this.historyCollection })); }, diff --git a/UI/Missing/MissingLayout.js b/UI/Missing/MissingLayout.js index 6f5e3c88e..1f58b22f4 100644 --- a/UI/Missing/MissingLayout.js +++ b/UI/Missing/MissingLayout.js @@ -16,59 +16,48 @@ define([ pager : '#x-pager' }, - showTable: function () { - - var columns = [ - { - name : 'series.Title', - label : 'Series Title', - editable : false, - cell : Backgrid.TemplateBackedCell.extend({ template: 'Missing/SeriesTitleTemplate' }), - headerCell: 'nzbDrone' - }, - { - name : 'episode', - label : 'Episode', - editable : false, - sortable : false, - cell : Backgrid.TemplateBackedCell.extend({ template: 'Missing/EpisodeColumnTemplate' }), - headerCell: 'nzbDrone' - }, - { - name : 'title', - label : 'Episode Title', - editable : false, - sortable : false, - cell : 'string', - headerCell: 'nzbDrone' - }, - { - name : 'airDate', - label : 'Air Date', - editable : false, - cell : 'airDate', - headerCell: 'nzbDrone' - }, - { - name : 'edit', - label : '', - editable : false, - sortable : false, - cell : Backgrid.TemplateBackedCell.extend({ template: 'Missing/ControlsColumnTemplate' }), - headerCell: 'nzbDrone' - } - ]; + columns: [ + { + name : 'series.Title', + label : 'Series Title', + cell : Backgrid.TemplateBackedCell.extend({ template: 'Missing/SeriesTitleTemplate' }) + }, + { + name : 'episode', + label : 'Episode', + sortable : false, + cell : Backgrid.TemplateBackedCell.extend({ template: 'Missing/EpisodeColumnTemplate' }) + }, + { + name : 'title', + label : 'Episode Title', + sortable : false, + cell : 'string' + }, + { + name : 'airDate', + label : 'Air Date', + cell : 'airDate' + }, + { + name : 'edit', + label : '', + sortable : false, + cell : Backgrid.TemplateBackedCell.extend({ template: 'Missing/ControlsColumnTemplate' }) + } + ], + showTable: function () { this.missing.show(new Backgrid.Grid( { row : NzbDrone.Missing.Row, - columns : columns, + columns : this.columns, collection: this.missingCollection, className : 'table table-hover' })); this.pager.show(new Backgrid.NzbDronePaginator({ - columns: columns, + columns: this.columns, collection: this.missingCollection })); }, diff --git a/UI/Mixins/backbone.Backgrid.mixin.js b/UI/Mixins/backbone.Backgrid.mixin.js index 85eb1460e..57b57a6d4 100644 --- a/UI/Mixins/backbone.Backgrid.mixin.js +++ b/UI/Mixins/backbone.Backgrid.mixin.js @@ -1,5 +1,16 @@ "use strict"; +Backgrid.Column.prototype.defaults = { + name: undefined, + label: undefined, + sortable: true, + editable: false, + renderable: true, + formatter: undefined, + cell: undefined, + headerCell: 'nzbDrone' +}; + Backgrid.TemplateBackedCell = Backgrid.Cell.extend({ className: '', template: 'Series/Index/Table/ControlsColumnTemplate', diff --git a/UI/Series/Details/SeasonLayout.js b/UI/Series/Details/SeasonLayout.js index 9b57c0212..28a749c23 100644 --- a/UI/Series/Details/SeasonLayout.js +++ b/UI/Series/Details/SeasonLayout.js @@ -10,26 +10,23 @@ define(['app', 'Series/Details/EpisodeDetailCell'], function () { columns: [ { name : 'details', - editable: false, + label : 'Details', cell : NzbDrone.Series.Details.EpisodeDetailCell }, { name : 'episodeNumber', label : '#', - editable: false, cell : 'integer' }, { name : 'title', label : 'Title', - editable: false, cell : 'string' }, { name : 'airDate', label : 'Air Date', - editable: false, cell : 'date' //formatter: new Backgrid.AirDateFormatter() } diff --git a/UI/Series/Index/SeriesIndexLayout.js b/UI/Series/Index/SeriesIndexLayout.js index 018aadabc..296d113b8 100644 --- a/UI/Series/Index/SeriesIndexLayout.js +++ b/UI/Series/Index/SeriesIndexLayout.js @@ -18,73 +18,57 @@ define([ toolbar: '#x-toolbar' }, - showTable: function () { + columns: [ + { + name : 'status', + label : '', + cell : 'seriesStatus' + }, + { + name : 'title', + label : 'Title', + cell : Backgrid.TemplateBackedCell.extend({ template: 'Series/Index/Table/SeriesTitleTemplate' }) + }, + { + name : 'seasonCount', + label : 'Seasons', + cell : 'integer' + }, + { + name : 'quality', + label : 'Quality', + cell : 'integer' + }, + { + name : 'network', + label : 'Network', + cell : 'string' + }, + { + name : 'nextAiring', + label : 'Next Airing', + cell : 'airDate' + }, + { + name : 'episodes', + label : 'Episodes', + sortable : false, + cell : Backgrid.TemplateBackedCell.extend({ template: 'Series/EpisodeProgressTemplate' }) + }, + { + name : 'edit', + label : '', + sortable : false, + cell : Backgrid.TemplateBackedCell.extend({ template: 'Series/Index/Table/ControlsColumnTemplate' }) + } + ], - var columns = [ - { - name : 'status', - label : '', - editable : false, - cell : 'seriesStatus', - headerCell: 'nzbDrone' - }, - { - name : 'title', - label : 'Title', - editable : false, - cell : Backgrid.TemplateBackedCell.extend({ template: 'Series/Index/Table/SeriesTitleTemplate' }), - headerCell: 'nzbDrone' - }, - { - name : 'seasonCount', - label : 'Seasons', - editable : false, - cell : 'integer', - headerCell: 'nzbDrone' - }, - { - name : 'quality', - label : 'Quality', - editable : false, - cell : 'integer', - headerCell: 'nzbDrone' - }, - { - name : 'network', - label : 'Network', - editable : false, - cell : 'string', - headerCell: 'nzbDrone' - }, - { - name : 'nextAiring', - label : 'Next Airing', - editable : false, - cell : 'airDate', - headerCell: 'nzbDrone' - }, - { - name : 'episodes', - label : 'Episodes', - editable : false, - sortable : false, - cell : Backgrid.TemplateBackedCell.extend({ template: 'Series/EpisodeProgressTemplate' }), - headerCell: 'nzbDrone' - }, - { - name : 'edit', - label : '', - editable : false, - sortable : false, - cell : Backgrid.TemplateBackedCell.extend({ template: 'Series/Index/Table/ControlsColumnTemplate' }), - headerCell: 'nzbDrone' - } - ]; + showTable: function () { this.series.show(new Backgrid.Grid( { row : NzbDrone.Series.Index.Table.Row, - columns : columns, + columns : this.columns, collection: this.seriesCollection, className : 'table table-hover' }));