diff --git a/js/h5p-content-upgrade.js b/js/h5p-content-upgrade.js index 9c1e4ce..03f04a0 100644 --- a/js/h5p-content-upgrade.js +++ b/js/h5p-content-upgrade.js @@ -66,9 +66,10 @@ * Start a new content upgrade. * * @param {Number} libraryId + * @param {Object} events * @returns {_L1.ContentUpgrade} */ - function ContentUpgrade(libraryId) { + function ContentUpgrade(libraryId, events) { var self = this; // Get selected version @@ -84,7 +85,11 @@ // Track number of working self.working = 0; + self.events = events || {}; + var start = function () { + self.trigger('start'); + // Get the next batch self.nextBatch({ libraryId: libraryId, @@ -194,6 +199,9 @@ * @param {String} msg */ ContentUpgrade.prototype.setStatus = function (msg) { + this.trigger('status', { + message: msg + }); $container.html(msg); }; @@ -247,6 +255,10 @@ self.current++; self.working++; + self.trigger('assign', { + id: id + }); + if (worker) { worker.postMessage({ action: 'newJob', @@ -296,6 +308,12 @@ // Update progress message self.throbber.setProgress(Math.round((info.total - self.left + self.current) / (info.total / 100)) + ' %'); + self.trigger('upgraded', { + id: id, + params: result, + percentComplete: percentComplete, + }); + // Assign next job if (self.assignWork(worker) === false && self.working === 0) { // All workers have finsihed. @@ -319,6 +337,8 @@ self.workers[i].terminate(); } } + + self.trigger('terminate'); }; var librariesLoadedCallbacks = {}; @@ -417,7 +437,25 @@ error = info.errorScript.replace('%lib', error.library); } + self.trigger('error', { + message: error, + infoError: info.error, + }); + self.setStatus('
' + info.error + '
' + error + '