You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

update.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 upgrade 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. $(window).on('beforeunload.inprogress', function () {
  26. return t('core', 'The upgrade is in progress, leaving this page might interrupt the process in some environments.');
  27. });
  28. this.addMessage(t(
  29. 'core',
  30. 'Updating {productName} to version {version}, this may take a while.', {
  31. productName: options.productName || 'ownCloud',
  32. version: options.version
  33. }),
  34. 'bold'
  35. ).append('<br />'); // FIXME: these should be ul/li with CSS paddings!
  36. var updateEventSource = new OC.EventSource(OC.webroot+'/core/ajax/update.php');
  37. updateEventSource.listen('success', function(message) {
  38. $('<span>').append(message).append('<br />').appendTo($el);
  39. });
  40. updateEventSource.listen('notice', function(message) {
  41. $('<span>').addClass('error').append(message).append('<br />').appendTo($el);
  42. hasWarnings = true;
  43. });
  44. updateEventSource.listen('error', function(message) {
  45. message = message || t('core', 'An error occurred.');
  46. $(window).off('beforeunload.inprogress');
  47. $('<span>').addClass('error').append(message).append('<br />').appendTo($el);
  48. message = t('core', 'Please reload the page.');
  49. $('<span>').addClass('error').append('<a href=".">'+message+'</a><br />').appendTo($el);
  50. updateEventSource.close();
  51. });
  52. updateEventSource.listen('failure', function(message) {
  53. $(window).off('beforeunload.inprogress');
  54. $('<span>').addClass('error').append(message).append('<br />').appendTo($el);
  55. $('<span>')
  56. .addClass('bold')
  57. .append(t('core', 'The update was unsuccessful. ' +
  58. 'Please report this issue to the ' +
  59. '<a href="https://github.com/owncloud/core/issues" target="_blank">ownCloud community</a>.'))
  60. .appendTo($el);
  61. });
  62. updateEventSource.listen('done', function() {
  63. $(window).off('beforeunload.inprogress');
  64. if (hasWarnings) {
  65. $('<span>').addClass('bold')
  66. .append('<br />')
  67. .append(t('core', 'The update was successful. There were warnings.'))
  68. .appendTo($el);
  69. var message = t('core', 'Please reload the page.');
  70. $('<span>').append('<br />').append(message).append('<br />').appendTo($el);
  71. } else {
  72. // FIXME: use product name
  73. $('<span>').addClass('bold')
  74. .append('<br />')
  75. .append(t('core', 'The update was successful. Redirecting you to ownCloud now.'))
  76. .appendTo($el);
  77. setTimeout(function () {
  78. OC.redirect(OC.webroot + '/');
  79. }, 3000);
  80. }
  81. });
  82. },
  83. addMessage: function(message, className) {
  84. var $span = $('<span>');
  85. $span.addClass(className).append(message).append('<br />').appendTo(this.$el);
  86. return $span;
  87. }
  88. };
  89. })();
  90. $(document).ready(function() {
  91. $('.updateButton').on('click', function() {
  92. var $updateEl = $('.update');
  93. var $progressEl = $('.updateProgress');
  94. $progressEl.removeClass('hidden');
  95. $('.updateOverview').addClass('hidden');
  96. OC.Update.start($progressEl, {
  97. productName: $updateEl.attr('data-productname'),
  98. version: $updateEl.attr('data-version'),
  99. });
  100. return false;
  101. });
  102. });