rjs -> webpack

pull/6/head
Keivan Beigi 10 years ago
parent 344f3d66ef
commit 428a1439e5

1
.gitignore vendored

@ -122,3 +122,4 @@ setup/Output/
#VS outout folders #VS outout folders
bin bin
obj obj
output/*

@ -221,15 +221,12 @@ Function PackageTests()
Function RunGulp() Function RunGulp()
{ {
Write-Host "##teamcity[progressStart 'Running Gulp']" Write-Host "##teamcity[progressStart 'Running Gulp']"
$gulpPath = '.\node_modules\gulp\bin\gulp'
Invoke-Expression 'npm install' Invoke-Expression 'npm install'
CheckExitCode CheckExitCode
Invoke-Expression ('node ' + $gulpPath + ' build') -ErrorAction Continue -Verbose Invoke-Expression 'gulp build' -ErrorAction Continue -Verbose
CheckExitCode CheckExitCode
Remove-Item $outputFolder\UI\build.txt -ErrorAction Continue
Write-Host "##teamcity[progressFinish 'Running Gulp']" Write-Host "##teamcity[progressFinish 'Running Gulp']"
} }

@ -0,0 +1,50 @@
<Query Kind="Program" />
void Main()
{
var files = Directory.GetFiles("c:\\git\\sonarr\\src\\UI","*.js", SearchOption.AllDirectories);
var moduleRegex = new Regex(@"module.exports\s*=\s*\(function\s*\(\)\s*{\n\s*return\s*(\w|\W)*\)\.call\(this\);$");
var functionHead = new Regex(@"\s*\(function\s*\(\)\s*{\n\s*return\s*");
var functionTail = new Regex(@"\}\).call\(this\);$");
var multiVar = new Regex(@"^(?<d>var\s*\w*\s*=\s*require\(.*\)),");
var seperateDeclearatuin = new Regex(@"^((\w|\$|_)*\s=\srequire\(.*\))(,|;)", RegexOptions.Multiline);
foreach (var filePath in files)
{
var text = File.ReadAllText(filePath);
var newContent = text.Replace("// Generated by uRequire v0.7.0-beta.14 template: 'nodejs'","");
newContent = newContent.Replace("var __isAMD = !!(typeof define === 'function' && define.amd),","");
newContent = newContent.Replace("__isNode = (typeof exports === 'object'),","");
newContent = newContent.Replace("__isWeb = !__isNode;","");
newContent = newContent.Replace("\"use strict\";","'use strict';");
newContent = newContent.Trim();
if(moduleRegex.IsMatch(newContent))
{
filePath.Dump();
newContent = functionHead.Replace(newContent," ");
newContent = functionTail.Replace(newContent,"");
}
if(multiVar.IsMatch(newContent))
{
newContent = multiVar.Replace(newContent,"$1;"); //first one
}
newContent = seperateDeclearatuin.Replace(newContent,"var $1;"); //ones after
newContent.Replace("var $ = require('jquery'), var","var $ = require('jquery');");
File.WriteAllText(filePath,newContent.Trim());
}
}
// Define other methods and classes here

@ -2,12 +2,11 @@ var gulp = require('gulp');
var runSequence = require('run-sequence'); var runSequence = require('run-sequence');
require('./clean'); require('./clean');
require('./requirejs');
require('./less'); require('./less');
require('./handlebars'); require('./handlebars');
require('./copy'); require('./copy');
gulp.task('build', function () { gulp.task('build', function () {
return runSequence('clean', return runSequence('clean',
['requireJs', 'less', 'handlebars', 'copyHtml', 'copyContent']); ['webpack', 'less', 'handlebars', 'copyHtml', 'copyContent', 'copyJs']);
}); });

@ -5,7 +5,12 @@ var cache = require('gulp-cached');
var paths = require('./paths.js'); var paths = require('./paths.js');
gulp.task('copyJs', function () { gulp.task('copyJs', function () {
return gulp.src(paths.src.scripts) return gulp.src(
[
paths.src.root + "piwikCheck.js",
paths.src.root + "polyfills.js",
paths.src.root + "JsLibraries\\handlebars.runtime.js",
])
.pipe(cache('copyJs')) .pipe(cache('copyJs'))
.pipe(print()) .pipe(print())
.pipe(gulp.dest(paths.dest.root)); .pipe(gulp.dest(paths.dest.root));

@ -1,12 +1,12 @@
require('./watch.js'); require('./watch.js');
require('./build.js'); require('./build.js');
require('./clean.js'); require('./clean.js');
require('./requirejs.js');
require('./jshint.js'); require('./jshint.js');
require('./handlebars.js'); require('./handlebars.js');
require('./copy.js'); require('./copy.js');
require('./less.js'); require('./less.js');
require('./stripBom.js'); require('./stripBom.js');
require('./imageMin.js'); require('./imageMin.js');
require('./webpack.js');

@ -2,7 +2,6 @@ var gulp = require('gulp');
var handlebars = require('gulp-handlebars'); var handlebars = require('gulp-handlebars');
var declare = require('gulp-declare'); var declare = require('gulp-declare');
var concat = require('gulp-concat'); var concat = require('gulp-concat');
var wrapAmd = require('gulp-wrap-amd');
var wrap = require("gulp-wrap"); var wrap = require("gulp-wrap");
var path = require('path'); var path = require('path');
var streamqueue = require('streamqueue'); var streamqueue = require('streamqueue');
@ -48,10 +47,6 @@ gulp.task('handlebars', function () {
partialStream, partialStream,
coreStream coreStream
).pipe(concat('templates.js')) ).pipe(concat('templates.js'))
.pipe(wrapAmd({
deps: ['handlebars'],
params: ['Handlebars'],
exports: 'this["T"]'
}))
.pipe(gulp.dest(paths.dest.root)); .pipe(gulp.dest(paths.dest.root));
}); });

@ -15,6 +15,7 @@ gulp.task('jshint', function () {
'-W100': false, //Silently deleted characters (in locales) '-W100': false, //Silently deleted characters (in locales)
'undef': true, 'undef': true,
'globals': { 'globals': {
'module': true,
'require': true, 'require': true,
'define': true, 'define': true,
'window': true, 'window': true,

@ -1,32 +0,0 @@
var gulp = require('gulp');
var requirejs = require('requirejs');
var paths = require('./paths');
require('./handlebars.js');
require('./jshint.js');
gulp.task('requireJs', ['jshint'], function (cb) {
var config = {
mainConfigFile: 'src/UI/app.js',
fileExclusionRegExp: /^.*\.(?!js$)[^.]+$/,
preserveLicenseComments: false,
dir: paths.dest.root,
optimize: 'none',
removeCombined: true,
inlineText: false,
keepBuildDir: true,
modules: [
{
name: 'app',
exclude: ['templates.js']
}
]};
requirejs.optimize(config, function (buildResponse) {
console.log(buildResponse);
cb();
});
});

@ -8,9 +8,11 @@ require('./jshint.js');
require('./handlebars.js'); require('./handlebars.js');
require('./less.js'); require('./less.js');
require('./copy.js'); require('./copy.js');
require('./webpack.js');
gulp.task('watch', ['jshint', 'handlebars', 'less', 'copyJs', 'copyHtml', 'copyContent'], function () { gulp.task('watch', ['jshint', 'handlebars', 'less','copyHtml', 'copyContent','copyJs'], function () {
gulp.start('webpackWatch');
gulp.watch([paths.src.scripts, paths.src.exclude.libs], ['jshint','copyJs']); gulp.watch([paths.src.scripts, paths.src.exclude.libs], ['jshint','copyJs']);
gulp.watch(paths.src.templates, ['handlebars']); gulp.watch(paths.src.templates, ['handlebars']);
gulp.watch([paths.src.less, paths.src.exclude.libs], ['less']); gulp.watch([paths.src.less, paths.src.exclude.libs], ['less']);
@ -18,7 +20,7 @@ gulp.task('watch', ['jshint', 'handlebars', 'less', 'copyJs', 'copyHtml', 'copyC
gulp.watch([paths.src.content + '**/*.*', '!**/*.less'], ['copyContent']); gulp.watch([paths.src.content + '**/*.*', '!**/*.less'], ['copyContent']);
}); });
gulp.task('liveReload', ['jshint', 'handlebars', 'less', 'copyJs'], function () { gulp.task('liveReload', ['jshint', 'handlebars', 'less', 'webPack'], function () {
var server = livereload(); var server = livereload();
gulp.watch([ gulp.watch([
'app/**/*.js', 'app/**/*.js',

@ -0,0 +1,20 @@
var gulp = require('gulp');
var gulpWebpack = require('gulp-webpack');
var webpack = require('webpack');
var webpackConfig = require('../webpack.config');
webpackConfig.devtool = "#source-map";
gulp.task('webpack', function() {
return gulp.src('main.js')
.pipe(gulpWebpack(webpackConfig, webpack))
.pipe(gulp.dest(''));
});
gulp.task('webpackWatch', function() {
webpackConfig.watch = true;
return gulp.src('main.js')
.pipe(gulpWebpack(webpackConfig, webpack))
.pipe(gulp.dest(''));
});

@ -1,8 +1,8 @@
{ {
"name": "Sonarr", "name": "Sonarr",
"version": "0.0.0", "version": "2.0.0",
"description": "Sonarr", "description": "Sonarr",
"main": "index.js", "main": "main.js",
"scripts": { "scripts": {
"preinstall": "" "preinstall": ""
}, },
@ -15,10 +15,10 @@
"gitHead": "9ff7aa1bf7fe38c4c5bdb92f56c8ad556916ed67", "gitHead": "9ff7aa1bf7fe38c4c5bdb92f56c8ad556916ed67",
"readmeFilename": "readme.md", "readmeFilename": "readme.md",
"dependencies": { "dependencies": {
"del": "0.1.3",
"fs-extra": "0.12.0", "fs-extra": "0.12.0",
"gulp": "3.8.10", "gulp": "3.8.10",
"gulp-cached": "1.0.1", "gulp-cached": "1.0.1",
"del": "0.1.3",
"gulp-concat": "2.4.2", "gulp-concat": "2.4.2",
"gulp-declare": "0.3.0", "gulp-declare": "0.3.0",
"gulp-handlebars": "2.2.0", "gulp-handlebars": "2.2.0",
@ -26,10 +26,11 @@
"gulp-less": "1.3.6", "gulp-less": "1.3.6",
"gulp-print": "1.1.0", "gulp-print": "1.1.0",
"gulp-replace": "0.5.0", "gulp-replace": "0.5.0",
"gulp-run": "1.6.6",
"webpack": "1.4.15",
"gulp-webpack": "1.2.0",
"gulp-wrap": "0.5.0", "gulp-wrap": "0.5.0",
"gulp-wrap-amd": "0.3.1",
"jshint-stylish": "1.0.0", "jshint-stylish": "1.0.0",
"requirejs": "2.1.15",
"run-sequence": "1.0.2", "run-sequence": "1.0.2",
"streamqueue": "0.1.1" "streamqueue": "0.1.1"
} }

@ -27,6 +27,7 @@ namespace NzbDrone.Api.Frontend.Mappers
{ {
return resourceUrl.StartsWith("/Content") || return resourceUrl.StartsWith("/Content") ||
resourceUrl.EndsWith(".js") || resourceUrl.EndsWith(".js") ||
resourceUrl.EndsWith(".map") ||
resourceUrl.EndsWith(".css") || resourceUrl.EndsWith(".css") ||
(resourceUrl.EndsWith(".ico") && !resourceUrl.Equals("/favicon.ico")) || (resourceUrl.EndsWith(".ico") && !resourceUrl.Equals("/favicon.ico")) ||
resourceUrl.EndsWith(".swf"); resourceUrl.EndsWith(".swf");

@ -19,6 +19,8 @@
<JSCodeStyleSettings> <JSCodeStyleSettings>
<option name="SPACE_BEFORE_PROPERTY_COLON" value="true" /> <option name="SPACE_BEFORE_PROPERTY_COLON" value="true" />
<option name="ALIGN_OBJECT_PROPERTIES" value="2" /> <option name="ALIGN_OBJECT_PROPERTIES" value="2" />
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
<option name="OBJECT_LITERAL_WRAP" value="2" />
</JSCodeStyleSettings> </JSCodeStyleSettings>
<XML> <XML>
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" /> <option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
@ -29,14 +31,18 @@
</indentOptions> </indentOptions>
</codeStyleSettings> </codeStyleSettings>
<codeStyleSettings language="JavaScript"> <codeStyleSettings language="JavaScript">
<option name="LINE_COMMENT_AT_FIRST_COLUMN" value="true" />
<option name="KEEP_LINE_BREAKS" value="false" /> <option name="KEEP_LINE_BREAKS" value="false" />
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" /> <option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
<option name="ELSE_ON_NEW_LINE" value="true" /> <option name="ELSE_ON_NEW_LINE" value="true" />
<option name="CATCH_ON_NEW_LINE" value="true" /> <option name="CATCH_ON_NEW_LINE" value="true" />
<option name="FINALLY_ON_NEW_LINE" value="true" /> <option name="FINALLY_ON_NEW_LINE" value="true" />
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
<option name="SPACE_BEFORE_METHOD_PARENTHESES" value="true" /> <option name="SPACE_BEFORE_METHOD_PARENTHESES" value="true" />
<option name="METHOD_PARAMETERS_WRAP" value="5" /> <option name="SPACE_BEFORE_IF_PARENTHESES" value="false" />
<option name="ARRAY_INITIALIZER_WRAP" value="2" /> <option name="SPACE_BEFORE_METHOD_LBRACE" value="false" />
<option name="TERNARY_OPERATION_SIGNS_ON_NEXT_LINE" value="true" />
<option name="ARRAY_INITIALIZER_WRAP" value="1" />
<option name="IF_BRACE_FORCE" value="3" /> <option name="IF_BRACE_FORCE" value="3" />
<option name="DOWHILE_BRACE_FORCE" value="3" /> <option name="DOWHILE_BRACE_FORCE" value="3" />
<option name="WHILE_BRACE_FORCE" value="3" /> <option name="WHILE_BRACE_FORCE" value="3" />
@ -47,4 +53,3 @@
<option name="USE_PER_PROJECT_SETTINGS" value="true" /> <option name="USE_PER_PROJECT_SETTINGS" value="true" />
</component> </component>
</project> </project>

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" /> <component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false">
<file url="file://$PROJECT_DIR$/System/Logs/Files/LogFileModel.js" charset="UTF-8" />
</component>
</project> </project>

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="JSHintConfiguration" version="2.1.10" use-config-file="false"> <component name="JSHintConfiguration" version="2.6.0" use-config-file="false">
<option bitwise="true" /> <option bitwise="true" />
<option camelcase="true" /> <option camelcase="true" />
<option curly="true" /> <option curly="true" />
@ -14,7 +14,7 @@
<option nonew="true" /> <option nonew="true" />
<option plusplus="false" /> <option plusplus="false" />
<option undef="true" /> <option undef="true" />
<option strict="true" /> <option strict="false" />
<option trailing="false" /> <option trailing="false" />
<option latedef="true" /> <option latedef="true" />
<option unused="true" /> <option unused="true" />
@ -27,40 +27,46 @@
<option esnext="false" /> <option esnext="false" />
<option evil="false" /> <option evil="false" />
<option expr="false" /> <option expr="false" />
<option funcscope="false" />
<option globalstrict="true" /> <option globalstrict="true" />
<option iterator="false" />
<option lastsemic="false" /> <option lastsemic="false" />
<option laxbreak="false" /> <option laxbreak="false" />
<option laxcomma="false" /> <option laxcomma="false" />
<option loopfunc="false" />
<option multistr="false" /> <option multistr="false" />
<option notypeof="false" />
<option proto="false" /> <option proto="false" />
<option scripturl="false" /> <option scripturl="false" />
<option smarttabs="false" />
<option shadow="false" />
<option sub="false" /> <option sub="false" />
<option supernew="false" />
<option validthis="false" />
<option browser="true" /> <option browser="true" />
<option couch="false" /> <option couch="false" />
<option devel="true" /> <option devel="true" />
<option dojo="false" /> <option dojo="false" />
<option freeze="false" />
<option funcscope="false" />
<option gcl="false" />
<option iterator="false" />
<option loopfunc="false" />
<option shadow="false" />
<option jquery="false" /> <option jquery="false" />
<option mootools="false" />
<option node="false" />
<option nonstandard="false" /> <option nonstandard="false" />
<option nomen="false" />
<option maxerr="50" />
<option moz="false" />
<option noyield="false" />
<option phantom="false" />
<option smarttabs="false" />
<option supernew="false" />
<option validthis="false" />
<option mootools="false" />
<option node="true" />
<option nonbsp="false" />
<option prototypejs="false" /> <option prototypejs="false" />
<option rhino="false" /> <option rhino="false" />
<option worker="false" /> <option worker="false" />
<option wsh="false" /> <option wsh="false" />
<option yui="false" /> <option yui="false" />
<option nomen="false" />
<option onevar="false" /> <option onevar="false" />
<option passfail="false" /> <option passfail="false" />
<option white="false" /> <option white="false" />
<option maxerr="50" /> <option predef="window, define, require, module" />
<option predef="window, define, require" />
</component> </component>
</project> </project>

@ -1,40 +1,32 @@
'use strict'; var Marionette = require('marionette');
define( var Backbone = require('backbone');
[ var Backgrid = require('backgrid');
'marionette', var HistoryLayout = require('./History/HistoryLayout');
'backbone', var BlacklistLayout = require('./Blacklist/BlacklistLayout');
'backgrid', var QueueLayout = require('./Queue/QueueLayout');
'Activity/History/HistoryLayout',
'Activity/Blacklist/BlacklistLayout',
'Activity/Queue/QueueLayout'
], function (Marionette, Backbone, Backgrid, HistoryLayout, BlacklistLayout, QueueLayout) {
return Marionette.Layout.extend({
template: 'Activity/ActivityLayoutTemplate',
module.exports = Marionette.Layout.extend({
template : 'Activity/ActivityLayoutTemplate',
regions : { regions : {
queueRegion : '#queue', queueRegion : '#queue',
history : '#history', history : '#history',
blacklist : '#blacklist' blacklist : '#blacklist'
}, },
ui : { ui : {
queueTab : '.x-queue-tab', queueTab : '.x-queue-tab',
historyTab : '.x-history-tab', historyTab : '.x-history-tab',
blacklistTab : '.x-blacklist-tab' blacklistTab : '.x-blacklist-tab'
}, },
events : { events : {
'click .x-queue-tab' : '_showQueue', "click .x-queue-tab" : '_showQueue',
'click .x-history-tab' : '_showHistory', "click .x-history-tab" : '_showHistory',
'click .x-blacklist-tab' : '_showBlacklist' "click .x-blacklist-tab" : '_showBlacklist'
}, },
initialize : function(options){ initialize : function(options){
if(options.action) { if(options.action) {
this.action = options.action.toLowerCase(); this.action = options.action.toLowerCase();
} }
}, },
onShow : function(){ onShow : function(){
switch (this.action) { switch (this.action) {
case 'history': case 'history':
@ -47,39 +39,34 @@ define(
this._showQueue(); this._showQueue();
} }
}, },
_navigate : function(route){ _navigate : function(route){
Backbone.history.navigate(route, { trigger: false, replace: true }); Backbone.history.navigate(route, {
trigger : false,
replace : true
});
}, },
_showHistory : function(e){ _showHistory : function(e){
if(e) { if(e) {
e.preventDefault(); e.preventDefault();
} }
this.history.show(new HistoryLayout()); this.history.show(new HistoryLayout());
this.ui.historyTab.tab('show'); this.ui.historyTab.tab('show');
this._navigate('/activity/history'); this._navigate('/activity/history');
}, },
_showBlacklist : function(e){ _showBlacklist : function(e){
if(e) { if(e) {
e.preventDefault(); e.preventDefault();
} }
this.blacklist.show(new BlacklistLayout()); this.blacklist.show(new BlacklistLayout());
this.ui.blacklistTab.tab('show'); this.ui.blacklistTab.tab('show');
this._navigate('/activity/blacklist'); this._navigate('/activity/blacklist');
}, },
_showQueue : function(e){ _showQueue : function(e){
if(e) { if(e) {
e.preventDefault(); e.preventDefault();
} }
this.queueRegion.show(new QueueLayout()); this.queueRegion.show(new QueueLayout());
this.ui.queueTab.tab('show'); this.ui.queueTab.tab('show');
this._navigate('/activity/queue'); this._navigate('/activity/queue');
} }
}); });
});

@ -1,26 +1,16 @@
'use strict'; var NzbDroneCell = require('../../Cells/NzbDroneCell');
define(
[
'Cells/NzbDroneCell'
], function (NzbDroneCell) {
return NzbDroneCell.extend({
module.exports = NzbDroneCell.extend({
className : 'blacklist-controls-cell', className : 'blacklist-controls-cell',
events : { events : {
'click' : '_delete' 'click' : '_delete'
}, },
render : function(){ render : function(){
this.$el.empty(); this.$el.empty();
this.$el.html('<i class="icon-nd-delete"></i>'); this.$el.html('<i class="icon-nd-delete"></i>');
return this; return this;
}, },
_delete : function(){ _delete : function(){
this.model.destroy(); this.model.destroy();
} }
}); });
});

@ -1,21 +1,17 @@
'use strict'; var BlacklistModel = require('./BlacklistModel');
define( var PageableCollection = require('backbone.pageable');
[ var AsSortedCollection = require('../../Mixins/AsSortedCollection');
'Activity/Blacklist/BlacklistModel', var AsPersistedStateCollection = require('../../Mixins/AsPersistedStateCollection');
'backbone.pageable',
'Mixins/AsSortedCollection', module.exports = (function(){
'Mixins/AsPersistedStateCollection'
], function (BlacklistModel, PageableCollection, AsSortedCollection, AsPersistedStateCollection) {
var Collection = PageableCollection.extend({ var Collection = PageableCollection.extend({
url : window.NzbDrone.ApiRoot + '/blacklist', url : window.NzbDrone.ApiRoot + '/blacklist',
model : BlacklistModel, model : BlacklistModel,
state : { state : {
pageSize : 15, pageSize : 15,
sortKey : 'date', sortKey : 'date',
order : 1 order : 1
}, },
queryParams : { queryParams : {
totalPages : null, totalPages : null,
totalRecords : null, totalRecords : null,
@ -27,24 +23,17 @@ define(
'1' : 'desc' '1' : 'desc'
} }
}, },
sortMappings : {'series' : {sortKey : 'series.sortTitle'}},
sortMappings: {
'series' : { sortKey: 'series.sortTitle' }
},
parseState : function(resp){ parseState : function(resp){
return {totalRecords : resp.totalRecords}; return {totalRecords : resp.totalRecords};
}, },
parseRecords : function(resp){ parseRecords : function(resp){
if(resp) { if(resp) {
return resp.records; return resp.records;
} }
return resp; return resp;
} }
}); });
Collection = AsSortedCollection.call(Collection); Collection = AsSortedCollection.call(Collection);
return AsPersistedStateCollection.call(Collection); return AsPersistedStateCollection.call(Collection);
}); }).call(this);

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

@ -1,21 +1,14 @@
'use strict'; var Backbone = require('backbone');
define( var SeriesCollection = require('../../Series/SeriesCollection');
[
'backbone',
'Series/SeriesCollection'
], function (Backbone, SeriesCollection) {
return Backbone.Model.extend({
//Hack to deal with Backbone 1.0's bug module.exports = Backbone.Model.extend({
initialize : function(){ initialize : function(){
this.url = function(){ this.url = function(){
return this.collection.url + '/' + this.get('id'); return this.collection.url + '/' + this.get('id');
}; };
}, },
parse : function(model){ parse : function(model){
model.series = SeriesCollection.get(model.seriesId); model.series = SeriesCollection.get(model.seriesId);
return model; return model;
} }
}); });
});

@ -1,19 +1,13 @@
'use strict'; var Handlebars = require('handlebars');
define(
[
'handlebars'
], function (Handlebars) {
module.exports = (function(){
Handlebars.registerHelper('historyAge', function(){ Handlebars.registerHelper('historyAge', function(){
var unit = 'days'; var unit = 'days';
var age = this.age; var age = this.age;
if(age < 2) { if(age < 2) {
unit = 'hours'; unit = 'hours';
age = parseFloat(this.ageHours).toFixed(1); age = parseFloat(this.ageHours).toFixed(1);
} }
return new Handlebars.SafeString('<dt>Age (when grabbed):</dt><dd>{0} {1}</dd>'.format(age, unit)); return new Handlebars.SafeString('<dt>Age (when grabbed):</dt><dd>{0} {1}</dd>'.format(age, unit));
}); });
}); }).call(this);

@ -1,40 +1,23 @@
'use strict'; var $ = require('jquery');
define( var vent = require('../../../vent');
[ var Marionette = require('marionette');
'jquery', var HistoryDetailsView = require('./HistoryDetailsView');
'vent',
'marionette',
'Activity/History/Details/HistoryDetailsView'
], function ($, vent, Marionette, HistoryDetailsView) {
return Marionette.Layout.extend({ module.exports = Marionette.Layout.extend({
template : 'Activity/History/Details/HistoryDetailsLayoutTemplate', template : 'Activity/History/Details/HistoryDetailsLayoutTemplate',
regions : {bodyRegion : '.modal-body'},
regions: { events : {"click .x-mark-as-failed" : '_markAsFailed'},
bodyRegion: '.modal-body'
},
events: {
'click .x-mark-as-failed': '_markAsFailed'
},
onShow : function(){ onShow : function(){
this.bodyRegion.show(new HistoryDetailsView({model : this.model})); this.bodyRegion.show(new HistoryDetailsView({model : this.model}));
}, },
_markAsFailed : function(){ _markAsFailed : function(){
var url = window.NzbDrone.ApiRoot + '/history/failed'; var url = window.NzbDrone.ApiRoot + '/history/failed';
var data = { var data = {id : this.model.get('id')};
id: this.model.get('id')
};
$.ajax({ $.ajax({
url : url, url : url,
type : 'POST', type : 'POST',
data : data data : data
}); });
vent.trigger(vent.Commands.CloseModalCommand); vent.trigger(vent.Commands.CloseModalCommand);
} }
}); });
});

@ -1,11 +1,4 @@
'use strict'; var Marionette = require('marionette');
define( require('./HistoryDetailsAge');
[
'marionette',
'Activity/History/Details/HistoryDetailsAge'
], function (Marionette) {
return Marionette.ItemView.extend({ module.exports = Marionette.ItemView.extend({template : 'Activity/History/Details/HistoryDetailsViewTemplate'});
template: 'Activity/History/Details/HistoryDetailsViewTemplate'
});
});

@ -1,22 +1,18 @@
'use strict'; var HistoryModel = require('./HistoryModel');
define( var PageableCollection = require('backbone.pageable');
[ var AsFilteredCollection = require('../../Mixins/AsFilteredCollection');
'Activity/History/HistoryModel', var AsSortedCollection = require('../../Mixins/AsSortedCollection');
'backbone.pageable', var AsPersistedStateCollection = require('../../Mixins/AsPersistedStateCollection');
'Mixins/AsFilteredCollection',
'Mixins/AsSortedCollection', module.exports = (function(){
'Mixins/AsPersistedStateCollection'
], function (HistoryModel, PageableCollection, AsFilteredCollection, AsSortedCollection, AsPersistedStateCollection) {
var Collection = PageableCollection.extend({ var Collection = PageableCollection.extend({
url : window.NzbDrone.ApiRoot + '/history', url : window.NzbDrone.ApiRoot + '/history',
model : HistoryModel, model : HistoryModel,
state : { state : {
pageSize : 15, pageSize : 15,
sortKey : 'date', sortKey : 'date',
order : 1 order : 1
}, },
queryParams : { queryParams : {
totalPages : null, totalPages : null,
totalRecords : null, totalRecords : null,
@ -24,47 +20,37 @@ define(
sortKey : 'sortKey', sortKey : 'sortKey',
order : 'sortDir', order : 'sortDir',
directions : { directions : {
'-1': 'asc', "-1" : 'asc',
'1' : 'desc' "1" : 'desc'
} }
}, },
filterModes : { filterModes : {
'all' : [null, null], "all" : [null, null],
'grabbed' : ['eventType', '1'], "grabbed" : ['eventType', '1'],
'imported' : ['eventType', '3'], "imported" : ['eventType', '3'],
'failed' : ['eventType', '4'], "failed" : ['eventType', '4'],
'deleted' : ['eventType', '5'] "deleted" : ['eventType', '5']
}, },
sortMappings : {"series" : {sortKey : 'series.sortTitle'}},
sortMappings: {
'series' : { sortKey: 'series.sortTitle' }
},
initialize : function(options){ initialize : function(options){
delete this.queryParams.episodeId; delete this.queryParams.episodeId;
if(options) { if(options) {
if(options.episodeId) { if(options.episodeId) {
this.queryParams.episodeId = options.episodeId; this.queryParams.episodeId = options.episodeId;
} }
} }
}, },
parseState : function(resp){ parseState : function(resp){
return {totalRecords : resp.totalRecords}; return {totalRecords : resp.totalRecords};
}, },
parseRecords : function(resp){ parseRecords : function(resp){
if(resp) { if(resp) {
return resp.records; return resp.records;
} }
return resp; return resp;
} }
}); });
Collection = AsFilteredCollection.call(Collection); Collection = AsFilteredCollection.call(Collection);
Collection = AsSortedCollection.call(Collection); Collection = AsSortedCollection.call(Collection);
return AsPersistedStateCollection.call(Collection); return AsPersistedStateCollection.call(Collection);
}); }).call(this);

@ -1,27 +1,15 @@
'use strict'; var vent = require('../../vent');
var NzbDroneCell = require('../../Cells/NzbDroneCell');
define(
[
'vent',
'Cells/NzbDroneCell'
], function (vent, NzbDroneCell) {
return NzbDroneCell.extend({
module.exports = NzbDroneCell.extend({
className : 'history-details-cell', className : 'history-details-cell',
events : {"click" : '_showDetails'},
events: {
'click': '_showDetails'
},
render : function(){ render : function(){
this.$el.empty(); this.$el.empty();
this.$el.html('<i class="icon-info-sign"></i>'); this.$el.html('<i class="icon-info-sign"></i>');
return this; return this;
}, },
_showDetails : function(){ _showDetails : function(){
vent.trigger(vent.Commands.ShowHistoryDetails, {model : this.model}); vent.trigger(vent.Commands.ShowHistoryDetails, {model : this.model});
} }
}); });
});

@ -1,173 +1,126 @@
'use strict'; var Marionette = require('marionette');
define( var Backgrid = require('backgrid');
[ var HistoryCollection = require('./HistoryCollection');
'marionette', var EventTypeCell = require('../../Cells/EventTypeCell');
'backgrid', var SeriesTitleCell = require('../../Cells/SeriesTitleCell');
'Activity/History/HistoryCollection', var EpisodeNumberCell = require('../../Cells/EpisodeNumberCell');
'Cells/EventTypeCell', var EpisodeTitleCell = require('../../Cells/EpisodeTitleCell');
'Cells/SeriesTitleCell', var HistoryQualityCell = require('./HistoryQualityCell');
'Cells/EpisodeNumberCell', var RelativeDateCell = require('../../Cells/RelativeDateCell');
'Cells/EpisodeTitleCell', var HistoryDetailsCell = require('./HistoryDetailsCell');
'Activity/History/HistoryQualityCell', var GridPager = require('../../Shared/Grid/Pager');
'Cells/RelativeDateCell', var ToolbarLayout = require('../../Shared/Toolbar/ToolbarLayout');
'Activity/History/HistoryDetailsCell', var LoadingView = require('../../Shared/LoadingView');
'Shared/Grid/Pager',
'Shared/Toolbar/ToolbarLayout',
'Shared/LoadingView'
], function (Marionette,
Backgrid,
HistoryCollection,
EventTypeCell,
SeriesTitleCell,
EpisodeNumberCell,
EpisodeTitleCell,
HistoryQualityCell,
RelativeDateCell,
HistoryDetailsCell,
GridPager,
ToolbarLayout,
LoadingView) {
return Marionette.Layout.extend({
template: 'Activity/History/HistoryLayoutTemplate',
module.exports = Marionette.Layout.extend({
template : 'Activity/History/HistoryLayoutTemplate',
regions : { regions : {
history : '#x-history', history : '#x-history',
toolbar : '#x-history-toolbar', toolbar : '#x-history-toolbar',
pager : '#x-history-pager' pager : '#x-history-pager'
}, },
columns : [{
columns:
[
{
name : 'eventType', name : 'eventType',
label : '', label : '',
cell : EventTypeCell, cell : EventTypeCell,
cellValue : 'this' cellValue : 'this'
}, }, {
{
name : 'series', name : 'series',
label : 'Series', label : 'Series',
cell : SeriesTitleCell cell : SeriesTitleCell
}, }, {
{
name : 'episode', name : 'episode',
label : 'Episode', label : 'Episode',
cell : EpisodeNumberCell, cell : EpisodeNumberCell,
sortable : false sortable : false
}, }, {
{
name : 'episode', name : 'episode',
label : 'Episode Title', label : 'Episode Title',
cell : EpisodeTitleCell, cell : EpisodeTitleCell,
sortable : false sortable : false
}, }, {
{
name : 'this', name : 'this',
label : 'Quality', label : 'Quality',
cell : HistoryQualityCell, cell : HistoryQualityCell,
sortable : false sortable : false
}, }, {
{
name : 'date', name : 'date',
label : 'Date', label : 'Date',
cell : RelativeDateCell cell : RelativeDateCell
}, }, {
{
name : 'this', name : 'this',
label : '', label : '',
cell : HistoryDetailsCell, cell : HistoryDetailsCell,
sortable : false sortable : false
} }],
],
initialize : function(){ initialize : function(){
this.collection = new HistoryCollection({tableName : 'history'}); this.collection = new HistoryCollection({tableName : 'history'});
this.listenTo(this.collection, 'sync', this._showTable); this.listenTo(this.collection, 'sync', this._showTable);
}, },
onShow : function(){ onShow : function(){
this.history.show(new LoadingView()); this.history.show(new LoadingView());
this._showToolbar(); this._showToolbar();
}, },
_showTable : function(collection){ _showTable : function(collection){
this.history.show(new Backgrid.Grid({ this.history.show(new Backgrid.Grid({
columns : this.columns, columns : this.columns,
collection : collection, collection : collection,
className : 'table table-hover' className : 'table table-hover'
})); }));
this.pager.show(new GridPager({ this.pager.show(new GridPager({
columns : this.columns, columns : this.columns,
collection : collection collection : collection
})); }));
}, },
_showToolbar : function(){ _showToolbar : function(){
var filterOptions = { var filterOptions = {
type : 'radio', type : 'radio',
storeState : true, storeState : true,
menuKey : 'history.filterMode', menuKey : 'history.filterMode',
defaultAction : 'all', defaultAction : 'all',
items : items : [{
[
{
key : 'all', key : 'all',
title : '', title : '',
tooltip : 'All', tooltip : 'All',
icon : 'icon-circle-blank', icon : 'icon-circle-blank',
callback : this._setFilter callback : this._setFilter
}, }, {
{
key : 'grabbed', key : 'grabbed',
title : '', title : '',
tooltip : 'Grabbed', tooltip : 'Grabbed',
icon : 'icon-nd-downloading', icon : 'icon-nd-downloading',
callback : this._setFilter callback : this._setFilter
}, }, {
{
key : 'imported', key : 'imported',
title : '', title : '',
tooltip : 'Imported', tooltip : 'Imported',
icon : 'icon-nd-imported', icon : 'icon-nd-imported',
callback : this._setFilter callback : this._setFilter
}, }, {
{
key : 'failed', key : 'failed',
title : '', title : '',
tooltip : 'Failed', tooltip : 'Failed',
icon : 'icon-nd-download-failed', icon : 'icon-nd-download-failed',
callback : this._setFilter callback : this._setFilter
}, }, {
{
key : 'deleted', key : 'deleted',
title : '', title : '',
tooltip : 'Deleted', tooltip : 'Deleted',
icon : 'icon-nd-deleted', icon : 'icon-nd-deleted',
callback : this._setFilter callback : this._setFilter
} }]
]
}; };
this.toolbar.show(new ToolbarLayout({ this.toolbar.show(new ToolbarLayout({
right : right : [filterOptions],
[
filterOptions
],
context : this context : this
})); }));
}, },
_setFilter : function(buttonContext){ _setFilter : function(buttonContext){
var mode = buttonContext.model.get('key'); var mode = buttonContext.model.get('key');
this.collection.state.currentPage = 1; this.collection.state.currentPage = 1;
var promise = this.collection.setFilterMode(mode); var promise = this.collection.setFilterMode(mode);
if(buttonContext) { if(buttonContext) {
buttonContext.ui.icon.spinForPromise(promise); buttonContext.ui.icon.spinForPromise(promise);
} }
} }
}); });
});

@ -1,11 +1,8 @@
'use strict'; var Backbone = require('backbone');
define( var SeriesModel = require('../../Series/SeriesModel');
[ var EpisodeModel = require('../../Series/EpisodeModel');
'backbone',
'Series/SeriesModel', module.exports = Backbone.Model.extend({
'Series/EpisodeModel'
], function (Backbone, SeriesModel, EpisodeModel) {
return Backbone.Model.extend({
parse : function(model){ parse : function(model){
model.series = new SeriesModel(model.series); model.series = new SeriesModel(model.series);
model.episode = new EpisodeModel(model.episode); model.episode = new EpisodeModel(model.episode);
@ -13,4 +10,3 @@ define(
return model; return model;
} }
}); });
});

@ -1,36 +1,24 @@
'use strict'; var NzbDroneCell = require('../../Cells/NzbDroneCell');
define(
[
'Cells/NzbDroneCell'
], function (NzbDroneCell) {
return NzbDroneCell.extend({
module.exports = NzbDroneCell.extend({
className : 'history-quality-cell', className : 'history-quality-cell',
render : function(){ render : function(){
var title = ''; var title = '';
var quality = this.model.get('quality'); var quality = this.model.get('quality');
var revision = quality.revision; var revision = quality.revision;
if(revision.real && revision.real > 0) { if(revision.real && revision.real > 0) {
title += ' REAL'; title += ' REAL';
} }
if(revision.version && revision.version > 1) { if(revision.version && revision.version > 1) {
title += ' PROPER'; title += ' PROPER';
} }
title = title.trim(); title = title.trim();
if(this.model.get('qualityCutoffNotMet')) { if(this.model.get('qualityCutoffNotMet')) {
this.$el.html('<span class="badge badge-inverse" title="{0}">{1}</span>'.format(title, quality.quality.name)); this.$el.html('<span class="badge badge-inverse" title="{0}">{1}</span>'.format(title, quality.quality.name));
} }
else { else {
this.$el.html('<span class="badge" title="{0}">{1}</span>'.format(title, quality.quality.name)); this.$el.html('<span class="badge" title="{0}">{1}</span>'.format(title, quality.quality.name));
} }
return this; return this;
} }
}); });
});

@ -1,29 +1,16 @@
'use strict'; var NzbDroneCell = require('../../Cells/NzbDroneCell');
define(
[
'Cells/NzbDroneCell'
], function (NzbDroneCell) {
return NzbDroneCell.extend({
module.exports = NzbDroneCell.extend({
className : 'progress-cell', className : 'progress-cell',
render : function(){ render : function(){
this.$el.empty(); this.$el.empty();
if(this.cellValue) { if(this.cellValue) {
var status = this.model.get('status').toLowerCase(); var status = this.model.get('status').toLowerCase();
if(status === 'downloading') { if(status === 'downloading') {
var progress = 100 - (this.model.get('sizeleft') / this.model.get('size') * 100); var progress = 100 - this.model.get('sizeleft') / this.model.get('size') * 100;
this.$el.html('<div class="progress" title="{0}%">'.format(progress.toFixed(1)) + '<div class="progress-bar progress-bar-purple" style="width: {0}%;"></div></div>'.format(progress));
this.$el.html('<div class="progress" title="{0}%">'.format(progress.toFixed(1)) +
'<div class="progress-bar progress-bar-purple" style="width: {0}%;"></div></div>'.format(progress));
} }
} }
return this; return this;
} }
}); });
});

@ -1,31 +1,22 @@
'use strict'; var _ = require('underscore');
define( var Backbone = require('backbone');
[ var PageableCollection = require('backbone.pageable');
'underscore', var QueueModel = require('./QueueModel');
'backbone', require('../../Mixins/backbone.signalr.mixin');
'backbone.pageable',
'Activity/Queue/QueueModel', module.exports = (function(){
'Mixins/backbone.signalr.mixin'
], function (_, Backbone, PageableCollection, QueueModel) {
var QueueCollection = PageableCollection.extend({ var QueueCollection = PageableCollection.extend({
url : window.NzbDrone.ApiRoot + '/queue', url : window.NzbDrone.ApiRoot + '/queue',
model : QueueModel, model : QueueModel,
state : {pageSize : 15},
state: {
pageSize: 15
},
mode : 'client', mode : 'client',
findEpisode : function(episodeId){ findEpisode : function(episodeId){
return _.find(this.fullCollection.models, function(queueModel){ return _.find(this.fullCollection.models, function(queueModel){
return queueModel.get('episode').id === episodeId; return queueModel.get('episode').id === episodeId;
}); });
} }
}); });
var collection = new QueueCollection().bindSignalR(); var collection = new QueueCollection().bindSignalR();
collection.fetch(); collection.fetch();
return collection; return collection;
}); }).call(this);

@ -1,11 +1,8 @@
'use strict'; var Backbone = require('backbone');
define( var SeriesModel = require('../../Series/SeriesModel');
[ var EpisodeModel = require('../../Series/EpisodeModel');
'backbone',
'Series/SeriesModel', module.exports = Backbone.Model.extend({
'Series/EpisodeModel'
], function (Backbone, SeriesModel, EpisodeModel) {
return Backbone.Model.extend({
parse : function(model){ parse : function(model){
model.series = new SeriesModel(model.series); model.series = new SeriesModel(model.series);
model.episode = new EpisodeModel(model.episode); model.episode = new EpisodeModel(model.episode);
@ -13,4 +10,3 @@ define(
return model; return model;
} }
}); });
});

@ -1,18 +1,11 @@
'use strict'; var Marionette = require('marionette');
var NzbDroneCell = require('../../Cells/NzbDroneCell');
define(
[
'marionette',
'Cells/NzbDroneCell'
], function (Marionette, NzbDroneCell) {
return NzbDroneCell.extend({
module.exports = NzbDroneCell.extend({
className : 'queue-status-cell', className : 'queue-status-cell',
template : 'Activity/Queue/QueueStatusCellTemplate', template : 'Activity/Queue/QueueStatusCellTemplate',
render : function(){ render : function(){
this.$el.empty(); this.$el.empty();
if(this.cellValue) { if(this.cellValue) {
var status = this.cellValue.get('status').toLowerCase(); var status = this.cellValue.get('status').toLowerCase();
var trackedDownloadStatus = this.cellValue.has('trackedDownloadStatus') ? this.cellValue.get('trackedDownloadStatus').toLowerCase() : 'ok'; var trackedDownloadStatus = this.cellValue.has('trackedDownloadStatus') ? this.cellValue.get('trackedDownloadStatus').toLowerCase() : 'ok';
@ -20,44 +13,35 @@ define(
var title = 'Downloading'; var title = 'Downloading';
var itemTitle = this.cellValue.get('title'); var itemTitle = this.cellValue.get('title');
var content = itemTitle; var content = itemTitle;
if(status === 'paused') { if(status === 'paused') {
icon = 'icon-pause'; icon = 'icon-pause';
title = 'Paused'; title = 'Paused';
} }
if(status === 'queued') { if(status === 'queued') {
icon = 'icon-cloud'; icon = 'icon-cloud';
title = 'Queued'; title = 'Queued';
} }
if(status === 'completed') { if(status === 'completed') {
icon = 'icon-inbox'; icon = 'icon-inbox';
title = 'Downloaded'; title = 'Downloaded';
} }
if(status === 'pending') { if(status === 'pending') {
icon = 'icon-time'; icon = 'icon-time';
title = 'Pending'; title = 'Pending';
} }
if(status === 'failed') { if(status === 'failed') {
icon = 'icon-nd-download-failed'; icon = 'icon-nd-download-failed';
title = 'Download failed'; title = 'Download failed';
} }
if(status === 'warning') { if(status === 'warning') {
icon = 'icon-nd-download-warning'; icon = 'icon-nd-download-warning';
title = 'Download warning: check download client for more details'; title = 'Download warning: check download client for more details';
} }
if(trackedDownloadStatus === 'warning') { if(trackedDownloadStatus === 'warning') {
icon += ' icon-nd-warning'; icon += ' icon-nd-warning';
this.templateFunction = Marionette.TemplateCache.get(this.template); this.templateFunction = Marionette.TemplateCache.get(this.template);
content = this.templateFunction(this.cellValue.toJSON()); content = this.templateFunction(this.cellValue.toJSON());
} }
if(trackedDownloadStatus === 'error') { if(trackedDownloadStatus === 'error') {
if(status === 'completed') { if(status === 'completed') {
icon = 'icon-nd-import-failed'; icon = 'icon-nd-import-failed';
@ -67,11 +51,9 @@ define(
icon = 'icon-nd-download-failed'; icon = 'icon-nd-download-failed';
title = 'Download failed'; title = 'Download failed';
} }
this.templateFunction = Marionette.TemplateCache.get(this.template); this.templateFunction = Marionette.TemplateCache.get(this.template);
content = this.templateFunction(this.cellValue.toJSON()); content = this.templateFunction(this.cellValue.toJSON());
} }
this.$el.html('<i class="{0}"></i>'.format(icon)); this.$el.html('<i class="{0}"></i>'.format(icon));
this.$el.popover({ this.$el.popover({
content : content, content : content,
@ -82,8 +64,6 @@ define(
container : this.$el container : this.$el
}); });
} }
return this; return this;
} }
}); });
});

@ -1,46 +1,33 @@
'use strict'; var _ = require('underscore');
define( var Marionette = require('marionette');
[ var QueueCollection = require('./QueueCollection');
'underscore',
'marionette',
'Activity/Queue/QueueCollection'
], function (_, Marionette, QueueCollection) {
return Marionette.ItemView.extend({
tagName: 'span',
module.exports = Marionette.ItemView.extend({
tagName : 'span',
initialize : function(){ initialize : function(){
this.listenTo(QueueCollection, 'sync', this.render); this.listenTo(QueueCollection, 'sync', this.render);
QueueCollection.fetch(); QueueCollection.fetch();
}, },
render : function(){ render : function(){
this.$el.empty(); this.$el.empty();
if(QueueCollection.length === 0) { if(QueueCollection.length === 0) {
return this; return this;
} }
var count = QueueCollection.fullCollection.length; var count = QueueCollection.fullCollection.length;
var label = 'label-info'; var label = 'label-info';
var errors = QueueCollection.fullCollection.some(function(model){ var errors = QueueCollection.fullCollection.some(function(model){
return model.has('trackedDownloadStatus') && model.get('trackedDownloadStatus').toLowerCase() === 'error'; return model.has('trackedDownloadStatus') && model.get('trackedDownloadStatus').toLowerCase() === 'error';
}); });
var warnings = QueueCollection.fullCollection.some(function(model){ var warnings = QueueCollection.fullCollection.some(function(model){
return model.has('trackedDownloadStatus') && model.get('trackedDownloadStatus').toLowerCase() === 'warning'; return model.has('trackedDownloadStatus') && model.get('trackedDownloadStatus').toLowerCase() === 'warning';
}); });
if(errors) { if(errors) {
label = 'label-danger'; label = 'label-danger';
} }
else if(warnings) { else if(warnings) {
label = 'label-warning'; label = 'label-warning';
} }
this.$el.html('<span class="label {0}">{1}</span>'.format(label, count)); this.$el.html('<span class="label {0}">{1}</span>'.format(label, count));
return this; return this;
} }
}); });
});

@ -1,38 +1,25 @@
'use strict'; var NzbDroneCell = require('../../Cells/NzbDroneCell');
var fileSize = require('filesize');
define( var moment = require('moment');
[ var UiSettingsModel = require('../../Shared/UiSettingsModel');
'Cells/NzbDroneCell', var FormatHelpers = require('../../Shared/FormatHelpers');
'filesize',
'moment',
'Shared/UiSettingsModel',
'Shared/FormatHelpers'
], function (NzbDroneCell, fileSize, moment, UiSettingsModel, FormatHelpers) {
return NzbDroneCell.extend({
module.exports = NzbDroneCell.extend({
className : 'timeleft-cell', className : 'timeleft-cell',
render : function(){ render : function(){
this.$el.empty(); this.$el.empty();
if(this.cellValue) { if(this.cellValue) {
//If the release is pending we want to use the timeleft as the time it will be processed at
if(this.cellValue.get('status').toLowerCase() === 'pending') { if(this.cellValue.get('status').toLowerCase() === 'pending') {
var ect = this.cellValue.get('estimatedCompletionTime'); var ect = this.cellValue.get('estimatedCompletionTime');
var time = '{0} at {1}'.format(FormatHelpers.relativeDate(ect), moment(ect).format(UiSettingsModel.time(true, false))); var time = '{0} at {1}'.format(FormatHelpers.relativeDate(ect), moment(ect).format(UiSettingsModel.time(true, false)));
this.$el.html('-'); this.$el.html('-');
this.$el.attr('title', 'Will be processed during the first RSS Sync after {0}'.format(time)); this.$el.attr('title', 'Will be processed during the first RSS Sync after {0}'.format(time));
this.$el.attr('data-container', 'body'); this.$el.attr('data-container', 'body');
return this; return this;
} }
var timeleft = this.cellValue.get('timeleft'); var timeleft = this.cellValue.get('timeleft');
var totalSize = fileSize(this.cellValue.get('size'), 1, false); var totalSize = fileSize(this.cellValue.get('size'), 1, false);
var remainingSize = fileSize(this.cellValue.get('sizeleft'), 1, false); var remainingSize = fileSize(this.cellValue.get('sizeleft'), 1, false);
if(timeleft === undefined) { if(timeleft === undefined) {
this.$el.html('-'); this.$el.html('-');
} }
@ -40,8 +27,6 @@ define(
this.$el.html('<span title="{1} / {2}">{0}</span>'.format(timeleft, remainingSize, totalSize)); this.$el.html('<span title="{1} / {2}">{0}</span>'.format(timeleft, remainingSize, totalSize));
} }
} }
return this; return this;
} }
}); });
});

@ -1,27 +1,18 @@
'use strict'; var Backbone = require('backbone');
define( var SeriesModel = require('../Series/SeriesModel');
[ var _ = require('underscore');
'backbone',
'Series/SeriesModel', module.exports = Backbone.Collection.extend({
'underscore'
], function (Backbone, SeriesModel, _) {
return Backbone.Collection.extend({
url : window.NzbDrone.ApiRoot + '/series/lookup', url : window.NzbDrone.ApiRoot + '/series/lookup',
model : SeriesModel, model : SeriesModel,
parse : function(response){ parse : function(response){
var self = this; var self = this;
_.each(response, function(model){ _.each(response, function(model){
model.id = undefined; model.id = undefined;
if(self.unmappedFolderModel) { if(self.unmappedFolderModel) {
model.path = self.unmappedFolderModel.get('folder').path; model.path = self.unmappedFolderModel.get('folder').path;
} }
}); });
return response; return response;
} }
}); });
});

@ -1,67 +1,40 @@
'use strict'; var vent = require('../vent');
define( var AppLayout = require('../AppLayout');
[ var Marionette = require('marionette');
'vent', var RootFolderLayout = require('./RootFolders/RootFolderLayout');
'AppLayout', var ExistingSeriesCollectionView = require('./Existing/AddExistingSeriesCollectionView');
'marionette', var AddSeriesView = require('./AddSeriesView');
'AddSeries/RootFolders/RootFolderLayout', var ProfileCollection = require('../Profile/ProfileCollection');
'AddSeries/Existing/AddExistingSeriesCollectionView', var RootFolderCollection = require('./RootFolders/RootFolderCollection');
'AddSeries/AddSeriesView', require('../Series/SeriesCollection');
'Profile/ProfileCollection',
'AddSeries/RootFolders/RootFolderCollection', module.exports = Marionette.Layout.extend({
'Series/SeriesCollection'
], function (vent,
AppLayout,
Marionette,
RootFolderLayout,
ExistingSeriesCollectionView,
AddSeriesView,
ProfileCollection,
RootFolderCollection) {
return Marionette.Layout.extend({
template : 'AddSeries/AddSeriesLayoutTemplate', template : 'AddSeries/AddSeriesLayoutTemplate',
regions : {workspace : '#add-series-workspace'},
regions: {
workspace: '#add-series-workspace'
},
events : { events : {
'click .x-import' : '_importSeries', 'click .x-import' : '_importSeries',
'click .x-add-new' : '_addSeries' 'click .x-add-new' : '_addSeries'
}, },
attributes : {id : 'add-series-screen'},
attributes: {
id: 'add-series-screen'
},
initialize : function(){ initialize : function(){
ProfileCollection.fetch(); ProfileCollection.fetch();
RootFolderCollection.fetch() RootFolderCollection.fetch().done(function(){
.done(function () {
RootFolderCollection.synced = true; RootFolderCollection.synced = true;
}); });
}, },
onShow : function(){ onShow : function(){
this.workspace.show(new AddSeriesView()); this.workspace.show(new AddSeriesView());
}, },
_folderSelected : function(options){ _folderSelected : function(options){
vent.trigger(vent.Commands.CloseModalCommand); vent.trigger(vent.Commands.CloseModalCommand);
this.workspace.show(new ExistingSeriesCollectionView({model : options.model})); this.workspace.show(new ExistingSeriesCollectionView({model : options.model}));
}, },
_importSeries : function(){ _importSeries : function(){
this.rootFolderLayout = new RootFolderLayout(); this.rootFolderLayout = new RootFolderLayout();
this.listenTo(this.rootFolderLayout, 'folderSelected', this._folderSelected); this.listenTo(this.rootFolderLayout, 'folderSelected', this._folderSelected);
AppLayout.modalRegion.show(this.rootFolderLayout); AppLayout.modalRegion.show(this.rootFolderLayout);
}, },
_addSeries : function(){ _addSeries : function(){
this.workspace.show(new AddSeriesView()); this.workspace.show(new AddSeriesView());
} }
}); });
});

@ -1,115 +1,78 @@
'use strict'; var _ = require('underscore');
define( var vent = require('../vent');
[ var Marionette = require('marionette');
'underscore', var AddSeriesCollection = require('./AddSeriesCollection');
'vent', var SearchResultCollectionView = require('./SearchResultCollectionView');
'marionette', var EmptyView = require('./EmptyView');
'AddSeries/AddSeriesCollection', var NotFoundView = require('./NotFoundView');
'AddSeries/SearchResultCollectionView', var ErrorView = require('./ErrorView');
'AddSeries/EmptyView', var LoadingView = require('../Shared/LoadingView');
'AddSeries/NotFoundView',
'AddSeries/ErrorView', module.exports = Marionette.Layout.extend({
'Shared/LoadingView'
], function (_, vent, Marionette, AddSeriesCollection, SearchResultCollectionView, EmptyView, NotFoundView, ErrorView, LoadingView) {
return Marionette.Layout.extend({
template : 'AddSeries/AddSeriesViewTemplate', template : 'AddSeries/AddSeriesViewTemplate',
regions : {searchResult : '#search-result'},
regions: {
searchResult: '#search-result'
},
ui : { ui : {
seriesSearch : '.x-series-search', seriesSearch : '.x-series-search',
searchBar : '.x-search-bar', searchBar : '.x-search-bar',
loadMore : '.x-load-more' loadMore : '.x-load-more'
}, },
events : {"click .x-load-more" : '_onLoadMore'},
events: {
'click .x-load-more': '_onLoadMore'
},
initialize : function(options){ initialize : function(options){
this.isExisting = options.isExisting; this.isExisting = options.isExisting;
this.collection = new AddSeriesCollection(); this.collection = new AddSeriesCollection();
if(this.isExisting) { if(this.isExisting) {
this.collection.unmappedFolderModel = this.model; this.collection.unmappedFolderModel = this.model;
} }
if(this.isExisting) { if(this.isExisting) {
this.className = 'existing-series'; this.className = 'existing-series';
} }
else { else {
this.className = 'new-series'; this.className = 'new-series';
} }
this.listenTo(vent, vent.Events.SeriesAdded, this._onSeriesAdded); this.listenTo(vent, vent.Events.SeriesAdded, this._onSeriesAdded);
this.listenTo(this.collection, 'sync', this._showResults); this.listenTo(this.collection, 'sync', this._showResults);
this.resultCollectionView = new SearchResultCollectionView({ this.resultCollectionView = new SearchResultCollectionView({
collection : this.collection, collection : this.collection,
isExisting : this.isExisting isExisting : this.isExisting
}); });
this.throttledSearch = _.debounce(this.search, 1000, {trailing : true}).bind(this); this.throttledSearch = _.debounce(this.search, 1000, {trailing : true}).bind(this);
}, },
onRender : function(){ onRender : function(){
var self = this; var self = this;
this.$el.addClass(this.className); this.$el.addClass(this.className);
this.ui.seriesSearch.keyup(function(e){ this.ui.seriesSearch.keyup(function(e){
//Ignore special keys: http://www.javascripter.net/faq/keycodes.htm
if(_.contains([9, 16, 17, 18, 19, 20, 33, 34, 35, 36, 37, 38, 39, 40, 91, 92, 93], e.keyCode)) { if(_.contains([9, 16, 17, 18, 19, 20, 33, 34, 35, 36, 37, 38, 39, 40, 91, 92, 93], e.keyCode)) {
return; return;
} }
self._abortExistingSearch(); self._abortExistingSearch();
self.throttledSearch({ self.throttledSearch({term : self.ui.seriesSearch.val()});
term: self.ui.seriesSearch.val()
});
}); });
this._clearResults(); this._clearResults();
if(this.isExisting) { if(this.isExisting) {
this.ui.searchBar.hide(); this.ui.searchBar.hide();
} }
}, },
onShow : function(){ onShow : function(){
this.ui.seriesSearch.focus(); this.ui.seriesSearch.focus();
}, },
search : function(options){ search : function(options){
var self = this; var self = this;
this.collection.reset(); this.collection.reset();
if(!options.term || options.term === this.collection.term) { if(!options.term || options.term === this.collection.term) {
return Marionette.$.Deferred().resolve(); return Marionette.$.Deferred().resolve();
} }
this.searchResult.show(new LoadingView()); this.searchResult.show(new LoadingView());
this.collection.term = options.term; this.collection.term = options.term;
this.currentSearchPromise = this.collection.fetch({ this.currentSearchPromise = this.collection.fetch({data : {term : options.term}});
data: { term: options.term }
});
this.currentSearchPromise.fail(function(){ this.currentSearchPromise.fail(function(){
self._showError(); self._showError();
}); });
return this.currentSearchPromise; return this.currentSearchPromise;
}, },
_onSeriesAdded : function(options){ _onSeriesAdded : function(options){
if(this.isExisting && options.series.get('path') === this.model.get('folder').path) { if(this.isExisting && options.series.get('path') === this.model.get('folder').path) {
this.close(); this.close();
} }
else if(!this.isExisting) { else if(!this.isExisting) {
this.collection.term = ''; this.collection.term = '';
this.collection.reset(); this.collection.reset();
@ -118,16 +81,13 @@ define(
this.ui.seriesSearch.focus(); this.ui.seriesSearch.focus();
} }
}, },
_onLoadMore : function(){ _onLoadMore : function(){
var showingAll = this.resultCollectionView.showMore(); var showingAll = this.resultCollectionView.showMore();
this.ui.searchBar.show(); this.ui.searchBar.show();
if(showingAll) { if(showingAll) {
this.ui.loadMore.hide(); this.ui.loadMore.hide();
} }
}, },
_clearResults : function(){ _clearResults : function(){
if(!this.isExisting) { if(!this.isExisting) {
this.searchResult.show(new EmptyView()); this.searchResult.show(new EmptyView());
@ -136,10 +96,8 @@ define(
this.searchResult.close(); this.searchResult.close();
} }
}, },
_showResults : function(){ _showResults : function(){
if(!this.isClosed) { if(!this.isClosed) {
if(this.collection.length === 0) { if(this.collection.length === 0) {
this.ui.searchBar.show(); this.ui.searchBar.show();
this.searchResult.show(new NotFoundView({term : this.collection.term})); this.searchResult.show(new NotFoundView({term : this.collection.term}));
@ -152,7 +110,6 @@ define(
} }
} }
}, },
_abortExistingSearch : function(){ _abortExistingSearch : function(){
if(this.currentSearchPromise && this.currentSearchPromise.readyState > 0 && this.currentSearchPromise.readyState < 4) { if(this.currentSearchPromise && this.currentSearchPromise.readyState > 0 && this.currentSearchPromise.readyState < 4) {
console.log('aborting previous pending search request.'); console.log('aborting previous pending search request.');
@ -162,7 +119,6 @@ define(
this._clearResults(); this._clearResults();
} }
}, },
_showError : function(){ _showError : function(){
if(!this.isClosed) { if(!this.isClosed) {
this.ui.searchBar.show(); this.ui.searchBar.show();
@ -171,4 +127,3 @@ define(
} }
} }
}); });
});

@ -1,11 +1,3 @@
'use strict'; var Marionette = require('marionette');
define( module.exports = Marionette.CompositeView.extend({template : 'AddSeries/EmptyViewTemplate'});
[
'marionette'
], function (Marionette) {
return Marionette.CompositeView.extend({
template: 'AddSeries/EmptyViewTemplate'
});
});

@ -1,20 +1,11 @@
'use strict'; var Marionette = require('marionette');
define( module.exports = Marionette.CompositeView.extend({
[
'marionette'
], function (Marionette) {
return Marionette.CompositeView.extend({
template : 'AddSeries/ErrorViewTemplate', template : 'AddSeries/ErrorViewTemplate',
initialize : function(options){ initialize : function(options){
this.options = options; this.options = options;
}, },
templateHelpers : function(){ templateHelpers : function(){
return this.options; return this.options;
} }
});
}); });

@ -1,59 +1,38 @@
'use strict'; var Marionette = require('marionette');
define( var AddSeriesView = require('../AddSeriesView');
[ var UnmappedFolderCollection = require('./UnmappedFolderCollection');
'marionette',
'AddSeries/AddSeriesView',
'AddSeries/Existing/UnmappedFolderCollection'
], function (Marionette, AddSeriesView, UnmappedFolderCollection) {
return Marionette.CompositeView.extend({
module.exports = Marionette.CompositeView.extend({
itemView : AddSeriesView, itemView : AddSeriesView,
itemViewContainer : '.x-loading-folders', itemViewContainer : '.x-loading-folders',
template : 'AddSeries/Existing/AddExistingSeriesCollectionViewTemplate', template : 'AddSeries/Existing/AddExistingSeriesCollectionViewTemplate',
ui : {loadingFolders : '.x-loading-folders'},
ui: {
loadingFolders: '.x-loading-folders'
},
initialize : function(){ initialize : function(){
this.collection = new UnmappedFolderCollection(); this.collection = new UnmappedFolderCollection();
this.collection.importItems(this.model); this.collection.importItems(this.model);
}, },
showCollection : function(){ showCollection : function(){
this._showAndSearch(0); this._showAndSearch(0);
}, },
appendHtml : function(collectionView, itemView, index){ appendHtml : function(collectionView, itemView, index){
collectionView.ui.loadingFolders.before(itemView.el); collectionView.ui.loadingFolders.before(itemView.el);
}, },
_showAndSearch : function(index){ _showAndSearch : function(index){
var self = this; var self = this;
var model = this.collection.at(index); var model = this.collection.at(index);
if(model) { if(model) {
var currentIndex = index; var currentIndex = index;
var folderName = model.get('folder').name; var folderName = model.get('folder').name;
this.addItemView(model, this.getItemView(), index); this.addItemView(model, this.getItemView(), index);
this.children.findByModel(model) this.children.findByModel(model).search({term : folderName}).always(function(){
.search({term: folderName})
.always(function () {
if(!self.isClosed) { if(!self.isClosed) {
self._showAndSearch(currentIndex + 1); self._showAndSearch(currentIndex + 1);
} }
}); });
} }
else { else {
this.ui.loadingFolders.hide(); this.ui.loadingFolders.hide();
} }
}, },
itemViewOptions : {isExisting : true}
itemViewOptions: {
isExisting: true
}
});
}); });

@ -1,18 +1,12 @@
'use strict'; var Backbone = require('backbone');
define( var UnmappedFolderModel = require('./UnmappedFolderModel');
[ var _ = require('underscore');
'backbone',
'AddSeries/Existing/UnmappedFolderModel',
'underscore'
], function (Backbone, UnmappedFolderModel,_) {
return Backbone.Collection.extend({
model: UnmappedFolderModel,
module.exports = Backbone.Collection.extend({
model : UnmappedFolderModel,
importItems : function(rootFolderModel){ importItems : function(rootFolderModel){
this.reset(); this.reset();
var rootFolder = rootFolderModel; var rootFolder = rootFolderModel;
_.each(rootFolderModel.get('unmappedFolders'), function(folder){ _.each(rootFolderModel.get('unmappedFolders'), function(folder){
this.push(new UnmappedFolderModel({ this.push(new UnmappedFolderModel({
rootFolder : rootFolder, rootFolder : rootFolder,
@ -21,4 +15,3 @@ define(
}, this); }, this);
} }
}); });
});

@ -1,10 +1,3 @@
'use strict'; var Backbone = require('backbone');
define( module.exports = Backbone.Model.extend({});
[
'backbone'
], function (Backbone) {
return Backbone.Model.extend({
});
});

@ -1,20 +1,11 @@
'use strict'; var Marionette = require('marionette');
define( module.exports = Marionette.CompositeView.extend({
[
'marionette'
], function (Marionette) {
return Marionette.CompositeView.extend({
template : 'AddSeries/NotFoundViewTemplate', template : 'AddSeries/NotFoundViewTemplate',
initialize : function(options){ initialize : function(options){
this.options = options; this.options = options;
}, },
templateHelpers : function(){ templateHelpers : function(){
return this.options; return this.options;
} }
});
}); });

@ -1,17 +1,11 @@
'use strict'; var Backbone = require('backbone');
define( var RootFolderModel = require('./RootFolderModel');
[ require('../../Mixins/backbone.signalr.mixin');
'backbone',
'AddSeries/RootFolders/RootFolderModel',
'Mixins/backbone.signalr.mixin'
], function (Backbone, RootFolderModel) {
module.exports = (function(){
var RootFolderCollection = Backbone.Collection.extend({ var RootFolderCollection = Backbone.Collection.extend({
url : window.NzbDrone.ApiRoot + '/rootfolder', url : window.NzbDrone.ApiRoot + '/rootfolder',
model : RootFolderModel model : RootFolderModel
}); });
//var collection = new RootFolderCollection().bindSignalR();
return new RootFolderCollection(); return new RootFolderCollection();
}); }).call(this);

@ -1,15 +1,8 @@
'use strict'; var Marionette = require('marionette');
var RootFolderItemView = require('./RootFolderItemView');
define( module.exports = Marionette.CompositeView.extend({
[
'marionette',
'AddSeries/RootFolders/RootFolderItemView'
], function (Marionette, RootFolderItemView) {
return Marionette.CompositeView.extend({
template : 'AddSeries/RootFolders/RootFolderCollectionViewTemplate', template : 'AddSeries/RootFolders/RootFolderCollectionViewTemplate',
itemViewContainer : '.x-root-folders', itemViewContainer : '.x-root-folders',
itemView : RootFolderItemView itemView : RootFolderItemView
}); });
});

@ -1,37 +1,22 @@
'use strict'; var Marionette = require('marionette');
define(
[
'marionette'
], function (Marionette) {
return Marionette.ItemView.extend({
module.exports = Marionette.ItemView.extend({
template : 'AddSeries/RootFolders/RootFolderItemViewTemplate', template : 'AddSeries/RootFolders/RootFolderItemViewTemplate',
tagName : 'tr', tagName : 'tr',
initialize : function(){ initialize : function(){
this.listenTo(this.model, 'change', this.render); this.listenTo(this.model, 'change', this.render);
}, },
events : { events : {
'click .x-delete' : 'removeFolder', 'click .x-delete' : 'removeFolder',
'click .x-folder' : 'folderSelected' 'click .x-folder' : 'folderSelected'
}, },
removeFolder : function(){ removeFolder : function(){
var self = this; var self = this;
this.model.destroy().success(function(){
this.model.destroy()
.success(function(){
self.close(); self.close();
}); });
}, },
folderSelected : function(){ folderSelected : function(){
this.trigger('folderSelected', this.model); this.trigger('folderSelected', this.model);
} }
}); });
});

@ -1,81 +1,54 @@
'use strict'; var Marionette = require('marionette');
var RootFolderCollectionView = require('./RootFolderCollectionView');
define( var RootFolderCollection = require('./RootFolderCollection');
[ var RootFolderModel = require('./RootFolderModel');
'marionette', var LoadingView = require('../../Shared/LoadingView');
'AddSeries/RootFolders/RootFolderCollectionView', var AsValidatedView = require('../../Mixins/AsValidatedView');
'AddSeries/RootFolders/RootFolderCollection', require('../../Mixins/FileBrowser');
'AddSeries/RootFolders/RootFolderModel',
'Shared/LoadingView', module.exports = (function(){
'Mixins/AsValidatedView',
'Mixins/FileBrowser'
], function (Marionette, RootFolderCollectionView, RootFolderCollection, RootFolderModel, LoadingView, AsValidatedView) {
var layout = Marionette.Layout.extend({ var layout = Marionette.Layout.extend({
template : 'AddSeries/RootFolders/RootFolderLayoutTemplate', template : 'AddSeries/RootFolders/RootFolderLayoutTemplate',
ui : {pathInput : '.x-path'},
ui: { regions : {currentDirs : '#current-dirs'},
pathInput: '.x-path'
},
regions: {
currentDirs: '#current-dirs'
},
events : { events : {
'click .x-add' : '_addFolder', 'click .x-add' : '_addFolder',
'keydown .x-path input' : '_keydown' 'keydown .x-path input' : '_keydown'
}, },
initialize : function(){ initialize : function(){
this.collection = RootFolderCollection; this.collection = RootFolderCollection;
this.rootfolderListView = new RootFolderCollectionView({collection : RootFolderCollection}); this.rootfolderListView = new RootFolderCollectionView({collection : RootFolderCollection});
this.listenTo(this.rootfolderListView, 'itemview:folderSelected', this._onFolderSelected); this.listenTo(this.rootfolderListView, 'itemview:folderSelected', this._onFolderSelected);
this.listenTo(RootFolderCollection, 'sync', this._showCurrentDirs); this.listenTo(RootFolderCollection, 'sync', this._showCurrentDirs);
}, },
onRender : function(){ onRender : function(){
this.currentDirs.show(new LoadingView()); this.currentDirs.show(new LoadingView());
if(RootFolderCollection.synced) { if(RootFolderCollection.synced) {
this._showCurrentDirs(); this._showCurrentDirs();
} }
this.ui.pathInput.fileBrowser(); this.ui.pathInput.fileBrowser();
}, },
_onFolderSelected : function(options){ _onFolderSelected : function(options){
this.trigger('folderSelected', options); this.trigger('folderSelected', options);
}, },
_addFolder : function(){ _addFolder : function(){
var self = this; var self = this;
var newDir = new RootFolderModel({Path : this.ui.pathInput.val()});
var newDir = new RootFolderModel({
Path: this.ui.pathInput.val()
});
this.bindToModelValidation(newDir); this.bindToModelValidation(newDir);
newDir.save().done(function(){ newDir.save().done(function(){
RootFolderCollection.add(newDir); RootFolderCollection.add(newDir);
self.trigger('folderSelected', {model : newDir}); self.trigger('folderSelected', {model : newDir});
}); });
}, },
_showCurrentDirs : function(){ _showCurrentDirs : function(){
this.currentDirs.show(this.rootfolderListView); this.currentDirs.show(this.rootfolderListView);
}, },
_keydown : function(e){ _keydown : function(e){
if(e.keyCode !== 13) { if(e.keyCode !== 13) {
return; return;
} }
this._addFolder(); this._addFolder();
} }
}); });
return AsValidatedView.apply(layout); return AsValidatedView.apply(layout);
}); }).call(this);

@ -1,12 +1,6 @@
'use strict'; var Backbone = require('backbone');
define(
[ module.exports = Backbone.Model.extend({
'backbone'
], function (Backbone) {
return Backbone.Model.extend({
urlRoot : window.NzbDrone.ApiRoot + '/rootfolder', urlRoot : window.NzbDrone.ApiRoot + '/rootfolder',
defaults: { defaults : {freeSpace : 0}
freeSpace: 0
}
});
}); });

@ -1,35 +1,24 @@
'use strict'; var Marionette = require('marionette');
define( var SearchResultView = require('./SearchResultView');
[
'marionette',
'AddSeries/SearchResultView'
], function (Marionette, SearchResultView) {
return Marionette.CollectionView.extend({
module.exports = Marionette.CollectionView.extend({
itemView : SearchResultView, itemView : SearchResultView,
initialize : function(options){ initialize : function(options){
this.isExisting = options.isExisting; this.isExisting = options.isExisting;
this.showing = 1; this.showing = 1;
}, },
showAll : function(){ showAll : function(){
this.showingAll = true; this.showingAll = true;
this.render(); this.render();
}, },
showMore : function(){ showMore : function(){
this.showing += 5; this.showing += 5;
this.render(); this.render();
return this.showing >= this.collection.length; return this.showing >= this.collection.length;
}, },
appendHtml : function(collectionView, itemView, index){ appendHtml : function(collectionView, itemView, index){
if(!this.isExisting || index < this.showing || index === 0) { if(!this.isExisting || index < this.showing || index === 0) {
collectionView.$el.append(itemView.el); collectionView.$el.append(itemView.el);
} }
} }
}); });
});

@ -1,19 +1,15 @@
define( var Marionette = require('marionette');
[ var ModalRegion = require('./Shared/Modal/ModalRegion');
'marionette', var FileBrowserModalRegion = require('./Shared/FileBrowser/FileBrowserModalRegion');
'Shared/Modal/ModalRegion', var ControlPanelRegion = require('./Shared/ControlPanel/ControlPanelRegion');
'Shared/FileBrowser/FileBrowserModalRegion',
'Shared/ControlPanel/ControlPanelRegion'
], function (Marionette, ModalRegion, FileBrowserModalRegion, ControlPanelRegion) {
'use strict';
module.exports = (function(){
'use strict';
var Layout = Marionette.Layout.extend({ var Layout = Marionette.Layout.extend({
regions : { regions : {
navbarRegion : '#nav-region', navbarRegion : '#nav-region',
mainRegion : '#main-region' mainRegion : '#main-region'
}, },
initialize : function(){ initialize : function(){
this.addRegions({ this.addRegions({
modalRegion : ModalRegion, modalRegion : ModalRegion,
@ -22,6 +18,5 @@ define(
}); });
} }
}); });
return new Layout({el : 'body'}); return new Layout({el : 'body'});
}); }).call(this);

@ -1,25 +1,18 @@
'use strict'; var Marionette = require('marionette');
define( var StatusModel = require('../System/StatusModel');
[ require('../Mixins/CopyToClipboard');
'marionette',
'System/StatusModel',
'Mixins/CopyToClipboard'
], function (Marionette, StatusModel) {
return Marionette.Layout.extend({
template: 'Calendar/CalendarFeedViewTemplate',
module.exports = Marionette.Layout.extend({
template : 'Calendar/CalendarFeedViewTemplate',
ui : { ui : {
icalUrl : '.x-ical-url', icalUrl : '.x-ical-url',
icalCopy : '.x-ical-copy' icalCopy : '.x-ical-copy'
}, },
templateHelpers : { templateHelpers : {
icalHttpUrl : window.location.protocol + '//' + window.location.host + StatusModel.get('urlBase') + '/feed/calendar/NzbDrone.ics?apikey=' + window.NzbDrone.ApiKey, icalHttpUrl : window.location.protocol + '//' + window.location.host + StatusModel.get('urlBase') + '/feed/calendar/NzbDrone.ics?apikey=' + window.NzbDrone.ApiKey,
icalWebCalUrl : 'webcal://' + window.location.host + StatusModel.get('urlBase') + '/feed/calendar/NzbDrone.ics?apikey=' + window.NzbDrone.ApiKey icalWebCalUrl : 'webcal://' + window.location.host + StatusModel.get('urlBase') + '/feed/calendar/NzbDrone.ics?apikey=' + window.NzbDrone.ApiKey
}, },
onShow : function(){ onShow : function(){
this.ui.icalCopy.copyToClipboard(this.ui.icalUrl); this.ui.icalCopy.copyToClipboard(this.ui.icalUrl);
} }
}); });
});

@ -1,40 +1,28 @@
'use strict'; var AppLayout = require('../AppLayout');
define( var Marionette = require('marionette');
[ var UpcomingCollectionView = require('./UpcomingCollectionView');
'AppLayout', var CalendarView = require('./CalendarView');
'marionette', var CalendarFeedView = require('./CalendarFeedView');
'Calendar/UpcomingCollectionView',
'Calendar/CalendarView',
'Calendar/CalendarFeedView'
], function (AppLayout, Marionette, UpcomingCollectionView, CalendarView, CalendarFeedView) {
return Marionette.Layout.extend({
template: 'Calendar/CalendarLayoutTemplate',
module.exports = Marionette.Layout.extend({
template : 'Calendar/CalendarLayoutTemplate',
regions : { regions : {
upcoming : '#x-upcoming', upcoming : '#x-upcoming',
calendar : '#x-calendar' calendar : '#x-calendar'
}, },
events : {"click .x-ical" : '_showiCal'},
events: {
'click .x-ical': '_showiCal'
},
onShow : function(){ onShow : function(){
this._showUpcoming(); this._showUpcoming();
this._showCalendar(); this._showCalendar();
}, },
_showUpcoming : function(){ _showUpcoming : function(){
this.upcoming.show(new UpcomingCollectionView()); this.upcoming.show(new UpcomingCollectionView());
}, },
_showCalendar : function(){ _showCalendar : function(){
this.calendar.show(new CalendarView()); this.calendar.show(new CalendarView());
}, },
_showiCal : function(){ _showiCal : function(){
var view = new CalendarFeedView(); var view = new CalendarFeedView();
AppLayout.modalRegion.show(view); AppLayout.modalRegion.show(view);
} }
}); });
});

@ -1,72 +1,54 @@
'use strict'; var $ = require('jquery');
var vent = require('../vent');
define( var Marionette = require('marionette');
[ var moment = require('moment');
'jquery', var CalendarCollection = require('./Collection');
'vent', var UiSettings = require('../Shared/UiSettingsModel');
'marionette', var QueueCollection = require('../Activity/Queue/QueueCollection');
'moment', var Config = require('../Config');
'Calendar/Collection', require('../Mixins/backbone.signalr.mixin');
'Shared/UiSettingsModel', require('fullcalendar');
'Activity/Queue/QueueCollection', require('jquery.easypiechart');
'Config',
'Mixins/backbone.signalr.mixin', module.exports = Marionette.ItemView.extend({
'fullcalendar',
'jquery.easypiechart'
], function ($, vent, Marionette, moment, CalendarCollection, UiSettings, QueueCollection, Config) {
return Marionette.ItemView.extend({
storageKey : 'calendar.view', storageKey : 'calendar.view',
initialize : function(){ initialize : function(){
this.collection = new CalendarCollection().bindSignalR({updateOnly : true}); this.collection = new CalendarCollection().bindSignalR({updateOnly : true});
this.listenTo(this.collection, 'change', this._reloadCalendarEvents); this.listenTo(this.collection, 'change', this._reloadCalendarEvents);
this.listenTo(QueueCollection, 'sync', this._reloadCalendarEvents); this.listenTo(QueueCollection, 'sync', this._reloadCalendarEvents);
}, },
render : function(){ render : function(){
this.$el.empty().fullCalendar(this._getOptions()); this.$el.empty().fullCalendar(this._getOptions());
}, },
onShow : function(){ onShow : function(){
this.$('.fc-button-today').click(); this.$('.fc-button-today').click();
}, },
_viewRender : function(view){ _viewRender : function(view){
if($(window).width() < 768) { if($(window).width() < 768) {
this.$('.fc-header-title').show(); this.$('.fc-header-title').show();
this.$('.calendar-title').remove(); this.$('.calendar-title').remove();
var title = this.$('.fc-header-title').text(); var title = this.$('.fc-header-title').text();
var titleDiv = '<div class="calendar-title"><h2>{0}</h2></div>'.format(title); var titleDiv = '<div class="calendar-title"><h2>{0}</h2></div>'.format(title);
this.$('.fc-header').before(titleDiv); this.$('.fc-header').before(titleDiv);
this.$('.fc-header-title').hide(); this.$('.fc-header-title').hide();
} }
if(Config.getValue(this.storageKey) !== view.name) { if(Config.getValue(this.storageKey) !== view.name) {
Config.setValue(this.storageKey, view.name); Config.setValue(this.storageKey, view.name);
} }
this._getEvents(view); this._getEvents(view);
}, },
_eventRender : function(event, element){ _eventRender : function(event, element){
this.$(element).addClass(event.statusLevel); this.$(element).addClass(event.statusLevel);
this.$(element).children('.fc-event-inner').addClass(event.statusLevel); this.$(element).children('.fc-event-inner').addClass(event.statusLevel);
if(event.downloading) { if(event.downloading) {
var progress = 100 - (event.downloading.get('sizeleft') / event.downloading.get('size') * 100); var progress = 100 - event.downloading.get('sizeleft') / event.downloading.get('size') * 100;
var releaseTitle = event.downloading.get('title'); var releaseTitle = event.downloading.get('title');
var estimatedCompletionTime = moment(event.downloading.get('estimatedCompletionTime')).fromNow(); var estimatedCompletionTime = moment(event.downloading.get('estimatedCompletionTime')).fromNow();
var status = event.downloading.get('status').toLocaleLowerCase(); var status = event.downloading.get('status').toLocaleLowerCase();
var errorMessage = event.downloading.get('errorMessage'); var errorMessage = event.downloading.get('errorMessage');
if(status === 'pending') { if(status === 'pending') {
this._addStatusIcon(element, 'icon-time', 'Release will be processed {0}'.format(estimatedCompletionTime)); this._addStatusIcon(element, 'icon-time', 'Release will be processed {0}'.format(estimatedCompletionTime));
} }
else if(errorMessage) { else if(errorMessage) {
if(status === 'completed') { if(status === 'completed') {
this._addStatusIcon(element, 'icon-nd-import-failed', 'Import failed: {0}'.format(errorMessage)); this._addStatusIcon(element, 'icon-nd-import-failed', 'Import failed: {0}'.format(errorMessage));
@ -75,19 +57,14 @@ define(
this._addStatusIcon(element, 'icon-nd-download-failed', 'Download failed: {0}'.format(errorMessage)); this._addStatusIcon(element, 'icon-nd-download-failed', 'Download failed: {0}'.format(errorMessage));
} }
} }
else if(status === 'failed') { else if(status === 'failed') {
this._addStatusIcon(element, 'icon-nd-download-failed', 'Download failed: check download client for more details'); this._addStatusIcon(element, 'icon-nd-download-failed', 'Download failed: check download client for more details');
} }
else if(status === 'warning') { else if(status === 'warning') {
this._addStatusIcon(element, 'icon-nd-download-warning', 'Download warning: check download client for more details'); this._addStatusIcon(element, 'icon-nd-download-warning', 'Download warning: check download client for more details');
} }
else { else {
this.$(element).find('.fc-event-time') this.$(element).find('.fc-event-time').after('<span class="chart pull-right" data-percent="{0}"></span>'.format(progress));
.after('<span class="chart pull-right" data-percent="{0}"></span>'.format(progress));
this.$(element).find('.chart').easyPieChart({ this.$(element).find('.chart').easyPieChart({
barColor : '#ffffff', barColor : '#ffffff',
trackColor : false, trackColor : false,
@ -96,7 +73,6 @@ define(
size : 14, size : 14,
animate : false animate : false
}); });
this.$(element).find('.chart').tooltip({ this.$(element).find('.chart').tooltip({
title : 'Episode is downloading - {0}% {1}'.format(progress.toFixed(1), releaseTitle), title : 'Episode is downloading - {0}% {1}'.format(progress.toFixed(1), releaseTitle),
container : '.fc-content' container : '.fc-content'
@ -104,30 +80,26 @@ define(
} }
} }
}, },
_getEvents : function(view){ _getEvents : function(view){
var start = view.start.toISOString(); var start = view.start.toISOString();
var end = view.end.toISOString(); var end = view.end.toISOString();
this.$el.fullCalendar('removeEvents'); this.$el.fullCalendar('removeEvents');
this.collection.fetch({ this.collection.fetch({
data : { start: start, end: end }, data : {
start : start,
end : end
},
success : this._setEventData.bind(this) success : this._setEventData.bind(this)
}); });
}, },
_setEventData : function(collection){ _setEventData : function(collection){
var events = []; var events = [];
var self = this; var self = this;
collection.each(function(model){ collection.each(function(model){
var seriesTitle = model.get('series').title; var seriesTitle = model.get('series').title;
var start = model.get('airDateUtc'); var start = model.get('airDateUtc');
var runtime = model.get('series').runtime; var runtime = model.get('series').runtime;
var end = moment(start).add('minutes', runtime).toISOString(); var end = moment(start).add('minutes', runtime).toISOString();
var event = { var event = {
title : seriesTitle, title : seriesTitle,
start : moment(start), start : moment(start),
@ -137,54 +109,41 @@ define(
downloading : QueueCollection.findEpisode(model.get('id')), downloading : QueueCollection.findEpisode(model.get('id')),
model : model model : model
}; };
events.push(event); events.push(event);
}); });
this.$el.fullCalendar('addEventSource', events); this.$el.fullCalendar('addEventSource', events);
}, },
_getStatusLevel : function(element, endTime){ _getStatusLevel : function(element, endTime){
var hasFile = element.get('hasFile'); var hasFile = element.get('hasFile');
var downloading = QueueCollection.findEpisode(element.get('id')) || element.get('grabbed'); var downloading = QueueCollection.findEpisode(element.get('id')) || element.get('grabbed');
var currentTime = moment(); var currentTime = moment();
var start = moment(element.get('airDateUtc')); var start = moment(element.get('airDateUtc'));
var end = moment(endTime); var end = moment(endTime);
var statusLevel = 'primary'; var statusLevel = 'primary';
if(hasFile) { if(hasFile) {
statusLevel = 'success'; statusLevel = 'success';
} }
else if(downloading) { else if(downloading) {
statusLevel = 'purple'; statusLevel = 'purple';
} }
else if(currentTime.isAfter(start) && currentTime.isBefore(end)) { else if(currentTime.isAfter(start) && currentTime.isBefore(end)) {
statusLevel = 'warning'; statusLevel = 'warning';
} }
else if(start.isBefore(currentTime) && !hasFile) { else if(start.isBefore(currentTime) && !hasFile) {
statusLevel = 'danger'; statusLevel = 'danger';
} }
else if(element.get('episodeNumber') === 1) { else if(element.get('episodeNumber') === 1) {
statusLevel = 'premiere'; statusLevel = 'premiere';
} }
if(end.isBefore(currentTime.startOf('day'))) { if(end.isBefore(currentTime.startOf('day'))) {
statusLevel += ' past'; statusLevel += ' past';
} }
return statusLevel; return statusLevel;
}, },
_reloadCalendarEvents : function(){ _reloadCalendarEvents : function(){
this.$el.fullCalendar('removeEvents'); this.$el.fullCalendar('removeEvents');
this._setEventData(this.collection); this._setEventData(this.collection);
}, },
_getOptions : function(){ _getOptions : function(){
var options = { var options = {
allDayDefault : false, allDayDefault : false,
@ -197,54 +156,40 @@ define(
vent.trigger(vent.Commands.ShowEpisodeDetails, {episode : event.model}); vent.trigger(vent.Commands.ShowEpisodeDetails, {episode : event.model});
} }
}; };
if($(window).width() < 768) { if($(window).width() < 768) {
options.defaultView = Config.getValue(this.storageKey, 'basicDay'); options.defaultView = Config.getValue(this.storageKey, 'basicDay');
options.header = { options.header = {
left : 'prev,next today', left : 'prev,next today',
center : 'title', center : 'title',
right : 'basicWeek,basicDay' right : 'basicWeek,basicDay'
}; };
} }
else { else {
options.defaultView = Config.getValue(this.storageKey, 'basicWeek'); options.defaultView = Config.getValue(this.storageKey, 'basicWeek');
options.header = { options.header = {
left : 'prev,next today', left : 'prev,next today',
center : 'title', center : 'title',
right : 'month,basicWeek,basicDay' right : 'month,basicWeek,basicDay'
}; };
} }
options.titleFormat = { options.titleFormat = {
month : 'MMMM YYYY', month : 'MMMM YYYY',
week : UiSettings.get('shortDateFormat'), week : UiSettings.get('shortDateFormat'),
day : UiSettings.get('longDateFormat') day : UiSettings.get('longDateFormat')
}; };
options.columnFormat = { options.columnFormat = {
month : 'ddd', // Mon month : 'ddd',
week : UiSettings.get('calendarWeekColumnHeader'), week : UiSettings.get('calendarWeekColumnHeader'),
day : 'dddd' // Monday day : 'dddd'
}; };
options.timeFormat = {"default" : UiSettings.get('timeFormat')};
options.timeFormat = {
'default': UiSettings.get('timeFormat')
};
return options; return options;
}, },
_addStatusIcon : function(element, icon, tooltip){ _addStatusIcon : function(element, icon, tooltip){
this.$(element).find('.fc-event-time') this.$(element).find('.fc-event-time').after('<span class="status pull-right"><i class="{0}"></i></span>'.format(icon));
.after('<span class="status pull-right"><i class="{0}"></i></span>'.format(icon));
this.$(element).find('.status').tooltip({ this.$(element).find('.status').tooltip({
title : tooltip, title : tooltip,
container : '.fc-content' container : '.fc-content'
}); });
} }
}); });
});

@ -1,17 +1,12 @@
'use strict'; var Backbone = require('backbone');
define( var EpisodeModel = require('../Series/EpisodeModel');
[
'backbone', module.exports = Backbone.Collection.extend({
'Series/EpisodeModel'
], function (Backbone, EpisodeModel) {
return Backbone.Collection.extend({
url : window.NzbDrone.ApiRoot + '/calendar', url : window.NzbDrone.ApiRoot + '/calendar',
model : EpisodeModel, model : EpisodeModel,
comparator : function(model){ comparator : function(model){
var date = new Date(model.get('airDateUtc')); var date = new Date(model.get('airDateUtc'));
var time = date.getTime(); var time = date.getTime();
return time; return time;
} }
}); });
});

@ -1,32 +1,23 @@
'use strict'; var Backbone = require('backbone');
define( var moment = require('moment');
[ var EpisodeModel = require('../Series/EpisodeModel');
'backbone',
'moment', module.exports = Backbone.Collection.extend({
'Series/EpisodeModel'
], function (Backbone, moment, EpisodeModel) {
return Backbone.Collection.extend({
url : window.NzbDrone.ApiRoot + '/calendar', url : window.NzbDrone.ApiRoot + '/calendar',
model : EpisodeModel, model : EpisodeModel,
comparator : function(model1, model2){ comparator : function(model1, model2){
var airDate1 = model1.get('airDateUtc'); var airDate1 = model1.get('airDateUtc');
var date1 = moment(airDate1); var date1 = moment(airDate1);
var time1 = date1.unix(); var time1 = date1.unix();
var airDate2 = model2.get('airDateUtc'); var airDate2 = model2.get('airDateUtc');
var date2 = moment(airDate2); var date2 = moment(airDate2);
var time2 = date2.unix(); var time2 = date2.unix();
if(time1 < time2) { if(time1 < time2) {
return -1; return -1;
} }
if(time1 > time2) { if(time1 > time2) {
return 1; return 1;
} }
return 0; return 0;
} }
}); });
});

@ -1,30 +1,21 @@
'use strict'; var _ = require('underscore');
var Marionette = require('marionette');
var UpcomingCollection = require('./UpcomingCollection');
var UpcomingItemView = require('./UpcomingItemView');
require('../Mixins/backbone.signalr.mixin');
define( module.exports = Marionette.CollectionView.extend({
[
'underscore',
'marionette',
'Calendar/UpcomingCollection',
'Calendar/UpcomingItemView',
'Mixins/backbone.signalr.mixin'
], function (_, Marionette, UpcomingCollection, UpcomingItemView) {
return Marionette.CollectionView.extend({
itemView : UpcomingItemView, itemView : UpcomingItemView,
initialize : function(){ initialize : function(){
this.collection = new UpcomingCollection().bindSignalR({updateOnly : true}); this.collection = new UpcomingCollection().bindSignalR({updateOnly : true});
this.collection.fetch(); this.collection.fetch();
this._fetchCollection = _.bind(this._fetchCollection, this); this._fetchCollection = _.bind(this._fetchCollection, this);
this.timer = window.setInterval(this._fetchCollection, 60 * 60 * 1000); this.timer = window.setInterval(this._fetchCollection, 60 * 60 * 1000);
}, },
onClose : function(){ onClose : function(){
window.clearInterval(this.timer); window.clearInterval(this.timer);
}, },
_fetchCollection : function(){ _fetchCollection : function(){
this.collection.fetch(); this.collection.fetch();
} }
}); });
});

@ -1,33 +1,19 @@
'use strict'; var vent = require('../vent');
var Marionette = require('marionette');
var moment = require('moment');
define( module.exports = Marionette.ItemView.extend({
[
'vent',
'marionette',
'moment'
], function (vent, Marionette, moment) {
return Marionette.ItemView.extend({
template : 'Calendar/UpcomingItemViewTemplate', template : 'Calendar/UpcomingItemViewTemplate',
tagName : 'div', tagName : 'div',
events : {"click .x-episode-title" : '_showEpisodeDetails'},
events: {
'click .x-episode-title': '_showEpisodeDetails'
},
initialize : function(){ initialize : function(){
var start = this.model.get('airDateUtc'); var start = this.model.get('airDateUtc');
var runtime = this.model.get('series').runtime; var runtime = this.model.get('series').runtime;
var end = moment(start).add('minutes', runtime); var end = moment(start).add('minutes', runtime);
this.model.set({end : end.toISOString()});
this.model.set({
end: end.toISOString()
});
this.listenTo(this.model, 'change', this.render); this.listenTo(this.model, 'change', this.render);
}, },
_showEpisodeDetails : function(){ _showEpisodeDetails : function(){
vent.trigger(vent.Commands.ShowEpisodeDetails, {episode : this.model}); vent.trigger(vent.Commands.ShowEpisodeDetails, {episode : this.model});
} }
}); });
});

@ -1,29 +1,18 @@
'use strict'; var Backgrid = require('backgrid');
define( var Marionette = require('marionette');
[ require('bootstrap');
'backgrid',
'marionette',
'bootstrap'
], function (Backgrid, Marionette) {
return Backgrid.Cell.extend({
module.exports = Backgrid.Cell.extend({
className : 'approval-status-cell', className : 'approval-status-cell',
template : 'Cells/ApprovalStatusCellTemplate', template : 'Cells/ApprovalStatusCellTemplate',
render : function(){ render : function(){
var rejections = this.model.get(this.column.get('name')); var rejections = this.model.get(this.column.get('name'));
if(rejections.length === 0) { if(rejections.length === 0) {
return this; return this;
} }
this.templateFunction = Marionette.TemplateCache.get(this.template); this.templateFunction = Marionette.TemplateCache.get(this.template);
var html = this.templateFunction(rejections); var html = this.templateFunction(rejections);
this.$el.html('<i class="icon-exclamation-sign"/>'); this.$el.html('<i class="icon-exclamation-sign"/>');
this.$el.popover({ this.$el.popover({
content : html, content : html,
html : true, html : true,
@ -32,8 +21,6 @@ define(
placement : 'left', placement : 'left',
container : this.$el container : this.$el
}); });
return this; return this;
} }
}); });
});

@ -1,33 +1,20 @@
'use strict'; var vent = require('../vent');
define( var Backgrid = require('backgrid');
[
'vent',
'backgrid'
], function (vent, Backgrid) {
return Backgrid.Cell.extend({
module.exports = Backgrid.Cell.extend({
className : 'delete-episode-file-cell', className : 'delete-episode-file-cell',
events : {"click" : '_onClick'},
events: {
'click': '_onClick'
},
render : function(){ render : function(){
this.$el.empty(); this.$el.empty();
this.$el.html('<i class="icon-nd-delete"></i>'); this.$el.html('<i class="icon-nd-delete"></i>');
return this; return this;
}, },
_onClick : function(){ _onClick : function(){
var self = this; var self = this;
if(window.confirm('Are you sure you want to delete \'{0}\' from disk?'.format(this.model.get('path')))) { if(window.confirm('Are you sure you want to delete \'{0}\' from disk?'.format(this.model.get('path')))) {
this.model.destroy() this.model.destroy().done(function(){
.done(function () {
vent.trigger(vent.Events.EpisodeFileDeleted, {episodeFile : self.model}); vent.trigger(vent.Events.EpisodeFileDeleted, {episodeFile : self.model});
}); });
} }
} }
}); });
});

@ -1,59 +1,44 @@
'use strict'; var Backgrid = require('backgrid');
define( var Marionette = require('marionette');
[ var _ = require('underscore');
'backgrid', var ProfileSchemaCollection = require('../../Settings/Profile/ProfileSchemaCollection');
'marionette',
'underscore',
'Settings/Profile/ProfileSchemaCollection'
], function (Backgrid, Marionette, _, ProfileSchemaCollection) {
return Backgrid.CellEditor.extend({
module.exports = Backgrid.CellEditor.extend({
className : 'quality-cell-editor', className : 'quality-cell-editor',
template : 'Cells/Edit/QualityCellEditorTemplate', template : 'Cells/Edit/QualityCellEditorTemplate',
tagName : 'select', tagName : 'select',
events : { events : {
'change' : 'save', "change" : 'save',
'blur' : 'close', "blur" : 'close',
'keydown': 'close' "keydown" : 'close'
}, },
render : function(){ render : function(){
var self = this; var self = this;
var profileSchemaCollection = new ProfileSchemaCollection(); var profileSchemaCollection = new ProfileSchemaCollection();
var promise = profileSchemaCollection.fetch(); var promise = profileSchemaCollection.fetch();
promise.done(function(){ promise.done(function(){
var templateName = self.template; var templateName = self.template;
self.schema = profileSchemaCollection.first(); self.schema = profileSchemaCollection.first();
var selected = _.find(self.schema.get('items'), function(model){ var selected = _.find(self.schema.get('items'), function(model){
return model.quality.id === self.model.get(self.column.get('name')).quality.id; return model.quality.id === self.model.get(self.column.get('name')).quality.id;
}); });
if(selected) { if(selected) {
selected.quality.selected = true; selected.quality.selected = true;
} }
self.templateFunction = Marionette.TemplateCache.get(templateName); self.templateFunction = Marionette.TemplateCache.get(templateName);
var data = self.schema.toJSON(); var data = self.schema.toJSON();
var html = self.templateFunction(data); var html = self.templateFunction(data);
self.$el.html(html); self.$el.html(html);
}); });
return this; return this;
}, },
save : function(e){ save : function(e){
var model = this.model; var model = this.model;
var column = this.column; var column = this.column;
var selected = parseInt(this.$el.val(), 10); var selected = parseInt(this.$el.val(), 10);
var profileItem = _.find(this.schema.get('items'), function(model){ var profileItem = _.find(this.schema.get('items'), function(model){
return model.quality.id === selected; return model.quality.id === selected;
}); });
var newQuality = { var newQuality = {
quality : profileItem.quality, quality : profileItem.quality,
revision : { revision : {
@ -61,18 +46,14 @@ define(
real : 0 real : 0
} }
}; };
model.set(column.get('name'), newQuality); model.set(column.get('name'), newQuality);
model.save(); model.save();
model.trigger('backgrid:edited', model, column, new Backgrid.Command(e)); model.trigger('backgrid:edited', model, column, new Backgrid.Command(e));
}, },
close : function(e){ close : function(e){
var model = this.model; var model = this.model;
var column = this.column; var column = this.column;
var command = new Backgrid.Command(e); var command = new Backgrid.Command(e);
model.trigger('backgrid:edited', model, column, command); model.trigger('backgrid:edited', model, column, command);
} }
}); });
});

@ -1,28 +1,16 @@
'use strict'; var vent = require('../vent');
var NzbDroneCell = require('./NzbDroneCell');
define( var CommandController = require('../Commands/CommandController');
[
'vent',
'Cells/NzbDroneCell',
'Commands/CommandController'
], function (vent, NzbDroneCell, CommandController) {
return NzbDroneCell.extend({
module.exports = NzbDroneCell.extend({
className : 'episode-actions-cell', className : 'episode-actions-cell',
events : { events : {
'click .x-automatic-search' : '_automaticSearch', "click .x-automatic-search" : '_automaticSearch',
'click .x-manual-search' : '_manualSearch' "click .x-manual-search" : '_manualSearch'
}, },
render : function(){ render : function(){
this.$el.empty(); this.$el.empty();
this.$el.html('<i class="icon-search x-automatic-search" title="Automatic Search"></i>' + '<i class="icon-nd-manual-search x-manual-search" title="Manual Search"></i>');
this.$el.html(
'<i class="icon-search x-automatic-search" title="Automatic Search"></i>' +
'<i class="icon-nd-manual-search x-manual-search" title="Manual Search"></i>'
);
CommandController.bindToCommand({ CommandController.bindToCommand({
element : this.$el.find('.x-automatic-search'), element : this.$el.find('.x-automatic-search'),
command : { command : {
@ -30,20 +18,20 @@ define(
episodeIds : [this.model.get('id')] episodeIds : [this.model.get('id')]
} }
}); });
this.delegateEvents(); this.delegateEvents();
return this; return this;
}, },
_automaticSearch : function(){ _automaticSearch : function(){
CommandController.Execute('episodeSearch', { CommandController.Execute('episodeSearch', {
name : 'episodeSearch', name : 'episodeSearch',
episodeIds : [this.model.get('id')] episodeIds : [this.model.get('id')]
}); });
}, },
_manualSearch : function(){ _manualSearch : function(){
vent.trigger(vent.Commands.ShowEpisodeDetails, { episode: this.cellValue, hideSeriesLink: true, openingTab: 'search' }); vent.trigger(vent.Commands.ShowEpisodeDetails, {
} episode : this.cellValue,
hideSeriesLink : true,
openingTab : 'search'
}); });
}
}); });

@ -1,63 +1,42 @@
'use strict'; var _ = require('underscore');
var ToggleCell = require('./ToggleCell');
define( var SeriesCollection = require('../Series/SeriesCollection');
[ var Messenger = require('../Shared/Messenger');
'underscore',
'Cells/ToggleCell',
'Series/SeriesCollection',
'Shared/Messenger'
], function (_, ToggleCell, SeriesCollection, Messenger) {
return ToggleCell.extend({
module.exports = ToggleCell.extend({
className : 'toggle-cell episode-monitored', className : 'toggle-cell episode-monitored',
_originalOnClick : ToggleCell.prototype._onClick, _originalOnClick : ToggleCell.prototype._onClick,
_onClick : function(e){ _onClick : function(e){
var series = SeriesCollection.get(this.model.get('seriesId')); var series = SeriesCollection.get(this.model.get('seriesId'));
if(!series.get('monitored')) { if(!series.get('monitored')) {
Messenger.show({ Messenger.show({
message : 'Unable to change monitored state when series is not monitored', message : 'Unable to change monitored state when series is not monitored',
type : 'error' type : 'error'
}); });
return; return;
} }
if(e.shiftKey && this.model.episodeCollection.lastToggled) { if(e.shiftKey && this.model.episodeCollection.lastToggled) {
this._selectRange(); this._selectRange();
return; return;
} }
this._originalOnClick.apply(this, arguments); this._originalOnClick.apply(this, arguments);
this.model.episodeCollection.lastToggled = this.model; this.model.episodeCollection.lastToggled = this.model;
}, },
_selectRange : function(){ _selectRange : function(){
var episodeCollection = this.model.episodeCollection; var episodeCollection = this.model.episodeCollection;
var lastToggled = episodeCollection.lastToggled; var lastToggled = episodeCollection.lastToggled;
var currentIndex = episodeCollection.indexOf(this.model); var currentIndex = episodeCollection.indexOf(this.model);
var lastIndex = episodeCollection.indexOf(lastToggled); var lastIndex = episodeCollection.indexOf(lastToggled);
var low = Math.min(currentIndex, lastIndex); var low = Math.min(currentIndex, lastIndex);
var high = Math.max(currentIndex, lastIndex); var high = Math.max(currentIndex, lastIndex);
var range = _.range(low + 1, high); var range = _.range(low + 1, high);
_.each(range, function(index){ _.each(range, function(index){
var model = episodeCollection.at(index); var model = episodeCollection.at(index);
model.set('monitored', lastToggled.get('monitored')); model.set('monitored', lastToggled.get('monitored'));
model.save(); model.save();
}); });
this.model.set('monitored', lastToggled.get('monitored')); this.model.set('monitored', lastToggled.get('monitored'));
this.model.save(); this.model.save();
this.model.episodeCollection.lastToggled = undefined; this.model.episodeCollection.lastToggled = undefined;
} }
}); });
});

@ -1,55 +1,38 @@
'use strict'; var NzbDroneCell = require('./NzbDroneCell');
var FormatHelpers = require('../Shared/FormatHelpers');
define( var _ = require('underscore');
[
'Cells/NzbDroneCell',
'Shared/FormatHelpers',
'underscore'
], function (NzbDroneCell, FormatHelpers, _) {
return NzbDroneCell.extend({
module.exports = NzbDroneCell.extend({
className : 'episode-number-cell', className : 'episode-number-cell',
render : function(){ render : function(){
this.$el.empty(); this.$el.empty();
var airDateField = this.column.get('airDateUtc') || 'airDateUtc'; var airDateField = this.column.get('airDateUtc') || 'airDateUtc';
var seasonField = this.column.get('seasonNumber') || 'seasonNumber'; var seasonField = this.column.get('seasonNumber') || 'seasonNumber';
var episodeField = this.column.get('episodes') || 'episodeNumber'; var episodeField = this.column.get('episodes') || 'episodeNumber';
var absoluteEpisodeField = 'absoluteEpisodeNumber'; var absoluteEpisodeField = 'absoluteEpisodeNumber';
if(this.model) { if(this.model) {
var result = 'Unknown'; var result = 'Unknown';
var airDate = this.model.get(airDateField); var airDate = this.model.get(airDateField);
var seasonNumber = this.model.get(seasonField); var seasonNumber = this.model.get(seasonField);
var episodes = this.model.get(episodeField); var episodes = this.model.get(episodeField);
var absoluteEpisodeNumber = this.model.get(absoluteEpisodeField); var absoluteEpisodeNumber = this.model.get(absoluteEpisodeField);
if(this.cellValue) { if(this.cellValue) {
if(!seasonNumber) { if(!seasonNumber) {
seasonNumber = this.cellValue.get(seasonField); seasonNumber = this.cellValue.get(seasonField);
} }
if(!episodes) { if(!episodes) {
episodes = this.cellValue.get(episodeField); episodes = this.cellValue.get(episodeField);
} }
if(absoluteEpisodeNumber === undefined) { if(absoluteEpisodeNumber === undefined) {
absoluteEpisodeNumber = this.cellValue.get(absoluteEpisodeField); absoluteEpisodeNumber = this.cellValue.get(absoluteEpisodeField);
} }
if(!airDate) { if(!airDate) {
this.model.get(airDateField); this.model.get(airDateField);
} }
} }
if(episodes) { if(episodes) {
var paddedEpisodes; var paddedEpisodes;
var paddedAbsoluteEpisode; var paddedAbsoluteEpisode;
if(episodes.constructor === Array) { if(episodes.constructor === Array) {
paddedEpisodes = _.map(episodes, function(episodeNumber){ paddedEpisodes = _.map(episodes, function(episodeNumber){
return FormatHelpers.pad(episodeNumber, 2); return FormatHelpers.pad(episodeNumber, 2);
@ -59,9 +42,7 @@ define(
paddedEpisodes = FormatHelpers.pad(episodes, 2); paddedEpisodes = FormatHelpers.pad(episodes, 2);
paddedAbsoluteEpisode = FormatHelpers.pad(absoluteEpisodeNumber, 2); paddedAbsoluteEpisode = FormatHelpers.pad(absoluteEpisodeNumber, 2);
} }
result = '{0}x{1}'.format(seasonNumber, paddedEpisodes); result = '{0}x{1}'.format(seasonNumber, paddedEpisodes);
if(absoluteEpisodeNumber !== undefined && paddedAbsoluteEpisode) { if(absoluteEpisodeNumber !== undefined && paddedAbsoluteEpisode) {
result += ' ({0})'.format(paddedAbsoluteEpisode); result += ' ({0})'.format(paddedAbsoluteEpisode);
} }
@ -69,11 +50,9 @@ define(
else if(airDate) { else if(airDate) {
result = new Date(airDate).toLocaleDateString(); result = new Date(airDate).toLocaleDateString();
} }
this.$el.html(result); this.$el.html(result);
} }
this.delegateEvents(); this.delegateEvents();
return this; return this;
} }
}); });
});

@ -1,33 +1,21 @@
'use strict'; var Marionette = require('marionette');
var NzbDroneCell = require('./NzbDroneCell');
define( module.exports = NzbDroneCell.extend({
[
'marionette',
'Cells/NzbDroneCell'
], function (Marionette, NzbDroneCell) {
return NzbDroneCell.extend({
className : 'episode-progress-cell', className : 'episode-progress-cell',
template : 'Cells/EpisodeProgressCellTemplate', template : 'Cells/EpisodeProgressCellTemplate',
render : function(){ render : function(){
var episodeCount = this.model.get('episodeCount'); var episodeCount = this.model.get('episodeCount');
var episodeFileCount = this.model.get('episodeFileCount'); var episodeFileCount = this.model.get('episodeFileCount');
var percent = 100; var percent = 100;
if(episodeCount > 0) { if(episodeCount > 0) {
percent = episodeFileCount / episodeCount * 100; percent = episodeFileCount / episodeCount * 100;
} }
this.model.set('percentOfEpisodes', percent); this.model.set('percentOfEpisodes', percent);
this.templateFunction = Marionette.TemplateCache.get(this.template); this.templateFunction = Marionette.TemplateCache.get(this.template);
var data = this.model.toJSON(); var data = this.model.toJSON();
var html = this.templateFunction(data); var html = this.templateFunction(data);
this.$el.html(html); this.$el.html(html);
return this; return this;
} }
}); });
});

@ -1,101 +1,72 @@
'use strict'; var reqres = require('../reqres');
var Backbone = require('backbone');
define( var NzbDroneCell = require('./NzbDroneCell');
[ var QueueCollection = require('../Activity/Queue/QueueCollection');
'reqres', var moment = require('moment');
'backbone', var FormatHelpers = require('../Shared/FormatHelpers');
'Cells/NzbDroneCell',
'Activity/Queue/QueueCollection', module.exports = NzbDroneCell.extend({
'moment',
'Shared/FormatHelpers'
], function (reqres, Backbone, NzbDroneCell, QueueCollection, moment, FormatHelpers) {
return NzbDroneCell.extend({
className : 'episode-status-cell', className : 'episode-status-cell',
render : function(){ render : function(){
this.listenTo(QueueCollection, 'sync', this._renderCell); this.listenTo(QueueCollection, 'sync', this._renderCell);
this._renderCell(); this._renderCell();
return this; return this;
}, },
_renderCell : function(){ _renderCell : function(){
if(this.episodeFile) { if(this.episodeFile) {
this.stopListening(this.episodeFile, 'change', this._refresh); this.stopListening(this.episodeFile, 'change', this._refresh);
} }
this.$el.empty(); this.$el.empty();
if(this.model) { if(this.model) {
var icon; var icon;
var tooltip; var tooltip;
var hasAired = moment(this.model.get('airDateUtc')).isBefore(moment()); var hasAired = moment(this.model.get('airDateUtc')).isBefore(moment());
this.episodeFile = this._getFile(); this.episodeFile = this._getFile();
if(this.episodeFile) { if(this.episodeFile) {
this.listenTo(this.episodeFile, 'change', this._refresh); this.listenTo(this.episodeFile, 'change', this._refresh);
var quality = this.episodeFile.get('quality'); var quality = this.episodeFile.get('quality');
var revision = quality.revision; var revision = quality.revision;
var size = FormatHelpers.bytes(this.episodeFile.get('size')); var size = FormatHelpers.bytes(this.episodeFile.get('size'));
var title = 'Episode downloaded'; var title = 'Episode downloaded';
if(revision.real && revision.real > 0) { if(revision.real && revision.real > 0) {
title += '[REAL]'; title += '[REAL]';
} }
if(revision.version && revision.version > 1) { if(revision.version && revision.version > 1) {
title += ' [PROPER]'; title += ' [PROPER]';
} }
if(size !== '') { if(size !== '') {
title += ' - {0}'.format(size); title += ' - {0}'.format(size);
} }
if(this.episodeFile.get('qualityCutoffNotMet')) { if(this.episodeFile.get('qualityCutoffNotMet')) {
this.$el.html('<span class="badge badge-inverse" title="{0}">{1}</span>'.format(title, quality.quality.name)); this.$el.html('<span class="badge badge-inverse" title="{0}">{1}</span>'.format(title, quality.quality.name));
} }
else { else {
this.$el.html('<span class="badge" title="{0}">{1}</span>'.format(title, quality.quality.name)); this.$el.html('<span class="badge" title="{0}">{1}</span>'.format(title, quality.quality.name));
} }
return; return;
} }
else { else {
var model = this.model; var model = this.model;
var downloading = QueueCollection.findEpisode(model.get('id')); var downloading = QueueCollection.findEpisode(model.get('id'));
if(downloading) { if(downloading) {
var progress = 100 - (downloading.get('sizeleft') / downloading.get('size') * 100); var progress = 100 - downloading.get('sizeleft') / downloading.get('size') * 100;
if(progress === 0) { if(progress === 0) {
icon = 'icon-nd-downloading'; icon = 'icon-nd-downloading';
tooltip = 'Episode is downloading'; tooltip = 'Episode is downloading';
} }
else { else {
this.$el.html('<div class="progress" title="Episode is downloading - {0}% {1}">'.format(progress.toFixed(1), downloading.get('title')) + this.$el.html('<div class="progress" title="Episode is downloading - {0}% {1}">'.format(progress.toFixed(1), downloading.get('title')) + '<div class="progress-bar progress-bar-purple" style="width: {0}%;"></div></div>'.format(progress));
'<div class="progress-bar progress-bar-purple" style="width: {0}%;"></div></div>'.format(progress));
return; return;
} }
} }
else if(this.model.get('grabbed')) { else if(this.model.get('grabbed')) {
icon = 'icon-nd-downloading'; icon = 'icon-nd-downloading';
tooltip = 'Episode is downloading'; tooltip = 'Episode is downloading';
} }
else if(!this.model.get('airDateUtc')) { else if(!this.model.get('airDateUtc')) {
icon = 'icon-nd-tba'; icon = 'icon-nd-tba';
tooltip = 'TBA'; tooltip = 'TBA';
} }
else if(hasAired) { else if(hasAired) {
icon = 'icon-nd-missing'; icon = 'icon-nd-missing';
tooltip = 'Episode missing from disk'; tooltip = 'Episode missing from disk';
@ -105,31 +76,23 @@ define(
tooltip = 'Episode has not aired'; tooltip = 'Episode has not aired';
} }
} }
this.$el.html('<i class="{0}" title="{1}"/>'.format(icon, tooltip)); this.$el.html('<i class="{0}" title="{1}"/>'.format(icon, tooltip));
} }
}, },
_getFile : function(){ _getFile : function(){
var hasFile = this.model.get('hasFile'); var hasFile = this.model.get('hasFile');
if(hasFile) { if(hasFile) {
var episodeFile; var episodeFile;
if(reqres.hasHandler(reqres.Requests.GetEpisodeFileById)) { if(reqres.hasHandler(reqres.Requests.GetEpisodeFileById)) {
episodeFile = reqres.request(reqres.Requests.GetEpisodeFileById, this.model.get('episodeFileId')); episodeFile = reqres.request(reqres.Requests.GetEpisodeFileById, this.model.get('episodeFileId'));
} }
else if(this.model.has('episodeFile')) { else if(this.model.has('episodeFile')) {
episodeFile = new Backbone.Model(this.model.get('episodeFile')); episodeFile = new Backbone.Model(this.model.get('episodeFile'));
} }
if(episodeFile) { if(episodeFile) {
return episodeFile; return episodeFile;
} }
} }
return undefined; return undefined;
} }
}); });
});

@ -1,33 +1,22 @@
'use strict'; var vent = require('../vent');
var NzbDroneCell = require('./NzbDroneCell');
define(
[
'vent',
'Cells/NzbDroneCell'
], function (vent, NzbDroneCell) {
return NzbDroneCell.extend({
module.exports = NzbDroneCell.extend({
className : 'episode-title-cell', className : 'episode-title-cell',
events : {"click" : '_showDetails'},
events: {
'click': '_showDetails'
},
render : function(){ render : function(){
var title = this.cellValue.get('title'); var title = this.cellValue.get('title');
if(!title || title === '') { if(!title || title === '') {
title = 'TBA'; title = 'TBA';
} }
this.$el.html(title); this.$el.html(title);
return this; return this;
}, },
_showDetails : function(){ _showDetails : function(){
var hideSeriesLink = this.column.get('hideSeriesLink'); var hideSeriesLink = this.column.get('hideSeriesLink');
vent.trigger(vent.Commands.ShowEpisodeDetails, {
vent.trigger(vent.Commands.ShowEpisodeDetails, { episode: this.cellValue, hideSeriesLink: hideSeriesLink }); episode : this.cellValue,
} hideSeriesLink : hideSeriesLink
}); });
}
}); });

@ -1,21 +1,12 @@
'use strict'; var NzbDroneCell = require('./NzbDroneCell');
define(
[
'Cells/NzbDroneCell'
], function (NzbDroneCell) {
return NzbDroneCell.extend({
module.exports = NzbDroneCell.extend({
className : 'history-event-type-cell', className : 'history-event-type-cell',
render : function(){ render : function(){
this.$el.empty(); this.$el.empty();
if(this.cellValue) { if(this.cellValue) {
var icon; var icon;
var toolTip; var toolTip;
switch (this.cellValue.get('eventType')) { switch (this.cellValue.get('eventType')) {
case 'grabbed': case 'grabbed':
icon = 'icon-nd-downloading'; icon = 'icon-nd-downloading';
@ -40,13 +31,9 @@ define(
default: default:
icon = 'icon-question'; icon = 'icon-question';
toolTip = 'unknown event'; toolTip = 'unknown event';
} }
this.$el.html('<i class="{0}" title="{1}" data-placement="right"/>'.format(icon, toolTip)); this.$el.html('<i class="{0}" title="{1}" data-placement="right"/>'.format(icon, toolTip));
} }
return this; return this;
} }
}); });
});

@ -1,14 +1,8 @@
'use strict'; var Backgrid = require('backgrid');
var FormatHelpers = require('../Shared/FormatHelpers');
define(
[
'backgrid',
'Shared/FormatHelpers'
], function (Backgrid, FormatHelpers) {
return Backgrid.Cell.extend({
module.exports = Backgrid.Cell.extend({
className : 'file-size-cell', className : 'file-size-cell',
render : function(){ render : function(){
var size = this.model.get(this.column.get('name')); var size = this.model.get(this.column.get('name'));
this.$el.html(FormatHelpers.bytes(size)); this.$el.html(FormatHelpers.bytes(size));
@ -16,4 +10,3 @@ define(
return this; return this;
} }
}); });
});

@ -1,16 +1,10 @@
'use strict'; var Backgrid = require('backgrid');
define(
[
'backgrid'
], function (Backgrid) {
return Backgrid.Cell.extend({
module.exports = Backgrid.Cell.extend({
className : 'indexer-cell', className : 'indexer-cell',
render : function(){ render : function(){
var indexer = this.model.get(this.column.get('name')); var indexer = this.model.get(this.column.get('name'));
this.$el.html(indexer); this.$el.html(indexer);
return this; return this;
} }
}); });
});

@ -1,20 +1,12 @@
'use strict'; var Backgrid = require('backgrid');
var Backbone = require('backbone');
define(
[
'backgrid',
'backbone'
], function (Backgrid, Backbone) {
return Backgrid.Cell.extend({
module.exports = Backgrid.Cell.extend({
_originalInit : Backgrid.Cell.prototype.initialize, _originalInit : Backgrid.Cell.prototype.initialize,
initialize : function(){ initialize : function(){
this._originalInit.apply(this, arguments); this._originalInit.apply(this, arguments);
this.cellValue = this._getValue(); this.cellValue = this._getValue();
this.listenTo(this.model, 'change', this._refresh); this.listenTo(this.model, 'change', this._refresh);
if(this._onEdit) { if(this._onEdit) {
this.listenTo(this.model, 'backgrid:edit', function(model, column, cell, editor){ this.listenTo(this.model, 'backgrid:edit', function(model, column, cell, editor){
if(column.get('name') === this.column.get('name')) { if(column.get('name') === this.column.get('name')) {
@ -23,41 +15,28 @@ define(
}); });
} }
}, },
_refresh : function(){ _refresh : function(){
this.cellValue = this._getValue(); this.cellValue = this._getValue();
this.render(); this.render();
}, },
_getValue : function(){ _getValue : function(){
var cellValue = this.column.get('cellValue'); var cellValue = this.column.get('cellValue');
if(cellValue) { if(cellValue) {
if(cellValue === 'this') { if(cellValue === 'this') {
return this.model; return this.model;
} }
} }
var name = this.column.get('name'); var name = this.column.get('name');
if(name === 'this') { if(name === 'this') {
return this.model; return this.model;
} }
var value = this.model.get(name); var value = this.model.get(name);
if(!value) { if(!value) {
return undefined; return undefined;
} }
//if not a model
if(!value.get && typeof value === 'object') { if(!value.get && typeof value === 'object') {
value = new Backbone.Model(value); value = new Backbone.Model(value);
} }
return value; return value;
} }
});
}); });

@ -1,25 +1,16 @@
'use strict'; var Backgrid = require('backgrid');
define( var ProfileCollection = require('../Profile/ProfileCollection');
[ var _ = require('underscore');
'backgrid',
'Profile/ProfileCollection',
'underscore'
], function (Backgrid, ProfileCollection,_) {
return Backgrid.Cell.extend({
className: 'profile-cell',
module.exports = Backgrid.Cell.extend({
className : 'profile-cell',
render : function(){ render : function(){
this.$el.empty(); this.$el.empty();
var profileId = this.model.get(this.column.get('name')); var profileId = this.model.get(this.column.get('name'));
var profile = _.findWhere(ProfileCollection.models, {id : profileId}); var profile = _.findWhere(ProfileCollection.models, {id : profileId});
if(profile) { if(profile) {
this.$el.html(profile.get('name')); this.$el.html(profile.get('name'));
} }
return this; return this;
} }
}); });
});

@ -1,13 +1,8 @@
'use strict'; var TemplatedCell = require('./TemplatedCell');
define( var QualityCellEditor = require('./Edit/QualityCellEditor');
[
'Cells/TemplatedCell',
'Cells/Edit/QualityCellEditor'
], function (TemplatedCell, QualityCellEditor) {
return TemplatedCell.extend({
module.exports = TemplatedCell.extend({
className : 'quality-cell', className : 'quality-cell',
template : 'Cells/QualityCellTemplate', template : 'Cells/QualityCellTemplate',
editor : QualityCellEditor editor : QualityCellEditor
}); });
});

@ -1,37 +1,25 @@
'use strict'; var NzbDroneCell = require('./NzbDroneCell');
define( var moment = require('moment');
[ var FormatHelpers = require('../Shared/FormatHelpers');
'Cells/NzbDroneCell', var UiSettings = require('../Shared/UiSettingsModel');
'moment',
'Shared/FormatHelpers',
'Shared/UiSettingsModel'
], function (NzbDroneCell, moment, FormatHelpers, UiSettings) {
return NzbDroneCell.extend({
module.exports = NzbDroneCell.extend({
className : 'relative-date-cell', className : 'relative-date-cell',
render : function(){ render : function(){
var dateStr = this.model.get(this.column.get('name')); var dateStr = this.model.get(this.column.get('name'));
if(dateStr) { if(dateStr) {
var date = moment(dateStr); var date = moment(dateStr);
var result = '<span title="{0}">{1}</span>'; var result = '<span title="{0}">{1}</span>';
var tooltip = date.format(UiSettings.longDateTime()); var tooltip = date.format(UiSettings.longDateTime());
var text; var text;
if(UiSettings.get('showRelativeDates')) { if(UiSettings.get('showRelativeDates')) {
text = FormatHelpers.relativeDate(dateStr); text = FormatHelpers.relativeDate(dateStr);
} }
else { else {
text = date.format(UiSettings.get('shortDateFormat')); text = date.format(UiSettings.get('shortDateFormat'));
} }
this.$el.html(result.format(tooltip, text)); this.$el.html(result.format(tooltip, text));
} }
return this; return this;
} }
}); });
});

@ -1,37 +1,25 @@
'use strict'; var NzbDroneCell = require('./NzbDroneCell');
define( var moment = require('moment');
[ var FormatHelpers = require('../Shared/FormatHelpers');
'Cells/NzbDroneCell', var UiSettings = require('../Shared/UiSettingsModel');
'moment',
'Shared/FormatHelpers',
'Shared/UiSettingsModel'
], function (NzbDroneCell, moment, FormatHelpers, UiSettings) {
return NzbDroneCell.extend({
module.exports = NzbDroneCell.extend({
className : 'relative-time-cell', className : 'relative-time-cell',
render : function(){ render : function(){
var dateStr = this.model.get(this.column.get('name')); var dateStr = this.model.get(this.column.get('name'));
if(dateStr) { if(dateStr) {
var date = moment(dateStr); var date = moment(dateStr);
var result = '<span title="{0}">{1}</span>'; var result = '<span title="{0}">{1}</span>';
var tooltip = date.format(UiSettings.longDateTime()); var tooltip = date.format(UiSettings.longDateTime());
var text; var text;
if(UiSettings.get('showRelativeDates')) { if(UiSettings.get('showRelativeDates')) {
text = date.fromNow(); text = date.fromNow();
} }
else { else {
text = date.format(UiSettings.shortDateTime()); text = date.format(UiSettings.shortDateTime());
} }
this.$el.html(result.format(tooltip, text)); this.$el.html(result.format(tooltip, text));
} }
return this; return this;
} }
}); });
});

@ -1,28 +1,17 @@
'use strict'; var NzbDroneCell = require('./NzbDroneCell');
define(
[
'Cells/NzbDroneCell'
], function (NzbDroneCell) {
return NzbDroneCell.extend({
module.exports = NzbDroneCell.extend({
className : 'release-title-cell', className : 'release-title-cell',
render : function(){ render : function(){
this.$el.empty(); this.$el.empty();
var title = this.model.get('title'); var title = this.model.get('title');
var infoUrl = this.model.get('infoUrl'); var infoUrl = this.model.get('infoUrl');
if(infoUrl) { if(infoUrl) {
this.$el.html('<a href="{0}">{1}</a>'.format(infoUrl, title)); this.$el.html('<a href="{0}">{1}</a>'.format(infoUrl, title));
} }
else { else {
this.$el.html(title); this.$el.html(title);
} }
return this; return this;
} }
}); });
});

@ -1,19 +1,11 @@
'use strict'; var Backgrid = require('backgrid');
define(
[
'backgrid'
], function (Backgrid) {
return Backgrid.Cell.extend({
module.exports = Backgrid.Cell.extend({
className : 'season-folder-cell', className : 'season-folder-cell',
render : function(){ render : function(){
this.$el.empty(); this.$el.empty();
var seasonFolder = this.model.get(this.column.get('name')); var seasonFolder = this.model.get(this.column.get('name'));
this.$el.html(seasonFolder.toString()); this.$el.html(seasonFolder.toString());
return this; return this;
} }
}); });
});

@ -1,49 +1,35 @@
'use strict'; var $ = require('jquery');
define( var _ = require('underscore');
[ var BackgridSelectAll = require('backgrid.selectall');
'jquery',
'underscore',
'backgrid.selectall'
], function ($, _, BackgridSelectAll) {
return BackgridSelectAll.extend({
module.exports = BackgridSelectAll.extend({
enterEditMode : function(e){ enterEditMode : function(e){
if(e.shiftKey && this.model.collection.lastToggled) { if(e.shiftKey && this.model.collection.lastToggled) {
this._selectRange(); this._selectRange();
} }
var checked = $(e.target).prop('checked'); var checked = $(e.target).prop('checked');
this.model.collection.lastToggled = this.model; this.model.collection.lastToggled = this.model;
this.model.collection.checked = checked; this.model.collection.checked = checked;
}, },
onChange : function(e){ onChange : function(e){
var checked = $(e.target).prop('checked'); var checked = $(e.target).prop('checked');
this.$el.parent().toggleClass('selected', checked); this.$el.parent().toggleClass('selected', checked);
this.model.trigger('backgrid:selected', this.model, checked); this.model.trigger('backgrid:selected', this.model, checked);
}, },
_selectRange : function(){ _selectRange : function(){
var collection = this.model.collection; var collection = this.model.collection;
var lastToggled = collection.lastToggled; var lastToggled = collection.lastToggled;
var checked = collection.checked; var checked = collection.checked;
var currentIndex = collection.indexOf(this.model); var currentIndex = collection.indexOf(this.model);
var lastIndex = collection.indexOf(lastToggled); var lastIndex = collection.indexOf(lastToggled);
var low = Math.min(currentIndex, lastIndex); var low = Math.min(currentIndex, lastIndex);
var high = Math.max(currentIndex, lastIndex); var high = Math.max(currentIndex, lastIndex);
var range = _.range(low + 1, high); var range = _.range(low + 1, high);
_.each(range, function(index){ _.each(range, function(index){
var model = collection.at(index); var model = collection.at(index);
model.trigger('backgrid:select', model, checked); model.trigger('backgrid:select', model, checked);
}); });
this.model.collection.lastToggled = undefined; this.model.collection.lastToggled = undefined;
this.model.collection.checked = undefined; this.model.collection.checked = undefined;
} }
}); });
});

@ -1,32 +1,17 @@
'use strict'; var vent = require('../vent');
var NzbDroneCell = require('./NzbDroneCell');
define( var CommandController = require('../Commands/CommandController');
[
'vent',
'Cells/NzbDroneCell',
'Commands/CommandController'
], function (vent, NzbDroneCell, CommandController) {
return NzbDroneCell.extend({
module.exports = NzbDroneCell.extend({
className : 'series-actions-cell', className : 'series-actions-cell',
ui : {refresh : '.x-refresh'},
ui: {
refresh: '.x-refresh'
},
events : { events : {
'click .x-edit' : '_editSeries', "click .x-edit" : '_editSeries',
'click .x-refresh' : '_refreshSeries' "click .x-refresh" : '_refreshSeries'
}, },
render : function(){ render : function(){
this.$el.empty(); this.$el.empty();
this.$el.html('<i class="icon-refresh x-refresh hidden-xs" title="" data-original-title="Update series info and scan disk"></i> ' + '<i class="icon-nd-edit x-edit" title="" data-original-title="Edit Series"></i>');
this.$el.html(
'<i class="icon-refresh x-refresh hidden-xs" title="" data-original-title="Update series info and scan disk"></i> ' +
'<i class="icon-nd-edit x-edit" title="" data-original-title="Edit Series"></i>'
);
CommandController.bindToCommand({ CommandController.bindToCommand({
element : this.$el.find('.x-refresh'), element : this.$el.find('.x-refresh'),
command : { command : {
@ -34,15 +19,12 @@ define(
seriesId : this.model.get('id') seriesId : this.model.get('id')
} }
}); });
this.delegateEvents(); this.delegateEvents();
return this; return this;
}, },
_editSeries : function(){ _editSeries : function(){
vent.trigger(vent.Commands.EditSeriesCommand, {series : this.model}); vent.trigger(vent.Commands.EditSeriesCommand, {series : this.model});
}, },
_refreshSeries : function(){ _refreshSeries : function(){
CommandController.Execute('refreshSeries', { CommandController.Execute('refreshSeries', {
name : 'refreshSeries', name : 'refreshSeries',
@ -50,4 +32,3 @@ define(
}); });
} }
}); });
});

@ -1,36 +1,26 @@
'use strict'; var NzbDroneCell = require('./NzbDroneCell');
define(
[
'Cells/NzbDroneCell'
], function (NzbDroneCell) {
return NzbDroneCell.extend({
className: 'series-status-cell',
module.exports = NzbDroneCell.extend({
className : 'series-status-cell',
render : function(){ render : function(){
this.$el.empty(); this.$el.empty();
var monitored = this.model.get('monitored'); var monitored = this.model.get('monitored');
var status = this.model.get('status'); var status = this.model.get('status');
if(status === 'ended') { if(status === 'ended') {
this.$el.html('<i class="icon-stop grid-icon" title="Ended"></i>'); this.$el.html('<i class="icon-stop grid-icon" title="Ended"></i>');
this._setStatusWeight(3); this._setStatusWeight(3);
} }
else if(!monitored) { else if(!monitored) {
this.$el.html('<i class="icon-pause grid-icon" title="Not Monitored"></i>'); this.$el.html('<i class="icon-pause grid-icon" title="Not Monitored"></i>');
this._setStatusWeight(2); this._setStatusWeight(2);
} }
else { else {
this.$el.html('<i class="icon-play grid-icon" title="Continuing"></i>'); this.$el.html('<i class="icon-play grid-icon" title="Continuing"></i>');
this._setStatusWeight(1); this._setStatusWeight(1);
} }
return this; return this;
}, },
_setStatusWeight : function(weight){ _setStatusWeight : function(weight){
this.model.set('statusWeight', weight, {silent : true}); this.model.set('statusWeight', weight, {silent : true});
} }
}); });
});

@ -1,12 +1,6 @@
'use strict'; var TemplatedCell = require('./TemplatedCell');
define(
[
'Cells/TemplatedCell'
], function (TemplatedCell) {
return TemplatedCell.extend({
module.exports = TemplatedCell.extend({
className : 'series-title-cell', className : 'series-title-cell',
template : 'Cells/SeriesTitleTemplate' template : 'Cells/SeriesTitleTemplate'
});
}); });

@ -1,23 +1,14 @@
'use strict'; var Marionette = require('marionette');
var NzbDroneCell = require('./NzbDroneCell');
define(
[
'marionette',
'Cells/NzbDroneCell'
], function (Marionette, NzbDroneCell) {
return NzbDroneCell.extend({
module.exports = NzbDroneCell.extend({
render : function(){ render : function(){
var templateName = this.column.get('template') || this.template; var templateName = this.column.get('template') || this.template;
this.templateFunction = Marionette.TemplateCache.get(templateName); this.templateFunction = Marionette.TemplateCache.get(templateName);
var data = this.cellValue.toJSON(); var data = this.cellValue.toJSON();
var html = this.templateFunction(data); var html = this.templateFunction(data);
this.$el.html(html); this.$el.html(html);
this.delegateEvents(); this.delegateEvents();
return this; return this;
} }
}); });
});

@ -1,53 +1,32 @@
'use strict'; var Backgrid = require('backgrid');
define(
[
'backgrid'
], function (Backgrid) {
return Backgrid.Cell.extend({
module.exports = Backgrid.Cell.extend({
className : 'toggle-cell', className : 'toggle-cell',
events : {"click" : '_onClick'},
events: {
'click': '_onClick'
},
_onClick : function(){ _onClick : function(){
var self = this; var self = this;
this.$el.tooltip('hide'); this.$el.tooltip('hide');
var name = this.column.get('name'); var name = this.column.get('name');
this.model.set(name, !this.model.get(name)); this.model.set(name, !this.model.get(name));
this.$('i').addClass('icon-spinner icon-spin'); this.$('i').addClass('icon-spinner icon-spin');
this.model.save().always(function(){ this.model.save().always(function(){
self.render(); self.render();
}); });
}, },
render : function(){ render : function(){
this.$el.empty(); this.$el.empty();
this.$el.html('<i />'); this.$el.html('<i />');
var name = this.column.get('name'); var name = this.column.get('name');
if(this.model.get(name)) { if(this.model.get(name)) {
this.$('i').addClass(this.column.get('trueClass')); this.$('i').addClass(this.column.get('trueClass'));
} }
else { else {
this.$('i').addClass(this.column.get('falseClass')); this.$('i').addClass(this.column.get('falseClass'));
} }
var tooltip = this.column.get('tooltip'); var tooltip = this.column.get('tooltip');
if(tooltip) { if(tooltip) {
this.$('i').attr('title', tooltip); this.$('i').attr('title', tooltip);
} }
return this; return this;
} }
}); });
});

@ -1,26 +1,18 @@
'use strict'; var Backbone = require('backbone');
define( var CommandModel = require('./CommandModel');
[ require('../Mixins/backbone.signalr.mixin');
'backbone',
'Commands/CommandModel',
'Mixins/backbone.signalr.mixin'
], function (Backbone, CommandModel) {
module.exports = (function(){
var CommandCollection = Backbone.Collection.extend({ var CommandCollection = Backbone.Collection.extend({
url : window.NzbDrone.ApiRoot + '/command', url : window.NzbDrone.ApiRoot + '/command',
model : CommandModel, model : CommandModel,
findCommand : function(command){ findCommand : function(command){
return this.find(function(model){ return this.find(function(model){
return model.isSameCommand(command); return model.isSameCommand(command);
}); });
} }
}); });
var collection = new CommandCollection().bindSignalR(); var collection = new CommandCollection().bindSignalR();
collection.fetch(); collection.fetch();
return collection; return collection;
}); }).call(this);

@ -1,69 +1,49 @@
'use strict'; var vent = require('../vent');
define( var CommandModel = require('./CommandModel');
[ var CommandCollection = require('./CommandCollection');
'vent', var CommandMessengerCollectionView = require('./CommandMessengerCollectionView');
'Commands/CommandModel', var _ = require('underscore');
'Commands/CommandCollection', var moment = require('moment');
'Commands/CommandMessengerCollectionView', var Messenger = require('../Shared/Messenger');
'underscore', require('../jQuery/jquery.spin');
'moment',
'Shared/Messenger', module.exports = (function(){
'jQuery/jquery.spin'
], function (vent, CommandModel, CommandCollection, CommandMessengerCollectionView, _, moment, Messenger) {
CommandMessengerCollectionView.render(); CommandMessengerCollectionView.render();
var singleton = function(){ var singleton = function(){
return { return {
_lastCommand : {}, _lastCommand : {},
Execute : function(name, properties){ Execute : function(name, properties){
var attr = _.extend({name : name.toLocaleLowerCase()}, properties); var attr = _.extend({name : name.toLocaleLowerCase()}, properties);
var commandModel = new CommandModel(attr); var commandModel = new CommandModel(attr);
if(this._lastCommand.command && this._lastCommand.command.isSameCommand(attr) && moment().add('seconds', -5).isBefore(this._lastCommand.time)) { if(this._lastCommand.command && this._lastCommand.command.isSameCommand(attr) && moment().add('seconds', -5).isBefore(this._lastCommand.time)) {
Messenger.show({ Messenger.show({
message : 'Please wait at least 5 seconds before running this command again', message : 'Please wait at least 5 seconds before running this command again',
hideAfter : 5, hideAfter : 5,
type : 'error' type : 'error'
}); });
return this._lastCommand.promise; return this._lastCommand.promise;
} }
var promise = commandModel.save().success(function(){ var promise = commandModel.save().success(function(){
CommandCollection.add(commandModel); CommandCollection.add(commandModel);
}); });
this._lastCommand = { this._lastCommand = {
command : commandModel, command : commandModel,
promise : promise, promise : promise,
time : moment() time : moment()
}; };
return promise; return promise;
}, },
bindToCommand : function(options){ bindToCommand : function(options){
var self = this; var self = this;
var existingCommand = CommandCollection.findCommand(options.command); var existingCommand = CommandCollection.findCommand(options.command);
if(existingCommand) { if(existingCommand) {
this._bindToCommandModel.call(this, existingCommand, options); this._bindToCommandModel.call(this, existingCommand, options);
} }
CommandCollection.bind('add', function(model){ CommandCollection.bind('add', function(model){
if(model.isSameCommand(options.command)) { if(model.isSameCommand(options.command)) {
self._bindToCommandModel.call(self, model, options); self._bindToCommandModel.call(self, model, options);
} }
}); });
CommandCollection.bind('sync', function(){ CommandCollection.bind('sync', function(){
var command = CommandCollection.findCommand(options.command); var command = CommandCollection.findCommand(options.command);
if(command) { if(command) {
@ -71,28 +51,25 @@ define(
} }
}); });
}, },
_bindToCommandModel : function bindToCommand (model, options){ _bindToCommandModel : function bindToCommand (model, options){
if(!model.isActive()) { if(!model.isActive()) {
options.element.stopSpin(); options.element.stopSpin();
return; return;
} }
model.bind('change:state', function(model){ model.bind('change:state', function(model){
if(!model.isActive()) { if(!model.isActive()) {
options.element.stopSpin(); options.element.stopSpin();
if(model.isComplete()) { if(model.isComplete()) {
vent.trigger(vent.Events.CommandComplete, { command: model, model: options.model }); vent.trigger(vent.Events.CommandComplete, {
command : model,
model : options.model
});
} }
} }
}); });
options.element.startSpin(); options.element.startSpin();
} }
}; };
}; };
return singleton(); return singleton();
}); }).call(this);

@ -1,14 +1,8 @@
'use strict'; var Marionette = require('marionette');
define( var commandCollection = require('./CommandCollection');
[ var CommandMessengerItemView = require('./CommandMessengerItemView');
'marionette',
'Commands/CommandCollection',
'Commands/CommandMessengerItemView'
], function (Marionette, commandCollection, CommandMessengerItemView) {
var CollectionView = Marionette.CollectionView.extend({
itemView: CommandMessengerItemView
});
module.exports = (function(){
var CollectionView = Marionette.CollectionView.extend({itemView : CommandMessengerItemView});
return new CollectionView({collection : commandCollection}); return new CollectionView({collection : commandCollection});
}); }).call(this);

@ -1,28 +1,20 @@
'use strict'; var Marionette = require('marionette');
define( var Messenger = require('../Shared/Messenger');
[
'marionette',
'Shared/Messenger'
], function ( Marionette, Messenger) {
return Marionette.ItemView.extend({
module.exports = Marionette.ItemView.extend({
initialize : function(){ initialize : function(){
this.listenTo(this.model, 'change', this.render); this.listenTo(this.model, 'change', this.render);
}, },
render : function(){ render : function(){
if(!this.model.get('message') || !this.model.get('sendUpdatesToClient')) { if(!this.model.get('message') || !this.model.get('sendUpdatesToClient')) {
return; return;
} }
var message = { var message = {
type : 'info', type : 'info',
message : '[{0}] {1}'.format(this.model.get('name'), this.model.get('message')), message : '[{0}] {1}'.format(this.model.get('name'), this.model.get('message')),
id : this.model.id, id : this.model.id,
hideAfter : 0 hideAfter : 0
}; };
switch (this.model.get('state')) { switch (this.model.get('state')) {
case 'completed': case 'completed':
message.hideAfter = 4; message.hideAfter = 4;
@ -34,18 +26,12 @@ define(
default: default:
message.hideAfter = 0; message.hideAfter = 0;
} }
if(this.messenger) { if(this.messenger) {
this.messenger.update(message); this.messenger.update(message);
} }
else { else {
this.messenger = Messenger.show(message); this.messenger = Messenger.show(message);
} }
console.log(message.message); console.log(message.message);
} }
});
}); });

@ -1,23 +1,16 @@
'use strict'; var _ = require('underscore');
define( var Backbone = require('backbone');
[
'underscore',
'backbone'
], function (_, Backbone) {
return Backbone.Model.extend({
url: window.NzbDrone.ApiRoot + '/command',
module.exports = Backbone.Model.extend({
url : window.NzbDrone.ApiRoot + '/command',
parse : function(response){ parse : function(response){
response.name = response.name.toLocaleLowerCase(); response.name = response.name.toLocaleLowerCase();
return response; return response;
}, },
isSameCommand : function(command){ isSameCommand : function(command){
if(command.name.toLocaleLowerCase() !== this.get('name').toLocaleLowerCase()) { if(command.name.toLocaleLowerCase() !== this.get('name').toLocaleLowerCase()) {
return false; return false;
} }
for (var key in command) { for (var key in command) {
if(key !== 'name') { if(key !== 'name') {
if(Array.isArray(command[key])) { if(Array.isArray(command[key])) {
@ -25,22 +18,17 @@ define(
return false; return false;
} }
} }
else if(command[key] !== this.get(key)) { else if(command[key] !== this.get(key)) {
return false; return false;
} }
} }
} }
return true; return true;
}, },
isActive : function(){ isActive : function(){
return this.get('state') !== 'completed' && this.get('state') !== 'failed'; return this.get('state') !== 'completed' && this.get('state') !== 'failed';
}, },
isComplete : function(){ isComplete : function(){
return this.get('state') === 'completed'; return this.get('state') === 'completed';
} }
}); });
});

@ -1,77 +1,51 @@
'use strict'; var NzbDroneController = require('./Shared/NzbDroneController');
define( var AppLayout = require('./AppLayout');
[ var Marionette = require('marionette');
'Shared/NzbDroneController', var ActivityLayout = require('./Activity/ActivityLayout');
'AppLayout', var SettingsLayout = require('./Settings/SettingsLayout');
'marionette', var AddSeriesLayout = require('./AddSeries/AddSeriesLayout');
'Activity/ActivityLayout', var WantedLayout = require('./Wanted/WantedLayout');
'Settings/SettingsLayout', var CalendarLayout = require('./Calendar/CalendarLayout');
'AddSeries/AddSeriesLayout', var ReleaseLayout = require('./Release/ReleaseLayout');
'Wanted/WantedLayout', var SystemLayout = require('./System/SystemLayout');
'Calendar/CalendarLayout', var SeasonPassLayout = require('./SeasonPass/SeasonPassLayout');
'Release/ReleaseLayout', var SeriesEditorLayout = require('./Series/Editor/SeriesEditorLayout');
'System/SystemLayout',
'SeasonPass/SeasonPassLayout', module.exports = NzbDroneController.extend({
'Series/Editor/SeriesEditorLayout'
], function (NzbDroneController,
AppLayout,
Marionette,
ActivityLayout,
SettingsLayout,
AddSeriesLayout,
WantedLayout,
CalendarLayout,
ReleaseLayout,
SystemLayout,
SeasonPassLayout,
SeriesEditorLayout) {
return NzbDroneController.extend({
addSeries : function(action){ addSeries : function(action){
this.setTitle('Add Series'); this.setTitle('Add Series');
this.showMainRegion(new AddSeriesLayout({action : action})); this.showMainRegion(new AddSeriesLayout({action : action}));
}, },
calendar : function(){ calendar : function(){
this.setTitle('Calendar'); this.setTitle('Calendar');
this.showMainRegion(new CalendarLayout()); this.showMainRegion(new CalendarLayout());
}, },
settings : function(action){ settings : function(action){
this.setTitle('Settings'); this.setTitle('Settings');
this.showMainRegion(new SettingsLayout({action : action})); this.showMainRegion(new SettingsLayout({action : action}));
}, },
wanted : function(action){ wanted : function(action){
this.setTitle('Wanted'); this.setTitle('Wanted');
this.showMainRegion(new WantedLayout({action : action})); this.showMainRegion(new WantedLayout({action : action}));
}, },
activity : function(action){ activity : function(action){
this.setTitle('Activity'); this.setTitle('Activity');
this.showMainRegion(new ActivityLayout({action : action})); this.showMainRegion(new ActivityLayout({action : action}));
}, },
rss : function(){ rss : function(){
this.setTitle('RSS'); this.setTitle('RSS');
this.showMainRegion(new ReleaseLayout()); this.showMainRegion(new ReleaseLayout());
}, },
system : function(action){ system : function(action){
this.setTitle('System'); this.setTitle('System');
this.showMainRegion(new SystemLayout({action : action})); this.showMainRegion(new SystemLayout({action : action}));
}, },
seasonPass : function(){ seasonPass : function(){
this.setTitle('Season Pass'); this.setTitle('Season Pass');
this.showMainRegion(new SeasonPassLayout()); this.showMainRegion(new SeasonPassLayout());
}, },
seriesEditor : function(){ seriesEditor : function(){
this.setTitle('Series Editor'); this.setTitle('Series Editor');
this.showMainRegion(new SeriesEditorLayout()); this.showMainRegion(new SeriesEditorLayout());
} }
}); });
});

@ -1,36 +1,21 @@
'use strict'; var $ = require('jquery');
var vent = require('../../vent');
define( var Marionette = require('marionette');
[ var NzbDroneCell = require('../../Cells/NzbDroneCell');
'jquery',
'vent',
'marionette',
'Cells/NzbDroneCell'
], function ($, vent, Marionette, NzbDroneCell) {
return NzbDroneCell.extend({
module.exports = NzbDroneCell.extend({
className : 'episode-actions-cell', className : 'episode-actions-cell',
events : {"click .x-failed" : '_markAsFailed'},
events: {
'click .x-failed' : '_markAsFailed'
},
render : function(){ render : function(){
this.$el.empty(); this.$el.empty();
if(this.model.get('eventType') === 'grabbed') { if(this.model.get('eventType') === 'grabbed') {
this.$el.html('<i class="icon-nd-delete x-failed" title="Mark download as failed"></i>'); this.$el.html('<i class="icon-nd-delete x-failed" title="Mark download as failed"></i>');
} }
return this; return this;
}, },
_markAsFailed : function(){ _markAsFailed : function(){
var url = window.NzbDrone.ApiRoot + '/history/failed'; var url = window.NzbDrone.ApiRoot + '/history/failed';
var data = { var data = {id : this.model.get('id')};
id: this.model.get('id')
};
$.ajax({ $.ajax({
url : url, url : url,
type : 'POST', type : 'POST',
@ -38,4 +23,3 @@ define(
}); });
} }
}); });
});

@ -1,25 +1,16 @@
'use strict'; var $ = require('jquery');
var vent = require('../../vent');
define( var Marionette = require('marionette');
[ var NzbDroneCell = require('../../Cells/NzbDroneCell');
'jquery', var HistoryDetailsView = require('../../Activity/History/Details/HistoryDetailsView');
'vent', require('bootstrap');
'marionette',
'Cells/NzbDroneCell',
'Activity/History/Details/HistoryDetailsView',
'bootstrap'
], function ($, vent, Marionette, NzbDroneCell, HistoryDetailsView) {
return NzbDroneCell.extend({
module.exports = NzbDroneCell.extend({
className : 'episode-activity-details-cell', className : 'episode-activity-details-cell',
render : function(){ render : function(){
this.$el.empty(); this.$el.empty();
this.$el.html('<i class="icon-info-sign"></i>'); this.$el.html('<i class="icon-info-sign"></i>');
var html = new HistoryDetailsView({model : this.model}).render().$el; var html = new HistoryDetailsView({model : this.model}).render().$el;
this.$el.popover({ this.$el.popover({
content : html, content : html,
html : true, html : true,
@ -28,8 +19,6 @@ define(
placement : 'left', placement : 'left',
container : this.$el container : this.$el
}); });
return this; return this;
} }
}); });
});

@ -1,84 +1,58 @@
'use strict'; var Marionette = require('marionette');
define( var Backgrid = require('backgrid');
[ var HistoryCollection = require('../../Activity/History/HistoryCollection');
'marionette', var EventTypeCell = require('../../Cells/EventTypeCell');
'backgrid', var QualityCell = require('../../Cells/QualityCell');
'Activity/History/HistoryCollection', var RelativeDateCell = require('../../Cells/RelativeDateCell');
'Cells/EventTypeCell', var EpisodeActivityActionsCell = require('./EpisodeActivityActionsCell');
'Cells/QualityCell', var EpisodeActivityDetailsCell = require('./EpisodeActivityDetailsCell');
'Cells/RelativeDateCell', var NoActivityView = require('./NoActivityView');
'Episode/Activity/EpisodeActivityActionsCell', var LoadingView = require('../../Shared/LoadingView');
'Episode/Activity/EpisodeActivityDetailsCell',
'Episode/Activity/NoActivityView',
'Shared/LoadingView'
], function (Marionette,
Backgrid,
HistoryCollection,
EventTypeCell,
QualityCell,
RelativeDateCell,
EpisodeActivityActionsCell,
EpisodeActivityDetailsCell,
NoActivityView,
LoadingView) {
return Marionette.Layout.extend({ module.exports = Marionette.Layout.extend({
template : 'Episode/Activity/EpisodeActivityLayoutTemplate', template : 'Episode/Activity/EpisodeActivityLayoutTemplate',
regions : {activityTable : '.activity-table'},
regions: { columns : [{
activityTable: '.activity-table'
},
columns:
[
{
name : 'eventType', name : 'eventType',
label : '', label : '',
cell : EventTypeCell, cell : EventTypeCell,
cellValue : 'this' cellValue : 'this'
}, }, {
{
name : 'sourceTitle', name : 'sourceTitle',
label : 'Source Title', label : 'Source Title',
cell : 'string' cell : 'string'
}, }, {
{
name : 'quality', name : 'quality',
label : 'Quality', label : 'Quality',
cell : QualityCell cell : QualityCell
}, }, {
{
name : 'date', name : 'date',
label : 'Date', label : 'Date',
cell : RelativeDateCell cell : RelativeDateCell
}, }, {
{
name : 'this', name : 'this',
label : '', label : '',
cell : EpisodeActivityDetailsCell, cell : EpisodeActivityDetailsCell,
sortable : false sortable : false
}, }, {
{
name : 'this', name : 'this',
label : '', label : '',
cell : EpisodeActivityActionsCell, cell : EpisodeActivityActionsCell,
sortable : false sortable : false
} }],
],
initialize : function(options){ initialize : function(options){
this.model = options.model; this.model = options.model;
this.series = options.series; this.series = options.series;
this.collection = new HistoryCollection({
this.collection = new HistoryCollection({ episodeId: this.model.id, tableName: 'episodeActivity' }); episodeId : this.model.id,
tableName : 'episodeActivity'
});
this.collection.fetch(); this.collection.fetch();
this.listenTo(this.collection, 'sync', this._showTable); this.listenTo(this.collection, 'sync', this._showTable);
}, },
onRender : function(){ onRender : function(){
this.activityTable.show(new LoadingView()); this.activityTable.show(new LoadingView());
}, },
_showTable : function(){ _showTable : function(){
if(this.collection.any()) { if(this.collection.any()) {
this.activityTable.show(new Backgrid.Grid({ this.activityTable.show(new Backgrid.Grid({
@ -87,10 +61,8 @@ define(
className : 'table table-hover table-condensed' className : 'table table-hover table-condensed'
})); }));
} }
else { else {
this.activityTable.show(new NoActivityView()); this.activityTable.show(new NoActivityView());
} }
} }
}); });
});

@ -1,11 +1,3 @@
'use strict'; var Marionette = require('marionette');
define(
[
'marionette'
], function (Marionette) {
return Marionette.ItemView.extend({ module.exports = Marionette.ItemView.extend({template : 'Episode/Activity/NoActivityViewTemplate'});
template: 'Episode/Activity/NoActivityViewTemplate'
});
});

@ -1,122 +1,97 @@
'use strict'; var Marionette = require('marionette');
define( var SummaryLayout = require('./Summary/EpisodeSummaryLayout');
[ var SearchLayout = require('./Search/EpisodeSearchLayout');
'marionette', var EpisodeActivityLayout = require('./Activity/EpisodeActivityLayout');
'Episode/Summary/EpisodeSummaryLayout', var SeriesCollection = require('../Series/SeriesCollection');
'Episode/Search/EpisodeSearchLayout', var Messenger = require('../Shared/Messenger');
'Episode/Activity/EpisodeActivityLayout',
'Series/SeriesCollection', module.exports = Marionette.Layout.extend({
'Shared/Messenger'
], function (Marionette, SummaryLayout, SearchLayout, EpisodeActivityLayout, SeriesCollection, Messenger) {
return Marionette.Layout.extend({
className : 'modal-lg', className : 'modal-lg',
template : 'Episode/EpisodeDetailsLayoutTemplate', template : 'Episode/EpisodeDetailsLayoutTemplate',
regions : { regions : {
summary : '#episode-summary', summary : '#episode-summary',
activity : '#episode-activity', activity : '#episode-activity',
search : '#episode-search' search : '#episode-search'
}, },
ui : { ui : {
summary : '.x-episode-summary', summary : '.x-episode-summary',
activity : '.x-episode-activity', activity : '.x-episode-activity',
search : '.x-episode-search', search : '.x-episode-search',
monitored : '.x-episode-monitored' monitored : '.x-episode-monitored'
}, },
events : { events : {
"click .x-episode-summary" : '_showSummary',
'click .x-episode-summary' : '_showSummary', "click .x-episode-activity" : '_showActivity',
'click .x-episode-activity' : '_showActivity', "click .x-episode-search" : '_showSearch',
'click .x-episode-search' : '_showSearch', "click .x-episode-monitored" : '_toggleMonitored'
'click .x-episode-monitored': '_toggleMonitored'
}, },
templateHelpers : {}, templateHelpers : {},
initialize : function(options){ initialize : function(options){
this.templateHelpers.hideSeriesLink = options.hideSeriesLink; this.templateHelpers.hideSeriesLink = options.hideSeriesLink;
this.series = SeriesCollection.get(this.model.get('seriesId')); this.series = SeriesCollection.get(this.model.get('seriesId'));
this.templateHelpers.series = this.series.toJSON(); this.templateHelpers.series = this.series.toJSON();
this.openingTab = options.openingTab || 'summary'; this.openingTab = options.openingTab || 'summary';
this.listenTo(this.model, 'sync', this._setMonitoredState); this.listenTo(this.model, 'sync', this._setMonitoredState);
}, },
onShow : function(){ onShow : function(){
this.searchLayout = new SearchLayout({model : this.model}); this.searchLayout = new SearchLayout({model : this.model});
if(this.openingTab === 'search') { if(this.openingTab === 'search') {
this.searchLayout.startManualSearch = true; this.searchLayout.startManualSearch = true;
this._showSearch(); this._showSearch();
} }
else { else {
this._showSummary(); this._showSummary();
} }
this._setMonitoredState(); this._setMonitoredState();
if(this.series.get('monitored')) { if(this.series.get('monitored')) {
this.$el.removeClass('series-not-monitored'); this.$el.removeClass('series-not-monitored');
} }
else { else {
this.$el.addClass('series-not-monitored'); this.$el.addClass('series-not-monitored');
} }
}, },
_showSummary : function(e){ _showSummary : function(e){
if(e) { if(e) {
e.preventDefault(); e.preventDefault();
} }
this.ui.summary.tab('show'); this.ui.summary.tab('show');
this.summary.show(new SummaryLayout({model: this.model, series: this.series})); this.summary.show(new SummaryLayout({
model : this.model,
series : this.series
}));
}, },
_showActivity : function(e){ _showActivity : function(e){
if(e) { if(e) {
e.preventDefault(); e.preventDefault();
} }
this.ui.activity.tab('show'); this.ui.activity.tab('show');
this.activity.show(new EpisodeActivityLayout({model: this.model, series: this.series})); this.activity.show(new EpisodeActivityLayout({
model : this.model,
series : this.series
}));
}, },
_showSearch : function(e){ _showSearch : function(e){
if(e) { if(e) {
e.preventDefault(); e.preventDefault();
} }
this.ui.search.tab('show'); this.ui.search.tab('show');
this.search.show(this.searchLayout); this.search.show(this.searchLayout);
}, },
_toggleMonitored : function(){ _toggleMonitored : function(){
if(!this.series.get('monitored')) { if(!this.series.get('monitored')) {
Messenger.show({ Messenger.show({
message : 'Unable to change monitored state when series is not monitored', message : 'Unable to change monitored state when series is not monitored',
type : 'error' type : 'error'
}); });
return; return;
} }
var name = 'monitored'; var name = 'monitored';
this.model.set(name, !this.model.get(name), {silent : true}); this.model.set(name, !this.model.get(name), {silent : true});
this.ui.monitored.addClass('icon-spinner icon-spin'); this.ui.monitored.addClass('icon-spinner icon-spin');
this.model.save(); this.model.save();
}, },
_setMonitoredState : function(){ _setMonitoredState : function(){
this.ui.monitored.removeClass('icon-spin icon-spinner'); this.ui.monitored.removeClass('icon-spin icon-spinner');
if(this.model.get('monitored')) { if(this.model.get('monitored')) {
this.ui.monitored.addClass('icon-bookmark'); this.ui.monitored.addClass('icon-bookmark');
this.ui.monitored.removeClass('icon-bookmark-empty'); this.ui.monitored.removeClass('icon-bookmark-empty');
@ -127,4 +102,3 @@ define(
} }
} }
}); });
});

@ -1,10 +1,3 @@
'use strict'; var Marionette = require('marionette');
define(
[
'marionette'
], function (Marionette) {
return Marionette.ItemView.extend({ module.exports = Marionette.ItemView.extend({template : 'Episode/Search/ButtonsViewTemplate'});
template: 'Episode/Search/ButtonsViewTemplate'
});
});

@ -1,88 +1,63 @@
'use strict'; var vent = require('../../vent');
define( var Marionette = require('marionette');
[ var ButtonsView = require('./ButtonsView');
'vent', var ManualSearchLayout = require('./ManualLayout');
'marionette', var ReleaseCollection = require('../../Release/ReleaseCollection');
'Episode/Search/ButtonsView', var SeriesCollection = require('../../Series/SeriesCollection');
'Episode/Search/ManualLayout', var CommandController = require('../../Commands/CommandController');
'Release/ReleaseCollection', var LoadingView = require('../../Shared/LoadingView');
'Series/SeriesCollection', var NoResultsView = require('./NoResultsView');
'Commands/CommandController',
'Shared/LoadingView', module.exports = Marionette.Layout.extend({
'Episode/Search/NoResultsView'
], function (vent, Marionette, ButtonsView, ManualSearchLayout, ReleaseCollection, SeriesCollection,CommandController, LoadingView, NoResultsView) {
return Marionette.Layout.extend({
template : 'Episode/Search/EpisodeSearchLayoutTemplate', template : 'Episode/Search/EpisodeSearchLayoutTemplate',
regions : {main : '#episode-search-region'},
regions: {
main: '#episode-search-region'
},
events : { events : {
'click .x-search-auto' : '_searchAuto', "click .x-search-auto" : '_searchAuto',
'click .x-search-manual': '_searchManual', "click .x-search-manual" : '_searchManual',
'click .x-search-back' : '_showButtons' "click .x-search-back" : '_showButtons'
}, },
initialize : function(){ initialize : function(){
this.mainView = new ButtonsView(); this.mainView = new ButtonsView();
this.releaseCollection = new ReleaseCollection(); this.releaseCollection = new ReleaseCollection();
this.listenTo(this.releaseCollection, 'sync', this._showSearchResults); this.listenTo(this.releaseCollection, 'sync', this._showSearchResults);
}, },
onShow : function(){ onShow : function(){
if(this.startManualSearch) { if(this.startManualSearch) {
this._searchManual(); this._searchManual();
} }
else { else {
this._showMainView(); this._showMainView();
} }
}, },
_searchAuto : function(e){ _searchAuto : function(e){
if(e) { if(e) {
e.preventDefault(); e.preventDefault();
} }
CommandController.Execute('episodeSearch', {episodeIds : [this.model.get('id')]});
CommandController.Execute('episodeSearch', {
episodeIds: [ this.model.get('id') ]
});
vent.trigger(vent.Commands.CloseModalCommand); vent.trigger(vent.Commands.CloseModalCommand);
}, },
_searchManual : function(e){ _searchManual : function(e){
if(e) { if(e) {
e.preventDefault(); e.preventDefault();
} }
this.mainView = new LoadingView(); this.mainView = new LoadingView();
this._showMainView(); this._showMainView();
this.releaseCollection.fetchEpisodeReleases(this.model.id); this.releaseCollection.fetchEpisodeReleases(this.model.id);
}, },
_showMainView : function(){ _showMainView : function(){
this.main.show(this.mainView); this.main.show(this.mainView);
}, },
_showButtons : function(){ _showButtons : function(){
this.mainView = new ButtonsView(); this.mainView = new ButtonsView();
this._showMainView(); this._showMainView();
}, },
_showSearchResults : function(){ _showSearchResults : function(){
if(this.releaseCollection.length === 0) { if(this.releaseCollection.length === 0) {
this.mainView = new NoResultsView(); this.mainView = new NoResultsView();
} }
else { else {
this.mainView = new ManualSearchLayout({collection : this.releaseCollection}); this.mainView = new ManualSearchLayout({collection : this.releaseCollection});
} }
this._showMainView(); this._showMainView();
} }
}); });
});

@ -1,76 +1,56 @@
'use strict'; var Marionette = require('marionette');
define( var Backgrid = require('backgrid');
[ var ReleaseTitleCell = require('../../Cells/ReleaseTitleCell');
'marionette', var FileSizeCell = require('../../Cells/FileSizeCell');
'backgrid', var QualityCell = require('../../Cells/QualityCell');
'Cells/ReleaseTitleCell', var ApprovalStatusCell = require('../../Cells/ApprovalStatusCell');
'Cells/FileSizeCell', var DownloadReportCell = require('../../Release/DownloadReportCell');
'Cells/QualityCell', var AgeCell = require('../../Release/AgeCell');
'Cells/ApprovalStatusCell', var ProtocolCell = require('../../Release/ProtocolCell');
'Release/DownloadReportCell', var PeersCell = require('../../Release/PeersCell');
'Release/AgeCell',
'Release/ProtocolCell',
'Release/PeersCell'
], function (Marionette, Backgrid, ReleaseTitleCell, FileSizeCell, QualityCell, ApprovalStatusCell, DownloadReportCell, AgeCell, ProtocolCell, PeersCell) {
return Marionette.Layout.extend({ module.exports = Marionette.Layout.extend({
template : 'Episode/Search/ManualLayoutTemplate', template : 'Episode/Search/ManualLayoutTemplate',
regions : {grid : '#episode-release-grid'},
regions: { columns : [{
grid: '#episode-release-grid'
},
columns:
[
{
name : 'protocol', name : 'protocol',
label : 'Source', label : 'Source',
cell : ProtocolCell cell : ProtocolCell
}, }, {
{
name : 'age', name : 'age',
label : 'Age', label : 'Age',
cell : AgeCell cell : AgeCell
}, }, {
{
name : 'title', name : 'title',
label : 'Title', label : 'Title',
cell : ReleaseTitleCell cell : ReleaseTitleCell
}, }, {
{
name : 'indexer', name : 'indexer',
label : 'Indexer', label : 'Indexer',
cell : Backgrid.StringCell cell : Backgrid.StringCell
}, }, {
{
name : 'size', name : 'size',
label : 'Size', label : 'Size',
cell : FileSizeCell cell : FileSizeCell
}, }, {
{
name : 'seeders', name : 'seeders',
label : 'Peers', label : 'Peers',
cell : PeersCell cell : PeersCell
}, }, {
{
name : 'quality', name : 'quality',
label : 'Quality', label : 'Quality',
cell : QualityCell cell : QualityCell
}, }, {
{
name : 'rejections', name : 'rejections',
label : '', label : '',
cell : ApprovalStatusCell, cell : ApprovalStatusCell,
sortable : false sortable : false
}, }, {
{
name : 'download', name : 'download',
label : '', label : '',
cell : DownloadReportCell, cell : DownloadReportCell,
sortable : true // Is the default sort, which sorts by the internal prioritization logic. sortable : true
} }],
],
onShow : function(){ onShow : function(){
if(!this.isClosed) { if(!this.isClosed) {
this.grid.show(new Backgrid.Grid({ this.grid.show(new Backgrid.Grid({
@ -82,5 +62,3 @@ define(
} }
} }
}); });
});

@ -1,10 +1,3 @@
'use strict'; var Marionette = require('marionette');
define( module.exports = Marionette.ItemView.extend({template : 'Episode/Search/NoResultsViewTemplate'});
[
'marionette'
], function (Marionette) {
return Marionette.ItemView.extend({
template: 'Episode/Search/NoResultsViewTemplate'
});
});

@ -1,106 +1,74 @@
'use strict'; var reqres = require('../../reqres');
define( var Marionette = require('marionette');
[ var Backgrid = require('backgrid');
'reqres', var EpisodeFileModel = require('../../Series/EpisodeFileModel');
'marionette', var EpisodeFileCollection = require('../../Series/EpisodeFileCollection');
'backgrid', var FileSizeCell = require('../../Cells/FileSizeCell');
'Series/EpisodeFileModel', var QualityCell = require('../../Cells/QualityCell');
'Series/EpisodeFileCollection', var DeleteEpisodeFileCell = require('../../Cells/DeleteEpisodeFileCell');
'Cells/FileSizeCell', var NoFileView = require('./NoFileView');
'Cells/QualityCell', var LoadingView = require('../../Shared/LoadingView');
'Cells/DeleteEpisodeFileCell',
'Episode/Summary/NoFileView', module.exports = Marionette.Layout.extend({
'Shared/LoadingView'
], function (reqres,
Marionette,
Backgrid,
EpisodeFileModel,
EpisodeFileCollection,
FileSizeCell,
QualityCell,
DeleteEpisodeFileCell,
NoFileView,
LoadingView) {
return Marionette.Layout.extend({
template : 'Episode/Summary/EpisodeSummaryLayoutTemplate', template : 'Episode/Summary/EpisodeSummaryLayoutTemplate',
regions : { regions : {
overview : '.episode-overview', overview : '.episode-overview',
activity : '.episode-file-info' activity : '.episode-file-info'
}, },
columns : [{
columns:
[
{
name : 'path', name : 'path',
label : 'Path', label : 'Path',
cell : 'string', cell : 'string',
sortable : false sortable : false
}, }, {
{
name : 'size', name : 'size',
label : 'Size', label : 'Size',
cell : FileSizeCell, cell : FileSizeCell,
sortable : false sortable : false
}, }, {
{
name : 'quality', name : 'quality',
label : 'Quality', label : 'Quality',
cell : QualityCell, cell : QualityCell,
sortable : false, sortable : false,
editable : true editable : true
}, }, {
{
name : 'this', name : 'this',
label : '', label : '',
cell : DeleteEpisodeFileCell, cell : DeleteEpisodeFileCell,
sortable : false sortable : false
} }],
],
templateHelpers : {}, templateHelpers : {},
initialize : function(options){ initialize : function(options){
if(!this.model.series) { if(!this.model.series) {
this.templateHelpers.series = options.series.toJSON(); this.templateHelpers.series = options.series.toJSON();
} }
}, },
onShow : function(){ onShow : function(){
if(this.model.get('hasFile')) { if(this.model.get('hasFile')) {
var episodeFileId = this.model.get('episodeFileId'); var episodeFileId = this.model.get('episodeFileId');
if(reqres.hasHandler(reqres.Requests.GetEpisodeFileById)) { if(reqres.hasHandler(reqres.Requests.GetEpisodeFileById)) {
var episodeFile = reqres.request(reqres.Requests.GetEpisodeFileById, episodeFileId); var episodeFile = reqres.request(reqres.Requests.GetEpisodeFileById, episodeFileId);
this.episodeFileCollection = new EpisodeFileCollection(episodeFile, {seriesId : this.model.get('seriesId')}); this.episodeFileCollection = new EpisodeFileCollection(episodeFile, {seriesId : this.model.get('seriesId')});
this.listenTo(episodeFile, 'destroy', this._episodeFileDeleted); this.listenTo(episodeFile, 'destroy', this._episodeFileDeleted);
this._showTable(); this._showTable();
} }
else { else {
this.activity.show(new LoadingView()); this.activity.show(new LoadingView());
var self = this; var self = this;
var newEpisodeFile = new EpisodeFileModel({id : episodeFileId}); var newEpisodeFile = new EpisodeFileModel({id : episodeFileId});
this.episodeFileCollection = new EpisodeFileCollection(newEpisodeFile, {seriesId : this.model.get('seriesId')}); this.episodeFileCollection = new EpisodeFileCollection(newEpisodeFile, {seriesId : this.model.get('seriesId')});
var promise = newEpisodeFile.fetch(); var promise = newEpisodeFile.fetch();
this.listenTo(newEpisodeFile, 'destroy', this._episodeFileDeleted); this.listenTo(newEpisodeFile, 'destroy', this._episodeFileDeleted);
promise.done(function(){ promise.done(function(){
self._showTable(); self._showTable();
}); });
} }
this.listenTo(this.episodeFileCollection, 'add remove', this._collectionChanged); this.listenTo(this.episodeFileCollection, 'add remove', this._collectionChanged);
} }
else { else {
this._showNoFileView(); this._showNoFileView();
} }
}, },
_showTable : function(){ _showTable : function(){
this.activity.show(new Backgrid.Grid({ this.activity.show(new Backgrid.Grid({
collection : this.episodeFileCollection, collection : this.episodeFileCollection,
@ -109,21 +77,17 @@ define(
emptyText : 'Nothing to see here!' emptyText : 'Nothing to see here!'
})); }));
}, },
_showNoFileView : function(){ _showNoFileView : function(){
this.activity.show(new NoFileView()); this.activity.show(new NoFileView());
}, },
_collectionChanged : function(){ _collectionChanged : function(){
if(!this.episodeFileCollection.any()) { if(!this.episodeFileCollection.any()) {
this._showNoFileView(); this._showNoFileView();
} }
else { else {
this._showTable(); this._showTable();
} }
}, },
_episodeFileDeleted : function(){ _episodeFileDeleted : function(){
this.model.set({ this.model.set({
episodeFileId : 0, episodeFileId : 0,
@ -131,4 +95,3 @@ define(
}); });
} }
}); });
});

@ -1,11 +1,3 @@
'use strict'; var Marionette = require('marionette');
define(
[
'marionette'
], function (Marionette) {
return Marionette.ItemView.extend({ module.exports = Marionette.ItemView.extend({template : 'Episode/Summary/NoFileViewTemplate'});
template: 'Episode/Summary/NoFileViewTemplate'
});
});

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save