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 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. this.$el = $el;
  23. this._started = true;
  24. this.addMessage(t(
  25. 'core',
  26. 'Updating {productName} to version {version}, this may take a while.', {
  27. productName: options.productName || 'ownCloud',
  28. version: options.version
  29. }),
  30. 'bold'
  31. ).append('<br />'); // FIXME: these should be ul/li with CSS paddings!
  32. var updateEventSource = new OC.EventSource(OC.webroot+'/core/ajax/update.php');
  33. updateEventSource.listen('success', function(message) {
  34. $('<span>').append(message).append('<br />').appendTo($el);
  35. });
  36. updateEventSource.listen('notice', function(message) {
  37. $('<span>').addClass('error').append(message).append('<br />').appendTo($el);
  38. });
  39. updateEventSource.listen('error', function(message) {
  40. $('<span>').addClass('error').append(message).append('<br />').appendTo($el);
  41. message = t('core', 'Please reload the page.');
  42. $('<span>').addClass('error').append(message).append('<br />').appendTo($el);
  43. updateEventSource.close();
  44. });
  45. updateEventSource.listen('failure', function(message) {
  46. $('<span>').addClass('error').append(message).append('<br />').appendTo($el);
  47. $('<span>')
  48. .addClass('bold')
  49. .append(t('core', 'The update was unsuccessful. ' +
  50. 'Please report this issue to the ' +
  51. '<a href="https://github.com/owncloud/core/issues" target="_blank">ownCloud community</a>.'))
  52. .appendTo($el);
  53. });
  54. updateEventSource.listen('done', function() {
  55. // FIXME: use product name
  56. $('<span>').addClass('bold')
  57. .append('<br />')
  58. .append(t('core', 'The update was successful. Redirecting you to ownCloud now.'))
  59. .appendTo($el);
  60. setTimeout(function () {
  61. OC.redirect(OC.webroot);
  62. }, 3000);
  63. });
  64. },
  65. addMessage: function(message, className) {
  66. var $span = $('<span>');
  67. $span.addClass(className).append(message).append('<br />').appendTo(this.$el);
  68. return $span;
  69. }
  70. };
  71. })();
  72. $(document).ready(function() {
  73. $('.updateButton').on('click', function() {
  74. var $updateEl = $('.update');
  75. var $progressEl = $('.updateProgress');
  76. $progressEl.removeClass('hidden');
  77. $('.updateOverview').addClass('hidden');
  78. OC.Update.start($progressEl, {
  79. productName: $updateEl.attr('data-productname'),
  80. version: $updateEl.attr('data-version'),
  81. });
  82. return false;
  83. });
  84. });