forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgradebook-history.js
More file actions
100 lines (90 loc) · 3.57 KB
/
Copy pathgradebook-history.js
File metadata and controls
100 lines (90 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* Copyright (C) 2011 Instructure, Inc.
*
* This file is part of Canvas.
*
* Canvas is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, version 3 of the License.
*
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
define([
'i18n!gradebook',
'jquery' /* $ */,
'jsx/gradebook/shared/helpers/GradeFormatHelper',
'jquery.ajaxJSON' /* ajaxJSON */,
'jquery.instructure_date_and_time' /* datetimeString */
], function (I18n, $, GradeFormatHelper) {
function announceUpdatedCurrentGrade (currentGrade) {
var noGrade = '--';
var flashMessage;
if (currentGrade === noGrade) {
flashMessage = I18n.t('Updated current grade to be empty');
} else {
flashMessage = I18n.t(
'Updated current grade to %{currentGrade}',
{ currentGrade: currentGrade }
);
}
$.screenReaderFlashMessage(flashMessage);
}
var GradebookHistory = {
init: function(){
$('.assignment_header').click(function(event) {
event.preventDefault();
var toggleLink = $(this).find('.assignment-header');
var currentState = toggleLink.attr('aria-expanded');
toggleLink.attr('aria-expanded', currentState == 'false' ? 'true' : 'false');
$(this).find('.ui-icon').toggleClass('ui-icon-circle-arrow-n').end()
.next('.assignment_details').slideToggle('fast');
});
$(".revert-grade-link").bind("mouseenter mouseleave", function(){
$(this).toggleClass("ui-state-hover");
})
.click(GradebookHistory.handleGradeSubmit);
},
handleGradeSubmit: function(event){
// 'this' should be the <a href> that they clicked on
var assignmentId = $(this).parents('tr').data('assignment-id');
var userId = $(this).parents('tr').data('user-id');
var grade = $(this).data('grade').toString().replace('--', '');
var url = $('.update_submission_grade_url').attr('href');
var method = $('.update_submission_grade_url').attr('title');
event.preventDefault();
$('.assignment_' + assignmentId + '_user_' + userId + '_current_grade').addClass('loading');
var formData = {
'submission[assignment_id]': assignmentId,
'submission[user_id]': userId
};
if(grade == "EX") {
formData['submission[excused]'] = 1;
} else {
formData['submission[grade]'] = grade;
}
$.ajaxJSON(url, method, formData, function(submissions) {
var currentGradeText;
$.each(submissions, function () {
var submission = this.submission;
var el = $('.assignment_' + submission.assignment_id + '_user_' + submission.user_id + '_current_grade');
el.removeClass('loading');
el.attr('title', I18n.t('graded_by_me', "%{graded_time} by me", { 'graded_time': $.datetimeString(submission.graded_at) }));
if (submission.excused) {
currentGradeText = 'EX';
} else {
currentGradeText = GradeFormatHelper.formatGrade(submission.grade) || '--';
}
el.text(currentGradeText);
});
announceUpdatedCurrentGrade(currentGradeText);
});
}
};
return GradebookHistory;
});