diff options
Diffstat (limited to 'core/js/update.js')
-rw-r--r-- | core/js/update.js | 142 |
1 files changed, 94 insertions, 48 deletions
diff --git a/core/js/update.js b/core/js/update.js index 77ac1bb20ff..419ab65449f 100644 --- a/core/js/update.js +++ b/core/js/update.js @@ -1,19 +1,16 @@ -/* - * Copyright (c) 2014 - * - * This file is licensed under the Affero General Public License version 3 - * or later. - * - * See the COPYING-README file. - * +/** + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2014 ownCloud Inc. + * SPDX-License-Identifier: AGPL-3.0-or-later */ (function() { OC.Update = { _started : false, + options: {}, /** - * Start the upgrade process. + * Start the update process. * * @param $el progress list element */ @@ -22,97 +19,146 @@ 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 upgrade is in progress, leaving this page might interrupt the process in some environments.'); + return t('core', 'The update is in progress, leaving this page might interrupt the process in some environments.'); }); - this.addMessage(t( + $('#update-progress-title').html(t( 'core', - 'Updating {productName} to version {version}, this may take a while.', { - productName: options.productName || 'ownCloud', + 'Update to {version}', { version: options.version - }), - 'bold' - ).append('<br />'); // FIXME: these should be ul/li with CSS paddings! + }) + ); - var updateEventSource = new OC.EventSource(OC.webroot+'/core/ajax/update.php'); + var updateEventSource = new OC.EventSource(OC.getRootPath()+'/core/ajax/update.php'); updateEventSource.listen('success', function(message) { - $('<span>').append(message).append('<br />').appendTo($el); + self.setMessage(message); }); updateEventSource.listen('notice', function(message) { - $('<span>').addClass('error').append(message).append('<br />').appendTo($el); + 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'); - $('<span>').addClass('error').append(message).append('<br />').appendTo($el); + self.setErrorMessage(message); message = t('core', 'Please reload the page.'); - $('<span>').addClass('error').append('<a href=".">'+message+'</a><br />').appendTo($el); + $('<p>').append('<a href=".">'+message+'</a>').appendTo($el); updateEventSource.close(); }); updateEventSource.listen('failure', function(message) { $(window).off('beforeunload.inprogress'); - $('<span>').addClass('error').append(message).append('<br />').appendTo($el); - var span = $('<span>') - .addClass('bold'); + $('#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.') { - span.append(t('core', 'The update was unsuccessful. For more information <a href="{url}">check our forum post</a> covering this issue.', {'url': 'https://forum.owncloud.org/viewtopic.php?f=17&t=32087'})); - } else { - span.append(t('core', 'The update was unsuccessful. ' + + 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 if (OC.Update.options.productName === 'Nextcloud') { + updateUnsuccessful.append(t('core', 'The update was unsuccessful. ' + 'Please report this issue to the ' + - '<a href="https://github.com/owncloud/core/issues" target="_blank">ownCloud community</a>.')); + '<a href="https://github.com/nextcloud/server/issues" target="_blank">Nextcloud community</a>.')); } - span.appendTo($el); + 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) { - $('<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); + $el.find('.update-show-detailed').before( + $('<input type="button" class="primary" value="'+t('core', 'Continue to {productName}', OC.Update.options)+'">').on('click', function() { + window.location.reload(); + }) + ); } else { - // FIXME: use product name - $('<span>').addClass('bold') - .append('<br />') - .append(t('core', 'The update was successful. Redirecting you to ownCloud now.')) - .appendTo($el); + $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(OC.webroot + '/'); + OC.redirect(window.location.href); }, 3000); } }); }, - addMessage: function(message, className) { - var $span = $('<span>'); - $span.addClass(className).append(message).append('<br />').appendTo(this.$el); - return $span; + 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('<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>'); } }; })(); -$(document).ready(function() { +window.addEventListener('DOMContentLoaded', function() { $('.updateButton').on('click', function() { var $updateEl = $('.update'); - var $progressEl = $('.updateProgress'); + var $progressEl = $('.update-progress'); $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'), + version: $updateEl.attr('data-version') }); return false; }); + + $('.update-show-detailed').on('click', function() { + $('#update-progress-detailed').toggleClass('hidden'); + return false; + }); }); |