sort enhancement

This commit is contained in:
Harry Bomrah 2015-12-01 21:31:47 +08:00
parent c0086c3c01
commit 83f2ef1fb9
10 changed files with 52 additions and 9 deletions

File diff suppressed because one or more lines are too long

View File

@ -14,6 +14,15 @@ class Admin::ExperienceTypesController < OrbitMemberController
render :partial=>'list', :layout=>false render :partial=>'list', :layout=>false
end end
def update_order
orders = params["order"]
ExperienceType.each do |et|
et.sort_position = orders["#{et.id}"]
et.save
end
render :json => {"success" => true}.to_json
end
def edit def edit
@experience_type = ExperienceType.find(params[:id]) @experience_type = ExperienceType.find(params[:id])
@url = admin_experience_type_path(@experience_type) @url = admin_experience_type_path(@experience_type)

View File

@ -11,7 +11,7 @@ class Admin::ExperiencesController < OrbitMemberController
before_action :allow_admin_only, :only => [:index, :setting] before_action :allow_admin_only, :only => [:index, :setting]
def index def index
@experiences = Experience.order_by(:end_date=>'desc',:start_date=>'desc').page(params[:page]).per(10) @experiences = Experience.desc(:end_date).page(params[:page]).per(10)
end end
def new def new

View File

@ -43,6 +43,7 @@ class Experience
"organizationt_title", "organizationt_title",
"department", "department",
"job_title", "job_title",
"experience_type",
"duration" "duration"
] ]
@ -65,19 +66,21 @@ class Experience
else else
date = "" date = ""
end end
pd_data << { "data_title" => date } pd_data << { "data_title" => date }
elsif t == "experience_type"
pd_data << {"data_title" => p.experience_type.title}
else else
pd_data << { "data_title" => p.send(t) } pd_data << { "data_title" => p.send(t) }
end end
end end
{ {
"pd_datas" => pd_data "pd_datas" => pd_data,
"type-sort" => p.experience_type.sort_position
} }
end end
plugin_datas = plugin_datas.sort{|k,v| k["type-sort"] <=> v["type-sort"]}
return [pd_title,plugin_datas] return [pd_title,plugin_datas]
end end

View File

@ -3,6 +3,7 @@ class ExperienceType
include Mongoid::Timestamps include Mongoid::Timestamps
field :title, localize: true field :title, localize: true
field :sort_position, type: Integer, :default => 0
has_many :experiences has_many :experiences
end end

View File

@ -1,4 +1,4 @@
<tr id="<%= dom_id list_experience_type %>"> <tr id="<%= dom_id list_experience_type %>" data-type-id="<%= list_experience_type.id.to_s %>">
<td><%= list_experience_type.title %></td> <td><%= list_experience_type.title %></td>
<td class="span2"> <td class="span2">

View File

@ -1,3 +1,6 @@
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "personal_experience/jquery-ui.min" %>
<% end %>
<style type="text/css"> <style type="text/css">
.element{ .element{
background: #FFF; background: #FFF;
@ -36,7 +39,7 @@
<div class="overview"> <div class="overview">
<table id="experience_types" class="table table-striped"> <table id="experience_types" class="table table-striped">
<tbody> <tbody>
<%= render :partial => 'list_experience_type', :collection => @experience_types %> <%= render :partial => 'list_experience_type', :collection => @experience_types.asc(:sort_position) %>
</tbody> </tbody>
</table> </table>
</div> </div>
@ -49,4 +52,22 @@
<div id="experience_type_qe"> <div id="experience_type_qe">
<div style="display:none;" class="modal" id="experience_type_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div style="display:none;" class="modal" id="experience_type_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
</div> </div>
</div> </div>
<script type="text/javascript">
$("#experience_types tbody").sortable({
update : function(){
var data = {};
$("#experience_types tbody tr").each(function(i){
data[$(this).data("type-id")] = i;
})
$.ajax({
url : "/admin/experience_types/update_order",
type : "post",
data : {"order" : data}
})
}
});
</script>

View File

@ -7,9 +7,9 @@
<% <%
if has_access? if has_access?
@experiences = Experience.where(member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) @experiences = Experience.where(member_profile_id: @member.id).order_by(:start_date => "desc", :end_date => "desc").page(params[:page]).per(10)
else else
@experiences = Experience.where(is_hidden: false, member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) @experiences = Experience.where(is_hidden: false, member_profile_id: @member.id).order_by(:start_date => "desc", :end_date => "desc").page(params[:page]).per(10)
end end
%> %>

View File

@ -24,6 +24,8 @@ Rails.application.routes.draw do
end end
resources :experience_types resources :experience_types
post "experience_types/update_order" => "experience_types#update_order"
end end
end end
end end