medivo 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. data/app/assets/javascripts/medivo/map.coffee +14 -0
  2. data/app/assets/javascripts/medivo/models.coffee +39 -5
  3. data/app/assets/javascripts/medivo/show_labs.coffee +25 -3
  4. data/config/routes.rb +1 -1
  5. data/lib/medivo/version.rb +1 -1
  6. data/spec/dummy/app/views/labs/search.html.haml +30 -2
  7. data/spec/dummy/config/routes.rb +1 -1
  8. data/spec/dummy/log/development.log +2599 -0
  9. data/spec/dummy/log/test.log +303 -0
  10. data/spec/dummy/tmp/cache/assets/C46/F00/sprockets%2F2281d588b540056c5a7306c32a3761b9 +0 -0
  11. data/spec/dummy/tmp/cache/assets/CAB/970/sprockets%2F6aa4308273851c94a14158394d4dcdc4 +0 -0
  12. data/spec/dummy/tmp/cache/assets/CC3/EF0/sprockets%2F453b504c1f8f374578636f699eaa455d +0 -0
  13. data/spec/dummy/tmp/cache/assets/CE4/E70/sprockets%2F091ec16b8699113092ce35de93ca1d87 +0 -0
  14. data/spec/dummy/tmp/cache/assets/CEE/250/sprockets%2F96688f33f2f8aa261bf6701c1d6d7575 +0 -0
  15. data/spec/dummy/tmp/cache/assets/CFF/7F0/sprockets%2F4007fd53da973506c55bc273a05c5c0d +0 -0
  16. data/spec/dummy/tmp/cache/assets/D19/310/sprockets%2F110931639fc185699ea1aaaf87dd488b +0 -0
  17. data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  18. data/spec/dummy/tmp/cache/assets/D54/ED0/sprockets%2F71c9fa01091d432b131da3bb73faf3d4 +0 -0
  19. data/spec/dummy/tmp/cache/assets/D62/380/sprockets%2F712d93afe40570cc939133bddca13bc7 +0 -0
  20. data/spec/dummy/tmp/cache/assets/D84/210/sprockets%2Fabd0103ccec2b428ac62c94e4c40b384 +0 -0
  21. data/spec/dummy/tmp/cache/assets/D9C/F50/sprockets%2F224e78bb9e1c414a2d518a3aaffd6f77 +0 -0
  22. data/spec/dummy/tmp/cache/assets/D9D/4E0/sprockets%2Fe9dab92986b1516fca08474613ccadcb +0 -0
  23. data/spec/dummy/tmp/cache/assets/DA2/040/sprockets%2F6ab79dcced8cc9933b734e7b21c3a183 +0 -0
  24. data/spec/dummy/tmp/cache/assets/DD2/A50/sprockets%2Fecb5dd9066b50eb678cd8c9dbb21d229 +0 -0
  25. data/spec/dummy/tmp/cache/assets/DD4/2B0/sprockets%2Fef214a63f29afe7f3cbffc65af943108 +0 -0
  26. data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  27. data/spec/dummy/tmp/cache/assets/E59/D50/sprockets%2Fbe1cc4d9b0efb617e58baa16dd1dee58 +0 -0
  28. data/spec/dummy/tmp/pids/server.pid +1 -1
  29. data/spec/requests/labs_spec.rb +7 -6
  30. metadata +17 -17
@@ -1,3 +1,17 @@
1
+ class window.LabListView
2
+ el: null
3
+ template: null
4
+
5
+ constructor: (@lab_list)->
6
+ this.el = $('ul#lab_list')
7
+ this.template = Handlebars.compile($('#lab_item_template').html())
8
+ this.render()
9
+
10
+ render: ->
11
+ view = this
12
+ view.el.empty()
13
+ $.each( @lab_list.labs, (index, lab)-> view.el.append( $(view.template(lab.data)) ) )
14
+
1
15
  class window.MapView
2
16
  constructor: (@collection, @center_point)->
3
17
  throw "you need a collection to make a MapView" unless @collection
@@ -1,7 +1,35 @@
1
+ ########## handlebars helpers ##############
2
+ String.prototype.capitalize = ->
3
+ this.charAt(0).toUpperCase() + this.substring(1).toLowerCase()
4
+
5
+ String.prototype.titleize = ->
6
+ res = []
7
+ parts = this.split(" ")
8
+ $.each(parts, (index, part)->
9
+ res.push(part.capitalize())
10
+ )
11
+ res.join(" ")
12
+
13
+ Handlebars.registerHelper("rounded", (number)->
14
+ if (number != undefined)
15
+ parseFloat(number).toFixed(2)
16
+ )
17
+
18
+ Handlebars.registerHelper("titleize", (string)->
19
+ if (string != undefined)
20
+ string.titleize()
21
+ )
22
+
23
+ Handlebars.registerHelper("address_without_comma", (lab)->
24
+ if (this.address != undefined)
25
+ this.address.replace(/(\s*,\s*$)/g, "").titleize()
26
+ )
27
+
28
+ ########## Lab model ##############
1
29
  class window.Lab
2
30
  constructor: (@data)->
3
31
  marker: null
4
- map_tooltip_template: Handlebars.compile("{{name}}\n{{address}}\n{{city}},{{state}} ")
32
+ map_tooltip_template: Handlebars.compile("{{titleize name}}\n{{address_without_comma address}}\n{{titleize city}},{{state}} ")
5
33
 
6
34
  clearMarker: ->
7
35
  if this.marker
@@ -25,13 +53,19 @@ class window.Lab
25
53
  makeIcon: ->
26
54
  new google.maps.MarkerImage("/assets/medivo/lab.png")
27
55
 
28
-
56
+ ########## LabList model ##############
29
57
  class window.LabList
30
58
 
31
- constructor: (@data)->
59
+ constructor: (lab_info)->
60
+ @labs = []
61
+ this.setLabs(lab_info)
62
+
63
+ setLabs: (lab_info)->
64
+ this.clearMarkers()
32
65
  labs = @labs = []
33
- $.each( @data, (index, lab_data)->
66
+ $.each( lab_info, (index, lab_data)->
34
67
  labs.push(new Lab(lab_data))
35
68
  )
36
69
 
37
- clearMarkers: -> $.each( @labs, (index, lab)-> lab.clearMarker() )
70
+ clearMarkers: ->
71
+ $.each( @labs, (index, lab)-> lab.clearMarker() )
@@ -1,10 +1,32 @@
1
1
  $(document).ready ->
2
+
3
+ map_view = null
4
+ lab_list = null
2
5
  data = $('#lab_list_container').data('labs')
3
6
  if data
4
7
  lab_list = new window.LabList( data.labs )
5
8
  map_view = new window.MapView( lab_list, data.zip_location )
9
+ lab_list_view = new window.LabListView( lab_list )
6
10
  map_view.render()
7
11
  else
8
- console.log('no data')
9
- # zip_code = $('input#zip_code').val()
10
- # Labs.find(zip_code)
12
+ console.log('no data')
13
+
14
+ ###### handle ajax lab data search ########
15
+ $("form#lab_data_search")
16
+ .bind('ajax:beforeSend', (event, data)->
17
+ zip_code = $(this).find('#zip_code').val()
18
+ if (!zip_code.match(/\d{5}/))
19
+ span = $('<span>Zip code should be 5 digits</span>')
20
+ $('form#lab_data_search .error_message').append(span)
21
+ span.fadeOut(4000)
22
+ false
23
+ )
24
+ .bind('ajax:success', (event, data)->
25
+ lab_list.setLabs(data.labs)
26
+ map_view.center_point = data.zip_location
27
+ map_view.render()
28
+ $('form#lab_data_search input[type=submit]').prop("disabled", false)
29
+ )
30
+ .bind('ajax:complete', (event, data)->
31
+ )
32
+
data/config/routes.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  Medivo::Engine.routes.draw do
2
- match '/labs/data/:zip_code' => "labs#data", :via => :get, :as=>:data_labs
2
+ match '/labs/data' => "labs#data", :via => :get, :as=>:data_labs
3
3
  end
@@ -1,3 +1,3 @@
1
1
  module Medivo
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,11 +1,39 @@
1
+ // sample template for rendering lab info
2
+ %script{:id=>"lab_item_template", :type=>"text/x-handlebars-template"}
3
+ %li.lab_info
4
+ .lab_image
5
+ %img{:src=>"{{image}}", :width=>'12px'} &nbsp;
6
+ %div
7
+ .lab_name
8
+ {{lab_name}}
9
+ .address
10
+ {{address_without_comma}}, {{titleize city}}, {{state}}
11
+ .phone
12
+ Tel: {{telephone}}
13
+ .link
14
+ = form_for :lab, :url=>'/select', :method=>'post' do |f|
15
+ %input{ :type=>:hidden, :name => 'id', :value=>"{{id}}" }
16
+ %input{ :type=>:hidden, :name => 'lab_id', :value=>"{{lab_id}}" }
17
+ %input{ :type=>:hidden, :name => 'lab_info[name]', :value=>"{{lab_name}}" }
18
+ %input{ :type=>:hidden, :name => 'lab_info[address]', :value=>"{{address_without_comma}}" }
19
+ %input{ :type=>:hidden, :name => 'lab_info[city]', :value=>"{{titleize city}}" }
20
+ %input{ :type=>:hidden, :name => 'lab_info[state]', :value=>"{{state}}" }
21
+ %input{ :type=>:hidden, :name => 'lab_info[zip]', :value=>"{{zip}}" }
22
+ %input{ :type=>:hidden, :name => 'lab_info[telephone]', :value=>"{{telephone}}" }
23
+ = f.submit 'Select location', :class=>'select_location button'
24
+
25
+ // map display
1
26
  #map_canvas_container
2
27
  #map_canvas{:style => "width:500px; height:350px"}
3
28
 
29
+ // lab list display
4
30
  #lab_list_container{ 'data-labs'=>@lab_data.to_json }
31
+ %ul#lab_list
5
32
 
6
- = form_tag(search_labs_path, :method=>:get) do
33
+ // form for ajax lab searches ..the code to handle return data is in show_labs.coffee
34
+ = form_tag(medivo.data_labs_path, :method=>:get, :id=>'lab_data_search', :remote=>true) do
7
35
  %div
8
- Change your Zip Code
36
+ Enter a new Zip Code
9
37
  .error_message
10
38
  &nbsp;
11
39
  = text_field_tag :zip_code, params[:zip_code]
@@ -1,4 +1,4 @@
1
1
  Rails.application.routes.draw do
2
2
  match "/labs/search" => "labs#search", :via => :get, :as=> :search_labs
3
- mount Medivo::Engine => "/medivo"
3
+ mount Medivo::Engine => "/medivo", :as => "medivo"
4
4
  end