field now modifiable

This commit is contained in:
Harry Bomrah 2016-04-01 13:56:20 +08:00
parent 4c89ab3a62
commit 083c3bef7c
5 changed files with 103 additions and 33 deletions

View File

@ -5,6 +5,7 @@ class PersonalBooksController < ApplicationController
page = Page.where(:page_id => params[:page_id]).first rescue nil
if page.custom_string_field == "table"
fields_to_show = page.custom_array_field rescue []
fields_to_show = [
"authors",
"book_title",
@ -12,7 +13,7 @@ class PersonalBooksController < ApplicationController
"publisher",
"isbn",
"publish_date"
]
] if fields_to_show.blank?
else
fields_to_show = [
"year",
@ -79,34 +80,49 @@ class PersonalBooksController < ApplicationController
"number_of_authors",
"isbn",
"url",
"file",
"publication_date",
"language"
]
{"plugin_datas"=>plugin.get_plugin_data(fields_to_show)}
end
# publication_date = book.publication_date.to_date.strftime("%Y/%m/%d") rescue nil
# publish_date = book.publish_date.to_date.strftime("%Y/%m/%d") rescue nil
# files = book.book_files.map{|file| { "file_url" => file.member_book_file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title) } } rescue []
# {
# "book_files" => files,
# "data" => {
# "title" => book.book_title,
# "year" => book.year,
# "authors" => book.authors,
# "isbn" => book.isbn,
# "language" => book.language,
# "pages" => book.pages,
# "keywords" => book.keywords,
# "publication_date" => publication_date ,
# "url" => book.url,
# "note" => book.note,
# "extracted_chapters" => book.extracted_chapters,
# "publish_date" => publish_date,
# "publisher" => book.publisher,
# "editor" => book.editor
# }
# }
def get_fields_for_index
@page = Page.find(params[:page_id]) rescue nil
@fields_to_show = [
"year",
"book_title",
"authors",
"book_paper_type",
"extracted_chapters",
"publisher",
"publish_date",
"pages",
"editor",
"author_type",
"number_of_authors",
"isbn",
"url",
"file",
"publication_date",
"language"
]
@fields_to_show = @fields_to_show.map{|fs| [t("personal_book.#{fs}"), fs]}
@default_fields_to_show = [
"authors",
"book_title",
"extracted_chapters",
"publisher",
"isbn",
"publish_date"
]
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

@ -64,14 +64,18 @@ class Book
def self.get_plugin_datas_to_member(datas)
page = Page.where(:module => "personal_book").first rescue nil
if !page.nil? && page.custom_string_field == "table"
fields_to_show = [
"authors",
"book_title",
"extracted_chapters",
"publisher",
"isbn",
"publish_date"
]
if !page.custom_array_field.blank?
fields_to_show = page.custom_array_field
else
fields_to_show = [
"authors",
"book_title",
"extracted_chapters",
"publisher",
"isbn",
"publish_date"
]
end
else
fields_to_show = [
"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_book.#{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_book.#{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

@ -28,5 +28,7 @@ Rails.application.routes.draw do
resources :book_types
resources :book_intros
end
get "/xhr/personal_book/get_fields_for_index" => "personal_books#get_fields_for_index"
post "/xhr/personal_book/save_index_fields" => "personal_books#save_index_fields"
end
end

View File

@ -4,7 +4,7 @@ module PersonalBook
OrbitApp.registration "PersonalBook",:type=> 'ModuleApp' do
module_label 'module_name.book'
base_url File.expand_path File.dirname(__FILE__)
personal_plugin :enable => true, :sort_number => '25', :app_name=>"Book", :intro_app_name=>"BookIntro",:path=>"/plugin/personal_book/profile",:front_path=>"/profile",:admin_path=>"/admin/books",:i18n=>'module_name.book',:module_app_name=>'PersonalBook', :one_line_title => true
personal_plugin :enable => true, :sort_number => '25', :app_name=>"Book", :intro_app_name=>"BookIntro",:path=>"/plugin/personal_book/profile",:front_path=>"/profile",:admin_path=>"/admin/books",:i18n=>'module_name.book',:module_app_name=>'PersonalBook', :one_line_title => true, :field_modifiable => true
version "0.1"
desktop_enabled true