forked from hubertlepicki/GoTranslateYourself
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add nested tabbed interface (not terribly proud of the code, but it w…
…orks fine).
- Loading branch information
Josh Adams
committed
Dec 28, 2010
1 parent
86cbfdc
commit 877d8ad
Showing
10 changed files
with
109 additions
and
31 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
app/controllers/go_translate_yourself/site_translations_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
app/helpers/go_translate_yourself/translation_table_helper.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
module GoTranslateYourself | |||
module TranslationTableHelper | |||
def translation_table_for(translations, locales) | |||
render :partial => 'go_translate_yourself/site_translations/translation_table', :locals => { :translations => translations, :locales => locales } | |||
end | |||
|
|||
def get_translations_under(child, translations) | |||
array_representation = translations.select{|k, v| child.values.include?(k)} | |||
hash_var = HashFromArray.hash_from_array(array_representation) | |||
end | |||
end | |||
end |
11 changes: 11 additions & 0 deletions
11
app/helpers/go_translate_yourself/translation_tabs_helper.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
module GoTranslateYourself | |||
module TranslationTabsHelper | |||
def tabs_for(hash) | |||
render :partial => 'go_translate_yourself/site_translations/tabs', :locals => { :hash => hash } | |||
end | |||
|
|||
def tabs_full_for(hash) | |||
render :partial => 'go_translate_yourself/site_translations/tabs_full', :locals => { :hash => hash } | |||
end | |||
end | |||
end |
23 changes: 23 additions & 0 deletions
23
app/views/go_translate_yourself/site_translations/_tabs.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,23 @@ | |||
<% id = "tabs-#{hash.object_id}" -%> | |||
<div id=<%= id -%>> | |||
<ul> | |||
<% hash.each do |key, child| %> | |||
<li><a href="#tabs-<%= hash.object_id -%>-<%= key.object_id -%>"><%= key -%></a></li> | |||
<% end %> | |||
</ul> | |||
<% hash.each do |key, child| %> | |||
<% child_translations = get_translations_under(child, @translations) -%> | |||
<% child_hash_array_representation = child.select{|k, v| v.is_a?(Hash) } -%> | |||
<div id="tabs-<%= hash.object_id -%>-<%= key.object_id -%>"> | |||
<%= translation_table_for(child_translations, @locales) -%> | |||
<% unless child_hash_array_representation.empty? -%> | |||
<%= tabs_for(HashFromArray.hash_from_array(child_hash_array_representation)) -%> | |||
<% end -%> | |||
</div> | |||
<% end %> | |||
</div> | |||
<script> | |||
$(function() { | |||
$('#<%= id -%>').tabs(); | |||
}); | |||
</script> |
8 changes: 8 additions & 0 deletions
8
app/views/go_translate_yourself/site_translations/_tabs_full.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
<% hash.each do |key, child| %> | |||
<h3><%= key -%></h3> | |||
<% child_translations = get_translations_under(child, @translations) -%> | |||
<% child_hash_array_representation = child.select{|k, v| v.is_a?(Hash) } -%> | |||
<% child_hash = HashFromArray.hash_from_array(child_hash_array_representation) -%> | |||
<%= tabs_full_for(child_hash) -%> | |||
<%= translation_table_for(child_translations, @locales) -%> | |||
<% end %> |
29 changes: 29 additions & 0 deletions
29
app/views/go_translate_yourself/site_translations/_translation_table.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,29 @@ | |||
<table class="gt_site_translations"> | |||
<tr class="gt_ths"> | |||
<th>Key</th> | |||
<th>Value</th> | |||
</tr> | |||
<% translations.each do |key, default_translation| %> | |||
<tr class="gt_separator"> | |||
<td colspan="2"></td> | |||
</tr> | |||
<tr class="gt_default_value"> | |||
<td class="gt_key"> | |||
<%= key %> | |||
</td> | |||
<td class="gt_value"> | |||
<%= default_translation %> | |||
</td> | |||
<% locales.each do |locale| %> | |||
<tr> | |||
<td> | |||
<%= locale %> | |||
</td> | |||
<td> | |||
<%= translation_text_field locale, key, default_translation %> | |||
</td> | |||
</tr> | |||
<% end %> | |||
</tr> | |||
<% end %> | |||
</table> |
32 changes: 2 additions & 30 deletions
32
app/views/go_translate_yourself/site_translations/edit.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,33 +1,5 @@ | |||
<h2>Translations Editor</h2> | |||
<%= form_tag update_site_translations_path, :method => :post do %> | <%= form_tag update_site_translations_path, :method => :post do %> | ||
<table class="gt_site_translations"> | <%= tabs_for(@translations_split) -%> | ||
<tr class="gt_ths"> | |||
<th>Key</th> | |||
<th>Value</th> | |||
</tr> | |||
<% @translations.each do |key, default_translation| %> | |||
<tr class="gt_separator"> | |||
<td colspan="2"></td> | |||
</tr> | |||
<tr class="gt_default_value"> | |||
<td class="gt_key"> | |||
<%= key %> | |||
</td> | |||
<td class="gt_value"> | |||
<%= default_translation %> | |||
</td> | |||
<% @locales.each do |locale| %> | |||
<tr> | |||
<td> | |||
<%= locale %> | |||
</td> | |||
<td> | |||
<%= translation_text_field locale, key, default_translation %> | |||
</td> | |||
</tr> | |||
<% end %> | |||
</tr> | |||
<% end %> | |||
</table> | |||
<%= submit_tag "Save" %> | <%= submit_tag "Save" %> | ||
<% end %> | <% end %> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
class HashFromArray | |||
def self.hash_from_array(array) | |||
array.inject({}) {|h, elem| h[elem[0]]=elem[1]; h} | |||
end | |||
end |