diff --git a/app/assets/images/desktop/book.svg b/app/assets/images/desktop/book.svg new file mode 100644 index 0000000..e69de29 diff --git a/app/controllers/admin/books_controller.rb b/app/controllers/admin/books_controller.rb index ecf8c1a..d20ff46 100644 --- a/app/controllers/admin/books_controller.rb +++ b/app/controllers/admin/books_controller.rb @@ -1,5 +1,5 @@ class Admin::BooksController < OrbitMemberController - include Admin::JournalPapersHelper + include Admin::BooksHelper layout "member_plugin" before_action :set_book, only: [:show, :edit , :update, :destroy] @@ -28,43 +28,46 @@ class Admin::BooksController < OrbitMemberController def edit @member = @book.member_profile + if params[:desktop] + render :layout => false + end end def update - respond_to do |format| - if @book.update_attributes(book_attributes) - format.html { redirect_to params['referer_url'] } - format.xml { head :ok } - else - format.html { render action: "edit" } - format.xml { render :xml => @book.errors, :status => :unprocessable_entity } - end + @member = @book.member_profile + @book.update_attributes(book_attributes) + @book.save + if params[:desktop] == "true" + render json: {"data" => get_paper_list}.to_json + else + redirect_to params['referer_url'] end end def new @book = Book.new - @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil + @member = MemberProfile.find_by(:id=>params['member_profile_id']) rescue nil + if params[:desktop] + render :layout => false + end end def create + @member = MemberProfile.find(book_attributes['member_profile_id']) rescue nil @book = Book.new(book_attributes) - respond_to do |format| - if @book.save - format.html { redirect_to params['referer_url'] } - 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 + @book.save + if params[:desktop] == "true" + render json: {"data" => get_paper_list}.to_json + else + redirect_to params['referer_url'] + end end - def book_setting + def book_setting if current_user.is_admin? @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 else @@ -74,10 +77,11 @@ class Admin::BooksController < OrbitMemberController def destroy @book.destroy - - respond_to do |format| - format.html { redirect_to(admin_books_url) } - format.js + respond_to do |format| + format.html { redirect_to(admin_books_url) } + # format.xml { head :ok } + format.js + format.json {render json: {"success" => true}} end end @@ -85,7 +89,7 @@ class Admin::BooksController < OrbitMemberController @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 @@ -94,7 +98,7 @@ class Admin::BooksController < OrbitMemberController 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 @@ -167,5 +171,5 @@ class Admin::BooksController < OrbitMemberController def set_types @author_types = BookAuthorType.all @book_types = BookType.all - end + end end diff --git a/app/controllers/desktop/books_controller.rb b/app/controllers/desktop/books_controller.rb new file mode 100644 index 0000000..6ff34e0 --- /dev/null +++ b/app/controllers/desktop/books_controller.rb @@ -0,0 +1,23 @@ +class Desktop::BooksController < DesktopAdminController + include Admin::BooksHelper + + def menu + user = OrbitHelper.current_user + [ + { + "title" => "List", + "layout" => "list" + }, + { + "title" => "Add/Edit", + "layout" => "form", + "new_path" => "/#{I18n.locale.to_s}/admin/books/new?member_profile_id=#{user.member_profile_id.to_param}", + } + ] + end + + def list + get_paper_list + end + +end \ No newline at end of file diff --git a/app/helpers/admin/books_helper.rb b/app/helpers/admin/books_helper.rb index 3849308..db9b76b 100644 --- a/app/helpers/admin/books_helper.rb +++ b/app/helpers/admin/books_helper.rb @@ -6,4 +6,30 @@ module Admin::BooksHelper book_page = page if book_page.nil? request.protocol+(request.host_with_port+book_page.url+'/'+book_object.to_param).gsub('//','/') rescue "/" end + + def get_paper_list + user = current_user.nil? ? OrbitHelper.current_user : current_user + user_profile = user.member_profile + books = Book.where(:member_profile_id => user_profile.id) + books = books.collect do |b| + files = b.book_files.collect do |bf| + { + "title" => bf.title, + "description" => bf.description, + "link" => bf.member_book_file.url, + "extension" => (bf.file.url.split(".").last rescue "") + } + end + { + "id" => b.id.to_s, + "edit_url" => "/#{I18n.locale.to_s}/admin/books/#{b.to_param}/edit", + "delete_url" => "/#{I18n.locale.to_s}/admin/books/#{b.id.to_s}", + "paper_title" => b.book_title, + "keywords" => b.keywords, + "files" => files + } + + end + books + end end diff --git a/app/models/book.rb b/app/models/book.rb index 93d4ab4..8d6edca 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -22,9 +22,11 @@ class Book field :publication_date, type: DateTime field :url, type: String field :note, type: String + field :create_user_id, :type => BSON::ObjectId + field :update_user_id, :type => BSON::ObjectId field :rss2_id, type: String field :number_of_authors - + paginates_per 10 belongs_to :member_profile @@ -50,7 +52,7 @@ class Book title << pd[0]+"/"+pd[1] end - title.join(', ') + title.join(', ') end def get_plugin_data(fields_to_show) @@ -79,7 +81,7 @@ class Book value = self.send(field).to_date.strftime("%Y-%m-%d") rescue nil when "file" files = [] - self.book_files.each do |book_file| + self.book_files.each do |book_file| url = book_file.member_book_file.url title = (book_file.title.blank? ? File.basename(book_file.member_book_file.path) : book_file.title) files << "