PageRenderTime 62ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/kalite/coachreports/static/js/coachreports/coach_reports/models.js

https://gitlab.com/gregtyka/ka-lite
JavaScript | 97 lines | 81 code | 14 blank | 2 comment | 7 complexity | 781ff52c04f19dd4cb08cb1cb3465670 MD5 | raw file
  1. var Backbone = require("base/backbone");
  2. var _ = require("underscore");
  3. var setGetParamDict = require("utils/get_params").setGetParamDict;
  4. var StateModel = Backbone.Model.extend({
  5. set: function(key, val, options) {
  6. if (key === "facility" || key.facility) {
  7. this.set({
  8. group: undefined,
  9. group_name: undefined
  10. });
  11. }
  12. if (key === "facility" || key.facility || key === "group" || key.group) {
  13. this.set({
  14. topic_ids: undefined
  15. });
  16. }
  17. Backbone.Model.prototype.set.call(this, key, val, options);
  18. }
  19. });
  20. var FacilityModel = Backbone.Model.extend();
  21. var GroupModel = Backbone.Model.extend();
  22. var FacilityCollection = Backbone.Collection.extend({
  23. url: window.FACILITY_RESOURCE_URL
  24. });
  25. var GroupCollection = Backbone.Collection.extend({
  26. url: window.GROUP_RESOURCE_URL
  27. });
  28. function normalizeEndDate(end_date) {
  29. // We want our date ranges to be inclusive, so send the day + 1
  30. // to the server in order to do this.
  31. var output;
  32. if (end_date) {
  33. output = new Date(end_date);
  34. output.setDate(output.getDate() + 1);
  35. output = output.getFullYear() + "/" + (output.getMonth() + 1) + "/" + output.getDate();
  36. }
  37. return output;
  38. }
  39. var CoachReportModel = Backbone.Model.extend({
  40. initialize: function(options) {
  41. this.facility = options.facility;
  42. this.group = options.group;
  43. this.start_date = options.start_date;
  44. this.end_date = options.end_date;
  45. this.topic_ids = options.topic_ids;
  46. },
  47. url: function() {
  48. return setGetParamDict(Urls.learner_logs(), {
  49. facility_id: this.facility,
  50. group_id: this.group,
  51. start_date: this.start_date,
  52. end_date: normalizeEndDate(this.end_date),
  53. topic_ids: this.topic_ids
  54. });
  55. }
  56. });
  57. var CoachReportAggregateModel = Backbone.Model.extend({
  58. initialize: function(options) {
  59. this.facility = options.facility;
  60. this.group = options.group;
  61. this.start_date = options.start_date;
  62. this.end_date = options.end_date;
  63. this.topic_ids = options.topic_ids;
  64. },
  65. url: function() {
  66. return setGetParamDict(Urls.aggregate_learner_logs(), {
  67. facility_id: this.facility,
  68. group_id: this.group,
  69. start_date: this.start_date,
  70. end_date: normalizeEndDate(this.end_date),
  71. topic_ids: this.topic_ids
  72. });
  73. }
  74. });
  75. module.exports = {
  76. StateModel: StateModel,
  77. FacilityModel: FacilityModel,
  78. GroupModel: GroupModel,
  79. FacilityCollection: FacilityCollection,
  80. GroupCollection: GroupCollection,
  81. CoachReportModel: CoachReportModel,
  82. CoachReportAggregateModel: CoachReportAggregateModel
  83. };