/** * This model is used by the system bootstrapper in public/bootstrap. * @constructor */ function BootstrapperViewModel() { this.el = '#bootstrapper'; this.data = { isCompleted: false, isRunning: false, operations: [] } this.methods = { bootstrap: function() { this.operations.push({ 'isCompleted': false, 'isRunning': false, 'name': 'Removing any previous versions', 'url': '?act=removePrevious' }); this.operations.push({ 'isCompleted': false, 'isRunning': false, 'name': 'Downloading new files', 'url': '?act=download' }); this.operations.push({ 'isCompleted': false, 'isRunning': false, 'name': 'Extracting new files', 'url': '?act=extract' }); this.operations.push({ 'isCompleted': false, 'isRunning': false, 'name': 'Cleaning up', 'url': '?act=finalise' }); this.isRunning = true; this.runOperation(this.operations[0], 0); }, runOperation: function(operation, index) { var self = this; operation.isRunning = true; $.post(operation.url) .done(function(result) { operation.isRunning = false; operation.isCompleted = true; index++; if (index < self.operations.length) { self.runOperation(self.operations[index], index); } else { //self.isRunning = false; self.isCompleted = true; window.location = '../'; } }) } } }