Files
grecia/app/assets/javascripts/globalize.js.coffee
iagirre b318c2be46 Add feature to delete a translation
To delete a translation, a link has been added. This
link works for the selected language. It hides all the
things related to a language (the tab and the text_area)
and empties the text area, so that the value is blank
in the param hash. A variable called `delete_translations[]`
is changed.

e.g. If admin wants to remove English language,
delete_translations[:en] will be 1; if not, it will be 0.

When the milestone is updated, there is a before_action
callback that cleans the selected languages for deletion
(looking the delete_translations[] variable).
Because of the deleted translations are blank in param hash,
them won't be saved in DB.
2018-05-09 16:07:12 +02:00

49 lines
1.6 KiB
CoffeeScript

App.Globalize =
display_locale: (locale) ->
$(".js-globalize-locale-link").each ->
if $(this).data("locale") == locale
$(this).show()
$(".js-globalize-locale option:selected").removeAttr("selected");
return
display_translations: (locale) ->
$(".js-globalize-attribute").each ->
if $(this).data("locale") == locale
$(this).show()
else
$(this).hide()
$('.delete-language').hide()
$('#delete-' + locale).show()
highlight_locale: (element) ->
$('.js-globalize-locale-link').removeClass('highlight');
element.addClass('highlight');
remove_language: (locale) ->
$(".js-globalize-attribute[data-locale=" + locale + "]").val('')
$(".js-globalize-attribute[data-locale=" + locale + "]").hide()
$(".js-globalize-locale-link[data-locale=" + locale + "]").hide()
$("#delete-" + locale).hide()
next = $(".js-globalize-locale-link:visible").first()
App.Globalize.highlight_locale(next)
$(".js-globalize-attribute[data-locale=" + next.data("locale") + "]").show()
$("#delete-" + next.data("locale")).show()
$("#delete_translations_" + locale).val(1)
initialize: ->
$('.js-globalize-locale').on 'change', ->
App.Globalize.display_translations($(this).val())
App.Globalize.display_locale($(this).val())
$('.js-globalize-locale-link').on 'click', ->
locale = $(this).data("locale")
App.Globalize.display_translations(locale)
App.Globalize.highlight_locale($(this))
$('.delete-language').on 'click', ->
locale = $(this).data("locale")
$(this).hide()
App.Globalize.remove_language(locale)