summaryrefslogtreecommitdiffstats
path: root/core/js/update.js
blob: bc8df0e20c058d8e3597c3a644711658a384b7cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
 * 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,

		/**
		 * Start the upgrade process.
		 *
		 * @param $el progress list element
		 */
		start: function($el, options) {
			if (this._started) {
				return;
			}

			var hasWarnings = false;

			this.$el = $el;

			this._started = true;
			this.addMessage(t(
				'core',
				'Updating {productName} to version {version}, this may take a while.', {
					productName: options.productName || 'ownCloud',
					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');
			updateEventSource.listen('success', function(message) {
				$('<span>').append(message).append('<br />').appendTo($el);
			});
			updateEventSource.listen('notice', function(message) {
				$('<span>').addClass('error').append(message).append('<br />').appendTo($el);
				hasWarnings = true;
			});
			updateEventSource.listen('error', function(message) {
				message = message || t('core', 'An error occurred.');
				$('<span>').addClass('error').append(message).append('<br />').appendTo($el);
				message = t('core', 'Please reload the page.');
				$('<span>').addClass('error').append('<a href=".">'+message+'</a><br />').appendTo($el);
				updateEventSource.close();
			});
			updateEventSource.listen('failure', function(message) {
				$('<span>').addClass('error').append(message).append('<br />').appendTo($el);
				$('<span>')
				.addClass('bold')
				.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>.'))
				.appendTo($el);
			});
			updateEventSource.listen('done', function() {
				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);
				} else {
					// FIXME: use product name
					$('<span>').addClass('bold')
						.append('<br />')
						.append(t('core', 'The update was successful. Redirecting you to ownCloud now.'))
						.appendTo($el);
					setTimeout(function () {
						OC.redirect(OC.webroot);
					}, 3000);
				}
			});
		},

		addMessage: function(message, className) {
			var $span = $('<span>');
			$span.addClass(className).append(message).append('<br />').appendTo(this.$el);
			return $span;
		}
	};

})();

$(document).ready(function() {
	$('.updateButton').on('click', function() {
		var $updateEl = $('.update');
		var $progressEl = $('.updateProgress');
		$progressEl.removeClass('hidden');
		$('.updateOverview').addClass('hidden');
		OC.Update.start($progressEl, {
			productName: $updateEl.attr('data-productname'),
			version: $updateEl.attr('data-version'),
		});
		return false;
	});
});