/* * 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, options: {}, /** * Start the update process. * * @param $el progress list element */ start: function($el, options) { if (this._started) { return; } this.options = options; var hasWarnings = false; 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( 'core', 'Update to {version}', { version: options.version }) ); var updateEventSource = new OC.EventSource(OC.getRootPath()+'/core/ajax/update.php'); updateEventSource.listen('success', function(message) { self.setMessage(message); }); updateEventSource.listen('notice', function(message) { self.setPermanentMessage(message); hasWarnings = true; }); 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); message = t('core', 'Please reload the page.'); $('

').append(''+message+'').appendTo($el); 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 = $('

'); if(message === 'Exception: Updates between multiple major versions and downgrades are unsupported.') { updateUnsuccessful.append(t('core', 'The update was unsuccessful. For more information check our forum post covering this issue.', {'url': 'https://help.nextcloud.com/t/updates-between-multiple-major-versions-are-unsupported/7094'})); } else if (OC.Update.options.productName === 'Nextcloud') { updateUnsuccessful.append(t('core', 'The update was unsuccessful. ' + 'Please report this issue to the ' + 'Nextcloud community.')); } updateUnsuccessful.appendTo($el); }); 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( $('').on('click', function() { window.location.reload(); }) ); } else { $el.find('.update-show-detailed').before( $('

') ); for(var i = 0; i <= 4; i++){ self.updateCountdown(i, 4); } setTimeout(function () { OC.redirect(window.location.href); }, 3000); } }); }, updateCountdown: function (i, total) { setTimeout(function(){ $("#redirect-countdown").text( n('core', 'The update was successful. Redirecting you to {productName} in %n second.', 'The update was successful. Redirecting you to {productName} in %n seconds.', i, OC.Update.options) ); }, (total - i) * 1000); }, setMessage: function(message) { $('#update-progress-message').html(message); $('#update-progress-detailed') .append('

' + message + '

'); }, setPermanentMessage: function(message) { $('#update-progress-message').html(message); $('#update-progress-message-warnings') .show() .append($('