PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/js/collections.js

https://github.com/fathead-1/MacGruber
JavaScript | 124 lines | 100 code | 24 blank | 0 comment | 1 complexity | 4b63b61d62ac24646b2481cd869b36ea MD5 | raw file
  1. App.Collection = {};
  2. App.Collection.Listings = Backbone.Collection.extend({
  3. model: App.Model.Listing,
  4. url: function() {
  5. return _.sprintf('%s/%s/Search', App.service_base_url, App.SystemID);
  6. },
  7. initialize: function() {
  8. _.bindAll(this, "parse");
  9. },
  10. parse: function(res) {
  11. this.RETS = {
  12. ReplyCode: res.ReplyCode,
  13. ReplyText: res.ReplyText,
  14. COUNT: res.COUNT
  15. };
  16. if (res.DATA) {
  17. var models = [];
  18. _.each(res.DATA, function(row) {
  19. var model = {};
  20. _.each(row, function(col, index) {
  21. model[ res.COLUMNS[index] ] = col;
  22. });
  23. models.push(model);
  24. });
  25. return models;
  26. }
  27. return [];
  28. }
  29. });
  30. App.Collection.UserSearches = Backbone.Collection.extend({
  31. model: App.Model.Search
  32. });
  33. App.Collection.UserListingsViewed = Backbone.Collection.extend({
  34. model: App.Model.ListingViewed
  35. });
  36. App.Collection.UserInfoRequests = Backbone.Collection.extend({
  37. model: App.Model.InfoRequest
  38. });
  39. App.Collection.UserShowingRequests = Backbone.Collection.extend({
  40. model: App.Model.ShowingRequest
  41. });
  42. App.Collection.PropertyTypes = Backbone.Collection.extend({
  43. model: App.Model.PropertyType,
  44. initialize: function() {
  45. _.bindAll(this, "fetch", "deSelectAll");
  46. App.system.bind('change', this.fetch);
  47. },
  48. deSelectAll: function() {
  49. this.each(function(model) { model.set({ selected: false }); });
  50. },
  51. fetch: function() {
  52. var self = this;
  53. var System = App.system.get('System');
  54. var Resource = System.Resource;
  55. var Classes = Resource.Property.Class
  56. var models = [];
  57. _.each(Classes, function(c, index) {
  58. var type = new App.Model.PropertyType({
  59. Description: c.Description,
  60. ClassName: c.ClassName,
  61. ResourceID: Resource.Property.ResourceID,
  62. selected: false
  63. });
  64. var listings = new App.Collection.Listings();
  65. listings.fetch({ data: {
  66. SearchType: 'Property',
  67. Class: c.ClassName,
  68. Count: 2,
  69. nocache: (new Date().getTime())
  70. }});
  71. listings.bind("reset", function() {
  72. type.set({ listing_count: listings.RETS.COUNT });
  73. });
  74. models.push(type);
  75. });
  76. self.reset(models);
  77. }
  78. });
  79. App.Collection.SortOptions = Backbone.Collection.extend({
  80. model: App.Model.SortOption,
  81. initialize: function() {
  82. _.bindAll(this, "fetch");
  83. },
  84. fetch: function(ClassName) {
  85. this.reset(App.SortOptions[ClassName]);
  86. }
  87. });
  88. App.Collection.SearchModeOptions = Backbone.Collection.extend({
  89. model: App.Model.SearchModeOption,
  90. initialize: function() {
  91. _.bindAll(this, "fetch");
  92. },
  93. fetch: function() {
  94. this.reset([
  95. { Display: 'List', Value: 'list', selected: true, position: 'left' },
  96. { Display: 'Photo', Value: 'photo', selected: false, position: 'middle' },
  97. { Display: 'Map', Value: 'map', selected: false, position: 'right' }
  98. ]);
  99. }
  100. });