Sha256: 5eb9bfb435c9ed4cae2e330f82b417f85b0f98d91c7728fe915bbe513fab833c

Contents?: true

Size: 1.85 KB

Versions: 2

Compression:

Stored size: 1.85 KB

Contents

#Script that add forms to edit non existing translation

$(document).ready () ->
  $('span.translation_missing').each ->
    span = $(this)
    content = get_content(span)
    span.attr('title', '')
    span.popover({
      html: true
      title: 'Translation missing, Input'
      content: content
    })

  $('.loadonready').each () ->
    container = $(this)
    url = container.data('url')
    $.get(url).success (data) ->
      container.html(data)

  $(document).on 'submit', 'form.translation_helper', (e)->
    e.preventDefault()
    form = $(this)

    form.find('button').prop('disabled', true);
    $.ajax({
      url: form.attr('action'),
      type: form.attr('method'),
      dataType: 'json',
      data: form.serialize()
    }).success( (data) ->
      if data.success
        form.find('button').html('Translation added')
        form.find('div.alert').hide()
      else
        handle_error(form,  data)
    ).error (data) ->
      handle_error(form, data)
    return false

get_content = (span)->
  url = '/translation/edit'
  key = span.attr('title').match(/translation missing: (.*)/)[1]
  console.log(key)
  content = "<form action='" + url + "' method='post' class='translation_helper'>"
  content += "<div class='alert alert-danger hidden'></div>"
  content += "<input type='hidden' name='key' value='" + key + "'>"
  content += "<label>Translate " + key + "</label>"
  content += "<input type='text' name='value' class='form-control'>"
  content += "<hr>"
  content += "<button class='btn btn-primary'>Add translation</button>"
  content += "</form>"
  content

handle_error = (form, data) ->
  form.find('button').prop('disabled', false);
  alert = form.find('div.alert')
  if data.status
    alert.html('Error: ' + data.status)
  else if data.error
    alert.html(data.error)
  alert.removeClass('hidden')

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
i18n_admin_utils-0.0.2 app/assets/javascripts/i18n_admin_utils/translation_helper.coffee
i18n_admin_utils-0.0.1 app/assets/javascripts/i18n_admin_utils/translation_helper.coffee