Commit 5d059a1c

mo k <mo@mokhan.ca>
2012-07-29 05:19:53
add city to the registration form on the login page.
1 parent fbcdfe2
Changed files (2)
app
views
devise
registrations
sessions
app/views/devise/registrations/new.html.erb
@@ -61,6 +61,12 @@
                   <%= f.password_field :password_confirmation, :placeholder => 'Password Confirmation' %>
                 </div>
               </div>
+              <div class="control-group">
+                <%= f.label :city, 'City', :class => "control-label" %>
+                <div class="controls">
+                  <%= f.text_field :city, :placeholder => 'City' %>
+                </div>
+              </div>
               <div class="control-group">
                 <label for="accepted" class="control-label"></label>
                 <div class="controls">
app/views/devise/sessions/new.html.erb
@@ -9,6 +9,36 @@
         $('#submit-registration').attr('disabled', 'disabled');
       }
     });
+    $('#user_city').autocomplete({
+      source: function(request, response){
+        $.ajax({
+          url: 'http://ws.geonames.org/searchJSON',
+          dataType: "jsonp",
+          data: {
+            featureClass: "P",
+            style: 'full',
+            maxRows: 12,
+            name_startsWith: request.term
+          },
+          success: function(data){
+            response( $.map(data.geonames, function(item){
+              return {
+                label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
+                value: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
+                latitude: item.lat,
+                longitude: item.lng
+              }
+            }));
+          }
+        });
+      },
+      minlength:2,
+      select:function(event, ui){
+        var item = ui.item;
+        $('#user_latitude').val(item.latitude);
+        $('#user_longitude').val(item.longitude);
+      }
+    });
   });
 </script>
 <% end %>
@@ -61,6 +91,12 @@
               <%= f.password_field :password_confirmation, :placeholder => 'Password Confirmation' %>
             </div>
           </div>
+          <div class="control-group">
+            <%= f.label :city, 'City', :class => "control-label" %>
+            <div class="controls">
+              <%= f.text_field :city, :placeholder => 'City' %>
+            </div>
+          </div>
           <div class="control-group">
             <label for="accepted" class="control-label"></label>
             <div class="controls">
@@ -70,6 +106,8 @@
           <div class="form-actions">
             <%= f.submit "Sign up", :id => 'submit-registration', :class=> "btn btn-primary" %>
           </div>
+          <%= f.hidden_field :latitude %>
+          <%= f.hidden_field :longitude %>
         <% end %>
       </div>
     </div>