spree_city_zones 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/admin/cities_controller.rb +12 -0
- data/app/helpers/admin/cities_helper.rb +2 -0
- data/app/models/city.rb +16 -0
- data/app/views/admin/cities/_form.html.erb +4 -0
- data/app/views/admin/cities/edit.html.erb +11 -0
- data/app/views/admin/cities/index.html.erb +32 -0
- data/app/views/admin/cities/new.html.erb +11 -0
- data/app/views/admin/zones/_city_member.html.erb +5 -0
- data/app/views/admin/zones/_form.html.erb +34 -0
- data/config/routes.rb +6 -0
- data/lib/spree_city_zones.rb +63 -0
- data/lib/spree_city_zones_hooks.rb +8 -0
- data/lib/tasks/install.rake +26 -0
- metadata +78 -0
data/app/models/city.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
<%= render :partial => 'admin/shared/configuration_menu' %>
|
2
|
+
|
3
|
+
<h1><%= t('editing_city') %></h1>
|
4
|
+
|
5
|
+
<%= error_messages_for :city %>
|
6
|
+
|
7
|
+
<% form_for(:city, :url => object_url, :html => { :method => :put }) do |f| %>
|
8
|
+
<%= render :partial => 'form', :locals => { :f => f } %>
|
9
|
+
<%= render :partial => 'admin/shared/edit_resource_links' %>
|
10
|
+
<% end %>
|
11
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<%= render :partial => 'admin/shared/configuration_menu' %>
|
2
|
+
|
3
|
+
<h1><%= t('cities') %></h1>
|
4
|
+
|
5
|
+
<table class="index">
|
6
|
+
<thead>
|
7
|
+
<tr>
|
8
|
+
<th><%= t('name') %></th>
|
9
|
+
<th><%= t('action') %></th>
|
10
|
+
</tr>
|
11
|
+
</thead>
|
12
|
+
<tbody>
|
13
|
+
<% @cities.each do |city| %>
|
14
|
+
<tr>
|
15
|
+
<td><%= city.name %></td>
|
16
|
+
<td class="actions">
|
17
|
+
<%= link_to_with_icon 'edit', t('edit'), edit_admin_city_url(city) %>
|
18
|
+
|
19
|
+
<%= link_to_with_icon 'delete', t('delete'), object_url(city), :method => :delete %>
|
20
|
+
</td>
|
21
|
+
</tr>
|
22
|
+
<% end %>
|
23
|
+
<% if @cities.empty? %>
|
24
|
+
<tr><td colspan="3"><%= t('none') %></td></tr>
|
25
|
+
<% end %>
|
26
|
+
</tbody>
|
27
|
+
</table>
|
28
|
+
|
29
|
+
<p>
|
30
|
+
<%= button_link_to t('new_city'), new_admin_city_url, :icon => 'add' %>
|
31
|
+
</p>
|
32
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%= render :partial => 'admin/shared/configuration_menu' %>
|
2
|
+
|
3
|
+
<h1><%= t('new_city') %></h1>
|
4
|
+
|
5
|
+
<%= error_messages_for :city %>
|
6
|
+
|
7
|
+
<% form_for(:city, :url => collection_url) do |f| %>
|
8
|
+
<%= render :partial => 'form', :locals => { :f => f } %>
|
9
|
+
<%= render :partial => 'admin/shared/new_resource_links' %>
|
10
|
+
<% end %>
|
11
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<% zone_form.field_container :name do %>
|
2
|
+
<%= zone_form.label :name, t("name") %><br />
|
3
|
+
<%=zone_form.text_field :name %>
|
4
|
+
<% end %>
|
5
|
+
|
6
|
+
<% zone_form.field_container :description do %>
|
7
|
+
<%= zone_form.label :description, t("description") %><br />
|
8
|
+
<%=zone_form.text_field :description %>
|
9
|
+
<% end %>
|
10
|
+
|
11
|
+
<p>
|
12
|
+
<label><%= t("type") %></label><br />
|
13
|
+
<label class="sub">
|
14
|
+
<%= zone_form.radio_button("kind", "country", {:id => "country_based"}) %>
|
15
|
+
<%= t("country_based") %>
|
16
|
+
</label>
|
17
|
+
<label class="sub">
|
18
|
+
<%= zone_form.radio_button("kind", "state", {:id => "state_based"}) %>
|
19
|
+
<%= t("state_based") %>
|
20
|
+
</label>
|
21
|
+
<label class="sub">
|
22
|
+
<%= zone_form.radio_button("kind", "city", {:id => "city_based"}) %>
|
23
|
+
<%= t("city_based") %>
|
24
|
+
</label>
|
25
|
+
<label class="sub">
|
26
|
+
<%= zone_form.radio_button("kind", "zone", {:id => "zone_based"}) %>
|
27
|
+
<%= t("zone_based") %>
|
28
|
+
</label>
|
29
|
+
</p>
|
30
|
+
|
31
|
+
<%= render "member_type", :type => "country", :zone_form => zone_form %>
|
32
|
+
<%= render "member_type", :type => "state", :zone_form => zone_form %>
|
33
|
+
<%= render "member_type", :type => "city", :zone_form => zone_form %>
|
34
|
+
<%= render "member_type", :type => "zone", :zone_form => zone_form %>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spree_core'
|
2
|
+
require 'spree_city_zones_hooks'
|
3
|
+
|
4
|
+
module SpreeCityZones
|
5
|
+
class Engine < Rails::Engine
|
6
|
+
|
7
|
+
def self.activate
|
8
|
+
|
9
|
+
# This is mostly copied from the Spree Zone methods,
|
10
|
+
# with added support for City zone members
|
11
|
+
Zone.class_eval do
|
12
|
+
|
13
|
+
def kind
|
14
|
+
member = self.members.last
|
15
|
+
case member && member.zoneable_type
|
16
|
+
when "State" then "state"
|
17
|
+
when "Zone" then "zone"
|
18
|
+
when "City" then "city"
|
19
|
+
else
|
20
|
+
"country"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Check for whether an address.city is available
|
25
|
+
def include?(address)
|
26
|
+
return false unless address
|
27
|
+
|
28
|
+
members.any? do |zone_member|
|
29
|
+
case zone_member.zoneable_type
|
30
|
+
when "Zone"
|
31
|
+
zone_member.zoneable.include?(address)
|
32
|
+
when "Country"
|
33
|
+
zone_member.zoneable == address.country
|
34
|
+
when "State"
|
35
|
+
zone_member.zoneable == address.state
|
36
|
+
when "City"
|
37
|
+
zone_member.zoneable.name == address.city
|
38
|
+
else
|
39
|
+
false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end # Zone
|
45
|
+
|
46
|
+
Admin::ZonesController.class_eval do
|
47
|
+
|
48
|
+
def load_data
|
49
|
+
@countries = Country.all.sort
|
50
|
+
@states = State.all.sort
|
51
|
+
@cities = City.all.sort
|
52
|
+
@zones = Zone.all.sort
|
53
|
+
end
|
54
|
+
|
55
|
+
end # Admin::ZonesController
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
config.to_prepare &method(:activate).to_proc
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
namespace :spree_city_zones do
|
2
|
+
desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
|
3
|
+
task :install do
|
4
|
+
Rake::Task['spree_city_zones:install:migrations'].invoke
|
5
|
+
Rake::Task['spree_city_zones:install:assets'].invoke
|
6
|
+
end
|
7
|
+
|
8
|
+
namespace :install do
|
9
|
+
|
10
|
+
desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
|
11
|
+
task :migrations do
|
12
|
+
source = File.join(File.dirname(__FILE__), '..', '..', 'db')
|
13
|
+
destination = File.join(Rails.root, 'db')
|
14
|
+
Spree::FileUtilz.mirror_files(source, destination)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
|
18
|
+
task :assets do
|
19
|
+
source = File.join(File.dirname(__FILE__), '..', '..', 'public')
|
20
|
+
destination = File.join(Rails.root, 'public')
|
21
|
+
puts "INFO: Mirroring assets from #{source} to #{destination}"
|
22
|
+
Spree::FileUtilz.mirror_files(source, destination)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spree_city_zones
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chetan Mittal
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-04-02 00:00:00 +05:30
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: spree_core
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.40.0
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
description: Allows zones to be created by city
|
28
|
+
email: chetan.mittal@niamtech.com
|
29
|
+
executables: []
|
30
|
+
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files: []
|
34
|
+
|
35
|
+
files:
|
36
|
+
- lib/tasks/install.rake
|
37
|
+
- lib/spree_city_zones_hooks.rb
|
38
|
+
- lib/spree_city_zones.rb
|
39
|
+
- app/views/admin/zones/_form.html.erb
|
40
|
+
- app/views/admin/zones/_city_member.html.erb
|
41
|
+
- app/views/admin/cities/edit.html.erb
|
42
|
+
- app/views/admin/cities/new.html.erb
|
43
|
+
- app/views/admin/cities/_form.html.erb
|
44
|
+
- app/views/admin/cities/index.html.erb
|
45
|
+
- app/models/city.rb
|
46
|
+
- app/controllers/admin/cities_controller.rb
|
47
|
+
- app/helpers/admin/cities_helper.rb
|
48
|
+
- config/routes.rb
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://www.niamtech.com
|
51
|
+
licenses: []
|
52
|
+
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 1.8.7
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
requirements:
|
71
|
+
- none
|
72
|
+
rubyforge_project: spree_city_zones
|
73
|
+
rubygems_version: 1.5.0
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: Allows zones to be created by city
|
77
|
+
test_files: []
|
78
|
+
|