PageRenderTime 60ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/templates/public/scripts/models/RaceEvent.js

https://bitbucket.org/taxilian/racecontrol5
JavaScript | 59 lines | 53 code | 6 blank | 0 comment | 4 complexity | 33feebe3fe8035678b704d276f96944d MD5 | raw file
Possible License(s): BSD-3-Clause
  1. define(["backbone", "underscore", "jquery", "defaults", "datelib"], function(Backbone, _, $, defaults) {
  2. var RaceEvent, RaceEvents;
  3. RaceEvent = Backbone.Model.extend({
  4. idAttribute: "uuid",
  5. urlRoot: '/newAPI/events',
  6. getDateObject: function() {
  7. var date = this.get("date");
  8. if (!(date instanceof Date))
  9. date = Date.parse(this.get("date"));
  10. return date;
  11. },
  12. getDate: function() {
  13. return this.getDateObject().toString(defaults.dateFormat);
  14. },
  15. getTime: function() {
  16. return this.getDateObject().toString(defaults.timeFormat);
  17. },
  18. isStartStation: function(stationNo) {
  19. return stationNo == this.get("startStation");
  20. },
  21. isFinishStation: function(stationNo) {
  22. return stationNo == this.get("finishStation");
  23. }
  24. }, {
  25. list: null,
  26. fetchById: function(id) {
  27. return RaceEvents.fetchAll().pipe(function(list) {
  28. return list.get(id);
  29. });
  30. }
  31. });
  32. RaceEvents = Backbone.Collection.extend({
  33. model: RaceEvent,
  34. url: '/newAPI/events'
  35. }, {
  36. list: null,
  37. fetchAll: function() {
  38. var self = this;
  39. if (self.list) {
  40. return self.list;
  41. }
  42. var tmp = new self();
  43. self.list = tmp.fetch().pipe(function() {
  44. return tmp;
  45. });
  46. return self.list;
  47. }
  48. });
  49. return {
  50. obj: RaceEvent,
  51. list: RaceEvents
  52. };
  53. });