added categories
This commit is contained in:
parent
f3e4275187
commit
e2fa75f424
|
@ -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
|
|
@ -155,6 +155,7 @@ class Admin::ResearchsController < OrbitMemberController
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_settings
|
def get_settings
|
||||||
|
@research_categories = ResearchCategory.all.asc(:sort_position)
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_plugin
|
def set_plugin
|
||||||
|
|
|
@ -29,6 +29,7 @@ class PersonalResearchesController < ApplicationController
|
||||||
plugin = Research.where(:is_hidden=>false).find_by(uid: params[:uid])
|
plugin = Research.where(:is_hidden=>false).find_by(uid: params[:uid])
|
||||||
fields_to_show =[
|
fields_to_show =[
|
||||||
"year",
|
"year",
|
||||||
|
"research_category",
|
||||||
"publish_date",
|
"publish_date",
|
||||||
"research_title",
|
"research_title",
|
||||||
"authors",
|
"authors",
|
||||||
|
|
|
@ -23,6 +23,8 @@ class Research
|
||||||
paginates_per 10
|
paginates_per 10
|
||||||
|
|
||||||
has_many :research_files, :autosave => true, :dependent => :destroy
|
has_many :research_files, :autosave => true, :dependent => :destroy
|
||||||
|
|
||||||
|
belongs_to :research_category
|
||||||
|
|
||||||
accepts_nested_attributes_for :research_files, :allow_destroy => true
|
accepts_nested_attributes_for :research_files, :allow_destroy => true
|
||||||
|
|
||||||
|
@ -44,34 +46,46 @@ class Research
|
||||||
|
|
||||||
fields_to_show = [
|
fields_to_show = [
|
||||||
"year",
|
"year",
|
||||||
|
"research_category",
|
||||||
"research_title",
|
"research_title",
|
||||||
"publish_date",
|
"publish_date",
|
||||||
"authors"
|
"authors"
|
||||||
]
|
]
|
||||||
|
|
||||||
pd_title = fields_to_show.collect do |t|
|
fields_to_remove = []
|
||||||
{
|
|
||||||
"plugin_data_title" => I18n.t("personal_research.#{t}")
|
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
|
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 = []
|
pd_data = []
|
||||||
fields_to_show.collect do |t|
|
fields_to_show.collect do |t|
|
||||||
if t == "research_title"
|
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
|
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.research_category.sort_position.to_i rescue -1),
|
||||||
|
"sort-index" => index
|
||||||
}
|
}
|
||||||
|
|
||||||
end
|
end
|
||||||
|
plugin_datas = plugin_datas.sort_by{|pd| [pd["type-sort"], pd["sort-index"]]}
|
||||||
return [pd_title,plugin_datas]
|
return [pd_title,plugin_datas]
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -79,15 +93,17 @@ class Research
|
||||||
def get_plugin_field_data(field)
|
def get_plugin_field_data(field)
|
||||||
case field
|
case field
|
||||||
when "language"
|
when "language"
|
||||||
value = I18n.t(self.language) rescue ""
|
value = self.language.nil? ? "" : I18n.t(self.language) rescue ""
|
||||||
when "publish_date"
|
when "publish_date"
|
||||||
value = self.publish_date.strftime("%Y-%m") rescue ""
|
value = self.publish_date.strftime("%Y-%m") rescue ""
|
||||||
|
when "research_category"
|
||||||
|
value = self.research_category.title rescue ""
|
||||||
when "file"
|
when "file"
|
||||||
files = []
|
files = []
|
||||||
self.research_files.each do |research_file|
|
self.research_files.each do |research_file|
|
||||||
url = research_file.file.url
|
url = research_file.file.url
|
||||||
title = (research_file.title.blank? ? File.basename(research_file.file.path) : research_file.title)
|
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
|
end
|
||||||
value = files.join("")
|
value = files.join("")
|
||||||
else
|
else
|
||||||
|
|
|
@ -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
|
|
@ -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 %>
|
|
@ -0,0 +1,2 @@
|
||||||
|
$("#research_categories tbody").html("<%= j render :partial => '/admin/researchs/research_category', :collection => @research_categories %>");
|
||||||
|
$("#research_category_modal").modal("hide");
|
|
@ -0,0 +1,2 @@
|
||||||
|
$("#research_categories tbody").html("<%= j render :partial => '/admin/researchs/research_category', :collection => @research_categories %>");
|
||||||
|
$("#research_category_modal").modal("hide");
|
|
@ -0,0 +1 @@
|
||||||
|
$("#research_category_modal").html("<%= j render 'form' %>");
|
|
@ -0,0 +1 @@
|
||||||
|
$("#research_category_modal").html("<%= j render 'form' %>");
|
|
@ -0,0 +1,2 @@
|
||||||
|
$("#research_categories tbody").html("<%= j render :partial => '/admin/researchs/research_category', :collection => @research_categories %>");
|
||||||
|
$("#research_category_modal").modal("hide");
|
|
@ -160,13 +160,21 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- publish_date -->
|
<!-- publish_date -->
|
||||||
<div class="control-group big-group">
|
<div class="control-group">
|
||||||
<label class="control-label muted"><%= t("personal_research.publication_date") %></label>
|
<label class="control-label muted"><%= t("personal_research.publication_date") %></label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<%= f.datetime_picker :publish_date, :no_label => true, :format=>"yyyy/MM", :value => @research.publish_date, :new_record => @research.new_record? %>
|
<%= f.datetime_picker :publish_date, :no_label => true, :format=>"yyyy/MM", :value => @research.publish_date, :new_record => @research.new_record? %>
|
||||||
</div>
|
</div>
|
||||||
</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 -->
|
<!-- url -->
|
||||||
<div class="control-group big-group">
|
<div class="control-group big-group">
|
||||||
<label class="control-label muted"><%= t("personal_research.url") %></label>
|
<label class="control-label muted"><%= t("personal_research.url") %></label>
|
||||||
|
|
|
@ -12,5 +12,6 @@
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td><%= research.member_profile.name rescue "" %></td>
|
<td><%= research.member_profile.name rescue "" %></td>
|
||||||
|
<td><%= research.research_category.title rescue "" %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
|
@ -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>
|
|
@ -5,6 +5,7 @@
|
||||||
<th class="span1"><%= t('personal_research.publication_date') %></th>
|
<th class="span1"><%= t('personal_research.publication_date') %></th>
|
||||||
<th class="span5"><%= t('personal_research.research_title') %></th>
|
<th class="span5"><%= t('personal_research.research_title') %></th>
|
||||||
<th class="span3"><%= t('users.name') %></th>
|
<th class="span3"><%= t('users.name') %></th>
|
||||||
|
<th class="span3"><%= t('personal_research.research_category') %></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="tbody_researchs" class="sort-holder">
|
<tbody id="tbody_researchs" class="sort-holder">
|
||||||
|
@ -29,6 +30,7 @@
|
||||||
</div>
|
</div>
|
||||||
</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-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>
|
||||||
<div class="pagination pagination-centered">
|
<div class="pagination pagination-centered">
|
||||||
<%= content_tag :div, paginate(@researchs), class: "pagination pagination-centered" %>
|
<%= content_tag :div, paginate(@researchs), class: "pagination pagination-centered" %>
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -15,4 +18,54 @@
|
||||||
.totle span{
|
.totle span{
|
||||||
font-size: 18px;
|
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>
|
|
@ -31,6 +31,7 @@
|
||||||
<th class="span2"><%= t('personal_research.year') %></th>
|
<th class="span2"><%= t('personal_research.year') %></th>
|
||||||
<th class="span2"><%= t('personal_research.publication_date') %></th>
|
<th class="span2"><%= t('personal_research.publication_date') %></th>
|
||||||
<th class="span8"><%= t('personal_research.research_title') %></th>
|
<th class="span8"><%= t('personal_research.research_title') %></th>
|
||||||
|
<th class="span3"><%= t('personal_research.research_category') %></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -54,6 +55,7 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
<td><%= research.research_category.title rescue "" %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -9,6 +9,7 @@ en:
|
||||||
authors : "Authors"
|
authors : "Authors"
|
||||||
tags : "Tags"
|
tags : "Tags"
|
||||||
year : "Year"
|
year : "Year"
|
||||||
|
research_category: Category
|
||||||
language : "Language"
|
language : "Language"
|
||||||
isbn : "ISSN(ISBN)"
|
isbn : "ISSN(ISBN)"
|
||||||
vol_no : "Vol.No"
|
vol_no : "Vol.No"
|
||||||
|
|
|
@ -10,6 +10,7 @@ zh_tw:
|
||||||
tags : "領域"
|
tags : "領域"
|
||||||
year : "年度"
|
year : "年度"
|
||||||
language : "語言"
|
language : "語言"
|
||||||
|
research_category: Category
|
||||||
isbn : "ISSN(ISBN)"
|
isbn : "ISSN(ISBN)"
|
||||||
vol_no : "卷數"
|
vol_no : "卷數"
|
||||||
issue_no : "期數"
|
issue_no : "期數"
|
||||||
|
|
|
@ -25,6 +25,8 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
resources :research_categories
|
||||||
|
post "research_categories/update_order" => "research_categories#update_order"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue