fix error and add number box for sorting
This commit is contained in:
parent
957ab330f7
commit
847ab9a325
|
@ -34,10 +34,10 @@ class UniversalTablesController < ApplicationController
|
|||
sort_class = "sort hide"
|
||||
when "text"
|
||||
if tc.make_categorizable
|
||||
select_values = tc.column_entries.distinct(:text)
|
||||
select_values = tc.column_entries.distinct("text.#{I18n.locale.to_s}")
|
||||
form_field = "<input type=\"hidden\" name=\"authenticity_token\" value=\"#{csrf_value}\"><select class='form-control' name='q'>"
|
||||
select_values.each do |sv|
|
||||
form_field = form_field + "<option value='#{sv[I18n.locale.to_s]}'>#{sv[I18n.locale.to_s]}</option>"
|
||||
form_field = form_field + "<option value='#{sv}'>#{sv}</option>"
|
||||
end
|
||||
form_field = form_field + "</select>"
|
||||
end
|
||||
|
|
|
@ -17,7 +17,7 @@ module Admin::UniversalTablesHelper
|
|||
end
|
||||
|
||||
def render_unique_texts(f,column,i)
|
||||
select_values = column.column_entries.distinct(:text).uniq
|
||||
select_values = column.column_entries.distinct(:text)
|
||||
select = "<select id='#{column.key}_#{i}'>"
|
||||
s = {"en" => "", "zh_tw" => ""}
|
||||
select = select + "<option class='muted' value='#{s.to_json.html_safe}'>---------------Select---------------</option>"
|
||||
|
@ -29,7 +29,7 @@ module Admin::UniversalTablesHelper
|
|||
end
|
||||
|
||||
def render_unique_number(f,column,i)
|
||||
select_values = column.column_entries.distinct(:number).uniq
|
||||
select_values = column.column_entries.distinct(:number)
|
||||
select = "<select id='#{column.key}_#{i}'>"
|
||||
s = ""
|
||||
select = select + "<option class='muted' value='#{s}'>---------------Select---------------</option>"
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<% @entries.each do |entry| %>
|
||||
<tr data-id="<%= entry.id %>">
|
||||
<td>
|
||||
<%= entry.sort_number %>
|
||||
<%= number_field_tag nil,entry.sort_number,class: 'sort_number',step: 1 %>
|
||||
</td>
|
||||
<% @columns.each_with_index do |column, index| %>
|
||||
<% ce = entry.column_entries.where(:table_column_id => column.id).first rescue nil %>
|
||||
|
|
|
@ -25,6 +25,74 @@
|
|||
update_sort();
|
||||
}
|
||||
});
|
||||
$('.sort_number').change(function(){
|
||||
var new_sort_number = parseFloat($(this).val());
|
||||
var min_number = $('.sort_number').length;
|
||||
var max_number = 0;
|
||||
var pool = $('.sort_number').not(this);
|
||||
var same_order = pool.filter(function(){
|
||||
var tmp_sort = parseFloat($(this).val());
|
||||
if (tmp_sort<min_number){
|
||||
min_number = tmp_sort;
|
||||
}
|
||||
if (tmp_sort>max_number){
|
||||
max_number = tmp_sort;
|
||||
}
|
||||
return tmp_sort==new_sort_number
|
||||
});
|
||||
var tmp_same_order = null;
|
||||
if (same_order.length>0){
|
||||
tmp_same_order = same_order.eq(0);
|
||||
tmp_same_order.parents('tr').eq(0).before($(this).parents('tr').eq(0));
|
||||
}else{
|
||||
//ex. 1 2 3 5,insert 4
|
||||
if (parseInt(pool.eq(0).val())<parseInt(pool.eq(-1).val())){ //asc
|
||||
$.each(pool,function(){
|
||||
var tmp_sort = parseFloat($(this).val());
|
||||
if (new_sort_number>max_number){
|
||||
if (tmp_sort<=new_sort_number){
|
||||
tmp_same_order = $(this);
|
||||
}
|
||||
}else{
|
||||
if (tmp_sort>=new_sort_number){
|
||||
tmp_same_order = $(this);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (new_sort_number>max_number){
|
||||
tmp_same_order.parents('tr').eq(0).after($(this).parents('tr').eq(0));
|
||||
}else{
|
||||
tmp_same_order.parents('tr').eq(0).before($(this).parents('tr').eq(0));
|
||||
}
|
||||
}else{ //desc
|
||||
//ex. 5 3 2 1,insert 4
|
||||
$.each(pool,function(){
|
||||
var tmp_sort = parseFloat($(this).val());
|
||||
if (new_sort_number<min_number){
|
||||
if (tmp_sort>=new_sort_number){
|
||||
tmp_same_order = $(this);
|
||||
}
|
||||
}else if (new_sort_number>max_number){
|
||||
if (tmp_sort<=new_sort_number){
|
||||
tmp_same_order = $(this);
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
if (tmp_sort<=new_sort_number){
|
||||
tmp_same_order = $(this);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (new_sort_number<min_number){
|
||||
tmp_same_order.parents('tr').eq(0).after($(this).parents('tr').eq(0));
|
||||
}else{
|
||||
tmp_same_order.parents('tr').eq(0).before($(this).parents('tr').eq(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
$(document).ready(function(){
|
||||
$('#update_sort_button').click(update_sort);
|
||||
|
|
Loading…
Reference in New Issue