sort enhancement
This commit is contained in:
parent
c0086c3c01
commit
83f2ef1fb9
File diff suppressed because one or more lines are too long
|
@ -14,6 +14,15 @@ class Admin::ExperienceTypesController < OrbitMemberController
|
|||
render :partial=>'list', :layout=>false
|
||||
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
|
||||
@experience_type = ExperienceType.find(params[:id])
|
||||
@url = admin_experience_type_path(@experience_type)
|
||||
|
|
|
@ -11,7 +11,7 @@ class Admin::ExperiencesController < OrbitMemberController
|
|||
before_action :allow_admin_only, :only => [:index, :setting]
|
||||
|
||||
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
|
||||
|
||||
def new
|
||||
|
|
|
@ -43,6 +43,7 @@ class Experience
|
|||
"organizationt_title",
|
||||
"department",
|
||||
"job_title",
|
||||
"experience_type",
|
||||
"duration"
|
||||
]
|
||||
|
||||
|
@ -65,19 +66,21 @@ class Experience
|
|||
else
|
||||
date = ""
|
||||
end
|
||||
|
||||
pd_data << { "data_title" => date }
|
||||
elsif t == "experience_type"
|
||||
pd_data << {"data_title" => p.experience_type.title}
|
||||
else
|
||||
pd_data << { "data_title" => p.send(t) }
|
||||
end
|
||||
end
|
||||
|
||||
{
|
||||
"pd_datas" => pd_data
|
||||
"pd_datas" => pd_data,
|
||||
"type-sort" => p.experience_type.sort_position
|
||||
}
|
||||
|
||||
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 ExperienceType
|
|||
include Mongoid::Timestamps
|
||||
|
||||
field :title, localize: true
|
||||
field :sort_position, type: Integer, :default => 0
|
||||
|
||||
has_many :experiences
|
||||
end
|
|
@ -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 class="span2">
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
<% content_for :page_specific_javascript do %>
|
||||
<%= javascript_include_tag "personal_experience/jquery-ui.min" %>
|
||||
<% end %>
|
||||
<style type="text/css">
|
||||
.element{
|
||||
background: #FFF;
|
||||
|
@ -36,7 +39,7 @@
|
|||
<div class="overview">
|
||||
<table id="experience_types" class="table table-striped">
|
||||
<tbody>
|
||||
<%= render :partial => 'list_experience_type', :collection => @experience_types %>
|
||||
<%= render :partial => 'list_experience_type', :collection => @experience_types.asc(:sort_position) %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
@ -50,3 +53,21 @@
|
|||
<div style="display:none;" class="modal" id="experience_type_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
|
||||
</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>
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
|
||||
<%
|
||||
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
|
||||
@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
|
||||
%>
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ Rails.application.routes.draw do
|
|||
end
|
||||
|
||||
resources :experience_types
|
||||
|
||||
post "experience_types/update_order" => "experience_types#update_order"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue