server/core/js/update.js

167 lines
4.8 KiB
JavaScript
Raw Normal View History

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 update process.
2014-05-26 16:43:26 +00:00
*
* @param $el progress list element
*/
start: function($el, options) {
2014-05-26 16:43:26 +00:00
if (this._started) {
return;
}
var hasWarnings = false;
2014-05-26 16:43:26 +00:00
this.$el = $el;
this._started = true;
var self = this;
$(window).on('beforeunload.inprogress', function () {
return t('core', 'The update is in progress, leaving this page might interrupt the process in some environments.');
});
$('#update-progress-title').html(t(
2014-05-26 16:43:26 +00:00
'core',
'Update to {version}', {
version: options.version
})
);
2014-05-26 16:43:26 +00:00
var updateEventSource = new OC.EventSource(OC.webroot+'/core/ajax/update.php');
updateEventSource.listen('success', function(message) {
self.setMessage(message);
2014-05-26 16:43:26 +00:00
});
updateEventSource.listen('notice', function(message) {
self.setPermanentMessage(message);
hasWarnings = true;
});
2014-05-26 16:43:26 +00:00
updateEventSource.listen('error', function(message) {
$('#update-progress-message').hide();
$('#update-progress-icon')
.addClass('icon-error-white')
.removeClass('icon-loading-dark');
message = message || t('core', 'An error occurred.');
$(window).off('beforeunload.inprogress');
self.setErrorMessage(message);
2014-05-26 16:43:26 +00:00
message = t('core', 'Please reload the page.');
$('<p>').append('<a href=".">'+message+'</a>').appendTo($el);
2014-05-26 16:43:26 +00:00
updateEventSource.close();
});
updateEventSource.listen('failure', function(message) {
$(window).off('beforeunload.inprogress');
$('#update-progress-message').hide();
$('#update-progress-icon')
.addClass('icon-error-white')
.removeClass('icon-loading-dark');
self.setErrorMessage(message);
var updateUnsuccessful = $('<p>');
if(message === 'Exception: Updates between multiple major versions and downgrades are unsupported.') {
updateUnsuccessful.append(t('core', 'The update was unsuccessful. For more information <a href="{url}">check our forum post</a> covering this issue.', {'url': 'https://help.nextcloud.com/t/updates-between-multiple-major-versions-are-unsupported/7094'}));
} else {
updateUnsuccessful.append(t('core', 'The update was unsuccessful. ' +
'Please report this issue to the ' +
'<a href="https://github.com/nextcloud/server/issues" target="_blank">Nextcloud community</a>.'));
}
updateUnsuccessful.appendTo($el);
2014-05-26 16:43:26 +00:00
});
updateEventSource.listen('done', function() {
$(window).off('beforeunload.inprogress');
$('#update-progress-message').hide();
$('#update-progress-icon')
.addClass('icon-checkmark-white')
.removeClass('icon-loading-dark');
if (hasWarnings) {
$el.find('.update-show-detailed').before(
$('<input type="button" class="update-continue" value="'+t('core', 'Continue to Nextcloud')+'">').on('click', function() {
window.location.reload();
})
);
} else {
// FIXME: use product name
$el.find('.update-show-detailed').before(
$('<p id="redirect-countdown"></p>')
);
for(var i = 0; i <= 4; i++){
self.updateCountdown(i, 4);
}
setTimeout(function () {
OC.redirect(window.location.href);
}, 3000);
}
2014-05-26 16:43:26 +00:00
});
},
updateCountdown: function (i, total) {
setTimeout(function(){
$("#redirect-countdown").text(n('core', 'The update was successful. Redirecting you to Nextcloud in %n second.', 'The update was successful. Redirecting you to Nextcloud in %n seconds.', i));
}, (total - i) * 1000);
},
setMessage: function(message) {
$('#update-progress-message').html(message);
$('#update-progress-detailed')
.append('<p>' + message + '</p>');
},
setPermanentMessage: function(message) {
$('#update-progress-message').html(message);
$('#update-progress-message-warnings')
.show()
.append($('<ul>').append(message));
$('#update-progress-detailed')
.append('<p>' + message + '</p>');
},
setErrorMessage: function (message) {
$('#update-progress-message-error')
.show()
.html(message);
$('#update-progress-detailed')
.append('<p>' + message + '</p>');
2014-05-26 16:43:26 +00:00
}
};
})();
$(document).ready(function() {
$('.updateButton').on('click', function() {
var $updateEl = $('.update');
var $progressEl = $('.update-progress');
2014-05-26 16:43:26 +00:00
$progressEl.removeClass('hidden');
$('.updateOverview').addClass('hidden');
$('#update-progress-message-error').hide();
$('#update-progress-message-warnings').hide();
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
});
$('.update-show-detailed').on('click', function() {
$('#update-progress-detailed').toggleClass('hidden');
return false;
});
});