update.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (c) 2014
  3. *
  4. * This file is licensed under the Affero General Public License version 3
  5. * or later.
  6. *
  7. * See the COPYING-README file.
  8. *
  9. */
  10. (function() {
  11. OC.Update = {
  12. _started : false,
  13. /**
  14. * Start the update process.
  15. *
  16. * @param $el progress list element
  17. */
  18. start: function($el, options) {
  19. if (this._started) {
  20. return;
  21. }
  22. var hasWarnings = false;
  23. this.$el = $el;
  24. this._started = true;
  25. var self = this;
  26. $(window).on('beforeunload.inprogress', function () {
  27. return t('core', 'The update is in progress, leaving this page might interrupt the process in some environments.');
  28. });
  29. $('#update-progress-title').html(t(
  30. 'core',
  31. 'Update to {version}', {
  32. version: options.version
  33. })
  34. );
  35. var updateEventSource = new OC.EventSource(OC.webroot+'/core/ajax/update.php');
  36. updateEventSource.listen('success', function(message) {
  37. self.setMessage(message);
  38. });
  39. updateEventSource.listen('notice', function(message) {
  40. self.setPermanentMessage(message);
  41. hasWarnings = true;
  42. });
  43. updateEventSource.listen('error', function(message) {
  44. $('#update-progress-message').hide();
  45. $('#update-progress-icon')
  46. .addClass('icon-error-white')
  47. .removeClass('icon-loading-dark');
  48. message = message || t('core', 'An error occurred.');
  49. $(window).off('beforeunload.inprogress');
  50. self.setErrorMessage(message);
  51. message = t('core', 'Please reload the page.');
  52. $('<span>').addClass('error').append('<a href=".">'+message+'</a><br />').appendTo($el);
  53. updateEventSource.close();
  54. });
  55. updateEventSource.listen('failure', function(message) {
  56. $(window).off('beforeunload.inprogress');
  57. $('#update-progress-message').hide();
  58. $('#update-progress-icon')
  59. .addClass('icon-error-white')
  60. .removeClass('icon-loading-dark');
  61. self.setErrorMessage(message);
  62. var span = $('<span>')
  63. .addClass('bold');
  64. if(message === 'Exception: Updates between multiple major versions and downgrades are unsupported.') {
  65. 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'}));
  66. } else {
  67. span.append(t('core', 'The update was unsuccessful. ' +
  68. 'Please report this issue to the ' +
  69. '<a href="https://github.com/nextcloud/server/issues" target="_blank">Nextcloud community</a>.'));
  70. }
  71. span.appendTo($el);
  72. });
  73. updateEventSource.listen('done', function() {
  74. $(window).off('beforeunload.inprogress');
  75. $('#update-progress-message').hide();
  76. $('#update-progress-icon')
  77. .addClass('icon-checkmark-white')
  78. .removeClass('icon-loading-dark');
  79. if (hasWarnings) {
  80. $el.find('.update-show-detailed').before(
  81. $('<input type="button" class="update-continue" value="'+t('core', 'Continue to Nextcloud')+'">').on('click', function() {
  82. window.location.reload();
  83. })
  84. );
  85. } else {
  86. // FIXME: use product name
  87. $el.find('.update-show-detailed').before(
  88. $('<p>'+t('core', 'The update was successful. Redirecting you to Nextcloud now.')+'</p>')
  89. );
  90. setTimeout(function () {
  91. OC.redirect(OC.webroot + '/');
  92. }, 3000);
  93. }
  94. });
  95. },
  96. setMessage: function(message) {
  97. $('#update-progress-message').html(message);
  98. $('#update-progress-detailed')
  99. .append($('<span>'))
  100. .append(message)
  101. .append($('<br>'));
  102. },
  103. setPermanentMessage: function(message) {
  104. $('#update-progress-message').html(message);
  105. $('#update-progress-message-warnings')
  106. .show()
  107. .append($('<ul>').append(message));
  108. $('#update-progress-detailed')
  109. .append($('<span>'))
  110. .append(message)
  111. .append($('<br>'));
  112. },
  113. setErrorMessage: function (message) {
  114. $('#update-progress-message-error')
  115. .show()
  116. .html(message);
  117. $('#update-progress-detailed')
  118. .append($('<span>'))
  119. .append(message)
  120. .append($('<br>'));
  121. }
  122. };
  123. })();
  124. $(document).ready(function() {
  125. $('.updateButton').on('click', function() {
  126. var $updateEl = $('.update');
  127. var $progressEl = $('.update-progress');
  128. $progressEl.removeClass('hidden');
  129. $('.updateOverview').addClass('hidden');
  130. $('#update-progress-message-error').hide();
  131. $('#update-progress-message-warnings').hide();
  132. OC.Update.start($progressEl, {
  133. productName: $updateEl.attr('data-productname'),
  134. version: $updateEl.attr('data-version')
  135. });
  136. return false;
  137. });
  138. $('.update-show-detailed').on('click', function() {
  139. $('#update-progress-detailed').toggleClass('hidden');
  140. return false;
  141. });
  142. });