Skip to content

Commit

Permalink
Can filter pins
Browse files Browse the repository at this point in the history
  • Loading branch information
jadehopepunk committed Mar 9, 2009
1 parent daab08e commit 60b4cc9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
14 changes: 7 additions & 7 deletions app/models/pin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def address
end

def to_json(options = {})
super(:methods => [:to_param, :url])
super(:methods => [:to_param, :url, :resource_types])
end

def to_param
Expand Down Expand Up @@ -91,14 +91,14 @@ def can_be_edited_by?(current_user)
user && current_user == user
end

def self.humanize_resource_type(resource_type)
result = resource_type.to_s
result = "provide_#{result}" if result.starts_with?('gardening')
result.humanize
end

protected

def humanize_resource_type(resource_type)
result = resource_type.to_s
result = "provide_#{result}" if result.starts_with?('gardening')
result.humanize
end

def first_resource_type
for type in RESOURCE_TYPES
return type if send(type)
Expand Down
6 changes: 6 additions & 0 deletions app/views/regions/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<%= render :partial => 'regions/map' %>

<p>
People who:
<%= Pin::RESOURCE_TYPES.map { |type| link_to_function(Pin.humanize_resource_type(type), "region_map.showOnlyOneType('#{type}')") }.join(" | ") %>
</p>


<br style="clear: both" />
<div class="map_section" style="float: left">
<div id="map" class="google_map" style="width: 400px; height: 500px; margin: 0 10px 10px 0"></div>
Expand Down
21 changes: 21 additions & 0 deletions public/javascripts/region_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var RegionMap = Class.create({
this.boundary = null;
this.boundary_markers = [];
this.pin_markers = {};
this.pin_details = [];
this.region = region;
this.boundary_editing = boundary_editing;
},
Expand Down Expand Up @@ -33,6 +34,26 @@ var RegionMap = Class.create({
this.pin_markers[pin.to_param] = marker;
marker.bindInfoWindowHtml(this.infoWindowHtml(pin));
}, this);

this.pin_details = pins;
},

showOnlyOneType: function(type_name) {
this.pin_details.each(function(pin) {
if (pin.resource_types.include(type_name)) {
this.showPin(pin.to_param)
} else {
this.hidePin(pin.to_param);
}
}, this);
},

hidePin: function(pin_id) {
this.pin_markers[pin_id].hide();
},

showPin: function(pin_id) {
this.pin_markers[pin_id].show();
},

centerOnPinIfHash: function() {
Expand Down

0 comments on commit 60b4cc9

Please sign in to comment.