Helper cleanup

pull/3113/head
Mark McDowall 12 years ago
parent 1fb944976e
commit 626d48c8ea

@ -6,5 +6,5 @@
<a href="/series/details/{{series.titleSlug}}">
<h4>{{series.title}}</h4>
</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>

@ -13,7 +13,9 @@ define(['app',
'Logs/Layout',
'Release/Layout',
'Missing/MissingLayout',
'History/HistoryLayout'],
'History/HistoryLayout',
'Shared/FormatHelpers',
'Shared/TemplateHelpers'],
function () {
var controller = Backbone.Marionette.Controller.extend({

@ -102,10 +102,8 @@
<script src="/Mixins/backbone.marionette.templates.js"></script>
<script src="/Mixins/backbone.marionette.region.mixin.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.backgrid.mixin.js"></script>
<script src="/Mixins/handlebars.mixin.js"></script>
<script src="/Mixins/backbone.signalr.mixin.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({
mutators: {
bestDateString : function () {
return bestDateString(this.get('airDate'));
},
paddedEpisodeNumber: function () {
return this.get('episodeNumber').pad(2);
},

@ -30,8 +30,8 @@
<div class="row">
<div class="span8">
{{#if isContinuing}}
{{#if bestDateString}}
<span class="label">{{bestDateString}}</span>
{{#if nextAiring}}
<span class="label">{{date nextAiring}}</span>
{{else}}
<span class="label label-inverse">Continuing</span>
{{/if}}

@ -21,8 +21,8 @@
<div class="center">
<div class="labels">
{{#if isContinuing}}
{{#if bestDateString}}
<span class="label label-inverse air-date" title="{{shortDate}}">{{bestDateString}}</span>
{{#if nextAiring}}
<span class="label label-inverse">{{date nextAiring}}</span>
{{else}}
<span class="label label-inverse">Continuing</span>
{{/if}}

@ -16,7 +16,6 @@ define([
ui: {
'progressbar': '.progress .bar',
'airDate': '.air-date',
'controls': '.series-controls'
},
@ -31,10 +30,6 @@ define([
this.qualityProfileCollection = options.qualityProfiles;
},
onRender: function () {
this.ui.airDate.tooltip();
},
editSeries: function () {
var view = new NzbDrone.Series.Edit.EditSeriesView({ model: this.model});
NzbDrone.modalRegion.show(view);

@ -6,7 +6,7 @@ Backgrid.AirDateCell = Backgrid.Cell.extend({
this.$el.empty();
var airDate = this.model.get(this.column.get("name"));
this.$el.html(bestDateString(airDate));
this.$el.html(NzbDrone.Shared.FormatHelpers.DateHelper(airDate));
return this;
}

@ -5,10 +5,6 @@ define(['app', 'Quality/QualityProfileCollection', 'AddSeries/RootFolders/RootFo
urlRoot: NzbDrone.Constants.ApiRoot + '/series',
mutators: {
bestDateString: function () {
return bestDateString(this.get('nextAiring'));
},
percentOfEpisodes: function () {
var episodeCount = this.get('episodeCount');
var episodeFileCount = this.get('episodeFileCount');

@ -4,11 +4,8 @@ NzbDrone.Shared.Cells.FileSizeCell = Backgrid.Cell.extend({
className: "file-size-cell",
render: function () {
var size = Number(this.model.get(this.column.get("name")));
this.$el.html(size.bytes(1));
var size = this.model.get(this.column.get("name"));
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',
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 = {
Toolbar : {},
Messenger: {},
Cells: {}
Cells: {},
FormatHelpers: {}
};
window.NzbDrone.Calendar = {};

Loading…
Cancel
Save