field modifiable now

This commit is contained in:
Harry Bomrah 2016-04-01 13:57:16 +08:00
parent bec2551b57
commit efe0e57d7b
5 changed files with 112 additions and 11 deletions

View File

@ -4,6 +4,7 @@ class PersonalJournalsController < ApplicationController
journal_papers = JournalPaper.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) journal_papers = JournalPaper.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
page = Page.where(:page_id => params[:page_id]).first rescue nil page = Page.where(:page_id => params[:page_id]).first rescue nil
if page.custom_string_field == "table" if page.custom_string_field == "table"
fields_to_show = page.custom_array_field rescue []
fields_to_show = [ fields_to_show = [
"paper_title", "paper_title",
"journal_title", "journal_title",
@ -12,7 +13,7 @@ class PersonalJournalsController < ApplicationController
"issue_no", "issue_no",
"vol_no", "vol_no",
"level_type" "level_type"
] ] if fields_to_show.blank?
else else
fields_to_show = [ fields_to_show = [
"year", "year",
@ -32,6 +33,8 @@ class PersonalJournalsController < ApplicationController
end end
when "level_type" when "level_type"
t << {"value" => ( !journal_paper.journal_levels.blank? ? "(#{journal_paper.journal_levels.collect{|x| x.title}.join(', ')})" : nil)} t << {"value" => ( !journal_paper.journal_levels.blank? ? "(#{journal_paper.journal_levels.collect{|x| x.title}.join(', ')})" : nil)}
when "publication_date"
t << {"value" => (journal_paper.send(fs).strftime("%Y/%m/%d") rescue "")}
else else
t << {"value" => journal_paper.send(fs)} t << {"value" => journal_paper.send(fs)}
end end
@ -84,4 +87,44 @@ class PersonalJournalsController < ApplicationController
{"plugin_datas"=>plugin.get_plugin_data(fields_to_show)} {"plugin_datas"=>plugin.get_plugin_data(fields_to_show)}
end end
def get_fields_for_index
@page = Page.find(params[:page_id]) rescue nil
@fields_to_show = [
"year",
"authors",
"author_type",
"paper_title",
"journal_title",
"vol_no",
"issue_no",
"form_to_start",
"form_to_end",
"level_type",
"paper_type",
"total_pages",
"publication_date",
"isbn",
"abstract",
"language",
"url"
]
@fields_to_show = @fields_to_show.map{|fs| [t("personal_journal.#{fs}"), fs]}
@default_fields_to_show = [
"paper_title",
"journal_title",
"authors",
"year",
"issue_no",
"vol_no",
"level_type"
]
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 end

View File

@ -73,6 +73,9 @@ class JournalPaper
page = Page.where(:module => "personal_journal").first rescue nil page = Page.where(:module => "personal_journal").first rescue nil
if !page.nil? && page.custom_string_field == "table" if !page.nil? && page.custom_string_field == "table"
if !page.custom_array_field.blank?
fields_to_show = page.custom_array_field
else
fields_to_show = [ fields_to_show = [
"paper_title", "paper_title",
"journal_title", "journal_title",
@ -82,6 +85,7 @@ class JournalPaper
"vol_no", "vol_no",
"level_type" "level_type"
] ]
end
else else
fields_to_show = [ fields_to_show = [
"year", "year",
@ -116,6 +120,8 @@ class JournalPaper
pd_data << { "data_title" => "<a href='#{OrbitHelper.url_to_plugin_show(p.to_param,'personal_journal')}' target='_blank'>#{p.paper_title}</a>" } pd_data << { "data_title" => "<a href='#{OrbitHelper.url_to_plugin_show(p.to_param,'personal_journal')}' target='_blank'>#{p.paper_title}</a>" }
when "level_type" when "level_type"
pd_data << {"data_title" => ( !p.journal_levels.blank? ? "(#{p.journal_levels.collect{|x| x.title}.join(', ')})" : nil)} pd_data << {"data_title" => ( !p.journal_levels.blank? ? "(#{p.journal_levels.collect{|x| x.title}.join(', ')})" : nil)}
when "publication_date"
pd_data << {"data_title" => (p.send(t).strftime("%Y/%m/%d") rescue "")}
else else
pd_data << {"data_title" => p.send(t)} pd_data << {"data_title" => p.send(t)}
end end
@ -183,6 +189,8 @@ class JournalPaper
value = self.journal_paper_author_types.collect{|type| type.title}.join(',') rescue "" value = self.journal_paper_author_types.collect{|type| type.title}.join(',') rescue ""
when "paper_type" when "paper_type"
value = self.journal_paper_type.title rescue "" value = self.journal_paper_type.title rescue ""
when "publication_date"
value = p.send(t).strftime("%Y/%m/%d") rescue ""
when "author_name" when "author_name"
value = [] value = []
([I18n.locale]+(Site.first.in_use_locales-[I18n.locale])).each do |locale| ([I18n.locale]+(Site.first.in_use_locales-[I18n.locale])).each do |locale|

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"><%= t("personal_journal.#{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_journal.#{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

@ -30,5 +30,7 @@ Rails.application.routes.draw do
resources :journal_paper_types resources :journal_paper_types
resources :journal_paper_intros resources :journal_paper_intros
end end
get "/xhr/personal_journal/get_fields_for_index" => "personal_journals#get_fields_for_index"
post "/xhr/personal_journal/save_index_fields" => "personal_journals#save_index_fields"
end end
end end

View File

@ -4,7 +4,7 @@ module PersonalJournal
OrbitApp.registration "PersonalJournal",:type=> 'ModuleApp' do OrbitApp.registration "PersonalJournal",:type=> 'ModuleApp' do
module_label 'module_name.journal_paper' module_label 'module_name.journal_paper'
base_url File.expand_path File.dirname(__FILE__) base_url File.expand_path File.dirname(__FILE__)
personal_plugin :enable => true, :sort_number => '5', :app_name=>"JournalPaper", :intro_app_name=>"JournalPaperlIntro",:path=>"/plugin/personal_journal/profile",:front_path=>"/profile",:admin_path=>"/admin/journal_papers/",:i18n=>'module_name.journal_paper', :module_app_name=>'PersonalJournal', :one_line_title => true personal_plugin :enable => true, :sort_number => '5', :app_name=>"JournalPaper", :intro_app_name=>"JournalPaperlIntro",:path=>"/plugin/personal_journal/profile",:front_path=>"/profile",:admin_path=>"/admin/journal_papers/",:i18n=>'module_name.journal_paper', :module_app_name=>'PersonalJournal', :one_line_title => true, :field_modifiable => true
version "0.1" version "0.1"
desktop_enabled true desktop_enabled true