Skip to content

Commit

Permalink
Globalize OptionType, Taxonomy and Taxon model
Browse files Browse the repository at this point in the history
Still need to hack around to make it display the localized taxon
names on the backend tree. So far localized taxons look good on the
frontend
  • Loading branch information
huoxito authored and schof committed May 19, 2013
1 parent 6918dff commit 8cdaa43
Show file tree
Hide file tree
Showing 18 changed files with 338 additions and 132 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ pkg
spec/dummy
.rvmrc
.sass-cache
public/spree
6 changes: 5 additions & 1 deletion app/controllers/spree/admin/translations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def klass
end

def resource
@resource ||= if klass.class_name == "SpreeProduct"
@resource ||= if slugged_models.include? klass.class_name
klass.find_by_permalink(params[:resource_id])
else
klass.find(params[:resource_id])
Expand All @@ -37,5 +37,9 @@ def resource
def collection_url
send "admin_#{resource_name}_url", @resource
end

def slugged_models
["SpreeProduct"]
end
end
end
7 changes: 7 additions & 0 deletions app/models/spree/option_type_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Spree
OptionType.class_eval do
translates :name, :presentation
attr_accessible :translations_attributes
accepts_nested_attributes_for :translations
end
end
7 changes: 7 additions & 0 deletions app/models/spree/taxon_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Spree
Taxon.class_eval do
translates :name, :description, :meta_title, :meta_description, :meta_keywords
attr_accessible :translations_attributes
accepts_nested_attributes_for :translations
end
end
7 changes: 7 additions & 0 deletions app/models/spree/taxonomy_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Spree
Taxonomy.class_eval do
translates :name
attr_accessible :translations_attributes
accepts_nested_attributes_for :translations
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- insert_bottom 'td.actions' -->
<%= link_to '', admin_translations_path('option_types', option_type.id),
class: 'icon_link with-tip icon-flag no-text' %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- insert_bottom 'td.actions' -->
<%= link_to '', admin_translations_path('taxonomies', taxonomy.id),
class: 'icon_link with-tip icon-flag no-text' %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- insert_top 'li' -->
<li>
<%= button_link_to t(:translations), spree.admin_translations_path('taxons', @taxon.id), :icon => 'icon-flag' %>
</li>
127 changes: 81 additions & 46 deletions app/views/spree/admin/translations/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,48 +1,83 @@
<%= form_for [:admin, @resource], :method => :put, :html => { :multipart => true } do |f| %>
<fieldset class="omega eight columns no-border-bottom">
<legend>Translations</legend>
<table id="attr_fields" class="no-borders">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<% Spree::Config.all_locales.each do |locale| %>
<%= f.globalize_fields_for locale.to_sym do |g| %>
<% @resource.class.translates.each_with_index do |attr,i| %>
<tr style="display:<%= i == 0 ? 'auto' : 'none' %>;" class="<%= attr %> <%= locale %> even">
<td style="padding:4px;" colspan="2">
<%= t(:this_file_language, :locale => locale) %> -
<%= t(attr, :locale => locale ) %>
</td>
</tr>
<tr style="display:<%= i == 0 ? 'auto' : 'none' %>;" class="<%= attr %> <%= locale %> odd">
<td class="flag table-column">
<% if locale.include?('-') %>
<img src="http://www.localeapp.com/assets/flags/regions/<%= locale.split('-').last %>.png">
<% else %>
<img src="http://www.localeapp.com/assets/flags/languages/<%= locale %>.png">
<% end %>
</td>
<td class="translation table-column">
<% if @resource.class.columns_hash[attr.to_s].type == :text %>
<%= g.text_area attr, :class => "fullwidth", :rows => 4 %>
<% else %>
<%= g.text_field attr, :class => "fullwidth" %>
<% end %>
</td>
</tr>
<% end %>
<div class="row">
<fieldset class="no-border-top">
<fieldset class="no-border-bottom">
<legend>Settings</legend>

<div class="alpha six columns field">
<label for="show-only">Show only: </label>
<ul>
<li><input type="radio" name="show-only" value="all" checked> <label>All Translations</label></li>
<li><input type="radio" name="show-only" value="incomplete"> <label>Only Incomplete</label></li>
<li><input type="radio" name="show-only"value="complete"> <label>Only Complete</label></li>
</ul>
</div>

<div class="omega six columns">
<label for="locale">Select locale: </label>
<%= select_tag(:locale, options_for_select(admin_options_for_locale_select, Spree::Config.all_locales), :class => 'fullwidth' , :multiple => 'true') %>
</div>
</fieldset>

<fieldset class="alpha four columns no-border-bottom">
<legend>Fields</legend>
<nav class="menu">
<ul id="attr_list">
<% @resource.class.translates.each_with_index do |attr,i| %>
<li class="<%= 'active' if i == 0 %>">
<a data-attr="<%= attr %>" href="#"><%= attr %></a>
</li>
<% end %>
<% end %>
</tbody>
<tfoot>
<tr style="display:none;">
<td colspan="2"></td>
</tr>
</tfoot>
</table>
</fieldset>
</ul>
</nav>
</fieldset>

<%= form_for [:admin, @resource], :method => :put, :html => { :multipart => true } do |f| %>
<fieldset class="omega eight columns no-border-bottom">
<legend>Translations</legend>
<table id="attr_fields" class="no-borders">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<% Spree::Config.all_locales.each do |locale| %>
<%= f.globalize_fields_for locale.to_sym do |g| %>
<% @resource.class.translates.each_with_index do |attr,i| %>
<tr style="display:<%= i == 0 ? 'auto' : 'none' %>;" class="<%= attr %> <%= locale %> even">
<td style="padding:4px;" colspan="2">
<%= t(:this_file_language, :locale => locale) %> -
<%= t(attr, :locale => locale ) %>
</td>
</tr>
<tr style="display:<%= i == 0 ? 'auto' : 'none' %>;" class="<%= attr %> <%= locale %> odd">
<td class="flag table-column">
<% if locale.include?('-') %>
<img src="http://www.localeapp.com/assets/flags/regions/<%= locale.split('-').last %>.png">
<% else %>
<img src="http://www.localeapp.com/assets/flags/languages/<%= locale %>.png">
<% end %>
</td>
<td class="translation table-column">
<% if @resource.class.columns_hash[attr.to_s].type == :text %>
<%= g.text_area attr, :class => "fullwidth", :rows => 4 %>
<% else %>
<%= g.text_field attr, :class => "fullwidth" %>
<% end %>
</td>
</tr>
<% end %>
<% end %>
<% end %>
</tbody>
<tfoot>
<tr style="display:none;">
<td colspan="2"></td>
</tr>
</tfoot>
</table>
</fieldset>

<%= render :partial => 'spree/admin/shared/edit_resource_links' %>
<% end %>
<%= render :partial => 'spree/admin/shared/edit_resource_links' %>
<% end %>
</fieldset>
</div>
14 changes: 14 additions & 0 deletions app/views/spree/admin/translations/option_type.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%= render :partial => 'spree/admin/shared/product_sub_menu' %>
<% content_for :page_title do %>
<%= t(:editing_option_type) %> <span class="green">"<%= @option_type.name %>"</span>
<% end %>
<% content_for :page_actions do %>
<li>
<%= button_link_to t(:back_to_option_types_list), spree.admin_option_types_path, :icon => 'icon-arrow-left' %>
</li>
<% end %>
<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @option_type } %>
<%= render 'form' %>
38 changes: 1 addition & 37 deletions app/views/spree/admin/translations/product.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,4 @@
</li>
<% end %>
<div class="row">
<fieldset class="no-border-top">
<fieldset class="no-border-bottom">
<legend>Settings</legend>

<div class="alpha six columns field">
<label for="show-only">Show only: </label>
<ul>
<li><input type="radio" name="show-only" value="all" checked> <label>All Translations</label></li>
<li><input type="radio" name="show-only" value="incomplete"> <label>Only Incomplete</label></li>
<li><input type="radio" name="show-only"value="complete"> <label>Only Complete</label></li>
</ul>
</div>

<div class="omega six columns">
<label for="locale">Select locale: </label>
<%= select_tag(:locale, options_for_select(admin_options_for_locale_select, Spree::Config.all_locales), :class => 'fullwidth' , :multiple => 'true') %>
</div>
</fieldset>

<fieldset class="alpha four columns no-border-bottom">
<legend>Product fields</legend>
<nav class="menu">
<ul id="attr_list">
<% @product.class.translates.each_with_index do |attr,i| %>
<li class="<%= 'active' if i == 0 %>">
<a data-attr="<%= attr %>" href="#"><%= attr %></a>
</li>
<% end %>
</ul>
</nav>
</fieldset>

<%= render 'form' %>

</fieldset>
</div>
<%= render 'form' %>
37 changes: 1 addition & 36 deletions app/views/spree/admin/translations/promotion.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,4 @@
</li>
<% end %>
<div class="row">
<fieldset class="no-border-top">
<fieldset class="no-border-bottom">
<legend>Settings</legend>

<div class="alpha six columns field">
<label for="show-only">Show only: </label>
<ul>
<li><input type="radio" name="show-only" value="all" checked> <label>All Translations</label></li>
<li><input type="radio" name="show-only" value="incomplete"> <label>Only Incomplete</label></li>
<li><input type="radio" name="show-only"value="complete"> <label>Only Complete</label></li>
</ul>
</div>

<div class="omega six columns">
<label for="locale">Select locale: </label>
<%= select_tag(:locale, options_for_select(admin_options_for_locale_select, Spree::Config.all_locales), :class => 'fullwidth' , :multiple => 'true') %>
</div>
</fieldset>

<fieldset class="alpha four columns no-border-bottom">
<legend>Fields</legend>
<nav class="menu">
<ul id="attr_list">
<% @resource.class.translates.each_with_index do |attr,i| %>
<li class="<%= 'active' if i == 0 %>">
<a data-attr="<%= attr %>" href="#"><%= attr %></a>
</li>
<% end %>
</ul>
</nav>
</fieldset>

<%= render 'form' %>
</fieldset>
</div>
<%= render 'form' %>
99 changes: 99 additions & 0 deletions app/views/spree/admin/translations/taxon.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<%= render :partial => 'spree/admin/shared/configuration_menu' %>
<% content_for :page_title do %>
<%= t(:taxon_edit) %>
<% end %>
<% content_for :page_actions do %>
<li>
<%= button_link_to t(:back_to_taxonomies_list), spree.admin_taxonomies_path, :icon => 'icon-arrow-left' %>
</li>
<% end %>

<div class="row">
<fieldset class="no-border-top">
<fieldset class="no-border-bottom">
<legend>Settings</legend>

<div class="alpha six columns field">
<label for="show-only">Show only: </label>
<ul>
<li><input type="radio" name="show-only" value="all" checked> <label>All Translations</label></li>
<li><input type="radio" name="show-only" value="incomplete"> <label>Only Incomplete</label></li>
<li><input type="radio" name="show-only"value="complete"> <label>Only Complete</label></li>
</ul>
</div>

<div class="omega six columns">
<label for="locale">Select locale: </label>
<%= select_tag(:locale, options_for_select(admin_options_for_locale_select, Spree::Config.all_locales), :class => 'fullwidth' , :multiple => 'true') %>
</div>
</fieldset>

<fieldset class="alpha four columns no-border-bottom">
<legend>Fields</legend>
<nav class="menu">
<ul id="attr_list">
<% @resource.class.translates.each_with_index do |attr,i| %>
<li class="<%= 'active' if i == 0 %>">
<a data-attr="<%= attr %>" href="#"><%= attr %></a>
</li>
<% end %>
</ul>
</nav>
</fieldset>

<%= form_for [:admin, @resource.taxonomy, @resource],
:url => admin_taxonomy_taxon_path(@taxon.taxonomy, @taxon.id),
:method => :put, :html => { :multipart => true } do |f| %>
<fieldset class="omega eight columns no-border-bottom">
<legend>Translations</legend>
<table id="attr_fields" class="no-borders">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<% Spree::Config.all_locales.each do |locale| %>
<%= f.globalize_fields_for locale.to_sym do |g| %>
<% @resource.class.translates.each_with_index do |attr,i| %>
<tr style="display:<%= i == 0 ? 'auto' : 'none' %>;" class="<%= attr %> <%= locale %> even">
<td style="padding:4px;" colspan="2">
<%= t(:this_file_language, :locale => locale) %> -
<%= t(attr, :locale => locale ) %>
</td>
</tr>
<tr style="display:<%= i == 0 ? 'auto' : 'none' %>;" class="<%= attr %> <%= locale %> odd">
<td class="flag table-column">
<% if locale.include?('-') %>
<img src="http://www.localeapp.com/assets/flags/regions/<%= locale.split('-').last %>.png">
<% else %>
<img src="http://www.localeapp.com/assets/flags/languages/<%= locale %>.png">
<% end %>
</td>
<td class="translation table-column">
<% if @resource.class.columns_hash[attr.to_s].type == :text %>
<%= g.text_area attr, :class => "fullwidth", :rows => 4 %>
<% else %>
<%= g.text_field attr, :class => "fullwidth" %>
<% end %>
</td>
</tr>
<% end %>
<% end %>
<% end %>
</tbody>
<tfoot>
<tr style="display:none;">
<td colspan="2"></td>
</tr>
</tfoot>
</table>
</fieldset>

<div class="form-buttons" data-hook="buttons">
<%= button t(:update), 'icon-refresh' %> <%= t(:or) %> <%= button_link_to t(:cancel), edit_admin_taxonomy_url(@taxon.taxonomy), :icon => "icon-remove" %>
</div>
<% end %>
</fieldset>
</div>
Loading

0 comments on commit 8cdaa43

Please sign in to comment.