2014-05-26 16:43:26 +00:00
/ *
* 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
* /
2015-01-14 10:31:42 +00:00
start : function ( $el , options ) {
2014-05-26 16:43:26 +00:00
if ( this . _started ) {
return ;
}
2015-07-07 11:38:24 +00:00
var hasWarnings = false ;
2014-05-26 16:43:26 +00:00
this . $el = $el ;
this . _started = true ;
2015-10-13 15:34:13 +00:00
2016-03-30 21:38:26 +00:00
var self = this ;
2015-10-13 15:34:13 +00:00
$ ( window ) . on ( 'beforeunload.inprogress' , function ( ) {
return t ( 'core' , 'The upgrade is in progress, leaving this page might interrupt the process in some environments.' ) ;
} ) ;
2016-03-30 21:38:26 +00:00
$ ( '#update-progress-title' ) . html ( t (
2014-05-26 16:43:26 +00:00
'core' ,
2016-03-30 21:38:26 +00:00
'Updating to {version}' , {
2015-01-14 10:31:42 +00:00
version : options . version
2016-03-30 21:38:26 +00:00
} )
) ;
2014-05-26 16:43:26 +00:00
var updateEventSource = new OC . EventSource ( OC . webroot + '/core/ajax/update.php' ) ;
updateEventSource . listen ( 'success' , function ( message ) {
2016-03-30 21:38:26 +00:00
self . setMessage ( message ) ;
2014-05-26 16:43:26 +00:00
} ) ;
2015-02-17 11:00:39 +00:00
updateEventSource . listen ( 'notice' , function ( message ) {
2016-03-30 21:38:26 +00:00
self . setPermanentMessage ( message ) ;
2015-07-07 11:38:24 +00:00
hasWarnings = true ;
2015-02-17 11:00:39 +00:00
} ) ;
2014-05-26 16:43:26 +00:00
updateEventSource . listen ( 'error' , function ( message ) {
2016-03-30 21:38:26 +00:00
$ ( '#update-progress-message' ) . hide ( ) ;
$ ( '#update-progress-icon' )
. addClass ( 'icon-error-white' )
. removeClass ( 'icon-loading-dark' ) ;
2015-10-14 06:17:52 +00:00
message = message || t ( 'core' , 'An error occurred.' ) ;
2015-10-14 08:04:20 +00:00
$ ( window ) . off ( 'beforeunload.inprogress' ) ;
2016-03-30 21:38:26 +00:00
self . setErrorMessage ( message ) ;
2014-05-26 16:43:26 +00:00
message = t ( 'core' , 'Please reload the page.' ) ;
2015-10-10 18:14:01 +00:00
$ ( '<span>' ) . addClass ( 'error' ) . append ( '<a href=".">' + message + '</a><br />' ) . appendTo ( $el ) ;
2014-05-26 16:43:26 +00:00
updateEventSource . close ( ) ;
} ) ;
updateEventSource . listen ( 'failure' , function ( message ) {
2015-10-14 08:04:20 +00:00
$ ( window ) . off ( 'beforeunload.inprogress' ) ;
2016-03-30 21:38:26 +00:00
$ ( '#update-progress-message' ) . hide ( ) ;
$ ( '#update-progress-icon' )
. addClass ( 'icon-error-white' )
. removeClass ( 'icon-loading-dark' ) ;
self . setErrorMessage ( message ) ;
2016-02-08 08:19:16 +00:00
var span = $ ( '<span>' )
. addClass ( 'bold' ) ;
if ( message === 'Exception: Updates between multiple major versions and downgrades are unsupported.' ) {
2016-02-08 09:28:20 +00:00
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' } ) ) ;
2016-02-08 08:19:16 +00:00
} else {
span . 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>.' ) ) ;
}
span . appendTo ( $el ) ;
2014-05-26 16:43:26 +00:00
} ) ;
2014-05-28 09:29:22 +00:00
updateEventSource . listen ( 'done' , function ( ) {
2015-10-13 15:34:13 +00:00
$ ( window ) . off ( 'beforeunload.inprogress' ) ;
2016-03-30 21:38:26 +00:00
$ ( '#update-progress-message' ) . hide ( ) ;
$ ( '#update-progress-icon' )
. addClass ( 'icon-checkmark-white' )
. removeClass ( 'icon-loading-dark' ) ;
2015-07-07 11:38:24 +00:00
if ( hasWarnings ) {
2016-03-31 12:27:01 +00:00
$el . find ( '.update-show-detailed' ) . before (
$ ( '<span>' )
. append ( '<br />' )
. append ( t ( 'core' , 'The update was successful. There were warnings.' ) )
) ;
2015-07-07 11:38:24 +00:00
var message = t ( 'core' , 'Please reload the page.' ) ;
2016-03-31 12:27:01 +00:00
$ ( '<span>' ) . append ( message ) . append ( '<br />' ) . appendTo ( $el ) ;
2015-07-07 11:38:24 +00:00
} else {
// FIXME: use product name
2016-03-30 21:38:26 +00:00
$ ( '<span>' )
2015-07-07 11:38:24 +00:00
. append ( t ( 'core' , 'The update was successful. Redirecting you to ownCloud now.' ) )
. appendTo ( $el ) ;
setTimeout ( function ( ) {
2015-12-07 17:08:00 +00:00
OC . redirect ( OC . webroot + '/' ) ;
2015-07-07 11:38:24 +00:00
} , 3000 ) ;
}
2014-05-26 16:43:26 +00:00
} ) ;
} ,
2016-03-30 21:38:26 +00:00
setMessage : function ( message ) {
$ ( '#update-progress-message' ) . html ( message ) ;
2016-03-31 12:27:01 +00:00
$ ( '#update-progress-detailed' )
. append ( $ ( '<span>' ) )
. append ( message )
. append ( $ ( '<br>' ) ) ;
2016-03-30 21:38:26 +00:00
} ,
setPermanentMessage : function ( message ) {
$ ( '#update-progress-message' ) . html ( message ) ;
$ ( '#update-progress-message-warnings' )
. show ( )
2016-03-31 12:27:01 +00:00
. append ( $ ( '<ul>' ) . append ( message ) ) ;
$ ( '#update-progress-detailed' )
. append ( $ ( '<span>' ) )
. append ( message )
. append ( $ ( '<br>' ) ) ;
2016-03-30 21:38:26 +00:00
} ,
setErrorMessage : function ( message ) {
$ ( '#update-progress-message-error' )
. show ( )
. html ( message ) ;
2016-03-31 12:27:01 +00:00
$ ( '#update-progress-detailed' )
. append ( $ ( '<span>' ) )
. append ( message )
. append ( $ ( '<br>' ) ) ;
2014-05-26 16:43:26 +00:00
}
} ;
} ) ( ) ;
$ ( document ) . ready ( function ( ) {
2014-05-28 09:29:22 +00:00
$ ( '.updateButton' ) . on ( 'click' , function ( ) {
2015-01-14 10:31:42 +00:00
var $updateEl = $ ( '.update' ) ;
2016-03-30 21:38:26 +00:00
var $progressEl = $ ( '.update-progress' ) ;
2014-05-26 16:43:26 +00:00
$progressEl . removeClass ( 'hidden' ) ;
2014-05-28 09:29:22 +00:00
$ ( '.updateOverview' ) . addClass ( 'hidden' ) ;
2016-03-30 21:38:26 +00:00
$ ( '#update-progress-message-error' ) . hide ( ) ;
$ ( '#update-progress-message-warnings' ) . hide ( ) ;
2015-01-14 10:31:42 +00:00
OC . Update . start ( $progressEl , {
productName : $updateEl . attr ( 'data-productname' ) ,
2016-03-30 21:38:26 +00:00
version : $updateEl . attr ( 'data-version' )
2015-01-14 10:31:42 +00:00
} ) ;
2014-05-26 16:43:26 +00:00
return false ;
2013-01-25 18:18:16 +00:00
} ) ;
2016-03-31 12:27:01 +00:00
$ ( '.update-show-detailed' ) . on ( 'click' , function ( ) {
$ ( '#update-progress-detailed' ) . toggleClass ( 'hidden' ) ;
return false ;
} ) ;
2013-07-10 22:00:01 +00:00
} ) ;