<% all_locales = I18n.available_locales %>
<% count = all_locales.length %>
<script type='text/javascript'>
$('.category_sort_number_form').ready(function(){
    $('form[name="category_sort_number_form"]').submit(function(){
        var eles = $('form[name="category_sort_number_form"]').serialize().split('&')
        var keys=[],values=[]
        for (var i=0;i<eles.length;i++){
            var temp = eles[i].split('=')
            keys.push(temp[0])
            values.push(temp[1])
        }
        if (navigator.onLine) {
            $.ajax({
                url : "/admin/archive_files/categories_order",
                dataType : "json",
                type : "post",
                data:{data_keys: keys, data_values: values},
                success:function(data){
                    location.reload();
                },
                error:function(){
                    alert('Your server has some problem, please try again later!')
                }
                })
        } else {
            alert('Please connect the network and try again later!')
        }
        return false;
    })
})
</script>
<div class='category_sort_number_form'>
<form method="post" action="/admin/archive_files/categories_order?" name="category_sort_number_form" >
<table>
<thead style='line-height: 3;'>
<tr style="text-align: center;">
<td><%= t('archive.category') %></td>
<td><%= t('archive.sort_number') %></td>
</tr>
</thead>
<tbody style='line-height: 4;'>
<% @cats.each do |cat| %>
    <% next if cat[0].nil?%>
    <tr>
    <td style='padding-right: 10px;'>
    <% all_locales.each_with_index do |locale,index| %>
    <%= "#{cat[0][:title][locale]}" %>
    <%= index!=(count-1) ? "/" : ":" %>
    <% end %>
    </td>
    <td>
    <input style='margin: 0;' type="number" name="sort_number-<%= cat[0].id %>" value="<%= cat[1].to_s %>">
    </td>
    </tr>
<% end %>
</tbody>
</table>
<input type="submit" value="<%= t('archive.save') %>">
</form>
</div>