app/assets/javascripts/medivo/models.coffee in medivo-0.0.1 vs app/assets/javascripts/medivo/models.coffee in medivo-0.0.2

- old
+ new

@@ -1,9 +1,37 @@ +########## 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("{{name}}\n{{address}}\n{{city}},{{state}} ") + 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 @@ -23,15 +51,21 @@ }) makeIcon: -> new google.maps.MarkerImage("/assets/medivo/lab.png") - +########## LabList model ############## class window.LabList - constructor: (@data)-> + constructor: (lab_info)-> + @labs = [] + this.setLabs(lab_info) + + setLabs: (lab_info)-> + this.clearMarkers() labs = @labs = [] - $.each( @data, (index, lab_data)-> + $.each( lab_info, (index, lab_data)-> labs.push(new Lab(lab_data)) ) - clearMarkers: -> $.each( @labs, (index, lab)-> lab.clearMarker() ) + clearMarkers: -> + $.each( @labs, (index, lab)-> lab.clearMarker() )