Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better translation UI #38

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ PATH
specs:
activeadmin-globalize (1.0.0)
activeadmin
globalize (~> 4.0.0)
globalize (>= 3.0.4)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -77,7 +77,7 @@ GEM
execjs (2.0.2)
formtastic (2.3.0.rc2)
actionpack (>= 3.0)
globalize (4.0.0)
globalize (4.0.1)
activemodel (>= 4.0.0, < 5)
activerecord (>= 4.0.0, < 5)
has_scope (0.6.0.rc)
Expand Down
2 changes: 1 addition & 1 deletion activeadmin-globalize.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ Gem::Specification.new do |s|
s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "README.md"]

s.add_dependency "activeadmin"
s.add_dependency "globalize", '~> 4.0.0'
s.add_dependency "globalize", '>= 3.0.4'
end

Binary file added app/assets/images/ad.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/af.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/ag.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/ai.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/al.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/am.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/an.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/ao.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/ar.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/as.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/at.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/au.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/aw.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/ax.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/az.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/ba.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/bb.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/bd.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/be.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/bf.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/bg.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/bh.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/bi.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/bj.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/bm.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/bn.gif
Binary file added app/assets/images/bo.gif
Binary file added app/assets/images/br.gif
Binary file added app/assets/images/bs.gif
Binary file added app/assets/images/bt.gif
Binary file added app/assets/images/bv.gif
Binary file added app/assets/images/bw.gif
Binary file added app/assets/images/by.gif
Binary file added app/assets/images/bz.gif
Binary file added app/assets/images/ca.gif
Binary file added app/assets/images/cc.gif
Binary file added app/assets/images/cd.gif
Binary file added app/assets/images/cf.gif
Binary file added app/assets/images/cg.gif
Binary file added app/assets/images/ch.gif
Binary file added app/assets/images/ci.gif
Binary file added app/assets/images/ck.gif
Binary file added app/assets/images/cl.gif
Binary file added app/assets/images/cm.gif
Binary file added app/assets/images/cn.gif
Binary file added app/assets/images/co.gif
Binary file added app/assets/images/cr.gif
Binary file added app/assets/images/cs.gif
Binary file added app/assets/images/cu.gif
Binary file added app/assets/images/cv.gif
Binary file added app/assets/images/cx.gif
Binary file added app/assets/images/cy.gif
Binary file added app/assets/images/cz.gif
Binary file added app/assets/images/de.gif
Binary file added app/assets/images/dj.gif
Binary file added app/assets/images/dk.gif
Binary file added app/assets/images/dm.gif
Binary file added app/assets/images/do.gif
Binary file added app/assets/images/dz.gif
Binary file added app/assets/images/ec.gif
Binary file added app/assets/images/ee.gif
Binary file added app/assets/images/eg.gif
Binary file added app/assets/images/eh.gif
Binary file added app/assets/images/en.gif
Binary file added app/assets/images/er.gif
Binary file added app/assets/images/es.gif
Binary file added app/assets/images/et.gif
Binary file added app/assets/images/fi.gif
Binary file added app/assets/images/fj.gif
Binary file added app/assets/images/fk.gif
Binary file added app/assets/images/fm.gif
Binary file added app/assets/images/fo.gif
Binary file added app/assets/images/fr.gif
Binary file added app/assets/images/ga.gif
Binary file added app/assets/images/gb.gif
Binary file added app/assets/images/gd.gif
Binary file added app/assets/images/ge.gif
Binary file added app/assets/images/gf.gif
Binary file added app/assets/images/gh.gif
Binary file added app/assets/images/gi.gif
Binary file added app/assets/images/gl.gif
Binary file added app/assets/images/gm.gif
Binary file added app/assets/images/gn.gif
Binary file added app/assets/images/gp.gif
Binary file added app/assets/images/gq.gif
Binary file added app/assets/images/gr.gif
Binary file added app/assets/images/gs.gif
Binary file added app/assets/images/gt.gif
Binary file added app/assets/images/gu.gif
Binary file added app/assets/images/gw.gif
Binary file added app/assets/images/gy.gif
Binary file added app/assets/images/hk.gif
Binary file added app/assets/images/hm.gif
Binary file added app/assets/images/hn.gif
Binary file added app/assets/images/hr.gif
Binary file added app/assets/images/ht.gif
Binary file added app/assets/images/hu.gif
Binary file added app/assets/images/id.gif
Binary file added app/assets/images/ie.gif
Binary file added app/assets/images/il.gif
Binary file added app/assets/images/in.gif
Binary file added app/assets/images/io.gif
Binary file added app/assets/images/iq.gif
Binary file added app/assets/images/ir.gif
Binary file added app/assets/images/is.gif
Binary file added app/assets/images/it.gif
Binary file added app/assets/images/jm.gif
Binary file added app/assets/images/jo.gif
Binary file added app/assets/images/jp.gif
Binary file added app/assets/images/ke.gif
Binary file added app/assets/images/kg.gif
Binary file added app/assets/images/kh.gif
Binary file added app/assets/images/ki.gif
Binary file added app/assets/images/km.gif
Binary file added app/assets/images/kn.gif
Binary file added app/assets/images/kp.gif
Binary file added app/assets/images/kr.gif
Binary file added app/assets/images/kw.gif
Binary file added app/assets/images/ky.gif
Binary file added app/assets/images/kz.gif
Binary file added app/assets/images/la.gif
Binary file added app/assets/images/lb.gif
Binary file added app/assets/images/lc.gif
Binary file added app/assets/images/li.gif
Binary file added app/assets/images/lk.gif
Binary file added app/assets/images/lr.gif
Binary file added app/assets/images/ls.gif
Binary file added app/assets/images/lt.gif
Binary file added app/assets/images/lu.gif
Binary file added app/assets/images/lv.gif
Binary file added app/assets/images/ly.gif
Binary file added app/assets/images/ma.gif
Binary file added app/assets/images/mc.gif
Binary file added app/assets/images/md.gif
Binary file added app/assets/images/me.gif
Binary file added app/assets/images/mg.gif
Binary file added app/assets/images/mh.gif
Binary file added app/assets/images/mk.gif
Binary file added app/assets/images/ml.gif
Binary file added app/assets/images/mm.gif
Binary file added app/assets/images/mn.gif
Binary file added app/assets/images/mo.gif
Binary file added app/assets/images/mp.gif
Binary file added app/assets/images/mq.gif
Binary file added app/assets/images/mr.gif
Binary file added app/assets/images/ms.gif
Binary file added app/assets/images/mt.gif
Binary file added app/assets/images/mu.gif
Binary file added app/assets/images/mv.gif
Binary file added app/assets/images/mw.gif
Binary file added app/assets/images/mx.gif
Binary file added app/assets/images/my.gif
Binary file added app/assets/images/mz.gif
Binary file added app/assets/images/na.gif
Binary file added app/assets/images/nc.gif
Binary file added app/assets/images/ne.gif
Binary file added app/assets/images/nf.gif
Binary file added app/assets/images/ng.gif
Binary file added app/assets/images/ni.gif
Binary file added app/assets/images/nl.gif
Binary file added app/assets/images/no.gif
Binary file added app/assets/images/np.gif
Binary file added app/assets/images/nr.gif
Binary file added app/assets/images/nu.gif
Binary file added app/assets/images/nz.gif
Binary file added app/assets/images/om.gif
Binary file added app/assets/images/pa.gif
Binary file added app/assets/images/pe.gif
Binary file added app/assets/images/pf.gif
Binary file added app/assets/images/pg.gif
Binary file added app/assets/images/ph.gif
Binary file added app/assets/images/pk.gif
Binary file added app/assets/images/pl.gif
Binary file added app/assets/images/pm.gif
Binary file added app/assets/images/pn.gif
Binary file added app/assets/images/pr.gif
Binary file added app/assets/images/ps.gif
Binary file added app/assets/images/pt.gif
Binary file added app/assets/images/pw.gif
Binary file added app/assets/images/py.gif
Binary file added app/assets/images/qa.gif
Binary file added app/assets/images/re.gif
Binary file added app/assets/images/ro.gif
Binary file added app/assets/images/rs.gif
Binary file added app/assets/images/ru.gif
Binary file added app/assets/images/rw.gif
Binary file added app/assets/images/sa.gif
Binary file added app/assets/images/sb.gif
Binary file added app/assets/images/sc.gif
Binary file added app/assets/images/sd.gif
Binary file added app/assets/images/se.gif
Binary file added app/assets/images/sg.gif
Binary file added app/assets/images/sh.gif
Binary file added app/assets/images/si.gif
Binary file added app/assets/images/sj.gif
Binary file added app/assets/images/sk.gif
Binary file added app/assets/images/sl.gif
Binary file added app/assets/images/sm.gif
Binary file added app/assets/images/sn.gif
Binary file added app/assets/images/so.gif
Binary file added app/assets/images/sr.gif
Binary file added app/assets/images/st.gif
Binary file added app/assets/images/sv.gif
Binary file added app/assets/images/sy.gif
Binary file added app/assets/images/sz.gif
Binary file added app/assets/images/tc.gif
Binary file added app/assets/images/td.gif
Binary file added app/assets/images/tf.gif
Binary file added app/assets/images/tg.gif
Binary file added app/assets/images/th.gif
Binary file added app/assets/images/tj.gif
Binary file added app/assets/images/tk.gif
Binary file added app/assets/images/tl.gif
Binary file added app/assets/images/tm.gif
Binary file added app/assets/images/tn.gif
Binary file added app/assets/images/to.gif
Binary file added app/assets/images/tr.gif
Binary file added app/assets/images/tt.gif
Binary file added app/assets/images/tv.gif
Binary file added app/assets/images/tw.gif
Binary file added app/assets/images/tz.gif
Binary file added app/assets/images/ua.gif
Binary file added app/assets/images/ug.gif
Binary file added app/assets/images/um.gif
Binary file added app/assets/images/us.gif
Binary file added app/assets/images/uy.gif
Binary file added app/assets/images/uz.gif
Binary file added app/assets/images/va.gif
Binary file added app/assets/images/vc.gif
Binary file added app/assets/images/ve.gif
Binary file added app/assets/images/vg.gif
Binary file added app/assets/images/vi.gif
Binary file added app/assets/images/vn.gif
Binary file added app/assets/images/vu.gif
Binary file added app/assets/images/wf.gif
Binary file added app/assets/images/ws.gif
Binary file added app/assets/images/ye.gif
Binary file added app/assets/images/yt.gif
Binary file added app/assets/images/za.gif
Binary file added app/assets/images/zm.gif
Binary file added app/assets/images/zw.gif
107 changes: 105 additions & 2 deletions app/assets/javascripts/active_admin/active_admin_globalize.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,131 @@ $ ->

translations = ->

# Hides or shows the + button and the remove button.
updateLocaleButtonsStatus = ($dom) ->
$localeList = $dom.find('.add-locale ul li:not(.hidden)')
if $localeList.length == 0
$dom.find('.add-locale').hide()
else
$dom.find('.add-locale').show()


# Hides or shows the locale tab and its corresponding element in the add menu.
toggleTab = ($tab, active) ->
$addButton = $tab.parents('ul').find('.add-locale li:has(a[href="' + $tab.attr('href') + '"])')
if active
$tab.addClass('hidden').show().removeClass('hidden')
$addButton.hide().addClass('hidden')
else
$tab.addClass('hidden').hide().addClass('hidden')
$addButton.show().removeClass('hidden')

$(".activeadmin-translations > ul").each ->
$dom = $(this)
if !$dom.data("ready")
$dom.data("ready", true)
$tabs = $("li > a", this)
$contents = $(this).siblings("fieldset")

$tabs.click ->
$tabs.click (e) ->
$tab = $(this)
$tabs.not($tab).removeClass("active")
$tab.addClass("active")
$contents.hide()
$contents.filter($tab.attr("href")).show()
false
e.preventDefault()

$tabs.eq(0).click()

# Collect tha available locales.
availableLocales = []
$tabs.not('.default').each ->
availableLocales.push($('<li></li>').append($(this).clone().removeClass('active')))

# Create a new tab as the root of the drop down menu.
$addLocaleButton = $('<li class="add-locale"><a href="#">+</a></li>')
$addLocaleButton.append($('<ul></ul>').append(availableLocales))

# Handle locale addition
$addLocaleButton.find('ul a').click (e) ->
href = $(this).attr('href')
$tab = $tabs.filter('[href="' + href + '"]')
toggleTab($tab, true)
$tab.click()
updateLocaleButtonsStatus($dom)
e.preventDefault()

# Remove a locale from the tab.
$removeButton = $('<span class="remove">x</span>').click (e) ->
e.stopImmediatePropagation()
e.preventDefault()
$tab = $(this).parent()
toggleTab($tab, false)
if $tab.hasClass('active')
$tabs.not('.hidden').eq(0).click()

updateLocaleButtonsStatus($dom)

# Add the remove button to every tab.
$tabs.not('.default').append($removeButton)

# Add the new button at the end of the locale list.
$dom.append($addLocaleButton)

$tabs.each ->
$tab = $(@)
$content = $contents.filter($tab.attr("href"))
containsErrors = $content.find(".input.error").length > 0
$tab.toggleClass("error", containsErrors)
# Find those tabs that are in use.
hide = true
# We will not hide the tabs that have any error.
if $tab.hasClass('error') || $tab.hasClass('default')
hide = false
else
# Check whether the input fields are empty or not.
$content.find('[name]').not('[type="hidden"]').each ->
if $(this).val()
# We will not hide the tab because it has some data.
hide = false
return false

if hide
toggleTab($tab, false)
else
toggleTab($tab, true)

# Remove the fields of hidden locales before form submission.
$form = $dom.parents('form')
if !$form.data('ready')
$form.data('ready')
$form.submit ->
# Get all translations (the nested ones too).
$('.activeadmin-translations > ul').each ->
# Get the corresponding fieldsets.
$fieldsets = $(this).siblings('fieldset')
$("li:not(.add-locale) > a", this).each ->
# Remove them if the locale is hidden.
if $(this).hasClass('hidden')
# check if it's an existing translation otherwise remove it
$currentFieldset = $("fieldset#{$(this).attr('href')}")
$translationId = $('input[id$=_id]', $currentFieldset)
if $translationId.val()
# mark it for database removal appending a _destroy element
$destroy = $('<input/>').attr(
type: 'hidden',
name: $translationId.attr('name').replace('[id]', '[_destroy]'),
id: $translationId.attr('id').replace('_id', '_destroy'),
value: '1'
)
$destroy.appendTo($currentFieldset)
else
# remove the fieldset from dom so it won't be submitted
$fieldsets.filter($(this).attr('href')).remove()

#Initially update the buttons' status
updateLocaleButtonsStatus($dom)
$tabs.filter('.default').click()

# this is to handle elements created with has_many
$("a").bind "click", ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
padding: 8px 15px
padding-bottom: 8px + 4px
margin-bottom: 0
position: relative

&.error
color: #932419
Expand All @@ -34,6 +35,72 @@
text-shadow: 0 1px 0 white
color: #666 !important

&> span
font-size: 0.75em
font-weight: bold
position: absolute
top: 2px
right: 4px
display: none

&:hover
+text-shadow(red, 1px, 1px, 2px)

&:hover
span
display: block

span.hidden
display: none

&> li.add-locale
font-weight: bold
position: relative
z-index: 100

&> ul
display: none
font-size: 17px
font-weight: normal
padding: 0
+border-bottom-radius(4px)
position: absolute
+shadow(3px, 3px, 5px, #aaa)
background: #f4f4f4
z-index: 100

&> li
font-size: 17px
padding: 8px 15px
padding-bottom: 8px + 4px
margin-bottom: 0

&:hover
background: #ddd
background: -webkit-linear-gradient(left, $secondary-gradient-stop, #f4f4f4)
background: -moz-linear-gradient(left, $secondary-gradient-stop, #f4f4f4)
background: linear-gradient(left, $secondary-gradient-stop, #f4f4f4)

&> a
text-decoration: none
color: #666

&> li:first-child
border-top-right-radius: 4px

&:hover
background: #f4f4f4
+inset-shadow(0, 4px, 4px, #ddd)
+border-top-radius(4px)
margin-bottom: 0
+gradient($secondary-gradient-stop, #f4f4f4)
text-shadow: 0 1px 0 white
color: #666 !important

&> ul
display: block


&> fieldset.inputs
margin-bottom: 0

Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/globalize/engine.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ActiveAdmin
module Globalize
class Engine < ::Rails::Engine
initializer "Active Admin precompile hook", group: :assets do |app|
initializer "Active Admin precompile hook", group: :all do |app|
app.config.assets.precompile += [
"active_admin/active_admin_globalize.css",
"active_admin/active_admin_globalize.js"
Expand Down
3 changes: 2 additions & 1 deletion lib/active_admin/globalize/form_builder_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ def translated_inputs(name = "Translations", options = {}, &block)
form_buffers.last << template.content_tag(:div, class: "activeadmin-translations") do
template.content_tag(:ul, class: "available-locales") do
(auto_sort ? I18n.available_locales.sort : I18n.available_locales).map do |locale|
default = 'default' if locale == I18n.default_locale
template.content_tag(:li) do
I18n.with_locale(switch_locale ? locale : I18n.locale) do
template.content_tag(:a, I18n.t(:"active_admin.globalize.language.#{locale}"), href:".locale-#{locale}")
template.content_tag(:a, I18n.t(:"active_admin.globalize.language.#{locale}"), href:".locale-#{locale}", :class => default)
end
end
end.join.html_safe
Expand Down
7 changes: 7 additions & 0 deletions lib/active_admin/globalize/index_table_for_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ def translation_status
end.join(" ").html_safe
end
end
def translation_status_flags
column I18n.t("active_admin.globalize.translations") do |obj|
obj.translated_locales.map do |l|
image_tag '%s.gif' % [ l.to_s ]
end.join(" ").html_safe
end
end
end
end
end
Expand Down