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,43 +28,46 @@ 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"
else render json: {"data" => get_paper_list}.to_json
format.html { render action: "edit" } else
format.xml { render :xml => @book.errors, :status => :unprocessable_entity } redirect_to params['referer_url']
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 redirect_to params['referer_url']
format.html { render action: "new" } end
format.xml { render :xml => @book.errors, :status => :unprocessable_entity }
end
end
end end
def book_setting def book_setting
if current_user.is_admin? if current_user.is_admin?
@set_author_type = BookAuthorType.new(display: 'List') @set_author_type = BookAuthorType.new(display: 'List')
@author_type_url = admin_books_path @author_type_url = admin_books_path
@set_book_type = BookType.new(display: 'List') @set_book_type = BookType.new(display: 'List')
@book_type_url = admin_books_path @book_type_url = admin_books_path
else else
@ -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
@ -85,7 +89,7 @@ class Admin::BooksController < OrbitMemberController
@set_author_type = BookAuthorType.new(display: 'List') @set_author_type = BookAuthorType.new(display: 'List')
@author_type_url = admin_book_author_types_path @author_type_url = admin_book_author_types_path
@set_author_type.id = params[:id] @set_author_type.id = params[:id]
respond_to do |format| respond_to do |format|
format.js format.js
end end
@ -94,7 +98,7 @@ class Admin::BooksController < OrbitMemberController
def edit_author_type def edit_author_type
@set_author_type = BookAuthorType.find(params[:book_id]) @set_author_type = BookAuthorType.find(params[:book_id])
@author_type_url = admin_book_author_type_path(@set_author_type) @author_type_url = admin_book_author_type_path(@set_author_type)
respond_to do |format| respond_to do |format|
format.js format.js
end end
@ -167,5 +171,5 @@ class Admin::BooksController < OrbitMemberController
def set_types def set_types
@author_types = BookAuthorType.all @author_types = BookAuthorType.all
@book_types = BookType.all @book_types = BookType.all
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,9 +22,11 @@ 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
paginates_per 10 paginates_per 10
belongs_to :member_profile belongs_to :member_profile
@ -50,7 +52,7 @@ class Book
title << pd[0]+"/"+pd[1] title << pd[0]+"/"+pd[1]
end end
title.join(', ') title.join(', ')
end end
def get_plugin_data(fields_to_show) 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 value = self.send(field).to_date.strftime("%Y-%m-%d") rescue nil
when "file" when "file"
files = [] files = []
self.book_files.each do |book_file| self.book_files.each do |book_file|
url = book_file.member_book_file.url url = book_file.member_book_file.url
title = (book_file.title.blank? ? File.basename(book_file.member_book_file.path) : book_file.title) title = (book_file.title.blank? ? File.basename(book_file.member_book_file.path) : book_file.title)
files << "<li><a href='#{url}'' target='_blank'>#{title}</li>" files << "<li><a href='#{url}'' target='_blank'>#{title}</li>"
@ -90,7 +92,7 @@ class Book
end end
value = (value =~ /\A#{URI::regexp(['http', 'https'])}\z/) ? "<a href='#{value}' target='blank'>#{value}</a>" : value value = (value =~ /\A#{URI::regexp(['http', 'https'])}\z/) ? "<a href='#{value}' target='blank'>#{value}</a>" : value
{ {
"key"=>field, "key"=>field,
"title_class"=>"book-#{field.gsub('_','-')}-field", "title_class"=>"book-#{field.gsub('_','-')}-field",

View File

@ -5,7 +5,7 @@
<%= stylesheet_link_tag "lib/main-list" %> <%= stylesheet_link_tag "lib/main-list" %>
<% end %> <% end %>
<% content_for :page_specific_javascript do %> <% content_for :page_specific_javascript do %>
<%= javascript_include_tag "lib/bootstrap-fileupload" %> <%= javascript_include_tag "lib/bootstrap-fileupload" %>
<%= javascript_include_tag "lib/file-type" %> <%= javascript_include_tag "lib/file-type" %>
<%= javascript_include_tag "lib/module-area" %> <%= javascript_include_tag "lib/module-area" %>
<%= javascript_include_tag "lib/bootstrap-datetimepicker.js" %> <%= javascript_include_tag "lib/bootstrap-datetimepicker.js" %>
@ -17,7 +17,7 @@
<!-- Input Area --> <!-- Input Area -->
<div class="input-area"> <div class="input-area">
<!-- Module Tabs --> <!-- Module Tabs -->
<div class="nav-name"><strong><%= t(:module) %></strong></div> <div class="nav-name"><strong><%= t(:module) %></strong></div>
<ul class="nav nav-pills module-nav"> <ul class="nav nav-pills module-nav">
<li></li> <li></li>
@ -70,7 +70,7 @@
<div class="controls"> <div class="controls">
<%= f.select :book_type_id, @book_types.collect {|t| [ t.title, t.id ]} %> <%= f.select :book_type_id, @book_types.collect {|t| [ t.title, t.id ]} %>
</div> </div>
</div> </div>
<!-- year --> <!-- year -->
<div class="control-group"> <div class="control-group">
@ -78,7 +78,7 @@
<div class="controls"> <div class="controls">
<%= select_year((@book.year ? @book.year.to_i : DateTime.now.year), {:start_year => DateTime.now.year, :end_year => 1930}, {:name => 'book[year]',:class => 'span1'} ) %> <%= select_year((@book.year ? @book.year.to_i : DateTime.now.year), {:start_year => DateTime.now.year, :end_year => 1930}, {:name => 'book[year]',:class => 'span1'} ) %>
</div> </div>
</div> </div>
<!-- publish_date --> <!-- publish_date -->
<div class="control-group"> <div class="control-group">
@ -94,7 +94,7 @@
<div class="controls"> <div class="controls">
<%= f.datetime_picker :publication_date, :no_label => true,:format=>"yyyy/MM/dd", :placeholder=>"YYYY/MM/DD" %> <%= f.datetime_picker :publication_date, :no_label => true,:format=>"yyyy/MM/dd", :placeholder=>"YYYY/MM/DD" %>
</div> </div>
</div> </div>
<!-- url --> <!-- url -->
<div class="control-group"> <div class="control-group">
@ -102,7 +102,7 @@
<div class="controls"> <div class="controls">
<%= f.text_field :url , :class => "span6" %> <%= f.text_field :url , :class => "span6" %>
</div> </div>
</div> </div>
<!-- keywords --> <!-- keywords -->
<div class="control-group"> <div class="control-group">
@ -110,7 +110,7 @@
<div class="controls"> <div class="controls">
<%= f.text_field :keywords %> <%= f.text_field :keywords %>
</div> </div>
</div> </div>
<!-- pages --> <!-- pages -->
<div class="control-group"> <div class="control-group">
@ -118,7 +118,7 @@
<div class="controls"> <div class="controls">
<%= f.text_field :pages %> <%= f.text_field :pages %>
</div> </div>
</div> </div>
<!-- isbn --> <!-- isbn -->
<div class="control-group"> <div class="control-group">
@ -126,7 +126,7 @@
<div class="controls"> <div class="controls">
<%= f.text_field :isbn %> <%= f.text_field :isbn %>
</div> </div>
</div> </div>
<!-- language --> <!-- language -->
<div class="control-group"> <div class="control-group">
@ -138,7 +138,7 @@
<% end %> <% end %>
</select> </select>
</div> </div>
</div> </div>
<!-- note --> <!-- note -->
<div class="control-group"> <div class="control-group">
@ -146,7 +146,7 @@
<div class="controls"> <div class="controls">
<%= f.text_area :note, rows: 2, class: "input-block-level" %> <%= f.text_area :note, rows: 2, class: "input-block-level" %>
</div> </div>
</div> </div>
</div> </div>
@ -181,13 +181,13 @@
<div class="tab-content language-area"> <div class="tab-content language-area">
<% @site_in_use_locales.each_with_index do |locale, i| %> <% @site_in_use_locales.each_with_index do |locale, i| %>
<div class="<%= locale %> tab-pane fade <%= ( i == 0 ) ? "in active" : '' %>"> <div class="<%= locale %> tab-pane fade <%= ( i == 0 ) ? "in active" : '' %>">
<!-- book_title--> <!-- book_title-->
<div class="control-group input-title"> <div class="control-group input-title">
<label class="control-label muted"><%= t("personal_book.book_title") %></label> <label class="control-label muted"><%= t("personal_book.book_title") %></label>
<div class="controls"> <div class="controls">
<%= f.fields_for :book_title_translations do |f| %> <%= f.fields_for :book_title_translations do |f| %>
<%= f.text_field locale, class: "input-block-level", placeholder: t("personal_book.book_title"), value: (@book.book_title_translations[locale] rescue nil) %> <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_book.book_title"), value: (@book.book_title_translations[locale] rescue nil) %>
<% end %> <% end %>
@ -197,7 +197,7 @@
<!-- extracted_chapters--> <!-- extracted_chapters-->
<div class="control-group input-title"> <div class="control-group input-title">
<label class="control-label muted"><%= t("personal_book.extracted_chapters") %></label> <label class="control-label muted"><%= t("personal_book.extracted_chapters") %></label>
<div class="controls"> <div class="controls">
<%= f.fields_for :extracted_chapters_translations do |f| %> <%= f.fields_for :extracted_chapters_translations do |f| %>
<%= f.text_field locale, class: "input-block-level", placeholder: t("personal_book.extracted_chapters"), value: (@book.extracted_chapters_translations[locale] rescue nil) %> <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_book.extracted_chapters"), value: (@book.extracted_chapters_translations[locale] rescue nil) %>
<% end %> <% end %>
@ -207,7 +207,7 @@
<!-- publisher--> <!-- publisher-->
<div class="control-group input-title"> <div class="control-group input-title">
<label class="control-label muted"><%= t("personal_book.publisher") %></label> <label class="control-label muted"><%= t("personal_book.publisher") %></label>
<div class="controls"> <div class="controls">
<%= f.fields_for :publisher_translations do |f| %> <%= f.fields_for :publisher_translations do |f| %>
<%= f.text_field locale, class: "input-block-level", placeholder: t("personal_book.publisher"), value: (@book.publisher_translations[locale] rescue nil) %> <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_book.publisher"), value: (@book.publisher_translations[locale] rescue nil) %>
<% end %> <% end %>
@ -217,7 +217,7 @@
<!-- editor--> <!-- editor-->
<div class="control-group input-title"> <div class="control-group input-title">
<label class="control-label muted"><%= t("personal_book.editor") %></label> <label class="control-label muted"><%= t("personal_book.editor") %></label>
<div class="controls"> <div class="controls">
<%= f.fields_for :editor_translations do |f| %> <%= f.fields_for :editor_translations do |f| %>
<%= f.text_field locale, class: "input-block-level", placeholder: t("personal_book.editor"), value: (@book.editor_translations[locale] rescue nil) %> <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_book.editor"), value: (@book.editor_translations[locale] rescue nil) %>
<% end %> <% end %>
@ -251,7 +251,7 @@
<%= f.fields_for :book_files, book_file do |f| %> <%= f.fields_for :book_files, book_file do |f| %>
<%= render :partial => 'form_file', :object => book_file, :locals => {:f => f, :i => i} %> <%= render :partial => 'form_file', :object => book_file, :locals => {:f => f, :i => i} %>
<% end %> <% end %>
<% end %> <% end %>
<hr> <hr>
</div> </div>
<% end %> <% end %>
@ -277,34 +277,29 @@
<div class="form-actions"> <div class="form-actions">
<input type="hidden" name="referer_url" value="<%= request.referer %>"> <input type="hidden" name="referer_url" value="<%= request.referer %>">
<%= f.submit t('submit'), class: 'btn btn-primary' %> <%= f.submit t('submit'), class: 'btn btn-primary' %>
<%= 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(); var new_id = $(this).prev().attr('value');
$(document).on('click', '#add_file', function(){ var old_id = new RegExp("new_book_files", "g");
var new_id = $(this).prev().attr('value'); var on = $('.language-nav li.active').index();
var old_id = new RegExp("new_book_files", "g"); var le = $(this).parent('.add-btn').prev('.add-target').children('.start-line').length;
var on = $('.language-nav li.active').index(); $(this).prev().attr('value', parseInt(new_id) + 1);
var le = $(this).parent('.add-btn').prev('.add-target').children('.start-line').length; $(this).parent().siblings('.add-target').append(("<%= escape_javascript(add_attribute 'form_file', f, :book_files) %>").replace(old_id, new_id));
$(this).prev().attr('value', parseInt(new_id) + 1); $(this).parent('.add-btn').prev('.add-target').children('.start-line').eq(le).children('.input-append').find('.tab-content').each(function() {
$(this).parent().siblings('.add-target').append(("<%= escape_javascript(add_attribute 'form_file', f, :book_files) %>").replace(old_id, new_id)); $(this).children('.tab-pane').eq(on).addClass('in active').siblings().removeClass('in active');
$(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');
});
formTip();
});
$(document).on('click', '.delete_file', function(){
$(this).parents('.input-prepend').remove();
}); });
$(document).on('click', '.remove_existing_record', function(){ $('.add-on').tooltip();
if(confirm("<%= I18n.t(:sure?)%>")){ } else if($(this).hasClass('delete_file')) {
$(this).children('.should_destroy').attr('value', 1); $(this).parents('.input-prepend').remove();
$(this).parents('.start-line').hide(); } else if($(this).hasClass('remove_existing_record')) {
} if(confirm("<%= I18n.t(:sure?)%>")){
}); $(this).children('.should_destroy').attr('value', 1);
}); $(this).parents('.start-line').hide();
</script> }
<% end %> }
});
</script>

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"