// Helpers to render the file view define('helpers/fileHelper', ['handlebars', 'utils/apitypes', 'helpers/formatTimeLeft'], 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 ''; } function fileIcon(media, options) { switch (media) { case Api.MediaType.Audio: return 'icon-music'; case Api.MediaType.Image: return 'icon-picture'; case Api.MediaType.Video: return 'icon-film'; case Api.MediaType.Document: return 'icon-file-text'; case Api.MediaType.Archive: return 'icon-archive'; case Api.MediaType.Executable: return 'icon-cog'; default: return 'icon-file-alt'; } } // TODO rest of the states function fileStatus(file, options) { var s; var msg = file.download.statusmsg; if (file.failed) { s = ' '; if (file.download.error) s += file.download.error; else s += msg; } else if (file.finished) s = ' ' + msg; else if (file.downloading) s = '
  ' + formatTime(file.eta) + '
'; else if (file.waiting) s = ' ' + 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; });