diff --git a/src/addon/mod/assign/components/submission/addon-mod-assign-submission.html b/src/addon/mod/assign/components/submission/addon-mod-assign-submission.html index 9d64740ec..1e8f391e9 100644 --- a/src/addon/mod/assign/components/submission/addon-mod-assign-submission.html +++ b/src/addon/mod/assign/components/submission/addon-mod-assign-submission.html @@ -149,7 +149,7 @@

{{ 'addon.mod_assign.gradeoutof' | translate: {$a: gradeInfo.grade} }}

- +

{{ 'addon.mod_assign.gradelocked' | translate }}

diff --git a/src/addon/mod/assign/components/submission/submission.ts b/src/addon/mod/assign/components/submission/submission.ts index 3095a5212..4910b8603 100644 --- a/src/addon/mod/assign/components/submission/submission.ts +++ b/src/addon/mod/assign/components/submission/submission.ts @@ -472,7 +472,8 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { applyToAll: false, scale: false, lang: false, - disabled: false + disabled: false, + type: this.domUtils.numberInputSupportsComma() ? 'number' : 'text' }; this.originalGrades = { @@ -506,7 +507,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { if (feedback.grade && feedback.grade.grade && !this.grade.grade) { const parsedGrade = parseFloat(feedback.grade.grade); this.grade.grade = parsedGrade || parsedGrade == 0 ? parsedGrade : null; - this.grade.gradebookGrade = this.grade.grade; + this.grade.gradebookGrade = this.utils.formatFloat(this.grade.grade); this.originalGrades.grade = this.grade.grade; } } else { @@ -585,7 +586,8 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { if (data && (!feedback || !feedback.gradeddate || feedback.gradeddate < data.timemodified)) { // If grade has been modified from gradebook, do not use offline. if (this.grade.modified < data.timemodified) { - this.grade.grade = data.grade; + this.grade.grade = !this.grade.scale && this.grade.type == 'text' ? + this.utils.formatFloat(data.grade) : data.grade; this.gradingStatusTranslationId = 'addon.mod_assign.gradenotsynced'; this.gradingColor = ''; this.originalGrades.grade = this.grade.grade; @@ -772,8 +774,6 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { userId: this.currentUserId }, this.siteId); }); - }).catch((error) => { - this.domUtils.showErrorModalDefault(error, 'core.error', true); }).finally(() => { // Select submission view. this.tabs.selectTab(0); @@ -802,6 +802,10 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { if (this.gradeInfo.scale) { this.grade.scale = this.utils.makeMenuFromList(this.gradeInfo.scale, this.translate.instant('core.nograde')); } else { + // If the grade uses a text input, format it. + this.grade.grade = this.grade.type == 'text' ? this.utils.formatFloat(this.grade.grade) : this.grade.grade; + this.originalGrades.grade = this.grade.grade; + // Get current language to format grade input field. this.langProvider.getCurrentLanguage().then((lang) => { this.grade.lang = lang; @@ -829,11 +833,11 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { // Not using outcomes or scale, get the numeric grade. if (this.grade.scale) { - this.grade.gradebookGrade = this.gradesHelper.getGradeValueFromLabel( - this.grade.scale, grade.gradeformatted); + this.grade.gradebookGrade = this.utils.formatFloat(this.gradesHelper.getGradeValueFromLabel( + this.grade.scale, grade.gradeformatted)); } else { const parsedGrade = parseFloat(grade.gradeformatted); - this.grade.gradebookGrade = parsedGrade || parsedGrade == 0 ? parsedGrade : null; + this.grade.gradebookGrade = parsedGrade || parsedGrade == 0 ? this.utils.formatFloat(parsedGrade) : null; } this.grade.disabled = grade.gradeislocked || grade.gradeisoverridden; diff --git a/src/addon/mod/assign/pages/submission-review/submission-review.ts b/src/addon/mod/assign/pages/submission-review/submission-review.ts index d6e39b6cd..be53916dc 100644 --- a/src/addon/mod/assign/pages/submission-review/submission-review.ts +++ b/src/addon/mod/assign/pages/submission-review/submission-review.ts @@ -15,6 +15,7 @@ import { Component, OnInit, ViewChild } from '@angular/core'; import { IonicPage, NavController, NavParams } from 'ionic-angular'; import { CoreAppProvider } from '@providers/app'; +import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreCourseProvider } from '@core/course/providers/course'; import { AddonModAssignProvider } from '../../providers/assign'; import { AddonModAssignSubmissionComponent } from '../../components/submission/submission'; @@ -44,7 +45,8 @@ export class AddonModAssignSubmissionReviewPage implements OnInit { protected forceLeave = false; // To allow leaving the page without checking for changes. constructor(navParams: NavParams, protected navCtrl: NavController, protected courseProvider: CoreCourseProvider, - protected appProvider: CoreAppProvider, protected assignProvider: AddonModAssignProvider) { + protected appProvider: CoreAppProvider, protected assignProvider: AddonModAssignProvider, + protected domUtils: CoreDomUtilsProvider) { this.moduleId = navParams.get('moduleId'); this.courseId = navParams.get('courseId'); @@ -162,6 +164,8 @@ export class AddonModAssignSubmissionReviewPage implements OnInit { this.forceLeave = true; this.navCtrl.pop(); } + }).catch((error) => { + this.domUtils.showErrorModalDefault(error, 'core.error', true); }); } } diff --git a/src/providers/utils/dom.ts b/src/providers/utils/dom.ts index 979a01980..c13a41b81 100644 --- a/src/providers/utils/dom.ts +++ b/src/providers/utils/dom.ts @@ -603,6 +603,15 @@ export class CoreDomUtilsProvider { return movedChildren; } + /** + * Check whether input number supports writing comma as a decimal separator. + * + * @return {boolean} Whether input number supports writing comma as a decimal separator. + */ + numberInputSupportsComma(): boolean { + return !this.platform.is('android') || this.platform.version().major > 5; + } + /** * Search and remove a certain element from inside another element. * diff --git a/src/providers/utils/utils.ts b/src/providers/utils/utils.ts index 408a4c950..acaca2707 100644 --- a/src/providers/utils/utils.ts +++ b/src/providers/utils/utils.ts @@ -471,7 +471,7 @@ export class CoreUtilsProvider { * @return {string} Locale float. */ formatFloat(float: any): string { - if (typeof float == 'undefined') { + if (typeof float == 'undefined' || float === null) { return ''; }