This repository has been archived by the owner on Mar 31, 2023. It is now read-only.
/
results.js
91 lines (76 loc) · 2.42 KB
/
results.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
PetBnB.Views.ResultsView = Backbone.View.extend({
template: JST['listings/results'],
className: 'results',
events: {
'change #checkin': 'checkDates',
'change #checkout': 'checkDates'
// 'mouseenter .listing': 'startBounce',
// 'mouseleave .listing': 'stopBounce'
},
initialize: function (options) {
var center = (options.coords.lat) ? options.coords :
{ lat: 0, lng: 0 };
PetBnB.mapView = new PetBnB.Views.MapShowView({
center: center
});
this._resultsSubview = new PetBnB.Views.resultsSubview();
this.listenToOnce(PetBnB.listings, 'sync', this.render);
},
render: function () {
var content = this.template({
listings: PetBnB.listings
});
this.$el.html(content);
$(document).attr('title', 'Search | PetBnB');
$('#navbar-search-container').addClass('active');
this.addSlider();
PetBnB.setDatepickers();
this.$('.search-map').html(PetBnB.mapView.$el);
google.maps.event.trigger(PetBnB.map, 'resize');
google.maps.event.trigger(PetBnB.map, 'idle');
this.$('.search-container').append(this._resultsSubview.render().$el);
return this;
},
addSlider: function () {
var min = 0;
var max = PetBnB.listings.getMaxPrice();
this.updateSliderPrices({ min: min, max: max });
$('#slider').slider({
range: true,
animate: true,
min: min,
max: max,
values: [min, max],
change: function (event, ui) {
var prices = { min: ui.values[0], max: ui.values[1] };
this.filterListings(prices);
}.bind(this)
});
},
updateSliderPrices: function (prices) {
$('#slider-min').html('$' + prices.min);
$('#slider-max').html('$' + prices.max);
},
filterListings: function (prices) {
this.updateSliderPrices(prices);
PetBnB.search({ min: prices.min, max: prices.max });
},
// Event handlers
checkDates: function () {
PetBnB.checkDates();
},
// startBounce: function (event) {
// var listingId = $(event.currentTarget).children('a').data('listing-id');
// PetBnB.mapView.startBounce(listingId);
// },
//
// stopBounce: function (event) {
// var listingId = $(event.currentTarget).children('a').data('listing-id');
// PetBnB.mapView.stopBounce(listingId);
// },
remove: function () {
Backbone.View.prototype.remove.call(this);
PetBnB.mapView.remove();
this._resultsSubview.remove();
}
});