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

View File

@ -64,6 +64,9 @@ class Book
def self.get_plugin_datas_to_member(datas) def self.get_plugin_datas_to_member(datas)
page = Page.where(:module => "personal_book").first rescue nil page = Page.where(:module => "personal_book").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 = [
"authors", "authors",
"book_title", "book_title",
@ -72,6 +75,7 @@ class Book
"isbn", "isbn",
"publish_date" "publish_date"
] ]
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_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_types
resources :book_intros resources :book_intros
end 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
end end

View File

@ -4,7 +4,7 @@ module PersonalBook
OrbitApp.registration "PersonalBook",:type=> 'ModuleApp' do OrbitApp.registration "PersonalBook",:type=> 'ModuleApp' do
module_label 'module_name.book' module_label 'module_name.book'
base_url File.expand_path File.dirname(__FILE__) 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" version "0.1"
desktop_enabled true desktop_enabled true