Skip to content

Commit

Permalink
SAK-33528 Fix JavaScript errors when columns are hidden (sakaiproject…
Browse files Browse the repository at this point in the history
…#4933)

* SAK-33528 fix js error when concurrent edit detected on hidden column or row

* SAK-33528 fix gradebookng JS error when scoring a assignment and the category average column has been hidden
  • Loading branch information
payten authored and jonespm committed Nov 1, 2017
1 parent c158432 commit 7505c0e
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions gradebookng/tool/src/webapp/scripts/gradebook-gbgrade-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ GbGradeTable.cellRenderer = function (instance, td, row, col, prop, value, cellP
$cellDiv.addClass("gb-concurrent-edit");
notifications.push({
type: 'concurrent-edit',
conflict: $.data(td, "concurrent-edit"),
conflict: GbGradeTable.conflictFor(student, column.assignmentId),
showSaveError: (scoreState == 'error')
});
} else if (scoreState == "error") {
Expand Down Expand Up @@ -1282,6 +1282,15 @@ GbGradeTable.hasConcurrentEdit = function(student, assignmentId) {
};


GbGradeTable.conflictFor = function(student, assignmentId) {
if (student.hasConcurrentEdit == null || student.conflicts == null) {
return null;
}

return student.conflicts[assignmentId];
};


GbGradeTable.setHasConcurrentEdit = function(conflict) {
var student = GbGradeTable.modelForStudent(conflict.studentUuid);

Expand All @@ -1295,15 +1304,25 @@ GbGradeTable.setHasConcurrentEdit = function(conflict) {
var row = GbGradeTable.rowForStudent(conflict.studentUuid);
var col = GbGradeTable.colForAssignment(conflict.assignmentId);

$.data(GbGradeTable.instance.getCell(row, col), "concurrent-edit", conflict);

var assignmentIndex = $.inArray(GbGradeTable.colModelForAssignment(conflict.assignmentId), GbGradeTable.columns);

student.hasConcurrentEdit = hasConcurrentEdit.substr(0, assignmentIndex) + "1" + hasConcurrentEdit.substr(assignmentIndex+1);

GbGradeTable.instance.setDataAtCell(row, GbGradeTable.STUDENT_COLUMN_INDEX, student);
GbGradeTable.redrawCell(row, col);
}
if (!student.hasOwnProperty('conflicts')) {
student.conflicts = {}
}
student.conflicts[conflict.assignmentId] = conflict;

// redraw student cell if visible
if (row >= 0) {
GbGradeTable.instance.setDataAtCell(row, GbGradeTable.STUDENT_COLUMN_INDEX, student);
GbGradeTable.redrawCell(row, GbGradeTable.STUDENT_COLUMN_INDEX);
}
// redraw grade cell if visible
if (row >= 0 && col >= 0) {
GbGradeTable.redrawCell(row, col);
}
};


GbGradeTable.colModelForCategoryScore = function(categoryName) {
Expand Down Expand Up @@ -2805,8 +2824,10 @@ GbGradeTable.syncCategoryAverage = function(studentId, categoryId, categoryScore
// update table
var tableRow = GbGradeTable.rowForStudent(studentId);
var tableCol = GbGradeTable.colForCategoryScore(categoryId);
GbGradeTable.setCellState('synced', tableRow, tableCol);
GbGradeTable.instance.setDataAtCell(tableRow, tableCol, categoryScoreAsLocaleString);
if (tableCol >= 0) { // column is visible?
GbGradeTable.setCellState('synced', tableRow, tableCol);
GbGradeTable.instance.setDataAtCell(tableRow, tableCol, categoryScoreAsLocaleString);
}

// update model
var modelRow = GbGradeTable.modelIndexForStudent(studentId);
Expand Down

0 comments on commit 7505c0e

Please sign in to comment.