Add sortable.
This commit is contained in:
parent
6feba1e50c
commit
998ffa0a8a
|
@ -13,6 +13,7 @@ class PersonalPluginField
|
||||||
field :backend_fields, :type => Hash, :default => {}
|
field :backend_fields, :type => Hash, :default => {}
|
||||||
field :frontend_fields, :type => Hash, :default => {}
|
field :frontend_fields, :type => Hash, :default => {}
|
||||||
field :log_text, :type => String, :default => ""
|
field :log_text, :type => String, :default => ""
|
||||||
|
field :fields_order, :type => Hash, :default => {}
|
||||||
before_save :check_plugin_exist
|
before_save :check_plugin_exist
|
||||||
def get_all_gem_plugins
|
def get_all_gem_plugins
|
||||||
extention_files = ["downloaded_extensions.rb","built_in_extensions.rb"]
|
extention_files = ["downloaded_extensions.rb","built_in_extensions.rb"]
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
<td><%= link_to t(:edit) ,edit_admin_personal_plugin_field_path(personal_plugin_field.id),:class=> "btn btn-primary" %>
|
<td><%= link_to t(:edit) ,edit_admin_personal_plugin_field_path(personal_plugin_field.id),:class=> "btn btn-primary" %>
|
||||||
<%= link_to thead_field('fields_display_setting') ,admin_personal_plugin_field_fields_setting_path(personal_plugin_field.id),:class=> "btn btn-primary" %>
|
<%= link_to thead_field('fields_display_setting') ,admin_personal_plugin_field_fields_setting_path(personal_plugin_field.id),:class=> "btn btn-primary" %>
|
||||||
<%= link_to thead_field(:copy) ,admin_personal_plugin_field_copy_path(personal_plugin_field.id),:class=> "btn btn-primary" %>
|
<%= link_to thead_field(:copy) ,admin_personal_plugin_field_copy_path(personal_plugin_field.id),:class=> "btn btn-primary" %>
|
||||||
|
<button class="generate_plugin btn btn-primary" type="button" data-url="<%= admin_personal_plugin_field_generate_plugin_path(personal_plugin_field.id) %>"><%= thead_field("generate_plugin") %></button>
|
||||||
<a data-confirm="Are you sure?" data-method="delete" href="<%=admin_personal_plugin_field_path(personal_plugin_field.id) %>" rel="nofollow" class="delete btn btn-primary"><%= t(:delete_) %></a>
|
<a data-confirm="Are you sure?" data-method="delete" href="<%=admin_personal_plugin_field_path(personal_plugin_field.id) %>" rel="nofollow" class="delete btn btn-primary"><%= t(:delete_) %></a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<div>
|
<div id="<%= "#{root_name}_#{page_name}" %>">
|
||||||
<% object = f.object
|
<% object = f.object
|
||||||
%>
|
%>
|
||||||
<h5><%=thead_field(page_name)%></h5>
|
<h5><%=thead_field(page_name)%></h5>
|
||||||
|
@ -7,46 +7,65 @@
|
||||||
<table class="table table-bordered" id="<%="#{root_name}_#{page_name}"%>">
|
<table class="table table-bordered" id="<%="#{root_name}_#{page_name}"%>">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
<% ths = [] %>
|
||||||
|
<% ii = -1 %>
|
||||||
<% object.primary_modal_fields.each do |field_value| %>
|
<% object.primary_modal_fields.each do |field_value| %>
|
||||||
<% next if (!access_field_types.include?(field_value[:field_type]) rescue false) %>
|
<% next if (!access_field_types.include?(field_value[:field_type]) rescue false) %>
|
||||||
<th><%="#{field_value[:translation_name][I18n.locale] rescue ""}-#{field_value[:field_name]}"%></th>
|
<% ths << "<th data-index=\"#{ii+=1}\">#{field_value[:translation_name][I18n.locale] rescue ""}-#{field_value[:field_name]}</th>" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if page_name != "analysis" %>
|
<% if page_name != "analysis" %>
|
||||||
<% f.object.related_modal_name.each_with_index do |related_modal_name,i| %>
|
<% f.object.related_modal_name.each_with_index do |related_modal_name,i| %>
|
||||||
<% field_values = f.object.related_modal_fields[i].to_a %>
|
<% field_values = f.object.related_modal_fields[i].to_a %>
|
||||||
<% field_values.each do |field_value| %>
|
<% field_values.each do |field_value| %>
|
||||||
<th><%="#{related_modal_name}-#{field_value[:translation_name][I18n.locale] rescue ""}-#{field_value[:field_name]}"%></th>
|
<% ths << "<th data-index=\"#{ii+=1}\">#{related_modal_name}-#{field_value[:translation_name][I18n.locale] rescue ""}-#{field_value[:field_name]}</th>" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% author_name_translation = @personal_plugin_field.author_name_translations[locale] rescue ""
|
<% author_name_translation = @personal_plugin_field.author_name_translations[locale] rescue ""
|
||||||
author_name_translation = I18n.t("personal_plugins.author") if author_name_translation.blank? %>
|
author_name_translation = I18n.t("personal_plugins.author") if author_name_translation.blank? %>
|
||||||
<th><%= author_name_translation %></th>
|
<% ths << "<th data-index=\"#{ii+=1}\">#{author_name_translation}</th>" %>
|
||||||
|
<% end %>
|
||||||
|
<% fields_order = (0...ths.count).to_a
|
||||||
|
if (object.fields_order["#{root_name}_#{page_name}"].present? rescue false)
|
||||||
|
object.fields_order["#{root_name}_#{page_name}"].to_a.each_with_index do |order,i|
|
||||||
|
fields_order[i] = order.to_i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
%>
|
||||||
|
<% ths = ths.sort_by.with_index{|th,i| fields_order[i]}%>
|
||||||
|
<% ths.each do |th| %>
|
||||||
|
<%= th.html_safe %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
|
<% tds = [] %>
|
||||||
<%= f.fields_for root_name do |f| %>
|
<%= f.fields_for root_name do |f| %>
|
||||||
<%= f.fields_for page_name do |f| %>
|
<%= f.fields_for page_name do |f| %>
|
||||||
<% object.primary_modal_fields.each do |field_value| %>
|
<% object.primary_modal_fields.each do |field_value| %>
|
||||||
<% next if (!access_field_types.include?(field_value[:field_type]) rescue false) %>
|
<% next if (!access_field_types.include?(field_value[:field_type]) rescue false) %>
|
||||||
<td>
|
<% tds << check_box_tag("#{f.object_name}[]", field_value[:field_name] , (object.send(root_name)[page_name].include?(field_value[:field_name]) rescue false),:id=>nil) %>
|
||||||
<%= check_box_tag "#{f.object_name}[]", field_value[:field_name] , (object.send(root_name)[page_name].include?(field_value[:field_name]) rescue false),:id=>nil %>
|
|
||||||
</td>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if page_name != "analysis" %>
|
<% if page_name != "analysis" %>
|
||||||
<% object.related_modal_name.each_with_index do |related_modal_name,i| %>
|
<% object.related_modal_name.each_with_index do |related_modal_name,i| %>
|
||||||
<% field_values = object.related_modal_fields[i].to_a %>
|
<% field_values = object.related_modal_fields[i].to_a %>
|
||||||
<% field_values.each do |field_value| %>
|
<% field_values.each do |field_value| %>
|
||||||
<td>
|
<% tds << check_box_tag("#{f.object_name}[]", "#{related_modal_name+'.'+field_value[:field_name]}" , (object.send(root_name)[page_name].include?(related_modal_name+'.'+field_value[:field_name]) rescue false),:id=>nil) %>
|
||||||
<%= check_box_tag "#{f.object_name}[]", "#{related_modal_name+'.'+field_value[:field_name]}" , (object.send(root_name)[page_name].include?(related_modal_name+'.'+field_value[:field_name]) rescue false),:id=>nil %>
|
|
||||||
</td>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<td><%= check_box_tag "#{f.object_name}[]", "member_profile" , (object.send(root_name)[page_name].include?("member_profile") rescue false),:id=>nil %></td>
|
<% tds << check_box_tag("#{f.object_name}[]", "member_profile" , (object.send(root_name)[page_name].include?("member_profile") rescue false),:id=>nil) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<% tds = tds.sort_by.with_index{|td,i| fields_order[i]}%>
|
||||||
|
<% tds.each do |td| %>
|
||||||
|
<td><%= td.html_safe %></td>
|
||||||
|
<% end %>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<% fields_order.each do |order| %>
|
||||||
|
<%= hidden_field_tag "#{f.object_name}[fields_order][#{root_name}_#{page_name}][]",order,:id=>nil %>
|
||||||
|
<% end %>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -43,6 +43,11 @@
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<style type="text/css">
|
||||||
|
.icons-list-2{
|
||||||
|
cursor: all-scroll;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(".select_all").click(function(){
|
$(".select_all").click(function(){
|
||||||
$(this).parent().find("table input").prop("checked",true);
|
$(this).parent().find("table input").prop("checked",true);
|
||||||
|
@ -68,5 +73,32 @@
|
||||||
$('#backend_fields_analysis').css( 'border','');
|
$('#backend_fields_analysis').css( 'border','');
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
$( ".table thead th" ).each(function(i,v){
|
||||||
|
$(v).attr("index",$(v).index());
|
||||||
|
$(v).html("<span class=\"brand ui-sortable-handle\"><i class=\"icons-list-2\"></i></span>" + $(v).html());
|
||||||
|
})
|
||||||
|
$( ".table thead >" ).sortable({
|
||||||
|
axis: "x",
|
||||||
|
revert: true,
|
||||||
|
handle: ".brand",
|
||||||
|
update: function(event, ui) {
|
||||||
|
var new_index = ui.item.index();
|
||||||
|
var old_index = ui.item.attr("index");
|
||||||
|
var indices = [new_index,old_index].sort();
|
||||||
|
for(var new_i=indices[0];new_i<=indices[1];new_i++){
|
||||||
|
var old_i = ui.item.parent().find(">").eq(new_i).attr("index");
|
||||||
|
var org_i = ui.item.parent().find(">").eq(new_i).data("index");
|
||||||
|
ui.item.parent().find(">").eq(new_i).attr("index",new_i);
|
||||||
|
ui.item.parent().parent().siblings("tbody").find("tr:eq(1) >").eq(org_i).val(new_i);
|
||||||
|
}
|
||||||
|
var tds = ui.item.parent().parent().siblings("tbody").find("tr:eq(0) >")
|
||||||
|
if(new_index > old_index){ //向後移動
|
||||||
|
tds.eq(new_index).after(tds.eq(old_index))
|
||||||
|
}
|
||||||
|
else if(new_index < old_index){ //向前移動
|
||||||
|
tds.eq(new_index).before(tds.eq(old_index))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
Loading…
Reference in New Issue