fields now modifiable

This commit is contained in:
Harry Bomrah 2016-04-01 13:58:56 +08:00
parent ac35478326
commit a1a4a53ffd
5 changed files with 108 additions and 10 deletions

View File

@ -4,6 +4,7 @@ class PersonalConferencesController < ApplicationController
writing_conferences = WritingConference.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) writing_conferences = WritingConference.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 = [
"authors", "authors",
"paper_title", "paper_title",
@ -11,7 +12,7 @@ class PersonalConferencesController < ApplicationController
"location", "location",
"paper_types", "paper_types",
"paper_levels" "paper_levels"
] ] if fields_to_show.blank?
else else
fields_to_show = [ fields_to_show = [
"year", "year",
@ -34,6 +35,8 @@ class PersonalConferencesController < ApplicationController
t << {"value" => ( !writing_conference.conference_paper_levels.blank? ? "(#{writing_conference.conference_paper_levels.collect{|x| x.title}.join(', ')})" : nil)} t << {"value" => ( !writing_conference.conference_paper_levels.blank? ? "(#{writing_conference.conference_paper_levels.collect{|x| x.title}.join(', ')})" : nil)}
when "paper_types" when "paper_types"
t << {"value" => ( !writing_conference.conference_paper_levels.blank? ? "(#{writing_conference.conference_paper_levels.collect{|x| x.title}.join(', ')})" : nil)} t << {"value" => ( !writing_conference.conference_paper_levels.blank? ? "(#{writing_conference.conference_paper_levels.collect{|x| x.title}.join(', ')})" : nil)}
when "publication_date"
t << {"value" => (writing_conference.send(fs).strftime("%Y/%m/%d") rescue "")}
else else
t << {"value" => writing_conference.send(fs)} t << {"value" => writing_conference.send(fs)}
end end
@ -87,4 +90,45 @@ class PersonalConferencesController < 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",
"paper_title",
"conference_title",
"location",
"period_start_date",
"period_end_date",
"paper_type",
"paper_level",
"sponsor",
"author_type",
"number_of_authors",
"abstract",
"url",
"publication_date",
"isbn",
"isi_number" ,
"language"
]
@fields_to_show = @fields_to_show.map{|fs| [t("personal_conference.#{fs}"), fs]}
@default_fields_to_show = [
"authors",
"paper_title",
"conference_title",
"location",
"paper_types",
"paper_levels"
]
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

@ -69,14 +69,18 @@ class WritingConference
def self.get_plugin_datas_to_member(datas) def self.get_plugin_datas_to_member(datas)
page = Page.where(:module => "personal_conference").first rescue nil page = Page.where(:module => "personal_conference").first rescue nil
if !page.nil? && page.custom_string_field == "table" if !page.nil? && page.custom_string_field == "table"
fields_to_show = [ if !page.custom_array_field.blank?
"authors", fields_to_show = page.custom_array_field
"paper_title", else
"conference_title", fields_to_show = [
"location", "authors",
"paper_types", "paper_title",
"paper_levels" "conference_title",
] "location",
"paper_types",
"paper_levels"
]
end
else else
fields_to_show = [ fields_to_show = [
"year", "year",

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_conference.#{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_conference.#{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 :conference_author_types resources :conference_author_types
resources :tags resources :tags
end end
get "/xhr/personal_conference/get_fields_for_index" => "personal_conferences#get_fields_for_index"
post "/xhr/personal_conference/save_index_fields" => "personal_conferences#save_index_fields"
end end
end end

View File

@ -4,7 +4,7 @@ module PersonalConference
OrbitApp.registration "PersonalConference",:type=> 'ModuleApp' do OrbitApp.registration "PersonalConference",:type=> 'ModuleApp' do
module_label 'module_name.personal_conference' module_label 'module_name.personal_conference'
base_url File.expand_path File.dirname(__FILE__) base_url File.expand_path File.dirname(__FILE__)
personal_plugin :enable => true, :sort_number => '6', :app_name=>"WritingConference", :intro_app_name=>"PersonalConferenceIntro",:path=>"/plugin/personal_conference/profile",:front_path=>"/profile",:admin_path=>"/admin/writing_conferences",:i18n=>'module_name.personal_conference', :module_app_name=>'PersonalConference', :one_line_title => true personal_plugin :enable => true, :sort_number => '6', :app_name=>"WritingConference", :intro_app_name=>"PersonalConferenceIntro",:path=>"/plugin/personal_conference/profile",:front_path=>"/profile",:admin_path=>"/admin/writing_conferences",:i18n=>'module_name.personal_conference', :module_app_name=>'PersonalConference', :one_line_title => true, :field_modifiable => true
version "0.1" version "0.1"
desktop_enabled true desktop_enabled true