desktop book

This commit is contained in:
JiangRu 2014-12-05 14:37:24 +08:00
parent 417048b7b9
commit 198a9f503a
7 changed files with 128 additions and 77 deletions

View File

View File

@ -1,5 +1,5 @@
class Admin::BooksController < OrbitMemberController class Admin::BooksController < OrbitMemberController
include Admin::JournalPapersHelper include Admin::BooksHelper
layout "member_plugin" layout "member_plugin"
before_action :set_book, only: [:show, :edit , :update, :destroy] before_action :set_book, only: [:show, :edit , :update, :destroy]
@ -28,35 +28,38 @@ class Admin::BooksController < OrbitMemberController
def edit def edit
@member = @book.member_profile @member = @book.member_profile
if params[:desktop]
render :layout => false
end
end end
def update def update
respond_to do |format| @member = @book.member_profile
if @book.update_attributes(book_attributes) @book.update_attributes(book_attributes)
format.html { redirect_to params['referer_url'] } @book.save
format.xml { head :ok } if params[:desktop] == "true"
render json: {"data" => get_paper_list}.to_json
else else
format.html { render action: "edit" } redirect_to params['referer_url']
format.xml { render :xml => @book.errors, :status => :unprocessable_entity }
end
end end
end end
def new def new
@book = Book.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 end
def create def create
@member = MemberProfile.find(book_attributes['member_profile_id']) rescue nil
@book = Book.new(book_attributes) @book = Book.new(book_attributes)
respond_to do |format| @book.save
if @book.save if params[:desktop] == "true"
format.html { redirect_to params['referer_url'] } render json: {"data" => get_paper_list}.to_json
format.xml { render :xml => @book, :status => :created, :location => @book }
else else
format.html { render action: "new" } redirect_to params['referer_url']
format.xml { render :xml => @book.errors, :status => :unprocessable_entity }
end
end end
end end
@ -74,10 +77,11 @@ class Admin::BooksController < OrbitMemberController
def destroy def destroy
@book.destroy @book.destroy
respond_to do |format| respond_to do |format|
format.html { redirect_to(admin_books_url) } format.html { redirect_to(admin_books_url) }
# format.xml { head :ok }
format.js format.js
format.json {render json: {"success" => true}}
end end
end end

View File

@ -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

View File

@ -6,4 +6,30 @@ module Admin::BooksHelper
book_page = page if book_page.nil? book_page = page if book_page.nil?
request.protocol+(request.host_with_port+book_page.url+'/'+book_object.to_param).gsub('//','/') rescue "/" request.protocol+(request.host_with_port+book_page.url+'/'+book_object.to_param).gsub('//','/') rescue "/"
end 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 end

View File

@ -22,6 +22,8 @@ class Book
field :publication_date, type: DateTime field :publication_date, type: DateTime
field :url, type: String field :url, type: String
field :note, 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 :rss2_id, type: String
field :number_of_authors field :number_of_authors

View File

@ -280,11 +280,9 @@
<%= link_to t('cancel'), get_go_back, :class=>"btn" %> <%= link_to t('cancel'), get_go_back, :class=>"btn" %>
</div> </div>
<% content_for :page_specific_javascript do %> <script>
<script> $('.main-forms').find('.add-on').tooltip().end().on('click', '.trigger, .delete_file, .remove_existing_record', function() {
$(document).ready(function() { if($(this).hasClass('trigger')) {
$('.main-forms .add-on').tooltip();
$(document).on('click', '#add_file', function(){
var new_id = $(this).prev().attr('value'); var new_id = $(this).prev().attr('value');
var old_id = new RegExp("new_book_files", "g"); var old_id = new RegExp("new_book_files", "g");
var on = $('.language-nav li.active').index(); var on = $('.language-nav li.active').index();
@ -294,17 +292,14 @@
$(this).parent('.add-btn').prev('.add-target').children('.start-line').eq(le).children('.input-append').find('.tab-content').each(function() { $(this).parent('.add-btn').prev('.add-target').children('.start-line').eq(le).children('.input-append').find('.tab-content').each(function() {
$(this).children('.tab-pane').eq(on).addClass('in active').siblings().removeClass('in active'); $(this).children('.tab-pane').eq(on).addClass('in active').siblings().removeClass('in active');
}); });
formTip(); $('.add-on').tooltip();
}); } else if($(this).hasClass('delete_file')) {
$(document).on('click', '.delete_file', function(){
$(this).parents('.input-prepend').remove(); $(this).parents('.input-prepend').remove();
}); } else if($(this).hasClass('remove_existing_record')) {
$(document).on('click', '.remove_existing_record', function(){
if(confirm("<%= I18n.t(:sure?)%>")){ if(confirm("<%= I18n.t(:sure?)%>")){
$(this).children('.should_destroy').attr('value', 1); $(this).children('.should_destroy').attr('value', 1);
$(this).parents('.start-line').hide(); $(this).parents('.start-line').hide();
} }
}
}); });
}); </script>
</script>
<% end %>

View File

@ -7,6 +7,7 @@ module PersonalBook
personal_plugin :enable => true, :sort_number => '25', :app_name=>"Book", :intro_app_name=>"BookIntro",:path=>"/plugin/book/profile",:front_path=>"/profile",:admin_path=>"/admin/books",:i18n=>'module_name.book',:module_app_name=>'Book' personal_plugin :enable => true, :sort_number => '25', :app_name=>"Book", :intro_app_name=>"BookIntro",:path=>"/plugin/book/profile",:front_path=>"/profile",:admin_path=>"/admin/books",:i18n=>'module_name.book',:module_app_name=>'Book'
version "0.1" version "0.1"
desktop_enabled true
organization "Rulingcom" organization "Rulingcom"
author "RD dep" author "RD dep"
intro "I am intro" intro "I am intro"