diff --git a/app/controllers/personal_books_controller.rb b/app/controllers/personal_books_controller.rb
index fd654f9..b40b0af 100644
--- a/app/controllers/personal_books_controller.rb
+++ b/app/controllers/personal_books_controller.rb
@@ -1,24 +1,63 @@
class PersonalBooksController < ApplicationController
def index
+ params = OrbitHelper.params
books = Book.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
- book_list = books.collect do |book|
- {
- "book_title" => book.create_link,
- "author" => book.authors,
- "year" => book.year,
- "book_paper_type" => (book.book_type.title rescue nil),
- "link_to_show" => OrbitHelper.url_to_show(book.to_param)
+ page = Page.where(:page_id => params[:page_id]).first rescue nil
+
+ if page.custom_string_field == "table"
+ fields_to_show = [
+ "authors",
+ "book_title",
+ "extracted_chapters",
+ "publisher",
+ "isbn",
+ "publish_date"
+ ]
+ else
+ fields_to_show = [
+ "year",
+ "book_title"
+ ]
+ end
+
+ book_list = []
+ books.each do |book|
+ t = []
+ fields_to_show.each do |fs|
+ case fs
+ when "book_title"
+ if page.custom_string_field == "table"
+ t << {"value" => "#{book.book_title}"}
+ else
+ t << {"value" => "#{book.create_link}"}
+ end
+ when "publish_date"
+ pd = ""
+ if !book.publish_date.nil?
+ pd = book.publish_date.strftime("%Y-%m-%d").split('-')
+ pd = pd[0]+"/"+pd[1]
+ end
+ t << {"value" => pd}
+ else
+ t << {"value" => book.send(fs)}
+ end
+ end
+ book_list << {"books" => t}
+ end
+
+ headers = []
+ fields_to_show.each do |fs|
+ col = 2
+ col = 3 if fs == "paper_title"
+ headers << {
+ "head-title" => t("personal_book.#{fs}"),
+ "col" => col
}
end
{
- "books" => book_list,
- "extras" => {
- "widget-title" => t("module_name.book"),
- "th_year" => t('personal_plugins.year'),
- "th_title" => t("personal_book.book_title"),
- "th_book_paper_type" => t("personal_book.book_paper_type"),
- "th_author" => t('personal_book.authors')
- },
+ "book_list" => book_list,
+ "extras" => {"widget-title" => t("module_name.book")},
+ "headers" => headers,
"total_pages" => books.total_pages
}
end
diff --git a/app/models/book.rb b/app/models/book.rb
index 5f8b929..f2f25b6 100644
--- a/app/models/book.rb
+++ b/app/models/book.rb
@@ -62,10 +62,22 @@ class Book
end
def self.get_plugin_datas_to_member(datas)
- fields_to_show = [
- "year",
- "book_title"
- ]
+ page = Page.where(:module => "personal_book").first rescue nil
+ if page.custom_string_field == "table"
+ fields_to_show = [
+ "authors",
+ "book_title",
+ "extracted_chapters",
+ "publisher",
+ "isbn",
+ "publish_date"
+ ]
+ else
+ fields_to_show = [
+ "year",
+ "book_title"
+ ]
+ end
fields_to_remove = []
@@ -88,10 +100,26 @@ class Book
pd_data = []
fields_to_show.collect do |t|
- if t == "book_title"
- pd_data << { "data_title" => "#{p.create_link}" }
+ if page.custom_string_field == "table"
+ case t
+ when "book_title"
+ pd_data << { "data_title" => "#{p.book_title}" }
+ when "publish_date"
+ pd = ""
+ if !p.publish_date.nil?
+ pd = p.publish_date.strftime("%Y-%m-%d").split('-')
+ pd = pd[0]+"/"+pd[1]
+ end
+ pd_data << {"data_title" => pd}
+ else
+ pd_data << { "data_title" => p.send(t) }
+ end
else
- pd_data << { "data_title" => p.send(t) }
+ if t == "book_title"
+ pd_data << { "data_title" => "#{p.create_link}" }
+ else
+ pd_data << { "data_title" => p.send(t) }
+ end
end
end
diff --git a/lib/personal_book/engine.rb b/lib/personal_book/engine.rb
index 799829f..81877c4 100644
--- a/lib/personal_book/engine.rb
+++ b/lib/personal_book/engine.rb
@@ -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'
+ 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
version "0.1"
desktop_enabled true