/Gradebook/Scripts/app/student.task.result.js
JavaScript | 58 lines | 48 code | 7 blank | 3 comment | 6 complexity | 56242444d598011ed83635911e9125a2 MD5 | raw file
- /// <reference path="../knockout-2.2.1.debug.js" />
- /// <reference path="student.js" />
- /// <reference path="task.js" />
-
- var StudentTaskResult = (function () {
- function StudentTaskResult(data) {
- var self = this;
- this.result = ko.observable().extend({ numeric: 0 });
- this.rank = ko.observable();
- this.comments = ko.observable();
- this.student = new Student();
- this.task = new TaskModel();
-
- if (data != null) {
- if (data.Result) this.result(data.Result);
-
- this.rank(data.Rank);
- this.comments(data.Comments);
-
- if (data.Student) {
- this.student = new Student(data.Student);
- }
- if (data.Task) {
- this.task = new TaskModel(data.Task.Id, data.Task.Name, data.Task.TotalMarks, data.Task.Weight);
- }
- }
-
- this.header = this.task.totalMarks > 1 ? this.task.totalMarks.toString() : '✓';
-
- this.rate = ko.computed(function () {
- var result = self.result();
- if (result) {
- var max = self.task.totalMarks;
- var rate = max ? (result * 100 / max) : 0;
- return rate ? Math.round(rate * 10) / 10 : null;
- }
- return null;
- });
-
- this.isDone = ko.computed({
- read: function () {
- return self.result() > 0;
- },
- write: function (value) {
- self.result(value ? 1 : 0);
- }
- });
- }
- StudentTaskResult.prototype.toGrade = function () {
- return {
- taskId: this.task.id,
- studentId: this.student.id,
- value: this.result() ? this.result() : 0,
- comments: this.comments()
- };
- };
- return StudentTaskResult;
- })();