Skip to content

Commit

Permalink
add countries to admin ui. closes #52
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Cooke committed Oct 31, 2013
1 parent 8b53ab8 commit 0871802
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/shoppe/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ header.main {
h2.delivery_services { background-image:image-url('shoppe/icons/box.svg'); background-position: 0 3px; background-size:20px;}
h2.tax_rates { background-image:image-url('shoppe/icons/currency.svg'); background-position: 0 2px; background-size:22px;}
h2.users { background-image:image-url('shoppe/icons/id.svg'); background-position: 0 2px; background-size:22px;}
h2.countries { background-image:image-url('shoppe/icons/globe.svg'); background-position: 0 2px; background-size:22px;}
h2.settings { background-image:image-url('shoppe/icons/toolbox.svg'); background-position: 0 2px; background-size:22px;}

}
Expand Down
47 changes: 47 additions & 0 deletions app/controllers/shoppe/countries_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module Shoppe
class CountriesController < Shoppe::ApplicationController

before_filter { @active_nav = :countries }
before_filter { params[:id] && @country = Shoppe::Country.find(params[:id]) }

def index
@countries = Shoppe::Country.ordered
end

def new
@country = Shoppe::Country.new
end

def create
@country = Shoppe::Country.new(safe_params)
if @country.save
redirect_to :countries, :flash => {:notice => "Country has been created successfully"}
else
render :action => "new"
end
end

def edit
end

def update
if @country.update(safe_params)
redirect_to [:edit, @country], :flash => {:notice => "Country has been updated successfully"}
else
render :action => "edit"
end
end

def destroy
@country.destroy
redirect_to :countries, :flash => {:notice => "Country has been removed successfully"}
end

private

def safe_params
params[:country].permit(:name, :code2, :code3, :continent, :tld, :currency, :eu_member)
end

end
end
1 change: 1 addition & 0 deletions app/views/layouts/shoppe/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
%li= link_to "Delivery Services", [:delivery_services], :class => @active_nav == :delivery_services ? 'active' : ''
%li= link_to "Tax Rates", :tax_rates, :class => @active_nav == :tax_rates ? 'active' : ''
%li= link_to "Users", [:users], :class => @active_nav == :users ? 'active' : ''
%li= link_to "Countries", :countries, :class => @active_nav == :countries ? 'active' : ''
%li= link_to "Settings", :settings, :class => @active_nav == :settings ? 'active' : ''
%li= link_to "Logout", [:logout], :method => :delete

Expand Down
31 changes: 31 additions & 0 deletions app/views/shoppe/countries/_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
= form_for @country do |f|
= f.error_messages
= field_set_tag "User Details" do
.splitContainer
%dl.third
%dt= f.label :name
%dd= f.text_field :name, :class => 'focus text'
%dl.third
%dt= f.label :code2, "ISO 3166-alpha-2"
%dd= f.text_field :code2, :class => 'text'
%dl.third
%dt= f.label :code3, "ISO 3166-alpha-3"
%dd= f.text_field :code3, :class => 'text'
.splitContainer
%dl.third
%dt= f.label :continent
%dd= f.text_field :continent, :class => 'text'
%dl.third
%dt= f.label :tld, "TLD"
%dd= f.text_field :tld, :class => 'text'
%dl.third
%dt= f.label :eu_member, "EU Member?"
%dd.checkbox
= f.check_box :eu_member
= f.label :eu_member, 'Country is an EU member?'

%p.submit
- unless @country.new_record?
%span.right= link_to "Delete", @country, :class => 'button purple', :method => :delete, :data => {:confirm => "Are you sure you wish to remove this country?"}
= f.submit :class => 'button green'
= link_to "Cancel", :countries, :class => 'button'
5 changes: 5 additions & 0 deletions app/views/shoppe/countries/edit.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- @page_title = "Countries"
= content_for :header do
%p.buttons= link_to "Back to countries", :countries, :class => 'button'
%h2.countries Countries
= render 'form'
25 changes: 25 additions & 0 deletions app/views/shoppe/countries/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
- @page_title = "Countries"

= content_for :header do
%p.buttons=link_to "New country", :new_country, :class => 'button green'
%h2.countries Countries

.table
%table.data
%thead
%tr
%th Name
%th ISO 3166-1-alpha-2
%th ISO 3166-1-alpha-3
%th Continent
%th TLD
%th EU?
%tbody
- for country in @countries
%tr
%td= link_to country.name, [:edit, country]
%td= country.code2
%td= country.code3
%td= country.continent
%td= country.tld
%td= boolean_tag country.eu_member?
5 changes: 5 additions & 0 deletions app/views/shoppe/countries/new.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- @page_title = "Countries"
= content_for :header do
%p.buttons= link_to "Back to countries", :countries, :class => 'button'
%h2.countries Countries
= render 'form'
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
end
resources :tax_rates
resources :users
resources :countries
resources :attachments, :only => :destroy

get 'settings'=> 'settings#edit'
Expand Down

0 comments on commit 0871802

Please sign in to comment.