added categories

This commit is contained in:
Harry Bomrah 2015-12-30 18:12:32 +08:00
parent f3e4275187
commit e2fa75f424
20 changed files with 197 additions and 12 deletions

View File

@ -0,0 +1,48 @@
class Admin::ResearchCategoriesController < OrbitMemberController
def new
@research_category = ResearchCategory.new
@url = admin_research_categories_path
end
def create
ResearchCategory.create(r_c_params)
@research_categories = ResearchCategory.all.asc(:sort_postion)
end
def edit
@research_category = ResearchCategory.find(params[:id]) rescue nil
@url = admin_research_category_path(@research_category)
end
def update
research_category = ResearchCategory.find(params[:id]) rescue nil
if !research_category.nil?
research_category.update_attributes(r_c_params)
research_category.save
end
@research_categories = ResearchCategory.all.asc(:sort_postion)
end
def destroy
research_category = ResearchCategory.find(params[:id]) rescue nil
research_category.destroy if !research_category.nil?
@research_categories = ResearchCategory.all.asc(:sort_postion)
end
def update_order
orders = params["order"]
ResearchCategory.each do |rc|
rc.sort_position = orders["#{rc.id}"]
rc.save
end
render :json => {"success" => true}.to_json
end
private
def r_c_params
params.require(:research_category).permit!
end
end

View File

@ -155,6 +155,7 @@ class Admin::ResearchsController < OrbitMemberController
end
def get_settings
@research_categories = ResearchCategory.all.asc(:sort_position)
end
def set_plugin

View File

@ -29,6 +29,7 @@ class PersonalResearchesController < ApplicationController
plugin = Research.where(:is_hidden=>false).find_by(uid: params[:uid])
fields_to_show =[
"year",
"research_category",
"publish_date",
"research_title",
"authors",

View File

@ -23,6 +23,8 @@ class Research
paginates_per 10
has_many :research_files, :autosave => true, :dependent => :destroy
belongs_to :research_category
accepts_nested_attributes_for :research_files, :allow_destroy => true
@ -44,34 +46,46 @@ class Research
fields_to_show = [
"year",
"research_category",
"research_title",
"publish_date",
"authors"
]
pd_title = fields_to_show.collect do |t|
{
"plugin_data_title" => I18n.t("personal_research.#{t}")
}
fields_to_remove = []
pd_title = []
fields_to_show.each do |t|
fields_to_remove << t if datas.where(t.to_sym.ne => nil).count == 0
pd_title << {
"plugin_data_title" => I18n.t("personal_research.#{t}")
} if !fields_to_remove.include?(t)
end
plugin_datas = datas.sort_for_frontend.collect do |p|
fields_to_show = fields_to_show - fields_to_remove
plugin_datas = datas.sort_for_frontend.collect.with_index do |p, index|
pd_data = []
fields_to_show.collect do |t|
if t == "research_title"
pd_data << { "data_title" => "<a href='#{OrbitHelper.url_to_plugin_show(p.to_param,'personal_research')}' target='_blank'>#{p.send(t)}" }
pd_data << { "data_title" => "<a href='#{OrbitHelper.url_to_plugin_show(p.to_param,'personal_research')}'>#{p.send(t)}" }
elsif t == "research_category"
pd_data << {"data_title" => (p.research_category.title rescue "")}
else
pd_data << { "data_title" => p.send(t) }
end
end
{
"pd_datas" => pd_data
"pd_datas" => pd_data,
"type-sort" => (p.research_category.sort_position.to_i rescue -1),
"sort-index" => index
}
end
plugin_datas = plugin_datas.sort_by{|pd| [pd["type-sort"], pd["sort-index"]]}
return [pd_title,plugin_datas]
end
@ -79,15 +93,17 @@ class Research
def get_plugin_field_data(field)
case field
when "language"
value = I18n.t(self.language) rescue ""
value = self.language.nil? ? "" : I18n.t(self.language) rescue ""
when "publish_date"
value = self.publish_date.strftime("%Y-%m") rescue ""
when "research_category"
value = self.research_category.title rescue ""
when "file"
files = []
self.research_files.each do |research_file|
url = research_file.file.url
title = (research_file.title.blank? ? File.basename(research_file.file.path) : research_file.title)
files << "<li><a href='#{url}'' target='_blank'>#{title}</li>"
files << "<li><a href='#{url}' target='_blank'>#{title}</li>"
end
value = files.join("")
else

View File

@ -0,0 +1,9 @@
class ResearchCategory
include Mongoid::Document
include Mongoid::Timestamps
field :title, localize: true
field :sort_position, type: Integer, default: 0
has_many :researches
end

View File

@ -0,0 +1,24 @@
<%= form_for(@research_category, :html =>{:class=>"form-horizontal", :style=>"margin: 0;"}, :remote => true, :url => @url ) do |f| %>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel"><%= t("personal_research.research_category") %></h3>
</div>
<div class="modal-body">
<%= f.fields_for :title_translations do |f| %>
<% @site_in_use_locales.each do |locale| %>
<div class="control-group">
<%= label_tag t(locale), t(locale), :class => 'control-label' %>
<div class="controls">
<%= f.text_field locale, :value => (@research_category.title_translations[locale] rescue nil) %>
</div>
</div>
<% end %>
<% end %>
</div>
<div class="modal-footer">
<%= f.submit t('submit'), :class=>'btn btn-primary' %>
<a class="btn" data-dismiss="modal"><%= t('cancel')%></a>
</div>
<% end %>

View File

@ -0,0 +1,2 @@
$("#research_categories tbody").html("<%= j render :partial => '/admin/researchs/research_category', :collection => @research_categories %>");
$("#research_category_modal").modal("hide");

View File

@ -0,0 +1,2 @@
$("#research_categories tbody").html("<%= j render :partial => '/admin/researchs/research_category', :collection => @research_categories %>");
$("#research_category_modal").modal("hide");

View File

@ -0,0 +1 @@
$("#research_category_modal").html("<%= j render 'form' %>");

View File

@ -0,0 +1 @@
$("#research_category_modal").html("<%= j render 'form' %>");

View File

@ -0,0 +1,2 @@
$("#research_categories tbody").html("<%= j render :partial => '/admin/researchs/research_category', :collection => @research_categories %>");
$("#research_category_modal").modal("hide");

View File

@ -160,13 +160,21 @@
</div>
<!-- publish_date -->
<div class="control-group big-group">
<div class="control-group">
<label class="control-label muted"><%= t("personal_research.publication_date") %></label>
<div class="controls">
<%= f.datetime_picker :publish_date, :no_label => true, :format=>"yyyy/MM", :value => @research.publish_date, :new_record => @research.new_record? %>
</div>
</div>
<!-- course_category -->
<div class="control-group">
<label class="control-label muted"><%= t("personal_research.research_category") %></label>
<div class="controls">
<%= f.select :research_category_id, ResearchCategory.all.collect {|t| [ t.title, t.id ]} %>
</div>
</div>
<!-- url -->
<div class="control-group big-group">
<label class="control-label muted"><%= t("personal_research.url") %></label>

View File

@ -12,5 +12,6 @@
</div>
</td>
<td><%= research.member_profile.name rescue "" %></td>
<td><%= research.research_category.title rescue "" %></td>
</tr>
<% end %>

View File

@ -0,0 +1,8 @@
<tr id="<%= dom_id research_category %>" data-type-id="<%= research_category.id.to_s %>">
<td><%= research_category.title %></td>
<td class="span2">
<a href="<%= edit_admin_research_category_path(research_category) %>#research_category_modal" data-toggle="modal" data-remote="true" class="action"><%= t(:edit) %></a>
<%= link_to t(:delete_), admin_research_category_path(research_category), "data-confirm" => t('sure?'), :method => :delete, :remote => true,:class=>"archive_toggle action" %>
</td>
</tr>

View File

@ -5,6 +5,7 @@
<th class="span1"><%= t('personal_research.publication_date') %></th>
<th class="span5"><%= t('personal_research.research_title') %></th>
<th class="span3"><%= t('users.name') %></th>
<th class="span3"><%= t('personal_research.research_category') %></th>
</tr>
</thead>
<tbody id="tbody_researchs" class="sort-holder">
@ -29,6 +30,7 @@
</div>
</div>
<%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t(:new_), new_admin_research_path, :class => 'btn btn-primary' %>
<%= link_to content_tag(:i, nil, :class => 'icon-cog icon-white') + t('setting'), admin_research_setting_path, :class => 'btn btn-primary pull-right' %>
</div>
<div class="pagination pagination-centered">
<%= content_tag :div, paginate(@researchs), class: "pagination pagination-centered" %>

View File

@ -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;
@ -15,4 +18,54 @@
.totle span{
font-size: 18px;
}
</style>
</style>
<div class="row">
<div class="element span4">
<div class="detail w-a h-a">
<p class="totle">
<a class="btn btn-small btn-primary pull-right" href="<%= new_admin_research_category_path %>#research_category_modal" data-toggle="modal" data-remote="true"><i class="icon-plus"></i> <%= t('add')%></a>
<span><%= t("personal_research.research_category") %></span>
</p>
<div class="detal-list my_scroll">
<div class="scrollbar">
<div class="track">
<div class="thumb">
<div class="end"></div>
</div>
</div>
</div>
<div class="viewport">
<div class="overview">
<table id="research_categories" class="table table-striped">
<tbody>
<%= render :partial => 'research_category', :collection => @research_categories %>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="paper_type_qe">
<div style="display:none;" class="modal" id="research_category_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
</div>
</div>
<script type="text/javascript">
$("#research_categories tbody").sortable({
update : function(){
var data = {};
$("#research_categories tbody tr").each(function(i){
data[$(this).data("type-id")] = i;
})
$.ajax({
url : "/admin/research_categories/update_order",
type : "post",
data : {"order" : data}
})
}
});
</script>

View File

@ -31,6 +31,7 @@
<th class="span2"><%= t('personal_research.year') %></th>
<th class="span2"><%= t('personal_research.publication_date') %></th>
<th class="span8"><%= t('personal_research.research_title') %></th>
<th class="span3"><%= t('personal_research.research_category') %></th>
</tr>
</thead>
<tbody>
@ -54,6 +55,7 @@
</ul>
</div>
</td>
<td><%= research.research_category.title rescue "" %></td>
</tr>
<% end %>
</tbody>

View File

@ -9,6 +9,7 @@ en:
authors : "Authors"
tags : "Tags"
year : "Year"
research_category: Category
language : "Language"
isbn : "ISSN(ISBN)"
vol_no : "Vol.No"

View File

@ -10,6 +10,7 @@ zh_tw:
tags : "領域"
year : "年度"
language : "語言"
research_category: Category
isbn : "ISSN(ISBN)"
vol_no : "卷數"
issue_no : "期數"

View File

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