sorting and dates fixed
This commit is contained in:
parent
f8f80a1373
commit
43a14b5c9e
|
@ -14,6 +14,15 @@ class Admin::HonorTypesController < OrbitMemberController
|
|||
render :partial=>'list', :layout=>false
|
||||
end
|
||||
|
||||
def update_order
|
||||
orders = params["order"]
|
||||
HonorType.each do |ht|
|
||||
ht.sort_position = orders["#{ht.id}"]
|
||||
ht.save
|
||||
end
|
||||
render :json => {"success" => true}.to_json
|
||||
end
|
||||
|
||||
def edit
|
||||
@honor_type = HonorType.find(params[:id])
|
||||
@url = admin_honor_type_path(@honor_type)
|
||||
|
|
|
@ -22,6 +22,8 @@ class Honor
|
|||
|
||||
before_validation :add_http
|
||||
|
||||
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc") }
|
||||
|
||||
def slug_title
|
||||
self.award_name+' '+self.awarding_unit rescue ""
|
||||
end
|
||||
|
@ -39,6 +41,7 @@ class Honor
|
|||
def self.get_plugin_datas_to_member(datas)
|
||||
|
||||
fields_to_show = [
|
||||
"honor_type",
|
||||
"year",
|
||||
"award_name",
|
||||
"awarding_unit"
|
||||
|
@ -50,23 +53,26 @@ class Honor
|
|||
}
|
||||
end
|
||||
|
||||
plugin_datas = datas.where(:is_hidden=>false).order_by(:year=>'desc').collect do |p|
|
||||
plugin_datas = datas.sort_for_frontend.collect do |p|
|
||||
|
||||
pd_data = []
|
||||
fields_to_show.collect do |t|
|
||||
if t == "award_name"
|
||||
pd_data << { "data_title" => "<a href='#{OrbitHelper.url_to_plugin_show(p.to_param,'personal_honor')}' target='_blank'>#{p.send(t)}" }
|
||||
elsif t == "honor_type"
|
||||
pd_data << {"data_title" => (p.honor_type.title rescue "")}
|
||||
else
|
||||
pd_data << { "data_title" => p.send(t) }
|
||||
end
|
||||
end
|
||||
|
||||
{
|
||||
"pd_datas" => pd_data
|
||||
"pd_datas" => pd_data,
|
||||
"type-sort" => (p.honor_type.sort_position rescue 1000)
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
plugin_datas = plugin_datas.sort{|k,v| k["type-sort"] <=> v["type-sort"]}
|
||||
return [pd_title,plugin_datas]
|
||||
|
||||
end
|
||||
|
|
|
@ -3,6 +3,7 @@ class HonorType
|
|||
include Mongoid::Timestamps
|
||||
|
||||
field :title, localize: true
|
||||
field :sort_position, :type => Integer, :default => 0
|
||||
|
||||
has_many :honors
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
<tr id="<%= dom_id list_honor_type %>">
|
||||
<tr id="<%= dom_id list_honor_type %>" data-type-id="<%= list_honor_type.id.to_s %>">
|
||||
<td><%= list_honor_type.title %></td>
|
||||
<td class="span2">
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
<% content_for :page_specific_javascript do %>
|
||||
<%= javascript_include_tag "lib/jquery-ui-sortable.min" %>
|
||||
<% end %>
|
||||
<style type="text/css">
|
||||
.element{
|
||||
background: #FFF;
|
||||
|
@ -36,7 +39,7 @@
|
|||
<div class="overview">
|
||||
<table id="honor_types" class="table table-striped">
|
||||
<tbody>
|
||||
<%= render :partial => 'list_honor_type', :collection => @honor_types %>
|
||||
<%= render :partial => 'list_honor_type', :collection => @honor_types.asc(:sort_position) %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
@ -49,4 +52,19 @@
|
|||
<div id="honor_type_qe">
|
||||
<div style="display:none;" class="modal" id="honor_type_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$("#honor_types tbody").sortable({
|
||||
update : function(){
|
||||
var data = {};
|
||||
$("#honor_types tbody tr").each(function(i){
|
||||
data[$(this).data("type-id")] = i;
|
||||
})
|
||||
$.ajax({
|
||||
url : "/admin/honor_types/update_order",
|
||||
type : "post",
|
||||
data : {"order" : data}
|
||||
})
|
||||
}
|
||||
});
|
||||
</script>
|
|
@ -24,6 +24,7 @@ Rails.application.routes.draw do
|
|||
end
|
||||
|
||||
resources :honor_types
|
||||
post "honor_types/update_order" => "honor_types#update_order"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue