From 0871802acc811ee78195b1724bf9195ac822548e Mon Sep 17 00:00:00 2001 From: Adam Cooke Date: Thu, 31 Oct 2013 19:53:37 +0000 Subject: [PATCH] add countries to admin ui. closes #52 --- .../stylesheets/shoppe/application.scss | 1 + .../shoppe/countries_controller.rb | 47 +++++++++++++++++++ .../layouts/shoppe/application.html.haml | 1 + app/views/shoppe/countries/_form.html.haml | 31 ++++++++++++ app/views/shoppe/countries/edit.html.haml | 5 ++ app/views/shoppe/countries/index.html.haml | 25 ++++++++++ app/views/shoppe/countries/new.html.haml | 5 ++ config/routes.rb | 1 + 8 files changed, 116 insertions(+) create mode 100644 app/controllers/shoppe/countries_controller.rb create mode 100644 app/views/shoppe/countries/_form.html.haml create mode 100644 app/views/shoppe/countries/edit.html.haml create mode 100644 app/views/shoppe/countries/index.html.haml create mode 100644 app/views/shoppe/countries/new.html.haml diff --git a/app/assets/stylesheets/shoppe/application.scss b/app/assets/stylesheets/shoppe/application.scss index 1e75a8ed..70b2c9aa 100644 --- a/app/assets/stylesheets/shoppe/application.scss +++ b/app/assets/stylesheets/shoppe/application.scss @@ -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;} } diff --git a/app/controllers/shoppe/countries_controller.rb b/app/controllers/shoppe/countries_controller.rb new file mode 100644 index 00000000..9c5de154 --- /dev/null +++ b/app/controllers/shoppe/countries_controller.rb @@ -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 diff --git a/app/views/layouts/shoppe/application.html.haml b/app/views/layouts/shoppe/application.html.haml index f1137da8..b32da418 100644 --- a/app/views/layouts/shoppe/application.html.haml +++ b/app/views/layouts/shoppe/application.html.haml @@ -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 diff --git a/app/views/shoppe/countries/_form.html.haml b/app/views/shoppe/countries/_form.html.haml new file mode 100644 index 00000000..434b2346 --- /dev/null +++ b/app/views/shoppe/countries/_form.html.haml @@ -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' diff --git a/app/views/shoppe/countries/edit.html.haml b/app/views/shoppe/countries/edit.html.haml new file mode 100644 index 00000000..8140a85d --- /dev/null +++ b/app/views/shoppe/countries/edit.html.haml @@ -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' \ No newline at end of file diff --git a/app/views/shoppe/countries/index.html.haml b/app/views/shoppe/countries/index.html.haml new file mode 100644 index 00000000..6bfd355e --- /dev/null +++ b/app/views/shoppe/countries/index.html.haml @@ -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? diff --git a/app/views/shoppe/countries/new.html.haml b/app/views/shoppe/countries/new.html.haml new file mode 100644 index 00000000..8140a85d --- /dev/null +++ b/app/views/shoppe/countries/new.html.haml @@ -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' \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 53e19ac5..7c9e4614 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -21,6 +21,7 @@ end resources :tax_rates resources :users + resources :countries resources :attachments, :only => :destroy get 'settings'=> 'settings#edit'