Helper cleanup
This commit is contained in:
parent
1fb944976e
commit
626d48c8ea
|
@ -6,5 +6,5 @@
|
||||||
<a href="/series/details/{{series.titleSlug}}">
|
<a href="/series/details/{{series.titleSlug}}">
|
||||||
<h4>{{series.title}}</h4>
|
<h4>{{series.title}}</h4>
|
||||||
</a>
|
</a>
|
||||||
<p>{{startTime}} {{bestDateString}}<span class="pull-right">{{seasonNumber}}x{{paddedEpisodeNumber}}</span><br>{{episodeTitle}}</p>
|
<p>{{startTime}} {{date airDate}}<span class="pull-right">{{seasonNumber}}x{{paddedEpisodeNumber}}</span><br>{{episodeTitle}}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -13,7 +13,9 @@ define(['app',
|
||||||
'Logs/Layout',
|
'Logs/Layout',
|
||||||
'Release/Layout',
|
'Release/Layout',
|
||||||
'Missing/MissingLayout',
|
'Missing/MissingLayout',
|
||||||
'History/HistoryLayout'],
|
'History/HistoryLayout',
|
||||||
|
'Shared/FormatHelpers',
|
||||||
|
'Shared/TemplateHelpers'],
|
||||||
function () {
|
function () {
|
||||||
var controller = Backbone.Marionette.Controller.extend({
|
var controller = Backbone.Marionette.Controller.extend({
|
||||||
|
|
||||||
|
|
|
@ -102,10 +102,8 @@
|
||||||
<script src="/Mixins/backbone.marionette.templates.js"></script>
|
<script src="/Mixins/backbone.marionette.templates.js"></script>
|
||||||
<script src="/Mixins/backbone.marionette.region.mixin.js"></script>
|
<script src="/Mixins/backbone.marionette.region.mixin.js"></script>
|
||||||
<script src="/Mixins/backbone.ajax.js"></script>
|
<script src="/Mixins/backbone.ajax.js"></script>
|
||||||
<script src="/Mixins/spoon.js"></script>
|
|
||||||
<script src="/Mixins/backbone.modelbinder.mixin.js"></script>
|
<script src="/Mixins/backbone.modelbinder.mixin.js"></script>
|
||||||
<script src="/Mixins/backbone.backgrid.mixin.js"></script>
|
<script src="/Mixins/backbone.backgrid.mixin.js"></script>
|
||||||
<script src="/Mixins/handlebars.mixin.js"></script>
|
|
||||||
<script src="/Mixins/backbone.signalr.mixin.js"></script>
|
<script src="/Mixins/backbone.signalr.mixin.js"></script>
|
||||||
|
|
||||||
<script data-main="/app" src="/JsLibraries/require.js"></script>
|
<script data-main="/app" src="/JsLibraries/require.js"></script>
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
Handlebars.registerHelper('partial', function (templateName) {
|
|
||||||
//TODO: We should be able to pass in the context, either an object or a property
|
|
||||||
|
|
||||||
var templateFunction = Marionette.TemplateCache.get(templateName);
|
|
||||||
return new Handlebars.SafeString(templateFunction(this));
|
|
||||||
});
|
|
||||||
|
|
||||||
Handlebars.registerHelper("debug", function(optionalValue) {
|
|
||||||
console.log("Current Context");
|
|
||||||
console.log("====================");
|
|
||||||
console.log(this);
|
|
||||||
|
|
||||||
if (optionalValue) {
|
|
||||||
console.log("Value");
|
|
||||||
console.log("====================");
|
|
||||||
console.log(optionalValue);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Handlebars.registerHelper("fileSize", function(size) {
|
|
||||||
return size.bytes(1);
|
|
||||||
});
|
|
|
@ -1,29 +0,0 @@
|
||||||
"use strict";
|
|
||||||
|
|
||||||
//TODO: global function, not good!
|
|
||||||
function bestDateString(sourceDate) {
|
|
||||||
if (!sourceDate) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
var date = Date.create(sourceDate);
|
|
||||||
|
|
||||||
if (date.isYesterday()) {
|
|
||||||
return 'Yesterday';
|
|
||||||
}
|
|
||||||
if (date.isToday()) {
|
|
||||||
return 'Today';
|
|
||||||
}
|
|
||||||
if (date.isTomorrow()) {
|
|
||||||
return 'Tomorrow';
|
|
||||||
}
|
|
||||||
if (date.isAfter(Date.create('tomorrow')) && date.isBefore(Date.create().addDays(7))) {
|
|
||||||
return date.format('{Weekday}');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (date.isAfter(Date.create().addDays(6))) {
|
|
||||||
return date.relative().replace(' from now', '');
|
|
||||||
}
|
|
||||||
|
|
||||||
return date.format('{MM}/{dd}/{yyyy}');
|
|
||||||
}
|
|
|
@ -3,9 +3,6 @@ define(['app'], function () {
|
||||||
NzbDrone.Series.EpisodeModel = Backbone.Model.extend({
|
NzbDrone.Series.EpisodeModel = Backbone.Model.extend({
|
||||||
|
|
||||||
mutators: {
|
mutators: {
|
||||||
bestDateString : function () {
|
|
||||||
return bestDateString(this.get('airDate'));
|
|
||||||
},
|
|
||||||
paddedEpisodeNumber: function () {
|
paddedEpisodeNumber: function () {
|
||||||
return this.get('episodeNumber').pad(2);
|
return this.get('episodeNumber').pad(2);
|
||||||
},
|
},
|
||||||
|
|
|
@ -30,8 +30,8 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="span8">
|
<div class="span8">
|
||||||
{{#if isContinuing}}
|
{{#if isContinuing}}
|
||||||
{{#if bestDateString}}
|
{{#if nextAiring}}
|
||||||
<span class="label">{{bestDateString}}</span>
|
<span class="label">{{date nextAiring}}</span>
|
||||||
{{else}}
|
{{else}}
|
||||||
<span class="label label-inverse">Continuing</span>
|
<span class="label label-inverse">Continuing</span>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
@ -21,8 +21,8 @@
|
||||||
<div class="center">
|
<div class="center">
|
||||||
<div class="labels">
|
<div class="labels">
|
||||||
{{#if isContinuing}}
|
{{#if isContinuing}}
|
||||||
{{#if bestDateString}}
|
{{#if nextAiring}}
|
||||||
<span class="label label-inverse air-date" title="{{shortDate}}">{{bestDateString}}</span>
|
<span class="label label-inverse">{{date nextAiring}}</span>
|
||||||
{{else}}
|
{{else}}
|
||||||
<span class="label label-inverse">Continuing</span>
|
<span class="label label-inverse">Continuing</span>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
@ -16,7 +16,6 @@ define([
|
||||||
|
|
||||||
ui: {
|
ui: {
|
||||||
'progressbar': '.progress .bar',
|
'progressbar': '.progress .bar',
|
||||||
'airDate': '.air-date',
|
|
||||||
'controls': '.series-controls'
|
'controls': '.series-controls'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -31,10 +30,6 @@ define([
|
||||||
this.qualityProfileCollection = options.qualityProfiles;
|
this.qualityProfileCollection = options.qualityProfiles;
|
||||||
},
|
},
|
||||||
|
|
||||||
onRender: function () {
|
|
||||||
this.ui.airDate.tooltip();
|
|
||||||
},
|
|
||||||
|
|
||||||
editSeries: function () {
|
editSeries: function () {
|
||||||
var view = new NzbDrone.Series.Edit.EditSeriesView({ model: this.model});
|
var view = new NzbDrone.Series.Edit.EditSeriesView({ model: this.model});
|
||||||
NzbDrone.modalRegion.show(view);
|
NzbDrone.modalRegion.show(view);
|
||||||
|
|
|
@ -6,7 +6,7 @@ Backgrid.AirDateCell = Backgrid.Cell.extend({
|
||||||
this.$el.empty();
|
this.$el.empty();
|
||||||
var airDate = this.model.get(this.column.get("name"));
|
var airDate = this.model.get(this.column.get("name"));
|
||||||
|
|
||||||
this.$el.html(bestDateString(airDate));
|
this.$el.html(NzbDrone.Shared.FormatHelpers.DateHelper(airDate));
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,6 @@ define(['app', 'Quality/QualityProfileCollection', 'AddSeries/RootFolders/RootFo
|
||||||
urlRoot: NzbDrone.Constants.ApiRoot + '/series',
|
urlRoot: NzbDrone.Constants.ApiRoot + '/series',
|
||||||
|
|
||||||
mutators: {
|
mutators: {
|
||||||
bestDateString: function () {
|
|
||||||
return bestDateString(this.get('nextAiring'));
|
|
||||||
},
|
|
||||||
|
|
||||||
percentOfEpisodes: function () {
|
percentOfEpisodes: function () {
|
||||||
var episodeCount = this.get('episodeCount');
|
var episodeCount = this.get('episodeCount');
|
||||||
var episodeFileCount = this.get('episodeFileCount');
|
var episodeFileCount = this.get('episodeFileCount');
|
||||||
|
|
|
@ -4,11 +4,8 @@ NzbDrone.Shared.Cells.FileSizeCell = 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 = Number(this.model.get(this.column.get("name")));
|
|
||||||
this.$el.html(size.bytes(1));
|
|
||||||
this.delegateEvents();
|
this.delegateEvents();
|
||||||
return this;
|
return NzbDrone.Shared.FormatHelpers.FileSizeHelper(size);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
define(['app'], function () {
|
||||||
|
NzbDrone.Shared.FormatHelpers.FileSizeHelper = function (sourceSize) {
|
||||||
|
var size = Number(sourceSize);
|
||||||
|
this.$el.html(size.bytes(1));
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
NzbDrone.Shared.FormatHelpers.DateHelper = function (sourceDate) {
|
||||||
|
if (!sourceDate) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
var date = Date.create(sourceDate);
|
||||||
|
|
||||||
|
if (date.isYesterday()) {
|
||||||
|
return 'Yesterday';
|
||||||
|
}
|
||||||
|
if (date.isToday()) {
|
||||||
|
return 'Today';
|
||||||
|
}
|
||||||
|
if (date.isTomorrow()) {
|
||||||
|
return 'Tomorrow';
|
||||||
|
}
|
||||||
|
if (date.isAfter(Date.create('tomorrow')) && date.isBefore(Date.create().addDays(7))) {
|
||||||
|
return date.format('{Weekday}');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (date.isAfter(Date.create().addDays(6))) {
|
||||||
|
return date.relative().replace(' from now', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
return date.format('{MM}/{dd}/{yyyy}');
|
||||||
|
};
|
||||||
|
});
|
|
@ -5,6 +5,4 @@ define(['app'], function () {
|
||||||
template : 'Shared/LoadingTemplate',
|
template : 'Shared/LoadingTemplate',
|
||||||
className: 'nz-loading row'
|
className: 'nz-loading row'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
define(['app'], function () {
|
||||||
|
Handlebars.registerHelper('partial', function (templateName) {
|
||||||
|
//TODO: We should be able to pass in the context, either an object or a property
|
||||||
|
|
||||||
|
var templateFunction = Marionette.TemplateCache.get(templateName);
|
||||||
|
return new Handlebars.SafeString(templateFunction(this));
|
||||||
|
});
|
||||||
|
|
||||||
|
Handlebars.registerHelper("debug", function(optionalValue) {
|
||||||
|
console.log("Current Context");
|
||||||
|
console.log("====================");
|
||||||
|
console.log(this);
|
||||||
|
|
||||||
|
if (optionalValue) {
|
||||||
|
console.log("Value");
|
||||||
|
console.log("====================");
|
||||||
|
console.log(optionalValue);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Handlebars.registerHelper("fileSize", function(size) {
|
||||||
|
return NzbDrone.Shared.FormatHelpers.FileSizeHelper(size);
|
||||||
|
});
|
||||||
|
|
||||||
|
Handlebars.registerHelper("date", function(date) {
|
||||||
|
//TODO: show actual date in tooltip
|
||||||
|
if (!date) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
var shortDate = Date.create(date).short();
|
||||||
|
var formattedDate = NzbDrone.Shared.FormatHelpers.DateHelper(date);
|
||||||
|
var result = '<div title="' + shortDate + '">' + formattedDate + '</div >';
|
||||||
|
|
||||||
|
return new Handlebars.SafeString(result);
|
||||||
|
});
|
||||||
|
});
|
|
@ -64,7 +64,8 @@ define('app', ['shared/modal/region'], function (ModalRegion) {
|
||||||
window.NzbDrone.Shared = {
|
window.NzbDrone.Shared = {
|
||||||
Toolbar : {},
|
Toolbar : {},
|
||||||
Messenger: {},
|
Messenger: {},
|
||||||
Cells: {}
|
Cells: {},
|
||||||
|
FormatHelpers: {}
|
||||||
|
|
||||||
};
|
};
|
||||||
window.NzbDrone.Calendar = {};
|
window.NzbDrone.Calendar = {};
|
||||||
|
|
Loading…
Reference in New Issue