blue-twilight/resources/js/bootstrapper.js

71 lines
1.9 KiB
JavaScript

/**
* 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()
{
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=cleanup'
});
this.isRunning = true;
this.runOperation(this.operations[0], 0);
},
runOperation(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;
}
})
}
}
}