From d2b45c5442aeb0e02f251916ae1beb06830ef4c1 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Tue, 12 Mar 2013 18:15:36 +0100 Subject: render download progress --- module/web/static/js/models/Progress.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'module/web/static/js/models/Progress.js') diff --git a/module/web/static/js/models/Progress.js b/module/web/static/js/models/Progress.js index ebbe34862..c6a2fc4d1 100644 --- a/module/web/static/js/models/Progress.js +++ b/module/web/static/js/models/Progress.js @@ -2,10 +2,11 @@ define(['jquery', 'backbone', 'underscore'], function($, Backbone, _) { return Backbone.Model.extend({ -// TODO -// idAttribute: 'fid', + // generated, not submitted + idAttribute: 'pid', defaults: { + pid: -1, plugin: null, name: null, statusmsg: -1, @@ -15,7 +16,6 @@ define(['jquery', 'backbone', 'underscore'], function($, Backbone, _) { download: null }, - // Model Constructor initialize: function() { @@ -26,8 +26,18 @@ define(['jquery', 'backbone', 'underscore'], function($, Backbone, _) { }, + toJSON: function(options) { + var obj = Backbone.Model.prototype.toJSON.call(this, options); + if (obj.total > 0) + obj.percent = Math.round(obj.done * 100 / obj.total); + else + obj.percent = 0; + + return obj; + }, + isDownload : function() { - return this.has('download') + return this.has('download'); } }); -- cgit v1.2.3