PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/Gradebook/Scripts/app/student.task.result.js

https://bitbucket.org/crackbrain/gradebook
JavaScript | 58 lines | 48 code | 7 blank | 3 comment | 6 complexity | 56242444d598011ed83635911e9125a2 MD5 | raw file
  1. /// <reference path="../knockout-2.2.1.debug.js" />
  2. /// <reference path="student.js" />
  3. /// <reference path="task.js" />
  4. var StudentTaskResult = (function () {
  5. function StudentTaskResult(data) {
  6. var self = this;
  7. this.result = ko.observable().extend({ numeric: 0 });
  8. this.rank = ko.observable();
  9. this.comments = ko.observable();
  10. this.student = new Student();
  11. this.task = new TaskModel();
  12. if (data != null) {
  13. if (data.Result) this.result(data.Result);
  14. this.rank(data.Rank);
  15. this.comments(data.Comments);
  16. if (data.Student) {
  17. this.student = new Student(data.Student);
  18. }
  19. if (data.Task) {
  20. this.task = new TaskModel(data.Task.Id, data.Task.Name, data.Task.TotalMarks, data.Task.Weight);
  21. }
  22. }
  23. this.header = this.task.totalMarks > 1 ? this.task.totalMarks.toString() : '✓';
  24. this.rate = ko.computed(function () {
  25. var result = self.result();
  26. if (result) {
  27. var max = self.task.totalMarks;
  28. var rate = max ? (result * 100 / max) : 0;
  29. return rate ? Math.round(rate * 10) / 10 : null;
  30. }
  31. return null;
  32. });
  33. this.isDone = ko.computed({
  34. read: function () {
  35. return self.result() > 0;
  36. },
  37. write: function (value) {
  38. self.result(value ? 1 : 0);
  39. }
  40. });
  41. }
  42. StudentTaskResult.prototype.toGrade = function () {
  43. return {
  44. taskId: this.task.id,
  45. studentId: this.student.id,
  46. value: this.result() ? this.result() : 0,
  47. comments: this.comments()
  48. };
  49. };
  50. return StudentTaskResult;
  51. })();