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
|
render :partial=>'list', :layout=>false
|
||||||
end
|
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
|
def edit
|
||||||
@project_type = ProjectType.find(params[:id])
|
@project_type = ProjectType.find(params[:id])
|
||||||
@url = admin_project_type_path(@project_type)
|
@url = admin_project_type_path(@project_type)
|
||||||
|
|
|
@ -34,6 +34,8 @@ class Project
|
||||||
|
|
||||||
before_validation :add_http
|
before_validation :add_http
|
||||||
|
|
||||||
|
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year=>'desc', :period_start_date=>'desc') }
|
||||||
|
|
||||||
def duration
|
def duration
|
||||||
"#{self.period_start_date.strftime("%Y.%m") rescue ""} ~ #{self.period_end_date.strftime("%Y.%m") rescue ""}"
|
"#{self.period_start_date.strftime("%Y.%m") rescue ""} ~ #{self.period_end_date.strftime("%Y.%m") rescue ""}"
|
||||||
end
|
end
|
||||||
|
@ -41,6 +43,7 @@ class Project
|
||||||
def self.get_plugin_datas_to_member(datas)
|
def self.get_plugin_datas_to_member(datas)
|
||||||
|
|
||||||
fields_to_show = [
|
fields_to_show = [
|
||||||
|
"project_type",
|
||||||
"year",
|
"year",
|
||||||
"project_title",
|
"project_title",
|
||||||
"participator",
|
"participator",
|
||||||
|
@ -55,7 +58,7 @@ class Project
|
||||||
}
|
}
|
||||||
end
|
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 = []
|
pd_data = []
|
||||||
fields_to_show.collect do |t|
|
fields_to_show.collect do |t|
|
||||||
|
@ -70,17 +73,20 @@ class Project
|
||||||
end
|
end
|
||||||
|
|
||||||
pd_data << { "data_title" => date }
|
pd_data << { "data_title" => date }
|
||||||
|
elsif t == "project_type"
|
||||||
|
pd_data << {"data_title" => (p.project_type.title rescue "")}
|
||||||
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.project_type.sort_position rescue 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
|
|
|
@ -3,6 +3,7 @@ class ProjectType
|
||||||
include Mongoid::Timestamps
|
include Mongoid::Timestamps
|
||||||
|
|
||||||
field :title, localize: true
|
field :title, localize: true
|
||||||
|
field :sort_position, type: Integer, default: 0
|
||||||
|
|
||||||
has_many :projects
|
has_many :projects
|
||||||
|
|
||||||
|
|
|
@ -181,7 +181,7 @@
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label muted"><%= t("personal_project.start_date") %></label>
|
<label class="control-label muted"><%= t("personal_project.start_date") %></label>
|
||||||
<div class="controls">
|
<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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label muted"><%= t("personal_project.end_date") %></label>
|
<label class="control-label muted"><%= t("personal_project.end_date") %></label>
|
||||||
<div class="controls">
|
<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>
|
||||||
</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><%= list_project_type.title %></td>
|
||||||
<td class="span2">
|
<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">
|
<style type="text/css">
|
||||||
.element{
|
.element{
|
||||||
background: #FFF;
|
background: #FFF;
|
||||||
|
@ -36,7 +39,7 @@
|
||||||
<div class="overview">
|
<div class="overview">
|
||||||
<table id="project_types" class="table table-striped">
|
<table id="project_types" class="table table-striped">
|
||||||
<tbody>
|
<tbody>
|
||||||
<%= render :partial => 'list_project_type', :collection => @project_types %>
|
<%= render :partial => 'list_project_type', :collection => @project_types.asc(:sort_position) %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
@ -49,4 +52,20 @@
|
||||||
<div id="project_type_qe">
|
<div id="project_type_qe">
|
||||||
<div style="display:none;" class="modal" id="project_type_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
|
<div style="display:none;" class="modal" id="project_type_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
|
||||||
</div>
|
</div>
|
||||||
</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
|
end
|
||||||
|
|
||||||
resources :project_types
|
resources :project_types
|
||||||
|
post "project_types/update_order" => "project_types#update_order"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue