Skip to content
This repository has been archived by the owner on Nov 15, 2018. It is now read-only.

Commit

Permalink
Admin portion of cities working.... cleanup probably needed, but, eno…
Browse files Browse the repository at this point in the history
…ugh to move on to zone side of things
  • Loading branch information
markalinn committed Oct 14, 2011
1 parent 3902326 commit 82a1676
Show file tree
Hide file tree
Showing 19 changed files with 243 additions and 0 deletions.
32 changes: 32 additions & 0 deletions app/controllers/admin/cities_controller.rb
@@ -0,0 +1,32 @@
class Admin::CitiesController < Admin::ResourceController
belongs_to :state
before_filter :load_data

def index
respond_with(@collection) do |format|
format.html
format.js { render :partial => 'city_list.html.erb' }
end
end

protected

def location_after_save
admin_country_state_cities_url(@country,@state)
end

def location_after_create
admin_country_state_cities_url(@country,@state)
end

def collection
super.order(:name)
end

def load_data
@countries = Country.order(:name)
@country = Country.find(params[:country_id])
@states = State.order(:name)
@state = State.find(params[:state_id])
end
end
5 changes: 5 additions & 0 deletions app/models/city.rb
@@ -0,0 +1,5 @@
class City < ActiveRecord::Base
belongs_to :state
validates_presence_of :name
validates_uniqueness_of :name, :scope => [:state_id]
end
3 changes: 3 additions & 0 deletions app/models/country_decorator.rb
@@ -0,0 +1,3 @@
Country.class_eval do
has_many :cities, :through => :states
end
3 changes: 3 additions & 0 deletions app/models/state_decorator.rb
@@ -0,0 +1,3 @@
State.class_eval do
has_many :cities
end
32 changes: 32 additions & 0 deletions app/views/admin/cities/_city_list.html.erb
@@ -0,0 +1,32 @@
<table class="index" id='listing_citys'>
<thead>
<tr>
<th><%= t("name") %></th>
<th></th>
</tr>
</thead>
<tbody>
<% @cities.each do |city|
state = city.state
country = @state.country
%>
<tr id="<%= dom_id city %>">
<td><%=city.name %></td>
<td class="actions">
<%= link_to_with_icon 'edit', t("edit"), edit_admin_country_state_city_url(country, state, city), :class => 'edit' %>
&nbsp;
<%= link_to 'Delete', admin_country_state_city_url(country, state, city), :method => 'delete' %>
</td>
</tr>
<% end %>
<% if @cities.empty? %>
<tr><td colspan="3"><%= t(:none) %></td></tr>
<% end %>
</tbody>
</table>
<div id="new_city"></div>
<p>
<%= button_link_to t("new_city"), new_admin_country_state_city_url(@country,@state), {:remote => true,
:icon => 'add',
:id => 'new_city'} %>
</p>
4 changes: 4 additions & 0 deletions app/views/admin/cities/_form.html.erb
@@ -0,0 +1,4 @@
<%= f.field_container :name do %>
<%= f.label :name, t("name") %><br />
<%=f.text_field :name %>
<% end %>
10 changes: 10 additions & 0 deletions app/views/admin/cities/edit.html.erb
@@ -0,0 +1,10 @@
<%= render :partial => 'admin/shared/configuration_menu' %>

<h1><%= t("editing_state") %></h1>

<%= render 'shared/error_messages', :target => @state %>
<%= form_for([:admin,@country,@state,@city], :html => { :method => :put }) do |f| %>
<%= render :partial => "form", :locals => { :f => f } %>
<%= render :partial => "admin/shared/cities_edit_resource_links" %>
<% end %>
23 changes: 23 additions & 0 deletions app/views/admin/cities/index.html.erb
@@ -0,0 +1,23 @@
<%= render :partial => 'admin/shared/configuration_menu' %>

<h1><%= t("Cities") %></h1>

<p>
<label for="country"><%= t('country') %></label>
<select id="country" class='observe_field' data-base-url="<%=admin_states_path(:format => :js)%>?country_id=" data-update="#state-list">
<%= options_from_collection_for_select(@countries, :id, :name, @country.id) %>
</select>
</p>

<p>
<label for="state"><%= t('state') %></label>
<select id="state" class='observe_field' data-base-url="<%=admin_cities_path(:format => :js)%>?country_id=<%= @country.id %>&state_id=" data-update="#city-list">
<%= options_from_collection_for_select(@states, :id, :name, @state.id) %>
</select>
</p>

<%= image_tag "spinner.gif", :plugin=>"spree", :style => "display:none", :id => 'busy_indicator' %>

<div id="city-list">
<%=render :partial => 'city_list'%>
</div>
8 changes: 8 additions & 0 deletions app/views/admin/cities/new.erb
@@ -0,0 +1,8 @@
<%= render :partial => 'admin/shared/configuration_menu' %>
<%= render 'shared/error_messages', :target => @city %>
<%= form_for([:admin,@country,@state,@city]) do |f| %>
<%= render :partial => "form", :locals => { :f => f } %>
<%= render :partial => "admin/shared/cities_new_resource_links" %>
<% end %>
4 changes: 4 additions & 0 deletions app/views/admin/shared/_cities_edit_resource_links.html.erb
@@ -0,0 +1,4 @@
<p class="form-buttons">
<%= button t("update") %>
<%= t("or") %> <%= link_to t("cancel"), admin_country_state_cities_url %>
</p>
4 changes: 4 additions & 0 deletions app/views/admin/shared/_cities_new_resource_links.html.erb
@@ -0,0 +1,4 @@
<p class="form-buttons">
<%= button t("actions.create") %>
<%= t("or") %> <%= link_to t("actions.cancel"), [:admin,@country,@state,@city] %>
</p>
4 changes: 4 additions & 0 deletions app/views/shared/_cities_admin_configurations_menu.erb
@@ -0,0 +1,4 @@
<tr>
<td><%= link_to t("Cities"), admin_country_state_cities_path(Spree::Config[:default_country_id],State.find(:first, :conditions => {:country_id => Spree::Config[:default_country_id], :abbr => 'CA'})) %></td>
<td><%= t("cities_description") %></td>
</tr>
11 changes: 11 additions & 0 deletions config/locales/.svn/all-wcprops
@@ -0,0 +1,11 @@
K 25
svn:wc:ra_dav:version-url
V 54
/stuff/!svn/ver/7/axialracing.com/trunk/config/locales
END
en.yml
K 25
svn:wc:ra_dav:version-url
V 61
/stuff/!svn/ver/7/axialracing.com/trunk/config/locales/en.yml
END
69 changes: 69 additions & 0 deletions config/locales/.svn/entries
@@ -0,0 +1,69 @@
10

dir
7
http://svn.xwcsolutions.com/stuff/axialracing.com/trunk/config/locales
http://svn.xwcsolutions.com/stuff



2011-09-01T04:24:47.489963Z
7
mlinn


svn:special svn:externals svn:needs-lock











804588ea-4340-4a75-919c-c824e102a980






0

en.yml
file




2011-08-24T21:11:13.000000Z
db4b902854e3f164eca50f0beba9bea7
2011-09-01T04:24:47.489963Z
7
mlinn





















213

5 changes: 5 additions & 0 deletions config/locales/.svn/text-base/en.yml.svn-base
@@ -0,0 +1,5 @@
# Sample localization file for English. Add more files in this directory for other locales.
# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.

en:
hello: "Hello world"
2 changes: 2 additions & 0 deletions config/locales/en.yml
@@ -0,0 +1,2 @@
en:
new_city: "New City"
9 changes: 9 additions & 0 deletions config/routes.rb
@@ -1,3 +1,12 @@
Rails.application.routes.draw do
# Add your extension routes here
namespace :admin do
resources :cities, :only => :index
resources :countries do
resources :states do
resources :cities do
end
end
end
end
end
14 changes: 14 additions & 0 deletions db/migrate/20111013214305_create_cities.rb
@@ -0,0 +1,14 @@
class CreateCities < ActiveRecord::Migration
def self.up
create_table :cities do |t|
t.string :name
t.integer :state_id

t.timestamps
end
end

def self.down
drop_table :cities
end
end
1 change: 1 addition & 0 deletions lib/spree_city_zones_hooks.rb
@@ -1,3 +1,4 @@
class SpreeCityZonesHooks < Spree::ThemeSupport::HookListener
# custom hooks go here
insert_after :admin_configurations_menu, 'shared/cities_admin_configurations_menu'
end

0 comments on commit 82a1676

Please sign in to comment.