########## handlebars helpers ############## String.prototype.capitalize = -> this.charAt(0).toUpperCase() + this.substring(1).toLowerCase() String.prototype.titleize = -> res = [] parts = this.split(" ") $.each(parts, (index, part)-> res.push(part.capitalize()) ) res.join(" ") Handlebars.registerHelper("rounded", (number)-> if (number != undefined) parseFloat(number).toFixed(2) ) Handlebars.registerHelper("titleize", (string)-> if (string != undefined) string.titleize() ) Handlebars.registerHelper("address_without_comma", (lab)-> if (this.address != undefined) this.address.replace(/(\s*,\s*$)/g, "").titleize() ) ########## Lab model ############## class window.Lab constructor: (@data)-> marker: null map_tooltip_template: Handlebars.compile("{{titleize name}}\n{{address_without_comma address}}\n{{titleize city}},{{state}} ") clearMarker: -> if this.marker this.marker.setMap(null) this.marker = null setMarker: (map, markerBounds)-> this.point = new google.maps.LatLng(@data.lat, @data.lng) this.marker = this.makeMarker(map) if markerBounds markerBounds.extend(this.point) makeMarker: (map)-> new google.maps.Marker({ position: this.point map: map title: this.map_tooltip_template(@data) icon: this.makeIcon() }) makeIcon: -> new google.maps.MarkerImage("/assets/medivo/lab.png") ########## LabList model ############## class window.LabList constructor: (lab_info)-> @labs = [] this.setLabs(lab_info) setLabs: (lab_info)-> this.clearMarkers() labs = @labs = [] $.each( lab_info, (index, lab_data)-> labs.push(new Lab(lab_data)) ) clearMarkers: -> $.each( @labs, (index, lab)-> lab.clearMarker() )