<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>app/views/geofence/_form.rhtml</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -20,15 +20,21 @@ class GeofenceController &lt; ApplicationController
 
   def new
     @devices = Device.get_devices(session[:account_id])
+    @geofence = Geofence.new(:account_id =&gt; session[:account_id],:device_id =&gt; 0,:radius =&gt; 0.1)
+    if not params[:lat].blank? and not params[:lng].blank?
+      @geofence.latitude = params[:lat].to_f
+      @geofence.longitude = params[:lng].to_f
+      @geofence.address = params[:addr]
+    end
     if request.post?
-      geofence = Geofence.new
-      add_and_edit(geofence)
-      if geofence.save
-        flash[:success] = &quot;#{geofence.name} created succesfully&quot;
-        redirect_to geofence_url
+      add_and_edit
+      if @geofence.save
+        flash[:success] = &quot;#{@geofence.name} created succesfully&quot;
+        redirect_to params[:ref_url]
       else
         flash[:error] = 'Location not created'
       end
+    else
     end
   end
 
@@ -51,7 +57,7 @@ class GeofenceController &lt; ApplicationController
     end
     if check_action_for_user
       if request.post?
-        add_and_edit(@geofence)
+        add_and_edit
         if @geofence.save
           flash[:success] = &quot;#{@geofence.name} updated succesfully&quot;
           redirect_to params[:ref_url]
@@ -148,13 +154,14 @@ class GeofenceController &lt; ApplicationController
     page
   end
 
-  def add_and_edit(geofence)
+  def add_and_edit
     fence = params[:bounds].split(&quot;,&quot;)
-    geofence.latitude, geofence.longitude, geofence.radius = fence[0], fence[1], fence[2]
-    geofence.name = params[:name]
-    geofence.address = params[:address]
-    geofence.account_id = params[:radio] == &quot;1&quot; ? session[:account_id] : 0
-    geofence.device_id = params[:radio] == &quot;2&quot; ? params[:device]  : 0
+    @geofence.latitude, @geofence.longitude, @geofence.radius = fence[0], fence[1], fence[2]
+    @geofence.name = params[:name]
+    @geofence.address = params[:address]
+    @geofence.account_id = params[:radio] == &quot;1&quot; ? session[:account_id] : 0
+    @geofence.device_id = params[:radio] == &quot;2&quot; ? params[:device]  : 0
+    @geofence.notify_enter_exit = (params[:notify_enter_exit] == 'on')
   end
 
 end</diff>
      <filename>app/controllers/geofence_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,7 +4,7 @@ class HomeController &lt; ApplicationController
   def index
     user = User.find(session[:user_id])
     if session[:group_value] or user.default_home_selection.nil?
-      redirect_to :action=&gt; (user.default_home_action || 'locations')
+      redirect_to :action=&gt; (user.default_home_action || session[:last_home_action] || 'locations')
     else
       redirect_to :action=&gt; 'show_devices',:group_type =&gt; user.default_home_selection
     end
@@ -55,6 +55,7 @@ class HomeController &lt; ApplicationController
   
 private
   def setup_home_info
+    session[:last_home_action] = params[:action]
     @device_count = Device.count(:all, :conditions =&gt; ['provision_status_id = 1 and account_id = ?', session[:account_id]])
     assign_the_selected_group_to_session 
   end</diff>
      <filename>app/controllers/home_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -25,6 +25,16 @@ module ApplicationHelper
     minutes = duration.to_i % 60
     sprintf('%02d:%02d',hours,minutes)
   end
+  
+  def standard_location(device,reading)
+    if reading.nil? or reading.short_address == ', '
+      'GPS Not Available'
+    elsif reading.nearby_geofence(device.account_id)
+        %(&lt;a href=&quot;/geofence/detail/#{reading.nearby_geofence.id}&quot; title=&quot;View this location&quot; class=&quot;link-all1&quot;&gt;#{reading.nearby_geofence.name}&lt;/a&gt;&lt;br/&gt;#{reading.nearby_geofence.address})
+    else
+        %(&lt;a href=&quot;/geofence/new?lat=#{reading.latitude}&amp;lng=#{reading.longitude}&amp;addr=#{reading.short_address}&quot; title=&quot;Add a new location&quot; class=&quot;link-all1&quot;&gt;#{reading.short_address}&lt;/a&gt;)
+    end
+  end
 
   def box_pagination_links(paginator, options={})
     options.merge!(ActionView::Helpers::PaginationHelper::DEFAULT_OPTIONS) {|key, old, new| old}
@@ -102,6 +112,7 @@ module ApplicationHelper
 
 
   def show_device(device)
+    return &quot;DEFAULT NEEDS TO BE REPLACED&quot;
     content = &quot;&quot;
     content &lt;&lt; %(&lt;tr class=&quot;#{cycle('dark_row', 'light_row')}&quot; id=&quot;row#{device.id}&quot;&gt; &lt;td&gt;)
     content &lt;&lt; %(&lt;a href=&quot;/reports/all/#{device.id}&quot;&gt;#{device.name}&lt;/a&gt;&lt;/td&gt;&lt;td&gt;)</diff>
      <filename>app/helpers/application_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -19,12 +19,24 @@ module HomeHelper
      end
      content
  end
+
+  def show_device_location(device)
+    show_device(device,true)
+  end
+  
+  def show_device_status(device)
+    show_device(device,false)
+  end
  
-  def show_device(device)
+  def show_device(device,show_location)
     content = &quot;&quot;
     content &lt;&lt; %(&lt;tr class=&quot;#{cycle('dark_row', 'light_row')}&quot; id=&quot;row#{device.id}&quot;&gt; &lt;td&gt;)
     if device.latest_gps_reading
-      content &lt;&lt; %(&lt;a href=&quot;javascript:centerMap(#{device.id});highlightRow(#{device.id});&quot; title=&quot;Center map on this device&quot; class=&quot;link-all1&quot;&gt;#{device.name}&lt;/a&gt;)
+      if show_location
+        content &lt;&lt; %(&lt;a href=&quot;javascript:centerMap(#{device.id});highlightRow(#{device.id});&quot; title=&quot;Center map on this device&quot; class=&quot;link-all1&quot;&gt;#{device.name}&lt;/a&gt;)
+      else
+        content &lt;&lt; %(&lt;a href=&quot;/reports/trip/#{device.id}&quot; title=&quot;View details&quot; class=&quot;link-all1&quot;&gt;#{device.name}&lt;/a&gt;)
+      end
     else
       content &lt;&lt; %(#{device.name})
     end      
@@ -32,7 +44,7 @@ module HomeHelper
 
     content &lt;&lt; %(&lt;td&gt;)
     if device.latest_gps_reading
-      content &lt;&lt; %(#{device.latest_gps_reading.short_address})
+      content &lt;&lt; standard_location(device,device.latest_gps_reading)
     else
       content &lt;&lt; %(N/A)
     end</diff>
      <filename>app/helpers/home_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,6 +6,8 @@ class Reading &lt; ActiveRecord::Base
   has_one :stop_event
   include ApplicationHelper
   
+  MAX_NEARBY_RADIUS = 0.25
+  
   acts_as_mappable  :lat_column_name =&gt; :latitude,:lng_column_name =&gt; :longitude
   
   def self.generate_direction_string(dir)
@@ -50,24 +52,32 @@ class Reading &lt; ActiveRecord::Base
     end
   end
   
+  def nearby_geofence(account_id = 0)
+    unless @nearby_geofence
+      distance_function = &quot;distance(latitude,longitude,#{self.latitude},#{self.longitude})&quot;
+      @nearby_geofence = Geofence.find(:first,:conditions =&gt; &quot;radius &lt;= #{MAX_NEARBY_RADIUS} and #{distance_function} &lt;= radius and (device_id = #{self.device_id} or account_id = #{account_id})&quot;,:order =&gt; distance_function)
+      @nearby_geofence ||= :false
+    end
+    return nil if @nearby_geofence == :false
+    return @nearby_geofence
+  end
   
   def short_address
-    if(admin_name1.nil?)
+    if admin_name1.nil?
       latitude.to_s + &quot;, &quot; + longitude.to_s
     else
       begin
         addressParts = Array.new
-        if(!street.nil?)
-          if(!street_number.nil?) 
+        unless street.blank?
+          if street_number.blank?
+            addressParts &lt;&lt; street
+          else 
             streetAddress = [street_number, street]
-            streetAddress.delete(&quot;&quot;)
             addressParts &lt;&lt; streetAddress.join(' ')
-          else 
-            addressParts &lt;&lt; street
           end
         end
-        addressParts &lt;&lt; place_name
-        addressParts &lt;&lt; admin_name1
+        addressParts &lt;&lt; place_name unless place_name.blank?
+        addressParts &lt;&lt; admin_name1 unless place_name.blank?
         addressString = addressParts.join(', ')
         addressString.empty? ? latitude.to_s + &quot;, &quot; + longitude.to_s : addressString
       rescue</diff>
      <filename>app/models/reading.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,65 +1 @@
-&lt;div class=&quot;container&quot;&gt;
-&lt;div id=&quot;ub_account_tbl&quot;&gt;
-    &lt;div&gt;&lt;h3&gt;Edit Location&lt;/h3&gt;&lt;/div&gt;
-    &lt;div&gt;
-   &lt;form method=&quot;post&quot; id=&quot;geofence_form&quot; onSubmit=&quot;return validate();&quot;&gt;
-    &lt;div&gt; &lt;input type=&quot;radio&quot; id=&quot;radio&quot; name=&quot;radio&quot; value=&quot;1&quot; &lt;% if @geofence.account_id != 0 %&gt;checked&lt;%end%&gt; onclick=&quot;enableDevice(this);&quot;/&gt; Account Level   &lt;input type=&quot;radio&quot; id=&quot;radio&quot; name=&quot;radio&quot; onclick=&quot;&lt;%if @devices.empty?%&gt;alert('You can\'t create device level location.');&lt;%else%&gt;enableDevice(this);&lt;%end%&gt;&quot; value=&quot;2&quot; &lt;% if @geofence.device_id != 0 %&gt;checked&lt;%end%&gt; /&gt; Vehicle Level&lt;/div&gt;
-    
-    &lt;div class=&quot;ub_editform&quot;&gt;Choose the vehicle: &lt;br/&gt;
-		&lt;select id=&quot;device&quot; name=&quot;device&quot; class=&quot;text_width&quot; &lt;% if @geofence.account_id != 0 &amp;&amp; @geofence.device_id == 0%&gt;disabled&lt;% end %&gt;&gt;
-		&lt;% @devices.each do |device| %&gt;
-			&lt;option value=&quot;&lt;%= device.id %&gt;&quot; &lt;%= &quot;selected='selected'&quot; if @geofence.device_id == device.id %&gt;&gt;&lt;%= device.name %&gt;&lt;/option&gt;
-		&lt;% end %&gt;	
-		&lt;/select&gt;	  
-    &lt;/div&gt;
-	
-    &lt;div&gt;Location name: &lt;br/&gt;
-      &lt;input   name=&quot;name&quot; type=&quot;text&quot; class=&quot;text_width&quot; value=&quot;&lt;%= @geofence.name %&gt;&quot; /&gt;
-    &lt;/div&gt;
-	&lt;input type=&quot;hidden&quot; name=&quot;ref_url&quot; value=&quot;&lt;%= session[:referral_url] %&gt;&quot;&gt;
-    
-    &lt;div&gt;Location address: &lt;br/&gt;
-		&lt;input  id=&quot;address&quot; name=&quot;address&quot; class=&quot;text_width&quot; value=&quot;&lt;%= @geofence.address %&gt;&quot; type=&quot;text&quot; /&gt;
-    &lt;/div&gt;
-
-    &lt;div&gt;
-		&lt;input type=&quot;button&quot; name=&quot;Preview&quot; value=&quot;preview&quot; onclick=&quot;geocode(document.getElementById('address').value); return false;&quot; /&gt;
-    &lt;/div&gt;
-
-	
-    &lt;div&gt;Radius: &lt;br/&gt;
-		&lt;select id=&quot;radius&quot; name=&quot;radius&quot; &gt;                
-                 &lt;% RADIUS_ARRAY.each do |rad|%&gt;
-			      &lt;option value=&quot;&lt;%=rad%&gt;&quot; &lt;%= &quot;selected='selected'&quot; if @geofence.radius == rad %&gt;&gt;&lt;%= rad%&gt;&lt;/option&gt;
-                &lt;%end%&gt;
-		&lt;/select&gt; (miles)
-    &lt;/div&gt;
-  &lt;/div&gt;
-  
-  &lt;input type=&quot;hidden&quot; name=&quot;bounds&quot; /&gt;
-  
-  &lt;div&gt;
-    &lt;input name=&quot;Create geofence&quot; type=&quot;submit&quot; value=&quot;update location&quot; style=&quot;cursor:pointer;&quot;/&gt;	
-    &lt;a href=&quot;&lt;%= session[:referral_url] %&gt;&quot; &gt;cancel&lt;/a&gt;
-  &lt;/div&gt;
-  &lt;/form&gt;
-&lt;/div&gt;
-
-&lt;div class=&quot;main_map&quot;&gt;
-        &lt;div id=&quot;geofence_map&quot; class=&quot;googlemap&quot;&gt;&lt;/div&gt;
-      &lt;/div&gt;
-&lt;/div&gt;
-
-&lt;% if !@geofence.nil? %&gt;
-    &lt;script&gt;     
-      var device_flag = 1
-      var remove_listener = 'false'
-         &lt;% if @geofence.device &amp;&amp; @geofence.device.latest_gps_reading %&gt;
-              var device = {name: '&lt;%= escape_javascript(@geofence.device.name ) %&gt;', lat: &lt;%= @geofence.device.latest_gps_reading.latitude %&gt;, lng: &lt;%= @geofence.device.latest_gps_reading.longitude %&gt;, address: '&lt;%= @geofence.device.latest_gps_reading.short_address %&gt;'}; 
-         &lt;% else %&gt;
-              var device = {name: '&lt;%= escape_javascript @geofence.name %&gt;', lat: &lt;%= @geofence.latitude %&gt;, lng: &lt;%= @geofence.longitude %&gt;};
-         &lt;%end%&gt;     
-         var gf_index = 0;	
-         geofences.push({id: &lt;%= @geofence.id%&gt;, name: '&lt;%= escape_javascript(@geofence.name) %&gt;', bounds: '&lt;%= @geofence.bounds %&gt;'});	
-    &lt;/script&gt;
-&lt;% end %&gt;
+&lt;%= render :partial =&gt; 'form' %&gt;</diff>
      <filename>app/views/geofence/edit.rhtml</filename>
    </modified>
    <modified>
      <diff>@@ -11,6 +11,7 @@
         &lt;td&gt;For&lt;/td&gt;
         &lt;td&gt;Address&lt;/td&gt;
         &lt;td&gt;Radius&lt;/th&gt;
+		&lt;td&gt;Notify?&lt;/td&gt;
         &lt;td&gt;&amp;nbsp;&lt;/td&gt;
       &lt;/tr&gt;
 	
@@ -26,6 +27,7 @@
            &lt;/td&gt;
            &lt;td &gt;&lt;%= geofence.get_lat_lng %&gt;&lt;/td&gt;
            &lt;td &gt;&lt;%= geofence.radius.to_s + ' ' + 'miles' %&gt;&lt;/td&gt;
+		   &lt;td&gt;&lt;%= geofence.notify_enter_exit ? 'yes' : 'no' %&gt;&lt;/td&gt;
            &lt;td &gt;                    
              &lt;a href=&quot;&lt;%= delete_url(:id=&gt;geofence.id)%&gt;&quot; onclick=&quot;return confirm('Are you sure you want to delete this location ?');&quot;&gt;delete&lt;/a&gt;
            &lt;/td&gt;</diff>
      <filename>app/views/geofence/index.rhtml</filename>
    </modified>
    <modified>
      <diff>@@ -1,78 +1 @@
-&lt;div class=&quot;container&quot;&gt;
-  &lt;div id=&quot;ub_account_tbl&quot;&gt;
-    &lt;div&gt;
-      &lt;h3&gt;Add New Locations&lt;/h3&gt;
-    &lt;/div&gt;
-
-    &lt;form method=&quot;post&quot; id=&quot;geofence_form&quot; onsubmit=&quot;return validate();&quot;&gt;
-      &lt;div style=&quot;background-color: #EDF3FE; padding: 10px;&quot;&gt;
-        &lt;div&gt;
-          &lt;div&gt;
-            &lt;strong&gt;This location applies to:&lt;/strong&gt;
-          &lt;/div&gt;	 			
-          &lt;input type=&quot;radio&quot; id=&quot;all&quot; name=&quot;radio&quot; value=&quot;1&quot; checked onclick=&quot;enableDevice(this);&quot;/&gt; All vehicles in this account&lt;br /&gt;
-          &lt;input type=&quot;radio&quot; id=&quot;single&quot; name=&quot;radio&quot; onclick=&quot;&lt;%if @devices.empty?%&gt;alert('You can\'t create vehicle-level locations');&lt;%else%&gt;enableDevice(this);&lt;%end%&gt;&quot; value=&quot;2&quot; /&gt; A single vehicle
-		
-          &lt;select id=&quot;device&quot; name=&quot;device&quot;  class=&quot;text_width&quot; disabled style=&quot;margin-top: 5px;&quot;&gt;
-            &lt;% @devices.each do |device| %&gt;
-              &lt;option value=&quot;&lt;%= device.id %&gt;&quot; &lt;% if params[:id].to_i == device.id %&gt;selected=&quot;selected&quot;&lt;% end %&gt;&gt;&lt;%= device.name %&gt;&lt;/option&gt;
-            &lt;% end %&gt;	
-          &lt;/select&gt;
-       &lt;/div&gt;
-
-       &lt;div&gt;
-         &lt;div&gt;
-           &lt;strong&gt;Location name:&lt;/strong&gt;
-         &lt;/div&gt;
-         &lt;input name=&quot;name&quot; type=&quot;text&quot; class=&quot;text_width&quot; /&gt;
-       &lt;/div&gt;
-	
-       &lt;div&gt;
-         &lt;div&gt;
-           &lt;strong&gt;Location address:&lt;/strong&gt;
-         &lt;/div&gt;
-         &lt;input id=&quot;address&quot; name=&quot;address&quot; type=&quot;text&quot; class=&quot;text_width&quot; /&gt;
-       &lt;/div&gt;
-
-       &lt;div&gt;
-         &lt;div&gt;
-           &lt;strong&gt;Radius:&lt;/strong&gt;
-         &lt;/div&gt;
-         &lt;select id=&quot;radius&quot; name=&quot;radius&quot;&gt;
-           &lt;% RADIUS_ARRAY.each do |rad|%&gt;
-             &lt;option value=&quot;&lt;%=rad%&gt;&quot;&gt;&lt;%= rad%&gt;&lt;/option&gt;
-           &lt;%end%&gt;
-         &lt;/select&gt; (miles)
-       &lt;/div&gt;
-
-       &lt;div style=&quot;margin-top: 10px;&quot;&gt;
-         &lt;input type=&quot;button&quot; name=&quot;Preview&quot; value=&quot;preview&quot; onclick=&quot;geocode(document.getElementById('address').value); return false;&quot; /&gt;
-       &lt;/div&gt;
-     &lt;/div&gt;
-  
-     &lt;input type=&quot;hidden&quot; name=&quot;bounds&quot;/&gt;
-
-     &lt;div style=&quot;margin-top: 15px;&quot;&gt;    
-       &lt;input name=&quot;Create geofence&quot; type=&quot;submit&quot; value=&quot;create location&quot;/&gt;	    
-       &lt;a href=&quot;&lt;%= session[:referral_url] %&gt;&quot; &gt;cancel&lt;/a&gt;
-     &lt;/div&gt;
-   &lt;/form&gt;
-  &lt;/div&gt;
-  
-  &lt;div class=&quot;main_map&quot;&gt;
-    &lt;div id=&quot;geofence_map&quot; class=&quot;googlemap&quot;&gt;&lt;/div&gt;
-  &lt;/div&gt;
-&lt;/div&gt;
-
-&lt;script&gt;
-    var device_flag = 0;
-    var remove_listener = 'false';
-    var device = 'false';
-    var gf_index = 0;
-    geofences.push({id: 0, name: '', bounds: '37.0625, -95.677068,0.1'});
-	&lt;% if params[:id] %&gt;
-	document.getElementById(&quot;single&quot;).checked = true;
-	document.getElementById(&quot;device&quot;).disabled = false;
-	&lt;% end %&gt;
-&lt;/script&gt;
-
+&lt;%= render :partial =&gt; 'form' %&gt;</diff>
      <filename>app/views/geofence/new.rhtml</filename>
    </modified>
    <modified>
      <diff>@@ -9,6 +9,6 @@
     &lt;th&gt;Last Status&lt;/th&gt;
     &lt;th&gt;Last Report&lt;/th&gt;
   &lt;/tr&gt;    
-  &lt;%= render :partial =&gt; &quot;group_rows&quot;,:locals =&gt; {:column_span =&gt; 4,:callback =&gt; &quot;show_device&quot;} %&gt;
+  &lt;%= render :partial =&gt; &quot;group_rows&quot;,:locals =&gt; {:column_span =&gt; 4,:callback =&gt; &quot;show_device_location&quot;} %&gt;
 &lt;/table&gt;
 </diff>
      <filename>app/views/home/locations.rhtml</filename>
    </modified>
    <modified>
      <diff>@@ -8,6 +8,6 @@
     &lt;th&gt;Last Status&lt;/th&gt;
     &lt;th&gt;Last Report&lt;/th&gt;
   &lt;/tr&gt;    
-  &lt;%= render :partial =&gt; &quot;group_rows&quot;,:locals =&gt; {:column_span =&gt; 4,:callback =&gt; &quot;show_device&quot;} %&gt;
+  &lt;%= render :partial =&gt; &quot;group_rows&quot;,:locals =&gt; {:column_span =&gt; 4,:callback =&gt; &quot;show_device_status&quot;} %&gt;
 &lt;/table&gt;
 </diff>
      <filename>app/views/home/status.rhtml</filename>
    </modified>
    <modified>
      <diff>@@ -3,24 +3,12 @@
 		&lt;td&gt;&lt;a href=&quot;/reports/trip_detail/&lt;%= trip.id %&gt;&quot; style=&quot;font-size:11px;&quot;&gt;details&lt;/a&gt;&lt;/td&gt;
 		&lt;td nowrap&gt;&lt;%= standard_date(trip.reading_start.created_at,last_start) %&gt;&lt;/td&gt;
 		&lt;td nowrap&gt;&lt;%= standard_time(trip.reading_start.created_at) %&gt;&lt;/td&gt;
-		&lt;td&gt;
-            &lt;% if trip.reading_start.short_address == ', '%&gt;
-				GPS Not Available
-            &lt;% else %&gt;
-				&lt;a href=&quot;/geofence/new?lat=&lt;%= trip.reading_start.latitude %&gt;&amp;lon=&lt;%= trip.reading_start.longitude %&gt;&quot;&gt;&lt;%= trip.reading_start.short_address %&gt;&lt;/a&gt;
-			&lt;% end %&gt;
-		&lt;/td&gt;
+		&lt;td&gt;&lt;%= standard_location(trip.device,trip.reading_start) %&gt;&lt;/td&gt;
 		&lt;script&gt;readings.push({id: &lt;%= trip.id %&gt;, start: true, lat: &lt;%= trip.reading_start.latitude %&gt;, lng: &lt;%= trip.reading_start.longitude %&gt;, address: '&lt;%= escape_javascript trip.reading_start.short_address %&gt;', dt: displayLocalDT(&lt;%= trip.reading_start.created_at.to_i*1000 %&gt;), event: '&lt;%= trip.reading_start.event_type %&gt;'});&lt;/script&gt;
 		&lt;% if trip.reading_stop %&gt;
 			&lt;td&gt;&lt;%= standard_duration(trip.duration) %&gt;&lt;/td&gt;
 			&lt;td&gt;&lt;%= sprintf('%2.1f',trip.distance) %&gt;&lt;/td&gt;
-			&lt;td&gt;
-	            &lt;% if trip.reading_stop.short_address == ', '%&gt;
-					GPS Not Available
-	            &lt;% else %&gt;
-					&lt;a href=&quot;/geofence/new?lat=&lt;%= trip.reading_stop.latitude %&gt;&amp;lon=&lt;%= trip.reading_stop.longitude %&gt;&quot;&gt;&lt;%= trip.reading_stop.short_address %&gt;&lt;/a&gt;
-				&lt;% end %&gt;
-			&lt;/td&gt;
+			&lt;td&gt;&lt;%= standard_location(trip.device,trip.reading_stop) %&gt;&lt;/td&gt;
 			&lt;script&gt;readings.push({id: &lt;%= trip.id %&gt;, stop: true, lat: &lt;%= trip.reading_stop.latitude %&gt;, lng: &lt;%= trip.reading_stop.longitude %&gt;, address: '&lt;%= escape_javascript trip.reading_stop.short_address %&gt;', dt: displayLocalDT(&lt;%= trip.reading_stop.created_at.to_i*1000 %&gt;), event: '&lt;%= trip.reading_stop.event_type %&gt;'});&lt;/script&gt;
 			&lt;td nowrap&gt;&lt;%= standard_time(trip.reading_stop.created_at) %&gt;&lt;/td&gt;
 			&lt;td&gt;&lt;%= standard_duration(trip.idle) %&gt;&lt;/td&gt;</diff>
      <filename>app/views/reports/_trip_row.rhtml</filename>
    </modified>
    <modified>
      <diff>@@ -2,10 +2,14 @@ class AddUserDefaults &lt; ActiveRecord::Migration
   def self.up
     add_column :users,:default_home_action,:string
     add_column :users,:default_home_selection,:string
+    
+    add_column :geofences,:notify_enter_exit,:boolean,:null =&gt; false,:default =&gt; false
   end
 
   def self.down
     remove_column :users,:default_home_action
     remove_column :users,:default_home_selection
+
+    remove_column :geofences,:notify_enter_exit
   end
 end</diff>
      <filename>db/migrate/20090320194931_add_user_defaults.rb</filename>
    </modified>
    <modified>
      <diff>@@ -76,16 +76,17 @@ ActiveRecord::Schema.define(:version =&gt; 20090320194931) do
   end
 
   create_table &quot;geofences&quot;, :force =&gt; true do |t|
-    t.string   &quot;name&quot;,       :limit =&gt; 30
-    t.integer  &quot;device_id&quot;,  :limit =&gt; 11
+    t.string   &quot;name&quot;,              :limit =&gt; 30
+    t.integer  &quot;device_id&quot;,         :limit =&gt; 11
     t.datetime &quot;created_at&quot;
     t.datetime &quot;updated_at&quot;
     t.string   &quot;address&quot;
-    t.integer  &quot;fence_num&quot;,  :limit =&gt; 11
-    t.decimal  &quot;latitude&quot;,                 :precision =&gt; 15, :scale =&gt; 10
-    t.decimal  &quot;longitude&quot;,                :precision =&gt; 15, :scale =&gt; 10
+    t.integer  &quot;fence_num&quot;,         :limit =&gt; 11
+    t.decimal  &quot;latitude&quot;,                        :precision =&gt; 15, :scale =&gt; 10
+    t.decimal  &quot;longitude&quot;,                       :precision =&gt; 15, :scale =&gt; 10
     t.float    &quot;radius&quot;
-    t.integer  &quot;account_id&quot;, :limit =&gt; 11
+    t.integer  &quot;account_id&quot;,        :limit =&gt; 11
+    t.boolean  &quot;notify_enter_exit&quot;,                                               :default =&gt; false, :null =&gt; false
   end
 
   create_table &quot;group_devices&quot;, :force =&gt; true do |t|</diff>
      <filename>db/schema.rb</filename>
    </modified>
    <modified>
      <diff>@@ -135,12 +135,12 @@ function createMarker(p) {
 function validate() {
      form = document.getElementById('geofence_form');  
 	if(form.name.value == '') {
-		alert('Please specify a name for your geofence');
+		alert('Please specify a name for your location');
 		return false;	
 	}
 	
 	if(form.bounds.value == '') {
-		alert('Please preview your geofence before saving');
+		alert('Please preview your location before saving');
 		return false;
 	}
 	
@@ -163,6 +163,7 @@ function displayGeofence(index) {
 		zoom = 14;
 	
 	gmap.setCenter(point, zoom);
+	form.bounds.value = geofences[index].bounds;
 }
 
 function go(url) {</diff>
      <filename>public/javascripts/geofence.js</filename>
    </modified>
    <modified>
      <diff>@@ -15,6 +15,8 @@ var zoom_val = get_cookie(&quot;zvalue&quot;);
 
 function load() 
 {
+  if (document.getElementById(&quot;map&quot;) == undefined)
+    return;
   if (GBrowserIsCompatible()) {
   	gmap = new GMap2(document.getElementById(&quot;map&quot;));
     gmap.addControl(new GLargeMapControl());</diff>
      <filename>public/javascripts/main.js</filename>
    </modified>
    <modified>
      <diff>@@ -55,34 +55,34 @@ class GeofenceControllerTest &lt; Test::Unit::TestCase
   end
   
   def test_new
-    post :new, {:id =&gt; &quot;1&quot;, :name =&gt; &quot;qwerty&quot;, :bounds=&gt;&quot;1,1,1&quot;, :address=&gt;&quot;1600 Penn Ave&quot;}, { :user =&gt; users(:dennis), :account_id =&gt; &quot;1&quot; }
+    post :new, {:id =&gt; &quot;1&quot;, :ref_url =&gt; '/geofence', :name =&gt; &quot;qwerty&quot;, :bounds=&gt;&quot;1,1,1&quot;, :address=&gt;&quot;1600 Penn Ave&quot;}, { :user =&gt; users(:dennis), :account_id =&gt; &quot;1&quot; }
     assert_equal flash[:success] , &quot;qwerty created succesfully&quot;
   end
   
   def test_invalid_device
-     post :new, {:id =&gt; &quot;1&quot;, :name =&gt;&quot;&quot;, :bounds=&gt;&quot;1,1,1&quot;, :address=&gt;&quot;1600 Penn Ave&quot;}, { :user =&gt; users(:dennis), :account_id =&gt; &quot;1&quot; }
+     post :new, {:id =&gt; &quot;1&quot;, :ref_url =&gt; '/geofence', :name =&gt;&quot;&quot;, :bounds=&gt;&quot;1,1,1&quot;, :address=&gt;&quot;1600 Penn Ave&quot;}, { :user =&gt; users(:dennis), :account_id =&gt; &quot;1&quot; }
      assert_equal flash[:error], &quot;Location not created&quot;      
   end
   
   def test_create
     #apparent bug in rail makes flash go away after first post in this test
-    post :new, {:id =&gt; &quot;1&quot;, :name =&gt; &quot;qwerty&quot;, :bounds=&gt;&quot;1,1,1&quot;, :address=&gt;&quot;1600 Penn Ave&quot;}, { :user =&gt; users(:dennis), :account_id =&gt; &quot;1&quot; }
+    post :new, {:id =&gt; &quot;1&quot;, :ref_url =&gt; '/geofence', :name =&gt; &quot;qwerty&quot;, :bounds=&gt;&quot;1,1,1&quot;, :address=&gt;&quot;1600 Penn Ave&quot;}, { :user =&gt; users(:dennis), :account_id =&gt; &quot;1&quot; }
     assert_redirected_to :controller =&gt; &quot;geofence&quot;, :action =&gt; &quot;index&quot; 
     assert_equal( &quot;qwerty created succesfully&quot;, @response.flash[:success] )
     #assert_equal 1, devices(:device1).geofences[0].radius
     #assert_equal 1, devices(:device1).geofences[0].latitude
     #assert_equal 1, devices(:device1).geofences[0].longitude
     
-    post :new, {:id =&gt; &quot;1&quot;, :name =&gt; &quot;qwerty&quot;, :bounds=&gt;&quot;1,1,1&quot;, :address=&gt;&quot;1600 Penn Ave&quot;}, { :user =&gt; users(:dennis), :account_id =&gt; &quot;1&quot; }
+    post :new, {:id =&gt; &quot;1&quot;, :ref_url =&gt; '/geofence', :name =&gt; &quot;qwerty&quot;, :bounds=&gt;&quot;1,1,1&quot;, :address=&gt;&quot;1600 Penn Ave&quot;}, { :user =&gt; users(:dennis), :account_id =&gt; &quot;1&quot; }
     assert_redirected_to :controller =&gt; &quot;geofence&quot;, :action =&gt; &quot;index&quot; 
 
-    post :new, {:id =&gt; &quot;1&quot;, :name =&gt; &quot;qwerty&quot;, :bounds=&gt;&quot;1,1,1&quot;, :address=&gt;&quot;1600 Penn Ave&quot;}, { :user =&gt; users(:dennis), :account_id =&gt; &quot;1&quot; }
+    post :new, {:id =&gt; &quot;1&quot;, :ref_url =&gt; '/geofence', :name =&gt; &quot;qwerty&quot;, :bounds=&gt;&quot;1,1,1&quot;, :address=&gt;&quot;1600 Penn Ave&quot;}, { :user =&gt; users(:dennis), :account_id =&gt; &quot;1&quot; }
     assert_redirected_to :controller =&gt; &quot;geofence&quot;, :action =&gt; &quot;index&quot; 
     
-    post :new, {:id =&gt; &quot;1&quot;, :name =&gt; &quot;qwerty&quot;, :bounds=&gt;&quot;1,1,1&quot;, :address=&gt;&quot;1600 Penn Ave&quot;}, { :user =&gt; users(:dennis), :account_id =&gt; &quot;1&quot; }
+    post :new, {:id =&gt; &quot;1&quot;, :ref_url =&gt; '/geofence', :name =&gt; &quot;qwerty&quot;, :bounds=&gt;&quot;1,1,1&quot;, :address=&gt;&quot;1600 Penn Ave&quot;}, { :user =&gt; users(:dennis), :account_id =&gt; &quot;1&quot; }
     assert_redirected_to :controller =&gt; &quot;geofence&quot;, :action =&gt; &quot;index&quot; 
     
-    post :new, {:id =&gt; &quot;1&quot;, :name =&gt; &quot;qwerty&quot;, :bounds=&gt;&quot;1,1,1&quot;, :address=&gt;&quot;1600 Penn Ave&quot;}, { :user =&gt; users(:dennis), :account_id =&gt; &quot;1&quot; }
+    post :new, {:id =&gt; &quot;1&quot;, :ref_url =&gt; '/geofence', :name =&gt; &quot;qwerty&quot;, :bounds=&gt;&quot;1,1,1&quot;, :address=&gt;&quot;1600 Penn Ave&quot;}, { :user =&gt; users(:dennis), :account_id =&gt; &quot;1&quot; }
     assert_redirected_to :controller =&gt; &quot;geofence&quot;, :action =&gt; &quot;index&quot; 
   end
   </diff>
      <filename>test/functional/geofence_controller_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>90c380b3869050ea6ab416167ecd5e641cb0a68f</id>
    </parent>
  </parents>
  <author>
    <name>semmons</name>
    <email>semmons@43da8e2a-8e9e-4132-97af-63a25ad0a55a</email>
  </author>
  <url>http://github.com/redinger/numerex_test/commit/084a0e5d57657c11f6d70da4618ec74ddfebd5aa</url>
  <id>084a0e5d57657c11f6d70da4618ec74ddfebd5aa</id>
  <committed-date>2009-03-21T16:04:12-07:00</committed-date>
  <authored-date>2009-03-21T16:04:12-07:00</authored-date>
  <message>support for optional geofence notification and display of nearby geofence</message>
  <tree>24c71710dee34a5898c5fc5521228f525a92f101</tree>
  <committer>
    <name>semmons</name>
    <email>semmons@43da8e2a-8e9e-4132-97af-63a25ad0a55a</email>
  </committer>
</commit>
