2014-05-26 16:43:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
* or later.
|
|
|
|
*
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
OC.Update = {
|
|
|
|
_started : false,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start the upgrade process.
|
|
|
|
*
|
|
|
|
* @param $el progress list element
|
|
|
|
*/
|
2015-01-14 10:31:42 +00:00
|
|
|
start: function($el, options) {
|
2014-05-26 16:43:26 +00:00
|
|
|
if (this._started) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-07 11:38:24 +00:00
|
|
|
var hasWarnings = false;
|
|
|
|
|
2014-05-26 16:43:26 +00:00
|
|
|
this.$el = $el;
|
|
|
|
|
|
|
|
this._started = true;
|
|
|
|
this.addMessage(t(
|
|
|
|
'core',
|
|
|
|
'Updating {productName} to version {version}, this may take a while.', {
|
2015-01-14 10:31:42 +00:00
|
|
|
productName: options.productName || 'ownCloud',
|
|
|
|
version: options.version
|
2014-05-26 16:43:26 +00:00
|
|
|
}),
|
|
|
|
'bold'
|
|
|
|
).append('<br />'); // FIXME: these should be ul/li with CSS paddings!
|
|
|
|
|
|
|
|
var updateEventSource = new OC.EventSource(OC.webroot+'/core/ajax/update.php');
|
|
|
|
updateEventSource.listen('success', function(message) {
|
|
|
|
$('<span>').append(message).append('<br />').appendTo($el);
|
|
|
|
});
|
2015-02-17 11:00:39 +00:00
|
|
|
updateEventSource.listen('notice', function(message) {
|
|
|
|
$('<span>').addClass('error').append(message).append('<br />').appendTo($el);
|
2015-07-07 11:38:24 +00:00
|
|
|
hasWarnings = true;
|
2015-02-17 11:00:39 +00:00
|
|
|
});
|
2014-05-26 16:43:26 +00:00
|
|
|
updateEventSource.listen('error', function(message) {
|
2015-10-14 06:17:52 +00:00
|
|
|
message = message || t('core', 'An error occurred.');
|
2014-05-26 16:43:26 +00:00
|
|
|
$('<span>').addClass('error').append(message).append('<br />').appendTo($el);
|
|
|
|
message = t('core', 'Please reload the page.');
|
|
|
|
$('<span>').addClass('error').append(message).append('<br />').appendTo($el);
|
|
|
|
updateEventSource.close();
|
|
|
|
});
|
|
|
|
updateEventSource.listen('failure', function(message) {
|
|
|
|
$('<span>').addClass('error').append(message).append('<br />').appendTo($el);
|
|
|
|
$('<span>')
|
2014-12-10 12:29:40 +00:00
|
|
|
.addClass('bold')
|
|
|
|
.append(t('core', 'The update was unsuccessful. ' +
|
2014-05-28 09:29:22 +00:00
|
|
|
'Please report this issue to the ' +
|
|
|
|
'<a href="https://github.com/owncloud/core/issues" target="_blank">ownCloud community</a>.'))
|
2014-05-26 16:43:26 +00:00
|
|
|
.appendTo($el);
|
|
|
|
});
|
2014-05-28 09:29:22 +00:00
|
|
|
updateEventSource.listen('done', function() {
|
2015-07-07 11:38:24 +00:00
|
|
|
if (hasWarnings) {
|
|
|
|
$('<span>').addClass('bold')
|
|
|
|
.append('<br />')
|
|
|
|
.append(t('core', 'The update was successful. There were warnings.'))
|
|
|
|
.appendTo($el);
|
|
|
|
var message = t('core', 'Please reload the page.');
|
|
|
|
$('<span>').append('<br />').append(message).append('<br />').appendTo($el);
|
|
|
|
} else {
|
|
|
|
// FIXME: use product name
|
|
|
|
$('<span>').addClass('bold')
|
|
|
|
.append('<br />')
|
|
|
|
.append(t('core', 'The update was successful. Redirecting you to ownCloud now.'))
|
|
|
|
.appendTo($el);
|
|
|
|
setTimeout(function () {
|
|
|
|
OC.redirect(OC.webroot);
|
|
|
|
}, 3000);
|
|
|
|
}
|
2014-05-26 16:43:26 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
addMessage: function(message, className) {
|
|
|
|
var $span = $('<span>');
|
|
|
|
$span.addClass(className).append(message).append('<br />').appendTo(this.$el);
|
|
|
|
return $span;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
2014-05-28 09:29:22 +00:00
|
|
|
$('.updateButton').on('click', function() {
|
2015-01-14 10:31:42 +00:00
|
|
|
var $updateEl = $('.update');
|
2014-05-26 16:43:26 +00:00
|
|
|
var $progressEl = $('.updateProgress');
|
|
|
|
$progressEl.removeClass('hidden');
|
2014-05-28 09:29:22 +00:00
|
|
|
$('.updateOverview').addClass('hidden');
|
2015-01-14 10:31:42 +00:00
|
|
|
OC.Update.start($progressEl, {
|
|
|
|
productName: $updateEl.attr('data-productname'),
|
|
|
|
version: $updateEl.attr('data-version'),
|
|
|
|
});
|
2014-05-26 16:43:26 +00:00
|
|
|
return false;
|
2013-01-25 18:18:16 +00:00
|
|
|
});
|
2013-07-10 22:00:01 +00:00
|
|
|
});
|