sorting and dates fixed
This commit is contained in:
parent
45cf5ab9e4
commit
1ccd146915
|
@ -14,6 +14,15 @@ class Admin::ProjectTypesController < OrbitMemberController
|
|||
render :partial=>'list', :layout=>false
|
||||
end
|
||||
|
||||
def update_order
|
||||
orders = params["order"]
|
||||
ProjectType.each do |pt|
|
||||
pt.sort_position = orders["#{pt.id}"]
|
||||
pt.save
|
||||
end
|
||||
render :json => {"success" => true}.to_json
|
||||
end
|
||||
|
||||
def edit
|
||||
@project_type = ProjectType.find(params[:id])
|
||||
@url = admin_project_type_path(@project_type)
|
||||
|
|
|
@ -34,6 +34,8 @@ class Project
|
|||
|
||||
before_validation :add_http
|
||||
|
||||
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year=>'desc', :period_start_date=>'desc') }
|
||||
|
||||
def duration
|
||||
"#{self.period_start_date.strftime("%Y.%m") rescue ""} ~ #{self.period_end_date.strftime("%Y.%m") rescue ""}"
|
||||
end
|
||||
|
@ -41,6 +43,7 @@ class Project
|
|||
def self.get_plugin_datas_to_member(datas)
|
||||
|
||||
fields_to_show = [
|
||||
"project_type",
|
||||
"year",
|
||||
"project_title",
|
||||
"participator",
|
||||
|
@ -55,7 +58,7 @@ class Project
|
|||
}
|
||||
end
|
||||
|
||||
plugin_datas = datas.where(:is_hidden=>false).order_by(:period_start_date=>'desc',:year=>'desc').collect do |p|
|
||||
plugin_datas = datas.sort_for_frontend.collect do |p|
|
||||
|
||||
pd_data = []
|
||||
fields_to_show.collect do |t|
|
||||
|
@ -70,17 +73,20 @@ class Project
|
|||
end
|
||||
|
||||
pd_data << { "data_title" => date }
|
||||
elsif t == "project_type"
|
||||
pd_data << {"data_title" => (p.project_type.title rescue "")}
|
||||
else
|
||||
pd_data << { "data_title" => p.send(t) }
|
||||
end
|
||||
end
|
||||
|
||||
{
|
||||
"pd_datas" => pd_data
|
||||
"pd_datas" => pd_data,
|
||||
"type-sort" => (p.project_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 ProjectType
|
|||
include Mongoid::Timestamps
|
||||
|
||||
field :title, localize: true
|
||||
field :sort_position, type: Integer, default: 0
|
||||
|
||||
has_many :projects
|
||||
|
||||
|
|
|
@ -181,7 +181,7 @@
|
|||
<div class="control-group">
|
||||
<label class="control-label muted"><%= t("personal_project.start_date") %></label>
|
||||
<div class="controls">
|
||||
<%= f.datetime_picker :period_start_date, :no_label => true, :format=>"yyyy/MM" %>
|
||||
<%= f.datetime_picker :period_start_date, :format=>"yyyy/MM", :value=> @project.period_start_date, :new_record => @project.new_record? %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -189,7 +189,7 @@
|
|||
<div class="control-group">
|
||||
<label class="control-label muted"><%= t("personal_project.end_date") %></label>
|
||||
<div class="controls">
|
||||
<%= f.datetime_picker :period_end_date, :no_label => true, :format=>"yyyy/MM" %>
|
||||
<%= f.datetime_picker :period_end_date, :no_label => true, :format=>"yyyy/MM", :value=> @project.period_end_date, :new_record => @project.new_record? %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<tr id="<%= dom_id list_project_type %>">
|
||||
<tr id="<%= dom_id list_project_type %>" data-type-id="<%= list_project_type.id.to_s %>">
|
||||
<td><%= list_project_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="project_types" class="table table-striped">
|
||||
<tbody>
|
||||
<%= render :partial => 'list_project_type', :collection => @project_types %>
|
||||
<%= render :partial => 'list_project_type', :collection => @project_types.asc(:sort_position) %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
@ -50,3 +53,19 @@
|
|||
<div style="display:none;" class="modal" id="project_type_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$("#project_types tbody").sortable({
|
||||
update : function(){
|
||||
var data = {};
|
||||
$("#project_types tbody tr").each(function(i){
|
||||
data[$(this).data("type-id")] = i;
|
||||
})
|
||||
$.ajax({
|
||||
url : "/admin/project_types/update_order",
|
||||
type : "post",
|
||||
data : {"order" : data}
|
||||
})
|
||||
}
|
||||
});
|
||||
</script>
|
|
@ -24,6 +24,7 @@ Rails.application.routes.draw do
|
|||
end
|
||||
|
||||
resources :project_types
|
||||
post "project_types/update_order" => "project_types#update_order"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue