PageRenderTime 1518ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/public/js/collections/collections.js

https://gitlab.com/matt-oakes/photo_project
JavaScript | 55 lines | 45 code | 10 blank | 0 comment | 4 complexity | e454cc80c71c232b049077deb5c5c864 MD5 | raw file
  1. App.collections = {};
  2. App.collections.SetStore = Backbone.Collection.extend({
  3. model: App.models.Set,
  4. fetched: false,
  5. url: '/set',
  6. initialize: function() {
  7. },
  8. getAll: function() {
  9. if (this.models.length === 0) {
  10. return null;
  11. }
  12. return this.filter(function(set) {
  13. return true;
  14. });
  15. },
  16. getById: function(setId) {
  17. return this.find(function(set) {
  18. return set.get('id') == setId;
  19. });
  20. }
  21. });
  22. App.collections.PhotoStore = Backbone.Collection.extend({
  23. model: App.models.Photo,
  24. setId: null,
  25. fetched: false,
  26. url: function() {
  27. if (!this.setId) {
  28. throw "Need to set a setId on the collection before fetching";
  29. }
  30. return '/photo?set_id=' + this.setId;
  31. },
  32. initialize: function() {
  33. },
  34. comparator: function(photo) {
  35. return Date.parseExact(photo.get('date_taken'), 'HH:mm:ss dd-MM-yyyy');
  36. },
  37. getAll: function() {
  38. if (this.models.length === 0) {
  39. return null;
  40. }
  41. return this.filter(function(set) {
  42. return true;
  43. });
  44. }
  45. });