cleaned up template helpers

pull/4/head
kay.one 12 years ago
parent d7fbfec01e
commit 8841e43c25

@ -4,7 +4,7 @@
<option name="myLocal" value="false" /> <option name="myLocal" value="false" />
<inspection_tool class="AssignmentResultUsedJS" enabled="true" level="WARNING" enabled_by_default="true" /> <inspection_tool class="AssignmentResultUsedJS" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AssignmentToForLoopParameterJS" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="AssignmentToForLoopParameterJS" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="AssignmentToFunctionParameterJS" enabled="true" level="WEAK WARNING" enabled_by_default="true" /> <inspection_tool class="AssignmentToFunctionParameterJS" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="BadExpressionStatementJS" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="BadExpressionStatementJS" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="BreakStatementJS" enabled="true" level="SERVER PROBLEM" enabled_by_default="true" /> <inspection_tool class="BreakStatementJS" enabled="true" level="SERVER PROBLEM" enabled_by_default="true" />
<inspection_tool class="BreakStatementWithLabelJS" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="BreakStatementWithLabelJS" enabled="true" level="ERROR" enabled_by_default="true" />
@ -67,7 +67,6 @@
<option name="m_limit" value="3" /> <option name="m_limit" value="3" />
</inspection_tool> </inspection_tool>
<inspection_tool class="JSDuplicatedDeclaration" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="JSDuplicatedDeclaration" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="JSHint" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="JSLastCommaInArrayLiteral" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="JSLastCommaInArrayLiteral" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="JSPotentiallyInvalidUsageOfThis" enabled="true" level="SERVER PROBLEM" enabled_by_default="true" /> <inspection_tool class="JSPotentiallyInvalidUsageOfThis" enabled="true" level="SERVER PROBLEM" enabled_by_default="true" />
<inspection_tool class="JSUndeclaredVariable" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="JSUndeclaredVariable" enabled="true" level="ERROR" enabled_by_default="true" />

@ -0,0 +1,3 @@
<component name="DependencyValidationManager">
<scope name="NzbDrone" pattern="!file:JsLibraries//*" />
</component>

@ -6,5 +6,5 @@
<a href="{{series.route}}"> <a href="{{series.route}}">
<h4>{{series.title}}</h4> <h4>{{series.title}}</h4>
</a> </a>
<p>{{startTime}} {{date airDate}}<span class="pull-right">{{seasonNumber}}x{{paddedEpisodeNumber}}</span><br>{{episodeTitle}}</p> <p>{{startTime}} {{ShortDate airDate}}<span class="pull-right">{{seasonNumber}}x{{paddedEpisodeNumber}}</span><br>{{episodeTitle}}</p>
</div> </div>

@ -11,7 +11,7 @@ define(
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.FileSizeHelper(size)); this.$el.html(FormatHelpers.Bytes(size));
this.delegateEvents(); this.delegateEvents();
return this; return this;
} }

@ -15,7 +15,7 @@
<tbody> <tbody>
<tr> <tr>
<td>{{path}}</td> <td>{{path}}</td>
<td>{{fileSize size}}</td> <td>{{Byte size}}</td>
<td>{{quality.quality.name}}</td> <td>{{quality.quality.name}}</td>
</tr> </tr>
</tbody> </tbody>

@ -1,18 +1,17 @@
'use strict'; 'use strict';
define( define(
[ [
'handlebars',
'sugar' 'sugar'
], { ], function (Handlebars) {
register: function (handlebars) { Handlebars.registerHelper('ShortDate', function (input) {
handlebars.registerHelper('ShortDate', function (input) { if (!input) {
if (!input) { return '';
return ''; }
}
var date = Date.create(input); var date = Date.create(input);
var result = '<span title="' + date.full() + '">' + date.short() + '</span>'; var result = '<span title="' + date.full() + '">' + date.short() + '</span>';
return new handlebars.SafeString(result); return new Handlebars.SafeString(result);
}); });
}
}); });

@ -0,0 +1,10 @@
'use strict';
define(
[
'handlebars'
], function (Handlebars) {
Handlebars.registerHelper('defaultImg', function () {
return new Handlebars.SafeString('onerror="this.src="/content/images/poster-dark.jpg";"');
});
});

@ -0,0 +1,10 @@
'use strict';
define(
[
'handlebars',
'Shared/FormatHelpers'
], function (Handlebars, FormatHelpers) {
Handlebars.registerHelper('Bytes', function (size) {
return new Handlebars.SafeString(FormatHelpers.Bytes(size));
});
});

@ -1,8 +1,11 @@
'use strict'; 'use strict';
define( define(
[ [
'templates' 'templates',
'Handlebars/Helpers/DateTime',
'Handlebars/Helpers/Html',
'Handlebars/Helpers/Numbers',
'Handlebars/Debug'
], function (Templates) { ], function (Templates) {
return function () { return function () {
this.get = function (templateId) { this.get = function (templateId) {

@ -0,0 +1,18 @@
'use strict';
define({
register: function (Handlebars) {
Handlebars.registerHelper("debug", function (optionalValue) {
console.group('Handlebar context');
console.log(this);
if (optionalValue) {
console.group('optional values');
console.log('optinal values');
console.groupEnd();
}
console.groupEnd();
});
}
});

@ -1,5 +1,4 @@
 'use strict';
'use strict';
define( define(
[ [
'marionette', 'marionette',

@ -31,7 +31,7 @@
<div class="span8"> <div class="span8">
{{#if isContinuing}} {{#if isContinuing}}
{{#if nextAiring}} {{#if nextAiring}}
<span class="label">{{date nextAiring}}</span> <span class="label">{{ShortDate nextAiring}}</span>
{{/if}} {{/if}}
<span class="label label-info">Season {{seasonCount}}</span> <span class="label label-info">Season {{seasonCount}}</span>
{{else}} {{else}}

@ -22,7 +22,7 @@
<div class="labels"> <div class="labels">
{{#if isContinuing}} {{#if isContinuing}}
{{#if nextAiring}} {{#if nextAiring}}
<span class="label label-inverse">{{date nextAiring}}</span> <span class="label label-inverse">{{ShortDate nextAiring}}</span>
{{/if}} {{/if}}
<span class="label label-info">Season {{seasonCount}}</span> <span class="label label-info">Season {{seasonCount}}</span>
{{else}} {{else}}

@ -1,5 +1,4 @@
 'use strict';
'use strict';
define( define(
[ [

@ -4,7 +4,7 @@ define(
[ [
'sugar' 'sugar'
], { ], {
FileSizeHelper: function (sourceSize) { Bytes: function (sourceSize) {
var size = Number(sourceSize); var size = Number(sourceSize);
return size.bytes(1); return size.bytes(1);
}, },

@ -1,47 +0,0 @@
'use strict';
define(
[
'handlebars',
'Shared/FormatHelpers'
], function (Handlebars, FormatHelpers) {
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 new Handlebars.SafeString(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 = FormatHelpers.DateHelper(date);
var result = '<span title="' + shortDate + '">' + formattedDate + '</span>';
return new Handlebars.SafeString(result);
});
Handlebars.registerHelper('defaultImg', function () {
return new Handlebars.SafeString('onerror="this.src="/content/images/poster-dark.jpg";"');
});
});

@ -1,4 +1,4 @@
'use strict'; 'use strict';
require.config({ require.config({
urlArgs: 'v=' + window.ServerStatus.version, urlArgs: 'v=' + window.ServerStatus.version,
@ -36,6 +36,14 @@ require.config({
} }
}, },
signalR: {
deps:
[
'$'
]
},
bootstrap: { bootstrap: {
deps: deps:
[ [
@ -57,7 +65,7 @@ require.config({
] ]
}, },
'underscore': { underscore: {
deps : deps :
[ [
'$' '$'
@ -90,30 +98,19 @@ require.config({
deps: deps:
[ [
'backbone', 'backbone',
'handlebars',
'Handlebars/backbone.marionette.templates', 'Handlebars/backbone.marionette.templates',
'mixins/AsNamedView', 'mixins/AsNamedView'
'Handlebars/Helpers/DateTime'
], ],
exports: 'Marionette', exports: 'Marionette',
init : function (Backbone, Handlebars, TemplateMixin, AsNamedView, DateTimeHelpers) { init : function (Backbone, TemplateMixin, AsNamedView) {
TemplateMixin.call(Marionette.TemplateCache); TemplateMixin.call(Marionette.TemplateCache);
AsNamedView.call(Marionette.ItemView.prototype); AsNamedView.call(Marionette.ItemView.prototype);
DateTimeHelpers.register(Handlebars);
} }
}, },
signalR: {
deps:
[
'$'
]
},
'backbone.pageable': { 'backbone.pageable': {
deps: deps:
[ [

Loading…
Cancel
Save