personal_plugin_generator/app/views/admin/personal_plugin_fields/_render_table.html.erb

79 lines
3.3 KiB
Plaintext

<table class="table table-bordered sortable_table">
<thead>
<th></th>
<th><%= t(:remove) %></th>
<th><%= thead_field("field_name") %></th>
<th><%= thead_field("translation_name") %></th>
<th><%= thead_field("field_type") %></th>
<th><%= thead_field("localize") %></th>
<th><%= thead_field("slug_title") %></th>
<th><%= thead_field("periodic_time") %></th>
</thead>
<tbody>
<%= f.fields_for root_name do |f| %>
<% field_values.each_with_index do |field_value,i| %>
<% i = "new_field_index" if field_value.nil? && !@include_blank %>
<tr index="<%=i%>">
<td>
<span class="brand ui-sortable-handle"><i class="icons-list-2"></i></span>
<input class="hidden_order" type="hidden" name="<%= "#{f.object_name}[#{i}][order]" %>" value="<%= i %>">
</td>
<td><span class="remove_btn">X</span></td>
<td><%= text_field_tag "#{f.object_name}[#{i}][field_name]",(field_value["field_name"] rescue nil) %></td>
<td>
<% @site_in_use_locales.each_with_index do |locale, ii| %>
<span class="<%= locale %> tab-pane fade <%= ( ii == 0 ) ? "in active" : '' %>">
<%= f.fields_for "#{i}][translation_name" do |f| %>
<%= text_field_tag "#{f.object_name}[#{locale}]", (field_value["translation_name"][locale] rescue nil) , class: "input-block-level" %>
<% end %>
</span>
<% end %>
</td>
<td><%= select_tag "#{f.object_name}[#{i}][field_type]",options_for_select(field_types,(field_value["field_type"] rescue nil)) %></td>
<td>
<%= hidden_field_tag "#{f.object_name}[#{i}][localize]", "0",:id=>nil %>
<%= check_box_tag "#{f.object_name}[#{i}][localize]", "1" , (field_value["localize"] == "1" rescue false),:id=>nil %>
</td>
<td>
<%= hidden_field_tag "#{f.object_name}[#{i}][slug_title]", "0",:id=>nil %>
<%= check_box_tag "#{f.object_name}[#{i}][slug_title]", "1" , (field_value["slug_title"] == "1" rescue false),:id=>nil,:class=>"slug_title" %>
</td>
<td>
<%= hidden_field_tag "#{f.object_name}[#{i}][periodic_time]", "0",:id=>nil %>
<%= check_box_tag "#{f.object_name}[#{i}][periodic_time]", "1" , (field_value["periodic_time"] == "1" rescue false),:id=>nil,:class=>"periodic_time" %>
</td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
<style type="text/css">
.icons-list-2{
cursor: all-scroll;
}
</style>
<script>
$(document).ready(function(){
$('.sortable_table').each(function(i,v){
if(!($(v).hasClass('already_init_sortable'))){
$(v).find('tbody').sortable({
axis: "y",
revert: true,
handle: ".brand",
update: function(event, ui) {
var item = ui.item;
var new_index = item.index();
var old_index = item.attr("index");
var indices = [new_index,old_index].sort();
for(var new_i=indices[0];new_i<=indices[1];new_i++){
var td = item.parent().find(">").eq(new_i);
td.attr("index",new_i);
td.find('.hidden_order').val(new_i);
}
}
});
$(v).addClass('already_init_sortable')
}
})
})
</script>