@@ -48,7 +48,7 @@ angular.module('mm.addons.mod_scorm')
4848 $scope . modebrowse = $mmaModScorm . MODEBROWSE ;
4949
5050 // Convenience function to get SCORM data.
51- function fetchScormData ( refresh ) {
51+ function fetchScormData ( refresh , checkCompletion ) {
5252 return $mmaModScorm . getScorm ( courseid , module . id , module . url ) . then ( function ( scormData ) {
5353 scorm = scormData ;
5454
@@ -76,6 +76,10 @@ angular.module('mm.addons.mod_scorm')
7676 $scope . syncTime = syncTime ;
7777 } ) ;
7878
79+ if ( checkCompletion ) {
80+ $mmCourse . checkModuleCompletion ( courseid , module . completionstatus ) ;
81+ }
82+
7983 // Get the number of attempts and check if SCORM is incomplete.
8084 return $mmaModScorm . getAttemptCount ( scorm . id ) . then ( function ( attemptsData ) {
8185 attempts = attemptsData ;
@@ -279,15 +283,15 @@ angular.module('mm.addons.mod_scorm')
279283 }
280284
281285 // Refreshes data.
282- function refreshData ( dontForceSync ) {
286+ function refreshData ( dontForceSync , checkCompletion ) {
283287 var promises = [ ] ;
284288 promises . push ( $mmaModScorm . invalidateScormData ( courseid ) ) ;
285289 if ( scorm ) {
286290 promises . push ( $mmaModScorm . invalidateAllScormData ( scorm . id ) ) ;
287291 }
288292
289293 return $q . all ( promises ) . finally ( function ( ) {
290- return fetchScormData ( ! dontForceSync ) ;
294+ return fetchScormData ( ! dontForceSync , checkCompletion ) ;
291295 } ) ;
292296 }
293297
@@ -339,11 +343,6 @@ angular.module('mm.addons.mod_scorm')
339343 if ( message ) {
340344 $mmUtil . showErrorModal ( message ) ;
341345 }
342-
343- if ( data . attemptFinished ) {
344- // An attempt was finished, check completion status.
345- $mmCourse . checkModuleCompletion ( courseid , module . completionstatus ) ;
346- }
347346 }
348347 } ) . catch ( function ( err ) {
349348 if ( showErrors ) {
@@ -416,7 +415,7 @@ angular.module('mm.addons.mod_scorm')
416415 // Refresh the data.
417416 $scope . scormLoaded = false ;
418417 scrollView . scrollTop ( ) ;
419- refreshData ( true ) . finally ( function ( ) {
418+ refreshData ( true , true ) . finally ( function ( ) {
420419 $scope . scormLoaded = true ;
421420 } ) ;
422421 } ) . finally ( function ( ) {
@@ -441,7 +440,7 @@ angular.module('mm.addons.mod_scorm')
441440 scrollView . scrollTop ( ) ;
442441 // Add a delay to make sure the player has started the last writing calls so we can detect conflicts.
443442 $timeout ( function ( ) {
444- refreshData ( ) . finally ( function ( ) {
443+ refreshData ( false , true ) . finally ( function ( ) {
445444 $scope . scormLoaded = true ;
446445 } ) ;
447446 } , 500 ) ;
@@ -453,14 +452,9 @@ angular.module('mm.addons.mod_scorm')
453452 if ( data && data . siteid == $mmSite . getId ( ) && data . scormid == scorm . id ) {
454453 $scope . scormLoaded = false ;
455454 scrollView . scrollTop ( ) ;
456- fetchScormData ( ) . finally ( function ( ) {
455+ fetchScormData ( false , true ) . finally ( function ( ) {
457456 $scope . scormLoaded = true ;
458457 } ) ;
459-
460- if ( data . attemptFinished ) {
461- // An attempt was finished, check completion status.
462- $mmCourse . checkModuleCompletion ( courseid , module . completionstatus ) ;
463- }
464458 }
465459 } ) ;
466460
0 commit comments