PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/templates/public/scripts/models/Entry.js

https://bitbucket.org/taxilian/racecontrol5
JavaScript | 87 lines | 83 code | 4 blank | 0 comment | 24 complexity | 6ef8f77cf5ff9a987ab1369399bce571 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. define(["backbone", "underscore", "jquery", "defaults", "datelib"], function(Backbone, _, $, defaults) {
  2. var Entry = Backbone.Model.extend({
  3. idAttribute: "station_stationNumber",
  4. url: function() {
  5. var url = "/newAPI/events/" + this.collection.eventId + "/participants/" + this.collection.runnerNo + "/entrys";
  6. if (!this.isNew()) {
  7. url += "/" + this.id;
  8. }
  9. return url;
  10. },
  11. getDateTimeIn: function(withS) {
  12. var time_in = this.get("time_in");
  13. return time_in && time_in.toString(defaults.dateFormat);
  14. },
  15. getGridTimeIn: function(withS) {
  16. var time_in = this.get("time_in");
  17. if (withS) {
  18. return time_in && time_in.toString(defaults.timeFormat);
  19. } else {
  20. return time_in && time_in.toString(defaults.shortTimeFormat);
  21. }
  22. },
  23. getGridTimeOut: function(withS) {
  24. var time_out = this.get("time_out");
  25. if (withS) {
  26. return time_out && time_out.toString(defaults.timeFormat);
  27. } else {
  28. return time_out && time_out.toString(defaults.shortTimeFormat);
  29. }
  30. },
  31. getDateTimeOut: function(withS) {
  32. var time_out = this.get("time_out");
  33. return time_out && time_out.toString(defaults.dateFormat);
  34. },
  35. hasValidTime: function() {
  36. return ((this.has("time_in") && this.get("time_in")) || (this.has("time_out") && this.get("time_out")));
  37. },
  38. getValidTime: function() {
  39. if ((this.has("time_in") && this.get("time_in"))) {
  40. return this.get("time_in");
  41. } else if ((this.has("time_out") && this.get("time_out"))) {
  42. return this.get("time_out");
  43. }
  44. },
  45. parse: function(raw_entry) {
  46. if (raw_entry.time_in) { raw_entry.time_in = Date.parse(raw_entry.time_in); }
  47. if (raw_entry.time_out) { raw_entry.time_out = Date.parse(raw_entry.time_out); }
  48. }
  49. });
  50. var Entrys = Backbone.Collection.extend({
  51. model: Entry,
  52. url: function() {
  53. return "/newAPI/events/" + this.eventId + "/participants/" + this.runnerNo + "/entrys";
  54. },
  55. parse: function(arr) {
  56. _.each(arr, Entry.prototype.parse);
  57. return arr;
  58. }
  59. }, {
  60. list: null,
  61. fetchAll: function(eventId, runnerNo) {
  62. var self = this, cache;
  63. if (!self.list) { self.list = {}; }
  64. if (!self.list[eventId]) { self.list[eventId] = {}; }
  65. cache = self.list[eventId][runnerNo];
  66. if (cache) {
  67. return cache;
  68. }
  69. var tmp = new self();
  70. tmp.eventId = eventId;
  71. tmp.runnerNo = runnerNo;
  72. cache = self.list[eventId][runnerNo] = tmp.fetch().pipe(function() {
  73. return (self.list[eventId][runnerNo] = tmp);
  74. });
  75. return cache;
  76. }
  77. });
  78. Entrys.parse = Entrys.prototype.parse;
  79. return {
  80. obj: Entry,
  81. list: Entrys
  82. };
  83. });