@@ -110,6 +110,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy {
110110 protected originalGrades : any = { } ; // Object with the original grade data, to check for changes.
111111 protected isDestroyed : boolean ; // Whether the component has been destroyed.
112112 protected syncObserver : CoreEventObserver ;
113+ protected hasOfflineGrade = false ;
113114
114115 constructor ( protected navCtrl : NavController , protected appProvider : CoreAppProvider , protected domUtils : CoreDomUtilsProvider ,
115116 sitesProvider : CoreSitesProvider , protected syncProvider : CoreSyncProvider , protected timeUtils : CoreTimeUtilsProvider ,
@@ -306,17 +307,23 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy {
306307 /**
307308 * Check if there's data to save (grade).
308309 *
310+ * @param isSubmit Whether the user is about to submit the grade.
309311 * @return Promise resolved with boolean: whether there's data to save.
310312 */
311- protected hasDataToSave ( ) : Promise < boolean > {
313+ protected async hasDataToSave ( isSubmit ?: boolean ) : Promise < boolean > {
312314 if ( ! this . canSaveGrades || ! this . loaded ) {
313- return Promise . resolve ( false ) ;
315+ return false ;
316+ }
317+
318+ if ( isSubmit && this . hasOfflineGrade ) {
319+ // Always allow sending if the grade is saved in offline.
320+ return true ;
314321 }
315322
316323 // Check if numeric grade and toggles changed.
317324 if ( this . originalGrades . grade != this . grade . grade || this . originalGrades . addAttempt != this . grade . addAttempt ||
318325 this . originalGrades . applyToAll != this . grade . applyToAll ) {
319- return Promise . resolve ( true ) ;
326+ return true ;
320327 }
321328
322329 // Check if outcomes changed.
@@ -326,20 +333,21 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy {
326333
327334 if ( this . originalGrades . outcomes [ outcome . id ] == 'undefined' ||
328335 this . originalGrades . outcomes [ outcome . id ] != outcome . selectedId ) {
329- return Promise . resolve ( true ) ;
336+ return true ;
330337 }
331338 }
332339 }
333340
334341 if ( this . feedback && this . feedback . plugins ) {
335- return this . assignHelper . hasFeedbackDataChanged ( this . assign , this . userSubmission , this . feedback , this . submitId )
336- . catch ( ( ) => {
342+ try {
343+ return this . assignHelper . hasFeedbackDataChanged ( this . assign , this . userSubmission , this . feedback , this . submitId ) ;
344+ } catch ( error ) {
337345 // Error ocurred, consider there are no changes.
338346 return false ;
339- } ) ;
347+ }
340348 }
341349
342- return Promise . resolve ( false ) ;
350+ return false ;
343351 }
344352
345353 /**
@@ -645,11 +653,13 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy {
645653 return this . assignOfflineProvider . getSubmissionGrade ( this . assign . id , this . submitId ) . catch ( ( ) => {
646654 // Grade not found.
647655 } ) . then ( ( data ) => {
656+ this . hasOfflineGrade = false ;
648657
649658 // Load offline grades.
650659 if ( data && ( ! feedback || ! feedback . gradeddate || feedback . gradeddate < data . timemodified ) ) {
651660 // If grade has been modified from gradebook, do not use offline.
652661 if ( this . grade . modified < data . timemodified ) {
662+ this . hasOfflineGrade = true ;
653663 this . grade . grade = ! this . grade . scale ? this . utils . formatFloat ( data . grade ) : data . grade ;
654664 this . gradingStatusTranslationId = 'addon.mod_assign.gradenotsynced' ;
655665 this . gradingColor = '' ;
@@ -790,7 +800,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy {
790800 */
791801 submitGrade ( ) : Promise < any > {
792802 // Check if there's something to be saved.
793- return this . hasDataToSave ( ) . then ( ( modified ) => {
803+ return this . hasDataToSave ( true ) . then ( ( modified ) => {
794804 if ( ! modified ) {
795805 return ;
796806 }
0 commit comments