fields modification implemented
This commit is contained in:
parent
66946f5a3c
commit
7bf694f717
|
@ -0,0 +1,101 @@
|
|||
class PersonalTechnologyTransfersController < ApplicationController
|
||||
def index
|
||||
params = OrbitHelper.params
|
||||
tts = TechnologyTransfer.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
|
||||
fields_to_show = Page.where(:page_id => params[:page_id]).first.custom_array_field rescue []
|
||||
|
||||
if fields_to_show.blank?
|
||||
fields_to_show = [
|
||||
"year",
|
||||
"title",
|
||||
"patent_title",
|
||||
"category",
|
||||
"patent_granted",
|
||||
"patent_number",
|
||||
"authors"
|
||||
]
|
||||
end
|
||||
|
||||
tts_list = []
|
||||
|
||||
tts.each do |tt|
|
||||
t = []
|
||||
fields_to_show.each do |fs|
|
||||
case fs
|
||||
when "title"
|
||||
t << {"value" => "<a href='#{OrbitHelper.url_to_show(tt.to_param)}'>" + (tt.send(fs) rescue "") + "</a>"}
|
||||
when "category"
|
||||
t << {"value" => (tt.send("technology_transfer_category").title rescue "")}
|
||||
when "authors"
|
||||
t << {"value" => (tt.send(:member_profile).name rescue "")}
|
||||
else
|
||||
t << {"value" => (tt.send(fs) rescue "")}
|
||||
end
|
||||
end
|
||||
tts_list << {"technology_transfers" => 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_technology_transfer.#{fs}")
|
||||
headers << {
|
||||
"head-title" => header,
|
||||
"col" => col
|
||||
}
|
||||
end
|
||||
{
|
||||
"tts" => tts_list,
|
||||
"extras" => { "widget-title" => t("module_name.personal_technology_transfer")},
|
||||
"headers" => headers,
|
||||
"total_pages" => tts.total_pages
|
||||
}
|
||||
end
|
||||
|
||||
def show
|
||||
params = OrbitHelper.params
|
||||
plugin = TechnologyTransfer.where(:is_hidden=>false).find_by(uid: params[:uid])
|
||||
fields_to_show = [
|
||||
"year",
|
||||
"title",
|
||||
"patent_title",
|
||||
"category",
|
||||
"patent_granted",
|
||||
"patent_number",
|
||||
"authors"
|
||||
]
|
||||
|
||||
{"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 = [
|
||||
"year",
|
||||
"title",
|
||||
"patent_title",
|
||||
"category",
|
||||
"patent_granted",
|
||||
"patent_number",
|
||||
"authors"
|
||||
]
|
||||
@fields_to_show = @fields_to_show.map{|fs| [(fs == "authors" ? t("users.name") : t("personal_technology_transfer.#{fs}")), fs]}
|
||||
@default_fields_to_show = [
|
||||
"category",
|
||||
"year",
|
||||
"title",
|
||||
"patent_granted",
|
||||
"patent_title",
|
||||
"patent_number"
|
||||
]
|
||||
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
|
|
@ -1,47 +0,0 @@
|
|||
class PersonalTechnologyTransfersController < ApplicationController
|
||||
def index
|
||||
tts = TechnologyTransfer.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
|
||||
tts_list = tts.collect do |tt|
|
||||
{
|
||||
"year" => tt.year,
|
||||
"title" => tt.title,
|
||||
"patent_title" => tt.patent_title,
|
||||
"category" => (tt.technology_transfer_category.title rescue ""),
|
||||
"patent_granted" => (tt.patent_granted ? "Yes" : "No"),
|
||||
"patent_number" => tt.patent_number,
|
||||
"authors" => (tt.member_profile.name rescue ""),
|
||||
"link_to_show" => OrbitHelper.url_to_show(tt.to_param)
|
||||
}
|
||||
end
|
||||
{
|
||||
"tts" => tts_list,
|
||||
"extras" => {
|
||||
"widget-title" => t("module_name.personal_technology_transfer"),
|
||||
"th_year" => t('personal_technology_transfer.year'),
|
||||
"th_title" => t("personal_technology_transfer.title"),
|
||||
"th_category" => t("personal_technology_transfer.category"),
|
||||
"th_patent_title" => t("personal_technology_transfer.patent_title"),
|
||||
"th_patent_granted" => t("personal_technology_transfer.patent_granted"),
|
||||
"th_patent_number" => t("personal_technology_transfer.patent_number"),
|
||||
"th_authors" => t('users.name')
|
||||
},
|
||||
"total_pages" => tts.total_pages
|
||||
}
|
||||
end
|
||||
|
||||
def show
|
||||
params = OrbitHelper.params
|
||||
plugin = TechnologyTransfer.where(:is_hidden=>false).find_by(uid: params[:uid])
|
||||
fields_to_show = [
|
||||
"year",
|
||||
"title",
|
||||
"patent_title",
|
||||
"technology_transfer_category",
|
||||
"patent_granted",
|
||||
"patent_number",
|
||||
"authors"
|
||||
]
|
||||
|
||||
{"plugin_datas"=>plugin.get_plugin_data(fields_to_show)}
|
||||
end
|
||||
end
|
|
@ -18,21 +18,28 @@ class TechnologyTransfer
|
|||
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year =>'desc') }
|
||||
|
||||
def self.get_plugin_datas_to_member(datas)
|
||||
page = Page.where(:module => "personal_technology_transfer").first rescue nil
|
||||
|
||||
fields_to_show = [
|
||||
"technology_transfer_category",
|
||||
"year",
|
||||
"title",
|
||||
"patent_granted",
|
||||
"patent_title",
|
||||
"patent_number"
|
||||
]
|
||||
if !page.nil? && !page.custom_array_field.blank?
|
||||
fields_to_show = page.custom_array_field
|
||||
else
|
||||
fields_to_show = [
|
||||
"category",
|
||||
"year",
|
||||
"title",
|
||||
"patent_granted",
|
||||
"patent_title",
|
||||
"patent_number",
|
||||
"authors"
|
||||
]
|
||||
end
|
||||
|
||||
fields_to_remove = []
|
||||
|
||||
pd_title = []
|
||||
|
||||
fields_to_show.each do |t|
|
||||
t = "technology_transfer_category" if t == "category"
|
||||
if (self.fields[t].type.to_s == "String" || self.fields[t].type.to_s == "Object" rescue false)
|
||||
fields_to_remove << t if (datas.where(t.to_sym.ne => nil, t.to_sym.ne => "").count == 0 rescue false)
|
||||
else
|
||||
|
@ -50,11 +57,13 @@ class TechnologyTransfer
|
|||
pd_data = []
|
||||
fields_to_show.collect do |t|
|
||||
if t == "title"
|
||||
pd_data << { "data_title" => "<a href='#{OrbitHelper.url_to_plugin_show(p.to_param,'personal_technology_transfer')}' target='_blank'>#{p.send(t)}" }
|
||||
elsif t == "technology_transfer_category"
|
||||
pd_data << {"data_title" => (p.technology_transfer_category.title rescue "")}
|
||||
pd_data << { "data_title" => "<a href='#{OrbitHelper.url_to_plugin_show(p.to_param,'personal_technology_transfer')}' target='_blank'>#{p.send(t)}" }
|
||||
elsif t == "category"
|
||||
pd_data << {"data_title" => (p.technology_transfer_category.title rescue "")}
|
||||
elsif t == "patent_granted"
|
||||
pd_data << {"data_title" => (p.patent_granted ? "Yes" : "No")}
|
||||
pd_data << {"data_title" => (p.patent_granted ? "Yes" : "No")}
|
||||
elsif t == "authors"
|
||||
pd_data << {"data_title" => (p.member_profile.name rescue "")}
|
||||
else
|
||||
pd_data << { "data_title" => p.send(t) }
|
||||
end
|
||||
|
|
|
@ -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"><%= t("personal_technology_transfer.#{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"><%= t("personal_technology_transfer.#{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 %>
|
|
@ -24,5 +24,7 @@ Rails.application.routes.draw do
|
|||
resources :technology_transfer_categories
|
||||
post "technology_transfer_categories/update_order" => "technology_transfer_categories#update_order"
|
||||
end
|
||||
get "/xhr/personal_technology_transfer/get_fields_for_index" => "personal_technology_transfers#get_fields_for_index"
|
||||
post "/xhr/personal_technology_transfer/save_index_fields" => "personal_technology_transfers#save_index_fields"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ module PersonalTechnologyTransfer
|
|||
OrbitApp.registration "PersonalTechnologyTransfer",:type=> 'ModuleApp' do
|
||||
module_label 'module_name.technology_transfers'
|
||||
base_url File.expand_path File.dirname(__FILE__)
|
||||
personal_plugin :enable => true, :sort_number => '35', :app_name=>"TechnologyTransfer", :intro_app_name=>"TechnologyTransferIntro",:path=>"/plugin/personal_technology_transfer/profile",:front_path=>"/profile",:admin_path=>"/admin/technology_transfers/",:i18n=>'module_name.technology_transfers', :module_app_name=>'TechnologyTransfer'
|
||||
personal_plugin :enable => true, :sort_number => '35', :app_name=>"TechnologyTransfer", :intro_app_name=>"TechnologyTransferIntro",:path=>"/plugin/personal_technology_transfer/profile",:front_path=>"/profile",:admin_path=>"/admin/technology_transfers/",:i18n=>'module_name.technology_transfers', :module_app_name=>'TechnologyTransfer', :field_modifiable => true
|
||||
|
||||
version "0.1"
|
||||
desktop_enabled true
|
||||
|
|
Loading…
Reference in New Issue