summaryrefslogtreecommitdiffstats
path: root/pyload/web/app/scripts/helpers
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-08-11 20:36:10 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-08-11 20:36:10 +0200
commit080643e89af62013d70bb574cd54cf4876628515 (patch)
treee79e3bebe9175da613c4a339fc4ac3fa172ecced /pyload/web/app/scripts/helpers
parentanother try to fix broken accounts (diff)
downloadpyload-080643e89af62013d70bb574cd54cf4876628515.tar.xz
improved account list
Diffstat (limited to 'pyload/web/app/scripts/helpers')
-rw-r--r--pyload/web/app/scripts/helpers/fileHelper.js2
-rw-r--r--pyload/web/app/scripts/helpers/formatSize.js6
-rw-r--r--pyload/web/app/scripts/helpers/formatTime.js21
-rw-r--r--pyload/web/app/scripts/helpers/formatTimeLeft.js17
4 files changed, 33 insertions, 13 deletions
diff --git a/pyload/web/app/scripts/helpers/fileHelper.js b/pyload/web/app/scripts/helpers/fileHelper.js
index 044887eea..2e14f939f 100644
--- a/pyload/web/app/scripts/helpers/fileHelper.js
+++ b/pyload/web/app/scripts/helpers/fileHelper.js
@@ -1,5 +1,5 @@
// Helpers to render the file view
-define('helpers/fileHelper', ['handlebars', 'utils/apitypes', 'helpers/formatTime'],
+define('helpers/fileHelper', ['handlebars', 'utils/apitypes', 'helpers/formatTimeLeft'],
function(Handlebars, Api, formatTime) {
'use strict';
diff --git a/pyload/web/app/scripts/helpers/formatSize.js b/pyload/web/app/scripts/helpers/formatSize.js
index 926c4793d..f72d62158 100644
--- a/pyload/web/app/scripts/helpers/formatSize.js
+++ b/pyload/web/app/scripts/helpers/formatSize.js
@@ -1,14 +1,14 @@
// Format bytes in human readable format
-define('helpers/formatSize', ['handlebars', './gettext'], function(Handlebars, gettext) {
+define('helpers/formatSize', ['handlebars', 'utils/i18n'], function(Handlebars, i18n) {
'use strict';
var sizes = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB'];
function formatSize(bytes, options) {
if (!bytes || bytes === 0) return '0 B';
if (bytes === -1)
- return gettext('not available');
+ return i18n.gettext('not available');
if (bytes === -2)
- return gettext('unlimited');
+ return i18n.gettext('unlimited');
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)), 10);
// round to two digits
diff --git a/pyload/web/app/scripts/helpers/formatTime.js b/pyload/web/app/scripts/helpers/formatTime.js
index 757ff73ad..0fb0f6058 100644
--- a/pyload/web/app/scripts/helpers/formatTime.js
+++ b/pyload/web/app/scripts/helpers/formatTime.js
@@ -1,15 +1,18 @@
-// Format bytes in human readable format
-define('helpers/formatTime', ['handlebars', 'vendor/remaining'], function(Handlebars, Remaining) {
+// Formats a timestamp
+define('helpers/formatTime', ['underscore','handlebars', 'moment', 'utils/i18n'],
+ function(_, Handlebars, moment, i18n) {
'use strict';
- function formatTime(seconds, options) {
- if (seconds === Infinity)
- return '∞';
- else if (!seconds || seconds <= 0)
- return '-';
+ function formatTime(time, format) {
+ if (time === -1)
+ return i18n.gettext('unkown');
+ else if (time === -2)
+ return i18n.gettext('unlimited');
- // TODO: digital or written string
- return Remaining.getStringDigital(seconds, window.dates);
+ if (!_.isString(format))
+ format = 'lll';
+
+ return moment(time).format(format);
}
Handlebars.registerHelper('formatTime', formatTime);
diff --git a/pyload/web/app/scripts/helpers/formatTimeLeft.js b/pyload/web/app/scripts/helpers/formatTimeLeft.js
new file mode 100644
index 000000000..dafeda3e2
--- /dev/null
+++ b/pyload/web/app/scripts/helpers/formatTimeLeft.js
@@ -0,0 +1,17 @@
+// Format seconds in human readable format
+define('helpers/formatTimeLeft', ['handlebars', 'vendor/remaining'], function(Handlebars, Remaining) {
+ 'use strict';
+
+ function formatTimeLeft(seconds, options) {
+ if (seconds === Infinity)
+ return '∞';
+ else if (!seconds || seconds <= 0)
+ return '-';
+
+ // TODO: digital or written string
+ return Remaining.getStringDigital(seconds, window.dates);
+ }
+
+ Handlebars.registerHelper('formatTimeLeft', formatTimeLeft);
+ return formatTimeLeft;
+}); \ No newline at end of file