2014-05-26 20:43:26 +04: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 ,
/ * *
2016-08-04 13:48:25 +03:00
* Start the update process .
2014-05-26 20:43:26 +04:00
*
* @ param $el progress list element
* /
2015-01-14 13:31:42 +03:00
start : function ( $el , options ) {
2014-05-26 20:43:26 +04:00
if ( this . _started ) {
return ;
}
2015-07-07 14:38:24 +03:00
var hasWarnings = false ;
2014-05-26 20:43:26 +04:00
this . $el = $el ;
this . _started = true ;
2015-10-13 18:34:13 +03:00
2016-03-31 00:38:26 +03:00
var self = this ;
2015-10-13 18:34:13 +03:00
$ ( window ) . on ( 'beforeunload.inprogress' , function ( ) {
2016-08-04 13:48:25 +03:00
return t ( 'core' , 'The update is in progress, leaving this page might interrupt the process in some environments.' ) ;
2015-10-13 18:34:13 +03:00
} ) ;
2016-03-31 00:38:26 +03:00
$ ( '#update-progress-title' ) . html ( t (
2014-05-26 20:43:26 +04:00
'core' ,
2016-08-04 13:48:25 +03:00
'Update to {version}' , {
2015-01-14 13:31:42 +03:00
version : options . version
2016-03-31 00:38:26 +03:00
} )
) ;
2014-05-26 20:43:26 +04:00
var updateEventSource = new OC . EventSource ( OC . webroot + '/core/ajax/update.php' ) ;
updateEventSource . listen ( 'success' , function ( message ) {
2016-03-31 00:38:26 +03:00
self . setMessage ( message ) ;
2014-05-26 20:43:26 +04:00
} ) ;
2015-02-17 14:00:39 +03:00
updateEventSource . listen ( 'notice' , function ( message ) {
2016-03-31 00:38:26 +03:00
self . setPermanentMessage ( message ) ;
2015-07-07 14:38:24 +03:00
hasWarnings = true ;
2015-02-17 14:00:39 +03:00
} ) ;
2014-05-26 20:43:26 +04:00
updateEventSource . listen ( 'error' , function ( message ) {
2016-03-31 00:38:26 +03:00
$ ( '#update-progress-message' ) . hide ( ) ;
$ ( '#update-progress-icon' )
. addClass ( 'icon-error-white' )
. removeClass ( 'icon-loading-dark' ) ;
2015-10-14 09:17:52 +03:00
message = message || t ( 'core' , 'An error occurred.' ) ;
2015-10-14 11:04:20 +03:00
$ ( window ) . off ( 'beforeunload.inprogress' ) ;
2016-03-31 00:38:26 +03:00
self . setErrorMessage ( message ) ;
2014-05-26 20:43:26 +04:00
message = t ( 'core' , 'Please reload the page.' ) ;
2018-08-01 19:54:48 +03:00
$ ( '<p>' ) . append ( '<a href=".">' + message + '</a>' ) . appendTo ( $el ) ;
2014-05-26 20:43:26 +04:00
updateEventSource . close ( ) ;
} ) ;
updateEventSource . listen ( 'failure' , function ( message ) {
2015-10-14 11:04:20 +03:00
$ ( window ) . off ( 'beforeunload.inprogress' ) ;
2016-03-31 00:38:26 +03:00
$ ( '#update-progress-message' ) . hide ( ) ;
$ ( '#update-progress-icon' )
. addClass ( 'icon-error-white' )
. removeClass ( 'icon-loading-dark' ) ;
self . setErrorMessage ( message ) ;
2018-08-03 14:30:49 +03:00
var updateUnsuccessful = $ ( '<p>' ) ;
2016-02-08 11:19:16 +03:00
if ( message === 'Exception: Updates between multiple major versions and downgrades are unsupported.' ) {
2018-08-03 14:30:49 +03:00
updateUnsuccessful . append ( t ( 'core' , 'The update was unsuccessful. For more information <a href="{url}">check our forum post</a> covering this issue.' , { 'url' : 'https://help.nextcloud.com/t/updates-between-multiple-major-versions-are-unsupported/7094' } ) ) ;
2016-02-08 11:19:16 +03:00
} else {
2018-08-03 14:30:49 +03:00
updateUnsuccessful . append ( t ( 'core' , 'The update was unsuccessful. ' +
2016-02-08 11:19:16 +03:00
'Please report this issue to the ' +
2016-06-14 18:02:55 +03:00
'<a href="https://github.com/nextcloud/server/issues" target="_blank">Nextcloud community</a>.' ) ) ;
2016-02-08 11:19:16 +03:00
}
2018-08-03 14:30:49 +03:00
updateUnsuccessful . appendTo ( $el ) ;
2014-05-26 20:43:26 +04:00
} ) ;
2014-05-28 13:29:22 +04:00
updateEventSource . listen ( 'done' , function ( ) {
2015-10-13 18:34:13 +03:00
$ ( window ) . off ( 'beforeunload.inprogress' ) ;
2016-03-31 00:38:26 +03:00
$ ( '#update-progress-message' ) . hide ( ) ;
$ ( '#update-progress-icon' )
. addClass ( 'icon-checkmark-white' )
2017-03-15 09:35:40 +03:00
. removeClass ( 'icon-loading-dark' ) ;
2016-03-31 00:38:26 +03:00
2015-07-07 14:38:24 +03:00
if ( hasWarnings ) {
2016-03-31 15:27:01 +03:00
$el . find ( '.update-show-detailed' ) . before (
2016-08-04 13:48:25 +03:00
$ ( '<input type="button" class="update-continue" value="' + t ( 'core' , 'Continue to Nextcloud' ) + '">' ) . on ( 'click' , function ( ) {
window . location . reload ( ) ;
} )
2016-03-31 15:27:01 +03:00
) ;
2015-07-07 14:38:24 +03:00
} else {
// FIXME: use product name
2017-03-14 23:36:17 +03:00
2016-08-04 13:48:25 +03:00
$el . find ( '.update-show-detailed' ) . before (
2017-03-14 23:36:17 +03:00
$ ( '<p id="redirect-countdown"></p>' )
2016-08-04 13:48:25 +03:00
) ;
2017-02-25 22:16:22 +03:00
2017-03-14 23:36:17 +03:00
for ( var i = 0 ; i <= 4 ; i ++ ) {
self . updateCountdown ( i , 4 ) ;
2017-02-25 22:16:22 +03:00
}
2015-07-07 14:38:24 +03:00
setTimeout ( function ( ) {
2018-08-09 16:19:58 +03:00
OC . redirect ( window . location . href ) ;
2015-07-07 14:38:24 +03:00
} , 3000 ) ;
}
2014-05-26 20:43:26 +04:00
} ) ;
} ,
2017-03-14 23:36:17 +03:00
updateCountdown : function ( i , total ) {
2017-02-25 22:16:22 +03:00
setTimeout ( function ( ) {
2017-03-14 23:36:17 +03:00
$ ( "#redirect-countdown" ) . text ( n ( 'core' , 'The update was successful. Redirecting you to Nextcloud in %n second.' , 'The update was successful. Redirecting you to Nextcloud in %n seconds.' , i ) ) ;
} , ( total - i ) * 1000 ) ;
2017-02-25 22:16:22 +03:00
} ,
2016-03-31 00:38:26 +03:00
setMessage : function ( message ) {
$ ( '#update-progress-message' ) . html ( message ) ;
2016-03-31 15:27:01 +03:00
$ ( '#update-progress-detailed' )
2018-08-03 14:30:49 +03:00
. append ( '<p>' + message + '</p>' ) ;
2016-03-31 00:38:26 +03:00
} ,
setPermanentMessage : function ( message ) {
$ ( '#update-progress-message' ) . html ( message ) ;
$ ( '#update-progress-message-warnings' )
. show ( )
2016-03-31 15:27:01 +03:00
. append ( $ ( '<ul>' ) . append ( message ) ) ;
$ ( '#update-progress-detailed' )
2018-08-03 14:30:49 +03:00
. append ( '<p>' + message + '</p>' ) ;
2016-03-31 00:38:26 +03:00
} ,
2016-08-04 13:48:25 +03:00
2016-03-31 00:38:26 +03:00
setErrorMessage : function ( message ) {
$ ( '#update-progress-message-error' )
. show ( )
. html ( message ) ;
2016-03-31 15:27:01 +03:00
$ ( '#update-progress-detailed' )
2018-08-03 14:30:49 +03:00
. append ( '<p>' + message + '</p>' ) ;
2014-05-26 20:43:26 +04:00
}
} ;
} ) ( ) ;
$ ( document ) . ready ( function ( ) {
2014-05-28 13:29:22 +04:00
$ ( '.updateButton' ) . on ( 'click' , function ( ) {
2015-01-14 13:31:42 +03:00
var $updateEl = $ ( '.update' ) ;
2016-03-31 00:38:26 +03:00
var $progressEl = $ ( '.update-progress' ) ;
2014-05-26 20:43:26 +04:00
$progressEl . removeClass ( 'hidden' ) ;
2014-05-28 13:29:22 +04:00
$ ( '.updateOverview' ) . addClass ( 'hidden' ) ;
2016-03-31 00:38:26 +03:00
$ ( '#update-progress-message-error' ) . hide ( ) ;
$ ( '#update-progress-message-warnings' ) . hide ( ) ;
2015-01-14 13:31:42 +03:00
OC . Update . start ( $progressEl , {
productName : $updateEl . attr ( 'data-productname' ) ,
2016-03-31 00:38:26 +03:00
version : $updateEl . attr ( 'data-version' )
2015-01-14 13:31:42 +03:00
} ) ;
2014-05-26 20:43:26 +04:00
return false ;
2013-01-25 22:18:16 +04:00
} ) ;
2016-03-31 15:27:01 +03:00
$ ( '.update-show-detailed' ) . on ( 'click' , function ( ) {
$ ( '#update-progress-detailed' ) . toggleClass ( 'hidden' ) ;
return false ;
} ) ;
2013-07-11 02:00:01 +04:00
} ) ;