refinerycms-retailers 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/app/assets/javascripts/refinery/subregion-select.js.coffee.erb +10 -0
  3. data/app/controllers/refinery/retailers/admin/retailers_controller.rb +32 -0
  4. data/app/controllers/refinery/retailers/retailers_controller.rb +14 -0
  5. data/app/helpers/refinery/retailers/controller_helper.rb +14 -0
  6. data/app/helpers/refinery/retailers/retailers_helper.rb +19 -0
  7. data/app/models/refinery/retailers/retailer.rb +27 -0
  8. data/app/views/refinery/retailers/admin/retailers/_actions.html.erb +25 -0
  9. data/app/views/refinery/retailers/admin/retailers/_form.html.erb +83 -0
  10. data/app/views/refinery/retailers/admin/retailers/_records.html.erb +16 -0
  11. data/app/views/refinery/retailers/admin/retailers/_retailer.html.erb +48 -0
  12. data/app/views/refinery/retailers/admin/retailers/_retailers.html.erb +2 -0
  13. data/app/views/refinery/retailers/admin/retailers/_sortable_list.html.erb +5 -0
  14. data/app/views/refinery/retailers/admin/retailers/_subregion_select.html.erb +12 -0
  15. data/app/views/refinery/retailers/admin/retailers/edit.html.erb +1 -0
  16. data/app/views/refinery/retailers/admin/retailers/index.html.erb +7 -0
  17. data/app/views/refinery/retailers/admin/retailers/new.html.erb +1 -0
  18. data/app/views/refinery/retailers/retailers/_retailer.html.erb +82 -0
  19. data/app/views/refinery/retailers/retailers/index.html.erb +29 -0
  20. data/config/locales/cs.yml +35 -0
  21. data/config/locales/en.yml +49 -0
  22. data/config/locales/es.yml +36 -0
  23. data/config/locales/fr.yml +49 -0
  24. data/config/locales/it.yml +35 -0
  25. data/config/locales/nb.yml +35 -0
  26. data/config/locales/nl.yml +35 -0
  27. data/config/locales/sk.yml +35 -0
  28. data/config/locales/tr.yml +35 -0
  29. data/config/locales/zh-CN.yml +37 -0
  30. data/config/routes.rb +20 -0
  31. data/db/migrate/1_create_retailers_retailers.rb +36 -0
  32. data/db/migrate/2_add_body_to_retailers.rb +5 -0
  33. data/db/migrate/3_translate_retailers.rb +26 -0
  34. data/db/seeds.rb +18 -0
  35. data/lib/generators/refinery/retailers/retailers_generator.rb +24 -0
  36. data/lib/generators/refinery/retailers/templates/config/initializers/refinery/retailers.rb.erb +7 -0
  37. data/lib/refinery/retailers.rb +27 -0
  38. data/lib/refinery/retailers/configuration.rb +10 -0
  39. data/lib/refinery/retailers/engine.rb +24 -0
  40. data/lib/refinerycms-retailers.rb +1 -0
  41. data/lib/tasks/refinery/retailers.rake +13 -0
  42. data/readme.md +60 -0
  43. metadata +166 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 471df177416af281fd6c988e248f11eefddd0b85
4
+ data.tar.gz: ba85c058fbc02c01fcccbea607ccce2bb1296079
5
+ SHA512:
6
+ metadata.gz: eb9b6efa650f5fda97964391ef5d9de863f16f04da9452b50b0821e2ce9efc1b04311172e56506abf8be62a8f4d7d4b6e25589563d30d9876ee26ede9601acca
7
+ data.tar.gz: 943c86243e5fdcdeedfe3765902e78fd18888552a225f2a4f9dabec3504ab37c238d633cd2275a29157ae1af5b2e39a7702fea3a97ad7564948872dc7883ef6c
@@ -0,0 +1,10 @@
1
+ $ ->
2
+ $('select#retailer_country_code').change (event) ->
3
+ select_wrapper = $('#retailer_state_code_wrapper')
4
+
5
+ $('select', select_wrapper).attr('disabled', true)
6
+
7
+ country_code = $(this).val()
8
+
9
+ url = "/<%= Refinery::Core.backend_route %>/retailers/subregion_options?parent_region=#{country_code}"
10
+ select_wrapper.load(url)
@@ -0,0 +1,32 @@
1
+ module Refinery
2
+ module Retailers
3
+ module Admin
4
+ class RetailersController < ::Refinery::AdminController
5
+ crudify :'refinery/retailers/retailer',
6
+ paging: false,
7
+ order: "lower(title) ASC"
8
+
9
+ helper :'refinery/retailers/retailers'
10
+
11
+ def subregion_options
12
+ render partial: 'subregion_select'
13
+ end
14
+
15
+ protected
16
+
17
+ def retailer_params
18
+ params.require(:retailer).permit(permitted_retailer_params)
19
+ end
20
+
21
+ private
22
+
23
+ def permitted_retailer_params
24
+ [
25
+ :title, :body, :contact, :address, :country_code,
26
+ :state_code, :city, :zipcode, :phone, :fax, :email, :website, :draft
27
+ ]
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,14 @@
1
+ module Refinery
2
+ module Retailers
3
+ class RetailersController < ::ApplicationController
4
+ include ControllerHelper
5
+
6
+ before_action :find_all_retailers, only: :index
7
+ before_action :find_page, only: :index
8
+
9
+ def index
10
+ @retailers = @retailers.group_by { |r| r.country_code }.sort_by{ |country_code, r| Carmen::Country.coded(country_code).name.parameterize }
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module Refinery
2
+ module Retailers
3
+ module ControllerHelper
4
+ protected
5
+ def find_all_retailers
6
+ @retailers = Retailer.published.order("country_code asc")
7
+ end
8
+
9
+ def find_page
10
+ @page = Page.find_by(link_url: Refinery::Retailers.page_path_index)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ module Refinery
2
+ module Retailers
3
+ module RetailersHelper
4
+ def country_name(country_code)
5
+ country = Carmen::Country.coded(country_code)
6
+ country.name unless country.nil?
7
+ end
8
+
9
+ def subregion_name(country_code, state_code)
10
+ subregion = Carmen::Country.coded(country_code).subregions.coded(state_code)
11
+ subregion.name unless subregion.nil?
12
+ end
13
+
14
+ def inline_address(retailer)
15
+ [retailer.address, retailer.city, retailer.state_code, retailer.zipcode, country_name(retailer.country_code)].reject(&:blank?).join(", ")
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ module Refinery
2
+ module Retailers
3
+ class Retailer < Refinery::Core::BaseModel
4
+ self.table_name = 'refinery_retailers'
5
+
6
+ translates :title, :body, :contact, :website, :address, :city
7
+
8
+ before_validation :smart_add_url_protocol
9
+
10
+ validates :address, presence: true, uniqueness: true
11
+
12
+ acts_as_indexed fields: [:title, :contact, :address, :country_code, :state_code, :city] if defined?(Refinery::ActsAsIndexed::Engine)
13
+
14
+ scope :published, -> { where draft: false }
15
+
16
+ protected
17
+
18
+ def smart_add_url_protocol
19
+ if self.website.present?
20
+ unless (self.website[/\Ahttp:\/\//] || self.website[/\Ahttps:\/\//])
21
+ self.website = "http://#{self.website}"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ <ul>
2
+ <% if ::Refinery::Retailers::Admin::RetailersController.searchable? %>
3
+ <li>
4
+ <%= render '/refinery/admin/search', url: refinery.retailers_admin_retailers_path %>
5
+ </li>
6
+ <% end %>
7
+ <li>
8
+ <%= link_to t('.create_new'), refinery.new_retailers_admin_retailer_path,
9
+ class: "add_icon" %>
10
+ </li>
11
+ <% if !searching? && ::Refinery::Retailers::Admin::RetailersController.sortable? && ::Refinery::Retailers::Retailer.many? %>
12
+ <li>
13
+ <%= link_to t('.reorder', what: "Retailers"),
14
+ refinery.retailers_admin_retailers_path,
15
+ id: "reorder_action",
16
+ class: "reorder_icon" %>
17
+
18
+ <%= link_to t('.reorder_done', what: "Retailers"),
19
+ refinery.retailers_admin_retailers_path,
20
+ id: "reorder_action_done",
21
+ style: "display: none;",
22
+ class: "reorder_icon" %>
23
+ </li>
24
+ <% end %>
25
+ </ul>
@@ -0,0 +1,83 @@
1
+ <%= form_for [refinery, :retailers_admin, @retailer] do |f| -%>
2
+ <%= render '/refinery/admin/error_messages',
3
+ object: @retailer,
4
+ include_object_name: true %>
5
+
6
+ <%= render '/refinery/admin/locale_picker',
7
+ current_locale: Globalize.locale %>
8
+
9
+ <div class='field'>
10
+ <%= f.label :title -%>
11
+ <%= f.text_field :title, class: 'larger widest' -%>
12
+ </div>
13
+
14
+ <div class='field'>
15
+ <%= render '/refinery/admin/wysiwyg',
16
+ f: f,
17
+ fields: [:body],
18
+ object: "retailers/retailer" -%>
19
+ </div>
20
+
21
+ <div class='field'>
22
+ <%= f.label :contact -%>
23
+ <%= f.text_field :contact, class: 'widest' -%>
24
+ </div>
25
+
26
+ <div class='field'>
27
+ <%= f.label :email -%>
28
+ <%= f.text_field :email, class: 'widest' -%>
29
+ </div>
30
+
31
+ <div class='field'>
32
+ <%= f.label :website -%>
33
+ <%= f.text_field :website, class: 'widest' -%>
34
+ </div>
35
+
36
+ <div class='field'>
37
+ <%= f.label :address -%>
38
+ <%= f.text_field :address, class: 'widest' -%>
39
+ </div>
40
+
41
+ <div class="field">
42
+ <%= f.label :country_code %>
43
+ <%= f.country_select :country_code, priority: Refinery::Retailers.country_priority, prompt: t('.please_select_a_country') %>
44
+ </div>
45
+
46
+ <div class="field">
47
+ <%= f.label :state_code %>
48
+ <%= render partial: 'subregion_select', locals: {parent_region: f.object.country_code} %>
49
+ </div>
50
+
51
+ <div class='field'>
52
+ <%= f.label :city -%>
53
+ <%= f.text_field :city, class: 'widest' -%>
54
+ </div>
55
+
56
+ <div class='field'>
57
+ <%= f.label :zipcode -%>
58
+ <%= f.text_field :zipcode -%>
59
+ </div>
60
+
61
+ <div class='field'>
62
+ <%= f.label :phone -%>
63
+ <%= f.text_field :phone -%>
64
+ </div>
65
+
66
+ <div class='field'>
67
+ <%= f.label :fax -%>
68
+ <%= f.text_field :fax -%>
69
+ </div>
70
+
71
+ <div class='field'>
72
+ <%= f.label :draft -%>
73
+ <%= f.check_box :draft -%>
74
+ </div>
75
+
76
+ <%= render '/refinery/admin/form_actions', f: f,
77
+ continue_editing: false,
78
+ delete_title: t('delete', scope: 'refinery.retailers.admin.retailers.retailer'),
79
+ delete_confirmation: t('message', scope: 'refinery.admin.delete', title: @retailer.title),
80
+ cancel_url: refinery.retailers_admin_retailers_path -%>
81
+ <% end -%>
82
+
83
+ <% content_for :javascripts, javascript_include_tag('refinery/subregion-select') %>
@@ -0,0 +1,16 @@
1
+ <%= render 'refinery/admin/search_header', url: refinery.retailers_admin_retailers_path %>
2
+ <div class='pagination_container'>
3
+ <% if @retailers.any? %>
4
+ <%= render 'retailers' %>
5
+ <% else %>
6
+ <p>
7
+ <% if searching? %>
8
+ <%= t('no_results', scope: 'refinery.admin.search') %>
9
+ <% else %>
10
+ <strong>
11
+ <%= t('.no_items_yet') %>
12
+ </strong>
13
+ <% end %>
14
+ </p>
15
+ <% end %>
16
+ </div>
@@ -0,0 +1,48 @@
1
+ <% # setup params for various action links
2
+ edit_url = refinery.edit_retailers_admin_retailer_path(retailer)
3
+ delete_url = refinery.retailers_admin_retailer_path(retailer)
4
+ delete_options = {
5
+ class: "cancel confirm-delete",
6
+ data: {
7
+ confirm: t('message',
8
+ scope: 'refinery.admin.delete',
9
+ title: translated_field(retailer, :title)
10
+ )
11
+ }
12
+ }
13
+ %>
14
+
15
+ <li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(retailer) -%>">
16
+ <span class='title'>
17
+ <%= translated_field(retailer, :title) %>
18
+
19
+ <% if Refinery::I18n.frontend_locales.many? %>
20
+ <span class='locales'>
21
+ <% retailer.translations.sort_by{ |t| Refinery::I18n.frontend_locales.index(t.locale)}.each do |translation| %>
22
+ <% if translation.title.present? %>
23
+ <%= link_to refinery.edit_retailers_admin_retailer_path(retailer, switch_locale: translation.locale),
24
+ class: 'locale', title: translation.locale.upcase do %>
25
+
26
+ <div class="<%=translation.locale %> locale_marker">
27
+ <%= locale_text_icon(translation.locale.upcase) %>
28
+ </div>
29
+ <% end %>
30
+ <% end %>
31
+ <% end %>
32
+ </span>
33
+ <% end %>
34
+
35
+ <% if retailer.draft? %>
36
+ <span class="label notice"><%= t('refinery.retailers.admin.retailers.retailer.draft') %></span>
37
+ <% end %>
38
+
39
+ <span class="preview">
40
+ <%= inline_address(retailer) %>
41
+ </span>
42
+ </span>
43
+
44
+ <span class='actions'>
45
+ <%= action_icon(:edit, edit_url , t('edit', scope: 'refinery.retailers.admin.retailers.retailer' ) ) %>
46
+ <%= action_icon(:delete, delete_url, t('delete', scope: 'refinery.retailers.admin.retailers.retailer' ), delete_options ) %>
47
+ </span>
48
+ </li>
@@ -0,0 +1,2 @@
1
+ <%= will_paginate @retailers if Refinery::Retailers::Admin::RetailersController.pageable? %>
2
+ <%= render 'sortable_list' %>
@@ -0,0 +1,5 @@
1
+ <ul id='sortable_list'>
2
+ <%= render partial: 'retailer', collection: @retailers %>
3
+ </ul>
4
+ <%= render '/refinery/admin/sortable_list',
5
+ continue_reordering: (local_assigns.keys.include?(:continue_reordering)) ? continue_reordering : true %>
@@ -0,0 +1,12 @@
1
+ <div id="retailer_state_code_wrapper">
2
+ <% parent_region ||= params[:parent_region] %>
3
+ <% country = Carmen::Country.coded(parent_region) %>
4
+
5
+ <% if country.nil? %>
6
+ <em><%= t('.please_select_a_country_above') %></em>
7
+ <% elsif country.subregions? %>
8
+ <%= subregion_select(:retailer, :state_code, parent_region) %>
9
+ <% else %>
10
+ <%= text_field(:retailer, :state_code) %>
11
+ <% end %>
12
+ </div>
@@ -0,0 +1 @@
1
+ <%= render 'form' %>
@@ -0,0 +1,7 @@
1
+ <section id='records'>
2
+ <%= render 'records' %>
3
+ </section>
4
+ <aside id='actions'>
5
+ <%= render 'actions' %>
6
+ </aside>
7
+ <%= render '/refinery/admin/make_sortable', options: {tree: false} if !searching? and ::Refinery::Retailers::Admin::RetailersController.sortable? and ::Refinery::Retailers::Retailer.many? %>
@@ -0,0 +1 @@
1
+ <%= render 'form' %>
@@ -0,0 +1,82 @@
1
+ <li class="retailer">
2
+ <div class="vcard">
3
+ <h3 class="org">
4
+ <%= retailer.title %>
5
+ </h3>
6
+
7
+ <div class="info">
8
+ <% if retailer.body? %>
9
+ <div class="note">
10
+ <%= raw retailer.body %>
11
+ </div>
12
+ <% end %>
13
+
14
+ <p class="adr">
15
+ <% if retailer.address? %>
16
+ <span class="street-address">
17
+ <%= retailer.address %>
18
+ </span>
19
+ <% end %>
20
+
21
+ <% if retailer.country_code? && retailer.state_code? %>
22
+ <span class="locality">
23
+ <%= "#{retailer.city}, #{subregion_name(retailer.country_code, retailer.state_code)}" %>
24
+ </span>
25
+ <% end %>
26
+
27
+ <% if retailer.zipcode? %>
28
+ <span class="postal-code">
29
+ <%= retailer.zipcode %>
30
+ </span>
31
+ <% end %>
32
+
33
+ <% if retailer.country_code? %>
34
+ <span class="country-name visuallyhidden">
35
+ <%= country_name(retailer.country_code) %>
36
+ </span>
37
+ <% end %>
38
+ </p>
39
+
40
+ <p>
41
+ <% if retailer.fax? %>
42
+ <span class="fax">
43
+ <span class="label">
44
+ <%= "#{t('.fax')} " %>
45
+ </span>
46
+
47
+ <span class="value">
48
+ <%= "#{retailer.fax}" %>
49
+ </span>
50
+ </span>
51
+ <% end %>
52
+
53
+ <% if retailer.phone? %>
54
+ <span class="tel">
55
+ <%= t('.phone', phone: retailer.phone).html_safe %>
56
+ </span>
57
+ <% end %>
58
+
59
+ <% if retailer.website? %>
60
+ <span class="url">
61
+ <%= link_to t('.website', title: retailer.title).html_safe, retailer.website, target: "_blank" %>
62
+ </span>
63
+ <% end %>
64
+
65
+ <% if retailer.contact? && retailer.email? %>
66
+ <h4 class="contact">
67
+ <%= t('.contact') %>
68
+ </h4>
69
+ <p class="fn email">
70
+ <%= mail_to retailer.email, retailer.contact, encode: 'hex' %>
71
+ </p>
72
+ <% else %>
73
+ <% if retailer.email? %>
74
+ <span class="email">
75
+ <%= mail_to retailer.email, t('.email', title: retailer.title).html_safe, encode: 'hex' %>
76
+ </span>
77
+ <% end %>
78
+ <% end %>
79
+ </p>
80
+ </div>
81
+ </div>
82
+ </li>
@@ -0,0 +1,29 @@
1
+ <% content_for :body do %>
2
+ <div id="retailers-list">
3
+ <% @retailers.each do |country, retailers| %>
4
+ <div id="<%= country.downcase %>" class="countries">
5
+ <h2><%= country_name(country) %></h2>
6
+ <ul>
7
+ <%= render partial: 'retailer', collection: retailers %>
8
+ </ul>
9
+ </div>
10
+ <% end %>
11
+ </div>
12
+ <% end %>
13
+
14
+ <% if @retailers.many? %>
15
+ <% content_for :side_body do %>
16
+ <nav id="retailers-countries">
17
+ <h2><%= t('.retailers_countries') %></h2>
18
+ <ul>
19
+ <% @retailers.each do |country, retailers| %>
20
+ <li><%= link_to country_name(country), "##{country.downcase}" %></li>
21
+ <% end %>
22
+ </ul>
23
+ </nav>
24
+ <% end %>
25
+ <% end %>
26
+
27
+ <div id="retailers-page">
28
+ <%= render '/refinery/content_page' %>
29
+ </div>