#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) window.load_script_on(container) $(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:not(.nosubmit)').html("") 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 = "
" content += "" content += "" content += "" content += "" content += "
" content += "" content += "
" 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')