modifiable fields added

This commit is contained in:
Harry Bomrah 2016-04-06 18:52:57 +08:00
parent ddf161dc6e
commit aed57b185c
5 changed files with 185 additions and 32 deletions

View File

@ -1,26 +1,55 @@
class PersonalPatentsController < ApplicationController
def index
params = OrbitHelper.params
patents = Patent.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
patent_list = patents.collect do |patent|
{
"publication_date" => patent.publish_date,
"patent_title" => patent.patent_title,
"patent_no" => patent.patent_no,
"patent_country" => patent.patent_country,
"authors" => (patent.member_profile.name rescue ""),
"link_to_show" => OrbitHelper.url_to_show(patent.to_param)
fields_to_show = Page.where(:page_id => params[:page_id]).first.custom_array_field rescue []
if fields_to_show.blank?
fields_to_show = [
"publish_date",
"patent_title",
"patent_no",
"patent_country",
"authors"
]
end
patent_list = []
patents.each do |patent|
t = []
fields_to_show.each do |fs|
case fs
when "title"
t << {"value" => "<a href='#{OrbitHelper.url_to_show(patent.to_param)}'>" + (patent.send(fs) rescue "") + "</a>"}
when "publish_date"
t << {"value" => (patent.publish_date.strftime("%Y/%m/%d") rescue "")}
when "application_date"
t << {"value" => (patent.application_date.strftime("%Y/%m/%d") rescue "")}
when "end_date"
t << {"value" => (patent.end_date.strftime("%Y/%m/%d") rescue "")}
when "patent_category"
t << {"value" => (patent.patent_types.collect{|pt| pt.title}.join(", ") rescue "")}
when "author_type"
t << {"value" => (patent.patent_author_types.collect{|pt| pt.title}.join(", ") rescue "")}
else
t << {"value" => patent.send(fs)}
end
end
patent_list << {"patent_list" => t}
end
headers = []
fields_to_show.each do |fs|
col = 2
col = 3 if fs == "patent_title"
header = fs == "authors" ? t("users.name") : t("personal_patent.#{fs}")
headers << {
"head-title" => header,
"col" => col
}
end
{
"patents" => patent_list,
"extras" => {
"widget-title" => t("module_name.personal_patent"),
"th_publication_date" => t('personal_patent.publication_date'),
"th_patent_title" => t("personal_patent.patent_title"),
"th_patent_no" => t('personal_patent.patent_no'),
"th_patent_country" => t("personal_patent.patent_country"),
"th_authors" => t('users.name')
},
"extras" => { "widget-title" => t("module_name.personal_patent") },
"headers" => headers,
"total_pages" => patents.total_pages
}
end
@ -34,8 +63,14 @@ class PersonalPatentsController < ApplicationController
"publish_date",
"patent_title",
"patent_no",
"patent_organization",
"progress_status",
"application_date",
"end_date",
"publish_date",
"patent_country",
"authors",
"author_type",
"url",
"language",
"keywords",
@ -45,4 +80,44 @@ class PersonalPatentsController < ApplicationController
{"plugin_datas"=>plugin.get_plugin_data(fields_to_show)}
end
def get_fields_for_index
@page = Page.find(params[:page_id]) rescue nil
@fields_to_show = [
"patent_category",
"year",
"publish_date",
"patent_title",
"patent_no",
"patent_organization",
"progress_status",
"application_date",
"end_date",
"publish_date",
"author_type",
"patent_country",
"authors",
"url",
"language",
"keywords",
"note"
]
@fields_to_show = @fields_to_show.map{|fs| [(fs == "authors" ? t("users.name") : t("personal_patent.#{fs}")), fs]}
@default_fields_to_show = [
"publish_date",
"patent_title",
"patent_no",
"patent_country",
"authors"
]
render :layout => false
end
def save_index_fields
page = Page.find(params[:page_id]) rescue nil
page.custom_array_field = params[:keys]
page.save
render :json => {"success" => true}.to_json
end
end

View File

@ -47,7 +47,11 @@ class Patent
end
def self.get_plugin_datas_to_member(datas)
page = Page.where(:module => "personal_patent").first rescue nil
if !page.nil? && !page.custom_array_field.blank?
fields_to_show = page.custom_array_field
else
fields_to_show = [
"publish_date",
"patent_title",
@ -55,6 +59,7 @@ class Patent
"patent_country",
"authors"
]
end
fields_to_remove = []
@ -64,7 +69,11 @@ class Patent
if (self.fields[t].type.to_s == "String" rescue false)
fields_to_remove << t if (datas.where(t.to_sym.ne => nil).or(t.to_sym.ne => "").count == 0 rescue false)
else
t = "patent_types" if t == "patent_category"
t = "patent_author_types" if t == "author_type"
fields_to_remove << t if (datas.where(t.to_sym.ne => nil).count == 0 rescue false)
t = "patent_category" if t == "patent_types"
t = "author_type" if t == "patent_author_types"
end
pd_title << {
"plugin_data_title" => I18n.t("personal_patent.#{t}")
@ -77,8 +86,19 @@ class Patent
pd_data = []
fields_to_show.collect do |t|
if t == "patent_title"
pd_data << { "data_title" => "<a href='#{OrbitHelper.url_to_plugin_show(p.to_param,'personal_patent')}' target='_blank'>#{p.send(t)}" }
case t
when "title"
pd_data << {"data_title" => "<a href='#{OrbitHelper.url_to_show(p.to_param)}'>" + (p.send(fs) rescue "") + "</a>"}
when "publish_date"
pd_data << {"data_title" => (p.publish_date.strftime("%Y/%m/%d") rescue "")}
when "application_date"
pd_data << {"data_title" => (p.application_date.strftime("%Y/%m/%d") rescue "")}
when "end_date"
pd_data << {"data_title" => (p.end_date.strftime("%Y/%m/%d") rescue "")}
when "patent_category"
pd_data << {"data_title" => (p.patent_types.collect{|pt| pt.title}.join(", ") rescue "")}
when "author_type"
pd_data << {"data_title" => (p.patent_author_types.collect{|pt| pt.title}.join(", ") rescue "")}
else
pd_data << {"data_title" => p.send(t)}
end
@ -100,6 +120,14 @@ class Patent
value = self.patent_types.collect{|patent_type| patent_type.title}.join(',') rescue ""
when "language"
value = I18n.t(self.language) if !self.language.nil? rescue ""
when "publish_date"
value = self.publish_date.strftime("%Y/%m/%d") rescue ""
when "application_date"
value = self.application_date.strftime("%Y/%m/%d") rescue ""
when "end_date"
value = self.end_date.strftime("%Y/%m/%d") rescue ""
when "author_type"
value = self.patent_author_types.collect{|pt| pt.title}.join(", ") rescue ""
when "file"
files = []
self.patent_files.each do |patent_file|

View File

@ -0,0 +1,48 @@
<% if !@page.nil? %>
<form id="form_for_plugin_fields" action="">
<div class="form-inline">
<ul class="current-fields">
<% if @page.custom_array_field.blank? %>
<% @default_fields_to_show.each do |fs| %>
<li data-attrib-key="<%= fs %>" class="clearfix"><span class="field-value"><%= fs == "authors" ? t("users.name") : t("personal_patent.#{fs}") %></span><span class="remove-field"><i class="icon-remove-sign"></i></span></li>
<% end %>
<% else %>
<% @page.custom_array_field.each do |fs| %>
<li data-attrib-key="<%= fs %>" class="clearfix"><span class="field-value"><%= fs == "authors" ? t("users.name") : t("personal_patent.#{fs}") %></span><span class="remove-field"><i class="icon-remove-sign"></i></span></li>
<% end %>
<% end %>
</ul>
</div>
<div class="form-horizontal controls-row">
<div class="attr-type-wrap control-group">
<label class="attr control-label">Fields: </label>
<div class="attr controls">
<%= select_tag "fields_to_show_for_pp", options_for_select(@fields_to_show), prompt: "---Select something---" %>
</div>
</div>
<a href="#" class="add-pp-field btn btn-info">Add Field</a>
<input type="hidden" name="plugin_key" value="<%= @page.module %>">
<input type="hidden" name="plugin_page_frontend_id" value="<%= @page.id.to_s %>">
</div>
</form>
<script type="text/javascript">
$(".current-fields").sortable();
var select = $("select#fields_to_show_for_pp");
$(".add-pp-field").on("click",function(){
var val = select.val(),
text = select.find("option:selected").text(),
li = null;
if(val != ""){
li = '<li class="clearfix" data-attrib-key="' + val + '"><span class="field-value">' + text + '</span><span class="remove-field"><i class="icon-remove-sign"></i></span></li>';
}
$("#modify_plugin_fields ul.current-fields").append(li);
})
$(document).on("click",".remove-field",function(){
$(this).parent().remove();
})
</script>
<% else %>
<h3>Page not found.</h3>
<% end %>

View File

@ -27,5 +27,7 @@ Rails.application.routes.draw do
resources :patent_types
end
get "/xhr/personal_patent/get_fields_for_index" => "personal_patents#get_fields_for_index"
post "/xhr/personal_patent/save_index_fields" => "personal_patents#save_index_fields"
end
end

View File

@ -4,7 +4,7 @@ module PersonalPatent
OrbitApp.registration "PersonalPatent",:type=> 'ModuleApp' do
module_label 'module_name.personal_patent'
base_url File.expand_path File.dirname(__FILE__)
personal_plugin :enable => true, :sort_number => '35', :app_name=>"Patent", :intro_app_name=>"PersonalPatentIntro",:path=>"/plugin/personal_patent/profile",:front_path=>"/profile",:admin_path=>"/admin/patents",:i18n=>'module_name.personal_patent', :module_app_name=>"PersonalPatent"
personal_plugin :enable => true, :sort_number => '35', :app_name=>"Patent", :intro_app_name=>"PersonalPatentIntro",:path=>"/plugin/personal_patent/profile",:front_path=>"/profile",:admin_path=>"/admin/patents",:i18n=>'module_name.personal_patent', :module_app_name=>"PersonalPatent", :field_modifiable => true
version "0.1"
desktop_enabled true