<div id="container_translation">
<div class="flash" style="display:none;">${lang('admin', 'translation_saved_sucessfully', 'Translation saved sucessfully')}</div>
<br />
<form method="get" action="">
    ${lang('admin', 'modules', 'Modules')}
    ${form_module.form()|n}
    <input type="submit" value="${lang('admin', 'change_module_to_translate', 'Change module to translate')}" />
</form>
<div id="saving" style="display:none;"><i class="fa fa-circle-o-notch fa-2x fa-spin fa-fw"></i> ${lang('admin', 'saving_translation', 'Saving translation')}</div>
<form method="post" action="#" id="send_text">
% if len(arr_i18n_form):

    <p><input type="submit" value="${lang('admin', 'send', 'Send')}" /></p>

    % for i18n_form in arr_i18n_form:
    
        <p>${i18n_form.form()|n}</p>
    
    % endfor
    
    <p><input type="submit" value="${lang('admin', 'send', 'Send')}" /></p>
    
% endif
${csrf_token("csrf_token")|n}
</form>
</div>

<script>
    
    $('#send_text').submit( function () {

        $('#send_text').hide();
        $('#saving').show();
        
        url="${make_admin_url('lang/translations',{'module_admin': selected_module, 'op': '1'})}";
        
        /*data=$(this).serializeArray().reduce(function(obj, item) {
            obj[item.name] = item.value;
            return obj;
        }, {});*/
        
        data=$(this).serialize()
        
        $.ajax({
            type: "POST",
            url: url,
            data: data,
            contentType: "application/x-www-form-urlencoded;charset=UTF-8",
            success: function (data) {
                
                $('#saving').hide();
                
                if(!data.error) {
                
                    $('#send_text').show();
                    $('.flash').show();
                    
                    setTimeout(function () { 
                        
                        $(".flash").fadeOut(1000)
                        
                    }, 3000);
                    
                }
                else
                {
                    
                    alert('Error: cannot update the translations');
                    
                }
                
            },
            error: function (data) {
            
                alert(JSON.stringify(data));
                $('#send_text').show();
            
            },
            dataType: 'json'
        });
        
        return false;
    
    });
</script>
