From 9db8ae9281264e5066f168c86b968b20f4684778 Mon Sep 17 00:00:00 2001 From: Saurabh Bhatia Date: Thu, 3 Jul 2014 15:48:28 +0800 Subject: [PATCH] Personal book module with frontend - modal needs fix --- .../javascripts/admin/book_author_types.js | 2 + app/assets/javascripts/admin/book_intros.js | 2 + app/assets/javascripts/admin/book_types.js | 2 + app/assets/javascripts/admin/books.js | 2 + app/assets/javascripts/books.js | 2 + .../stylesheets/admin/book_author_types.css | 4 + app/assets/stylesheets/admin/book_intros.css | 4 + app/assets/stylesheets/admin/book_types.css | 4 + app/assets/stylesheets/admin/books.css | 4 + app/assets/stylesheets/books.css | 4 + .../admin/book_author_types_controller.rb | 50 +++ .../admin/book_intros_controller.rb | 8 + .../admin/book_types_controller.rb | 50 +++ app/controllers/admin/books_controller.rb | 165 +++++++++ app/controllers/books_controller.rb | 43 +++ app/helpers/admin/book_author_types_helper.rb | 2 + app/helpers/admin/book_intros_helper.rb | 2 + app/helpers/admin/book_types_helper.rb | 2 + app/helpers/admin/books_helper.rb | 9 + app/helpers/books_helper.rb | 2 + app/models/book.rb | 94 +++++ app/models/book_author.rb | 14 + app/models/book_author_type.rb | 11 + app/models/book_file.rb | 12 + app/models/book_intro.rb | 3 + app/models/book_type.rb | 11 + .../create_book_setting.js.erb | 2 + .../delete_book_setting.js.erb | 3 + .../update_book_setting.js.erb | 2 + .../book_types/create_book_setting.js.erb | 2 + .../book_types/delete_book_setting.js.erb | 3 + .../book_types/update_book_setting.js.erb | 2 + .../admin/books/_author_autocomplete.html.erb | 33 ++ .../admin/books/_author_type_qe.html.erb | 33 ++ app/views/admin/books/_book_type_qe.html.erb | 34 ++ app/views/admin/books/_form.html.erb | 344 ++++++++++++++++++ app/views/admin/books/_form_author.html.erb | 39 ++ app/views/admin/books/_form_file.html.erb | 45 +++ .../admin/books/_list_author_type.html.erb | 11 + .../admin/books/_list_book_type.html.erb | 10 + app/views/admin/books/_writing_book.html.erb | 15 + app/views/admin/books/add_author_type.js.erb | 1 + app/views/admin/books/add_book_type.js.erb | 1 + app/views/admin/books/book_setting.html.erb | 110 ++++++ .../admin/books/create_book_setting.js.erb | 9 + app/views/admin/books/destroy.js.erb | 1 + app/views/admin/books/edit.html.erb | 15 + app/views/admin/books/edit_author_type.js.erb | 1 + app/views/admin/books/edit_book_type.js.erb | 1 + app/views/admin/books/index.html.erb | 27 ++ app/views/admin/books/new.html.erb | 15 + .../admin/books/update_book_setting.js.erb | 9 + app/views/books/index.html.erb | 1 + app/views/books/show.html.erb | 1 + app/views/plugin/book/_profile.html.erb | 108 ++++++ config/locales/en.yml | 6 +- config/locales/zh_tw.yml | 3 +- config/routes.rb | 17 +- lib/personal_book/engine.rb | 9 +- .../book_author_types_controller_test.rb | 9 + .../admin/book_intros_controller_test.rb | 7 + .../admin/book_types_controller_test.rb | 7 + .../admin/books_controller_test.rb | 9 + test/controllers/books_controller_test.rb | 14 + test/fixtures/book_author_types.yml | 11 + test/fixtures/book_authors.yml | 11 + test/fixtures/book_files.yml | 11 + test/fixtures/book_intros.yml | 11 + test/fixtures/book_types.yml | 11 + test/fixtures/books.yml | 31 ++ .../admin/book_author_types_helper_test.rb | 4 + test/helpers/admin/book_intros_helper_test.rb | 4 + test/helpers/admin/book_types_helper_test.rb | 4 + test/helpers/admin/books_helper_test.rb | 4 + test/helpers/books_helper_test.rb | 4 + test/models/book_author_test.rb | 7 + test/models/book_author_type_test.rb | 7 + test/models/book_file_test.rb | 7 + test/models/book_intro_test.rb | 7 + test/models/book_test.rb | 7 + test/models/book_type_test.rb | 7 + 81 files changed, 1607 insertions(+), 8 deletions(-) create mode 100644 app/assets/javascripts/admin/book_author_types.js create mode 100644 app/assets/javascripts/admin/book_intros.js create mode 100644 app/assets/javascripts/admin/book_types.js create mode 100644 app/assets/javascripts/admin/books.js create mode 100644 app/assets/javascripts/books.js create mode 100644 app/assets/stylesheets/admin/book_author_types.css create mode 100644 app/assets/stylesheets/admin/book_intros.css create mode 100644 app/assets/stylesheets/admin/book_types.css create mode 100644 app/assets/stylesheets/admin/books.css create mode 100644 app/assets/stylesheets/books.css create mode 100644 app/controllers/admin/book_author_types_controller.rb create mode 100644 app/controllers/admin/book_intros_controller.rb create mode 100644 app/controllers/admin/book_types_controller.rb create mode 100644 app/controllers/admin/books_controller.rb create mode 100644 app/controllers/books_controller.rb create mode 100644 app/helpers/admin/book_author_types_helper.rb create mode 100644 app/helpers/admin/book_intros_helper.rb create mode 100644 app/helpers/admin/book_types_helper.rb create mode 100644 app/helpers/admin/books_helper.rb create mode 100644 app/helpers/books_helper.rb create mode 100644 app/models/book.rb create mode 100644 app/models/book_author.rb create mode 100644 app/models/book_author_type.rb create mode 100644 app/models/book_file.rb create mode 100644 app/models/book_intro.rb create mode 100644 app/models/book_type.rb create mode 100644 app/views/admin/book_author_types/create_book_setting.js.erb create mode 100644 app/views/admin/book_author_types/delete_book_setting.js.erb create mode 100644 app/views/admin/book_author_types/update_book_setting.js.erb create mode 100644 app/views/admin/book_types/create_book_setting.js.erb create mode 100644 app/views/admin/book_types/delete_book_setting.js.erb create mode 100644 app/views/admin/book_types/update_book_setting.js.erb create mode 100644 app/views/admin/books/_author_autocomplete.html.erb create mode 100644 app/views/admin/books/_author_type_qe.html.erb create mode 100644 app/views/admin/books/_book_type_qe.html.erb create mode 100644 app/views/admin/books/_form.html.erb create mode 100644 app/views/admin/books/_form_author.html.erb create mode 100644 app/views/admin/books/_form_file.html.erb create mode 100644 app/views/admin/books/_list_author_type.html.erb create mode 100644 app/views/admin/books/_list_book_type.html.erb create mode 100644 app/views/admin/books/_writing_book.html.erb create mode 100644 app/views/admin/books/add_author_type.js.erb create mode 100644 app/views/admin/books/add_book_type.js.erb create mode 100644 app/views/admin/books/book_setting.html.erb create mode 100644 app/views/admin/books/create_book_setting.js.erb create mode 100644 app/views/admin/books/destroy.js.erb create mode 100644 app/views/admin/books/edit.html.erb create mode 100644 app/views/admin/books/edit_author_type.js.erb create mode 100644 app/views/admin/books/edit_book_type.js.erb create mode 100644 app/views/admin/books/index.html.erb create mode 100644 app/views/admin/books/new.html.erb create mode 100644 app/views/admin/books/update_book_setting.js.erb create mode 100644 app/views/books/index.html.erb create mode 100644 app/views/books/show.html.erb create mode 100644 app/views/plugin/book/_profile.html.erb create mode 100644 test/controllers/admin/book_author_types_controller_test.rb create mode 100644 test/controllers/admin/book_intros_controller_test.rb create mode 100644 test/controllers/admin/book_types_controller_test.rb create mode 100644 test/controllers/admin/books_controller_test.rb create mode 100644 test/controllers/books_controller_test.rb create mode 100644 test/fixtures/book_author_types.yml create mode 100644 test/fixtures/book_authors.yml create mode 100644 test/fixtures/book_files.yml create mode 100644 test/fixtures/book_intros.yml create mode 100644 test/fixtures/book_types.yml create mode 100644 test/fixtures/books.yml create mode 100644 test/helpers/admin/book_author_types_helper_test.rb create mode 100644 test/helpers/admin/book_intros_helper_test.rb create mode 100644 test/helpers/admin/book_types_helper_test.rb create mode 100644 test/helpers/admin/books_helper_test.rb create mode 100644 test/helpers/books_helper_test.rb create mode 100644 test/models/book_author_test.rb create mode 100644 test/models/book_author_type_test.rb create mode 100644 test/models/book_file_test.rb create mode 100644 test/models/book_intro_test.rb create mode 100644 test/models/book_test.rb create mode 100644 test/models/book_type_test.rb diff --git a/app/assets/javascripts/admin/book_author_types.js b/app/assets/javascripts/admin/book_author_types.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/app/assets/javascripts/admin/book_author_types.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/admin/book_intros.js b/app/assets/javascripts/admin/book_intros.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/app/assets/javascripts/admin/book_intros.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/admin/book_types.js b/app/assets/javascripts/admin/book_types.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/app/assets/javascripts/admin/book_types.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/admin/books.js b/app/assets/javascripts/admin/books.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/app/assets/javascripts/admin/books.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/books.js b/app/assets/javascripts/books.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/app/assets/javascripts/books.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/admin/book_author_types.css b/app/assets/stylesheets/admin/book_author_types.css new file mode 100644 index 0000000..afad32d --- /dev/null +++ b/app/assets/stylesheets/admin/book_author_types.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/app/assets/stylesheets/admin/book_intros.css b/app/assets/stylesheets/admin/book_intros.css new file mode 100644 index 0000000..afad32d --- /dev/null +++ b/app/assets/stylesheets/admin/book_intros.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/app/assets/stylesheets/admin/book_types.css b/app/assets/stylesheets/admin/book_types.css new file mode 100644 index 0000000..afad32d --- /dev/null +++ b/app/assets/stylesheets/admin/book_types.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/app/assets/stylesheets/admin/books.css b/app/assets/stylesheets/admin/books.css new file mode 100644 index 0000000..afad32d --- /dev/null +++ b/app/assets/stylesheets/admin/books.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/app/assets/stylesheets/books.css b/app/assets/stylesheets/books.css new file mode 100644 index 0000000..afad32d --- /dev/null +++ b/app/assets/stylesheets/books.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/app/controllers/admin/book_author_types_controller.rb b/app/controllers/admin/book_author_types_controller.rb new file mode 100644 index 0000000..1135803 --- /dev/null +++ b/app/controllers/admin/book_author_types_controller.rb @@ -0,0 +1,50 @@ +class Admin::BookAuthorTypesController < ApplicationController + before_action :set_book_author_type, only: [:edit, :update, :destroy] + + def initialize + super + @app_type = 'book_author_type' + end + + def new + @book_author_type = BookAuthorType.new + end + + def edit + end + + def create + @book_author_type = BookAuthorType.new(book_author_type_attributes) + + respond_to do |format| + if @book_author_type.save + format.js { render 'create_book_setting' } + end + end + end + + def update + respond_to do |format| + if @book_author_type.update_attributes(book_author_type_attributes) + format.js { render 'update_book_setting' } + end + end + end + + def destroy + @book_author_type.destroy + respond_to do |format| + format.js { render 'delete_book_setting' } + end + end + + private + + def set_book_author_type + @book_author_type = BookAuthorType.find(params[:id]) + end + + def book_author_type_attributes + params.require(:book_author_type).permit! rescue nil + end +end diff --git a/app/controllers/admin/book_intros_controller.rb b/app/controllers/admin/book_intros_controller.rb new file mode 100644 index 0000000..c852824 --- /dev/null +++ b/app/controllers/admin/book_intros_controller.rb @@ -0,0 +1,8 @@ +class Admin::BookIntrosController < Admin::PersonalPluginIntrosController + def initialize + super + @app_type = 'book_intro' + @app_type_name = 'book_paper' + @reback_name = 'Book' + end +end diff --git a/app/controllers/admin/book_types_controller.rb b/app/controllers/admin/book_types_controller.rb new file mode 100644 index 0000000..488dc13 --- /dev/null +++ b/app/controllers/admin/book_types_controller.rb @@ -0,0 +1,50 @@ +class Admin::BookTypesController < ApplicationController + before_action :set_book_type, only: [:edit, :update, :destroy] + + def initialize + super + @app_type = 'book_type' + end + + def new + @book_type = BookType.new + end + + def edit + end + + def create + @book_type = BookType.new(book_type_attributes) + respond_to do |format| + if @book_type.save + format.js { render 'create_book_setting' } + end + end + end + + def update + respond_to do |format| + if @book_type.update_attributes(book_type_attributes) + format.js { render 'update_book_setting' } + end + end + end + + def destroy + @book_type.destroy + respond_to do |format| + format.js { render 'delete_book_setting' } + end + end + + private + + def set_book_type + @book_type = BookType.find(params[:id]) + end + + def book_type_attributes + params.require(:book_type).permit! rescue nil + end + +end diff --git a/app/controllers/admin/books_controller.rb b/app/controllers/admin/books_controller.rb new file mode 100644 index 0000000..2e144b8 --- /dev/null +++ b/app/controllers/admin/books_controller.rb @@ -0,0 +1,165 @@ +class Admin::BooksController < OrbitMemberController + include Admin::JournalPapersHelper + + before_action :set_book, only: [:show, :edit , :update, :destroy] + before_action :get_plugins, only: [:index, :book_setting, :new, :create, :edit, :update] + before_action :set_types, only: [:index,:book_setting, :new, :edit, :create, :update] + + def index + @writing_books = Book.all + respond_to do |format| + format.html # index.html.erb + format.js { } + format.xml { render :xml => @books } + end + end + + def show + respond_to do |format| + format.html # show.html.erb + format.xml { render :xml => @book } + end + end + + def edit + @members_data = Book.member_data rescue nil + end + + def update + @book_authors = @book.book_authors + + respond_to do |format| + if @book.update_attributes(book_attributes) + format.html { redirect_to admin_books_path } + format.xml { head :ok } + else + format.html { render action: "edit" } + format.xml { render :xml => @book.errors, :status => :unprocessable_entity } + end + end + end + + def new + @book = Book.new + @members_data = Book.member_data rescue nil + + respond_to do |format| + format.html # new.html.erb + format.xml { render :xml => @book } + end + end + + def create + @book = Book.new(book_attributes) + respond_to do |format| + if @book.save + format.html { redirect_to admin_books_path } + format.xml { render :xml => @book, :status => :created, :location => @book } + else + format.html { render action: "new" } + format.xml { render :xml => @book.errors, :status => :unprocessable_entity } + end + end + end + + def book_setting + @set_author_type = BookAuthorType.new(display: 'List') + @author_type_url = admin_books_path + + @set_book_type = BookType.new(display: 'List') + @book_type_url = admin_books_path + end + + def destroy + @book.destroy + + respond_to do |format| + format.html { redirect_to(admin_books_url) } + format.js + end + end + + def add_author_type + @set_author_type = BookAuthorType.new(display: 'List') + @author_type_url = admin_book_author_types_path + @set_author_type.id = params[:id] + + respond_to do |format| + format.js + end + end + + def edit_author_type + @set_author_type = BookAuthorType.find(params[:book_id]) + @author_type_url = admin_book_author_type_path(@set_author_type) + + respond_to do |format| + format.js + end + end + + def add_book_type + @set_book_type = BookType.new(display: 'List') + @book_type_url = admin_book_types_path + @set_book_type.id = params[:id] + + respond_to do |format| + format.js + end + end + + def edit_book_type + @set_book_type = BookType.find(params[:book_id]) + @book_type_url = admin_book_type_path(@set_book_type) + + respond_to do |format| + format.js + end + end + + def data_share + if params[:ids] + @books = Book.any_in(_id: params[:ids]) + + @books.each do |book| + book.is_hidden = params[:disable] + book.save + end + end + + respond_to do |format| + format.html { redirect_to(admin_member_path(id: params[:member_profile_id],show_plugin_profile: "Book")) } + format.json { render json: {"success"=>true}.to_json} + end + end + + def delete + end + + private + + def set_book + path = request.path.split('/') + if path.last.include? '-' + uid = path[-1].split("-").last + uid = uid.split("?").first + else + uid = path[-2].split("-").last + uid = uid.split("?").first + end + @book = Book.find_by(uid: uid) + end + + def book_attributes + params.require(:book).permit! rescue nil + end + + def get_plugins + @plugins = OrbitApp::Plugin::Registration.all rescue nil + end + + def set_types + @author_types = BookAuthorType.all + @book_types = BookType.all + end +end diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb new file mode 100644 index 0000000..ea843f8 --- /dev/null +++ b/app/controllers/books_controller.rb @@ -0,0 +1,43 @@ +class BooksController < ApplicationController + def index + books = Book.asc(:created_at) + book_list = books.collect do |book| + { + "book_title" => book.book_title, + "authors" => book.authors, + "link_to_show" => OrbitHelper.url_to_show(book.to_param) + } + end + { + "books" => book_list, + "extras" => {"widget-title" => "Books"} + } + end + + def show + params = OrbitHelper.params + book = Book.find_by(uid: params[:uid]) + 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" => t(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 + } + } + end +end diff --git a/app/helpers/admin/book_author_types_helper.rb b/app/helpers/admin/book_author_types_helper.rb new file mode 100644 index 0000000..72adcd2 --- /dev/null +++ b/app/helpers/admin/book_author_types_helper.rb @@ -0,0 +1,2 @@ +module Admin::BookAuthorTypesHelper +end diff --git a/app/helpers/admin/book_intros_helper.rb b/app/helpers/admin/book_intros_helper.rb new file mode 100644 index 0000000..31fce53 --- /dev/null +++ b/app/helpers/admin/book_intros_helper.rb @@ -0,0 +1,2 @@ +module Admin::BookIntrosHelper +end diff --git a/app/helpers/admin/book_types_helper.rb b/app/helpers/admin/book_types_helper.rb new file mode 100644 index 0000000..7745eab --- /dev/null +++ b/app/helpers/admin/book_types_helper.rb @@ -0,0 +1,2 @@ +module Admin::BookTypesHelper +end diff --git a/app/helpers/admin/books_helper.rb b/app/helpers/admin/books_helper.rb new file mode 100644 index 0000000..3849308 --- /dev/null +++ b/app/helpers/admin/books_helper.rb @@ -0,0 +1,9 @@ +module Admin::BooksHelper + def page_for_book(book_object) + book_page = nil + page = Page.find_by(:module=>"book") rescue nil + + book_page = page if book_page.nil? + request.protocol+(request.host_with_port+book_page.url+'/'+book_object.to_param).gsub('//','/') rescue "/" + end +end diff --git a/app/helpers/books_helper.rb b/app/helpers/books_helper.rb new file mode 100644 index 0000000..4b9311e --- /dev/null +++ b/app/helpers/books_helper.rb @@ -0,0 +1,2 @@ +module BooksHelper +end diff --git a/app/models/book.rb b/app/models/book.rb new file mode 100644 index 0000000..6dd04c5 --- /dev/null +++ b/app/models/book.rb @@ -0,0 +1,94 @@ +class Book + include Mongoid::Document + include Mongoid::Timestamps + include Mongoid::Attributes::Dynamic + + include OrbitModel::Status + include MemberHelper + include Slug + + field :book_title, as: :slug_title, type: String, localize: true + field :extracted_chapters, type: String, localize: true + field :publisher, type: String, localize: true + field :editor, type: String, localize: true + field :year, type: String + field :language, type: String + field :publish_date, type: DateTime + field :pages, type: String + field :isbn, type: String + field :keywords, type: String + field :publication_date, type: DateTime + field :url, type: String + field :note, type: String + + paginates_per 10 + + belongs_to :member_profile + + has_many :book_files, autosave: true, dependent: :destroy + accepts_nested_attributes_for :book_files + + has_and_belongs_to_many :book_authors + accepts_nested_attributes_for :book_authors + + belongs_to :book_type + before_validation :add_http + + after_save :save_book_files, :save_book_authors + + + def create_link + title = [] + title << "#{self.book_authors.collect{|j| j.name}.join(', ')}" if self.book_authors.present? + title << self.book_title if self.book_title.present? + title << self.publisher if self.publisher.present? + title << self.isbn if self.isbn.present? + + if !self.publish_date.nil? + pd = self.publish_date.strftime("%Y-%m-%d").split('-') + title << pd[0]+"/"+pd[1] + end + + title.join(', ') + end + + def self.member_data + members = MemberProfile.all + member_data = [] + members.each do |m| + member_data << {"memberId" => m.id.to_s, "memberName" => m.name} + end + member_data.to_json + end + + def save_book_files + self.book_files.each do |t| + if t.should_destroy + t.destroy + end + end + end + + def save_book_authors + self.book_authors.each do |t| + if t.should_destroy + t.destroy + end + end + end + + def authors + authors = [] + authors << self.member_profile.name if self.member_profile_id.present? + authors << (!self.book_authors.blank? ? "#{self.book_authors.collect{|j| j.name}.join(', ')}" : nil) + authors.join(', ') + end + + protected + + def add_http + unless self.url.blank? || self.url[/^http:\/\//] || self.url[/^https:\/\//] + self.url = 'http://' + self.url + end + end +end diff --git a/app/models/book_author.rb b/app/models/book_author.rb new file mode 100644 index 0000000..21b310c --- /dev/null +++ b/app/models/book_author.rb @@ -0,0 +1,14 @@ +class BookAuthor + include Mongoid::Document + include Mongoid::Timestamps + + field :name, type: String, localize: true + field :email, type: String + field :should_destroy, type: Boolean + + has_and_belongs_to_many :books + has_and_belongs_to_many :book_author_types + + VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/ + validates :email, format: { with: VALID_EMAIL_REGEX }, allow_blank: true +end diff --git a/app/models/book_author_type.rb b/app/models/book_author_type.rb new file mode 100644 index 0000000..8374faf --- /dev/null +++ b/app/models/book_author_type.rb @@ -0,0 +1,11 @@ +class BookAuthorType + include Mongoid::Document + include Mongoid::Timestamps + include Mongoid::Attributes::Dynamic + include OrbitCoreLib::ObjectDisable + + field :key, type: String + field :title, type: String, localize: true + + has_and_belongs_to_many :book_authors +end diff --git a/app/models/book_file.rb b/app/models/book_file.rb new file mode 100644 index 0000000..4081924 --- /dev/null +++ b/app/models/book_file.rb @@ -0,0 +1,12 @@ +class BookFile + include Mongoid::Document + include Mongoid::Timestamps + include Mongoid::Attributes::Dynamic + + field :description, type: String, localize: true + field :title, type: String, localize: true + field :should_destroy, type: Boolean + + mount_uploader :member_book_file, AssetUploader + belongs_to :book +end diff --git a/app/models/book_intro.rb b/app/models/book_intro.rb new file mode 100644 index 0000000..4621f26 --- /dev/null +++ b/app/models/book_intro.rb @@ -0,0 +1,3 @@ +class BookIntro < PersonalPluginIntro + +end diff --git a/app/models/book_type.rb b/app/models/book_type.rb new file mode 100644 index 0000000..08f7541 --- /dev/null +++ b/app/models/book_type.rb @@ -0,0 +1,11 @@ +class BookType + include Mongoid::Document + include Mongoid::Timestamps + include Mongoid::Attributes::Dynamic + include OrbitCoreLib::ObjectDisable + + field :key, type: String + field :title, type: String, localize: true + + has_many :books +end diff --git a/app/views/admin/book_author_types/create_book_setting.js.erb b/app/views/admin/book_author_types/create_book_setting.js.erb new file mode 100644 index 0000000..9913b08 --- /dev/null +++ b/app/views/admin/book_author_types/create_book_setting.js.erb @@ -0,0 +1,2 @@ +$("#myModal2").modal('hide'); +$('<%= j render :partial => 'admin/books/list_author_type', :collection => [@book_author_type] %>').appendTo('#author_types').hide().fadeIn(); \ No newline at end of file diff --git a/app/views/admin/book_author_types/delete_book_setting.js.erb b/app/views/admin/book_author_types/delete_book_setting.js.erb new file mode 100644 index 0000000..1958000 --- /dev/null +++ b/app/views/admin/book_author_types/delete_book_setting.js.erb @@ -0,0 +1,3 @@ +$('.delete_author').bind('ajax:success', function() { + $(this).closest('tr').fadeOut(); +}); \ No newline at end of file diff --git a/app/views/admin/book_author_types/update_book_setting.js.erb b/app/views/admin/book_author_types/update_book_setting.js.erb new file mode 100644 index 0000000..4a57749 --- /dev/null +++ b/app/views/admin/book_author_types/update_book_setting.js.erb @@ -0,0 +1,2 @@ +$("#myModal2").modal('hide'); +$("#<%= dom_id @book_author_type %>").replaceWith("<%= j render :partial => 'admin/books/list_author_type', :collection => [@book_author_type] %>"); \ No newline at end of file diff --git a/app/views/admin/book_types/create_book_setting.js.erb b/app/views/admin/book_types/create_book_setting.js.erb new file mode 100644 index 0000000..db9dce7 --- /dev/null +++ b/app/views/admin/book_types/create_book_setting.js.erb @@ -0,0 +1,2 @@ +$("#myModal1").modal('hide'); +$('<%= j render :partial => 'admin/books/list_book_type', :collection => [@book_type] %>').appendTo('#level_types').hide().fadeIn(); \ No newline at end of file diff --git a/app/views/admin/book_types/delete_book_setting.js.erb b/app/views/admin/book_types/delete_book_setting.js.erb new file mode 100644 index 0000000..eb842a2 --- /dev/null +++ b/app/views/admin/book_types/delete_book_setting.js.erb @@ -0,0 +1,3 @@ +$('.delete_level').bind('ajax:success', function() { + $(this).closest('tr').fadeOut(); +}); \ No newline at end of file diff --git a/app/views/admin/book_types/update_book_setting.js.erb b/app/views/admin/book_types/update_book_setting.js.erb new file mode 100644 index 0000000..90c0a3c --- /dev/null +++ b/app/views/admin/book_types/update_book_setting.js.erb @@ -0,0 +1,2 @@ +$("#myModal1").modal('hide'); +$("#<%= dom_id @book_type %>").replaceWith("<%= j render :partial => 'admin/books/list_book_type', :collection => [@book_type] %>"); \ No newline at end of file diff --git a/app/views/admin/books/_author_autocomplete.html.erb b/app/views/admin/books/_author_autocomplete.html.erb new file mode 100644 index 0000000..1c0226c --- /dev/null +++ b/app/views/admin/books/_author_autocomplete.html.erb @@ -0,0 +1,33 @@ + \ No newline at end of file diff --git a/app/views/admin/books/_author_type_qe.html.erb b/app/views/admin/books/_author_type_qe.html.erb new file mode 100644 index 0000000..d4f3eec --- /dev/null +++ b/app/views/admin/books/_author_type_qe.html.erb @@ -0,0 +1,33 @@ +<% # encoding: utf-8 %> +<%= form_for(@set_author_type, :remote => true, :url => @author_type_url ) do |f| %> + + +