summaryrefslogtreecommitdiffstats
path: root/pyload/web/app/scripts/helpers/fileHelper.js
diff options
context:
space:
mode:
Diffstat (limited to 'pyload/web/app/scripts/helpers/fileHelper.js')
-rw-r--r--pyload/web/app/scripts/helpers/fileHelper.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/pyload/web/app/scripts/helpers/fileHelper.js b/pyload/web/app/scripts/helpers/fileHelper.js
new file mode 100644
index 000000000..156be58f0
--- /dev/null
+++ b/pyload/web/app/scripts/helpers/fileHelper.js
@@ -0,0 +1,55 @@
+// Helpers to render the file view
+define('helpers/fileHelper', ['handlebars', 'utils/apitypes', 'helpers/formatTime'],
+ function(Handlebars, Api, formatTime) {
+ 'use strict';
+
+ function fileClass(file, options) {
+ if (file.finished)
+ return 'finished';
+ else if (file.failed)
+ return 'failed';
+ else if (file.offline)
+ return 'offline';
+ else if (file.online)
+ return 'online';
+ else if (file.waiting)
+ return 'waiting';
+ else if (file.downloading)
+ return 'downloading';
+
+ return '';
+ }
+
+ // TODO
+ function fileIcon(media, options) {
+ return 'icon-music';
+ }
+
+ // TODO rest of the states
+ function fileStatus(file, options) {
+ var s;
+ var msg = file.download.statusmsg;
+
+ if (file.failed) {
+ s = '<i class="icon-remove"></i>&nbsp;';
+ if (file.download.error)
+ s += file.download.error;
+ else s += msg;
+ } else if (file.finished)
+ s = '<i class="icon-ok"></i>&nbsp;' + msg;
+ else if (file.downloading)
+ s = '<div class="progress"><div class="bar" style="width: ' + file.progress + '%">&nbsp;&nbsp;' +
+ formatTime(file.eta) + '</div></div>';
+ else if (file.waiting)
+ s = '<i class="icon-time"></i>&nbsp;' + formatTime(file.eta);
+ else
+ s = msg;
+
+ return new Handlebars.SafeString(s);
+ }
+
+ Handlebars.registerHelper('fileClass', fileClass);
+ Handlebars.registerHelper('fileIcon', fileIcon);
+ Handlebars.registerHelper('fileStatus', fileStatus);
+ return fileClass;
+ }); \ No newline at end of file