some changes for desktop

This commit is contained in:
Harry Bomrah 2014-11-26 19:39:19 +08:00
parent 53031c1831
commit 8c59b6929f
3 changed files with 35 additions and 27 deletions

View File

@ -47,6 +47,9 @@ class Admin::JournalPapersController < OrbitMemberController
@journal_paper = JournalPaper.new(journal_paper_attributes) @journal_paper = JournalPaper.new(journal_paper_attributes)
respond_to do |format| respond_to do |format|
if @journal_paper.save if @journal_paper.save
if params[:desktop] == "true"
format.json { render json: get_paper_list }
end
format.html { redirect_to params['referer_url'] } format.html { redirect_to params['referer_url'] }
format.json { render action: 'show', status: :created, location: @journal_paper } format.json { render action: 'show', status: :created, location: @journal_paper }
else else
@ -59,6 +62,9 @@ class Admin::JournalPapersController < OrbitMemberController
def update def update
respond_to do |format| respond_to do |format|
if @journal_paper.update_attributes(journal_paper_attributes) if @journal_paper.update_attributes(journal_paper_attributes)
if params[:desktop] == "true"
format.json { render json: get_paper_list }
end
format.html { redirect_to params['referer_url'] } format.html { redirect_to params['referer_url'] }
# format.js { render 'toggle_enable' } # format.js { render 'toggle_enable' }
format.json { head :no_content } format.json { head :no_content }
@ -71,11 +77,11 @@ class Admin::JournalPapersController < OrbitMemberController
def destroy def destroy
@journal_paper.destroy @journal_paper.destroy
respond_to do |format| respond_to do |format|
format.html { redirect_to(admin_journal_papers_url) } format.html { redirect_to(admin_journal_papers_url) }
# format.xml { head :ok } # format.xml { head :ok }
format.js format.js
format.json {render json: {"success" => true}}
end end
end end

View File

@ -1,4 +1,5 @@
class Desktop::JournalPapersController < DesktopAdminController class Desktop::JournalPapersController < DesktopAdminController
include Admin::JournalPapersHelper
def menu def menu
user = OrbitHelper.current_user user = OrbitHelper.current_user
[ [
@ -19,32 +20,6 @@ class Desktop::JournalPapersController < DesktopAdminController
] ]
end end
def get_paper_list
user = OrbitHelper.current_user
user_profile = user.member_profile
journals = JournalPaper.where(:member_profile_id => user_profile.id)
journals = journals.collect do |j|
files = j.journal_paper_files.collect do |jpf|
{
"title" => jpf.title,
"description" => jpf.description,
"link" => jpf.journal_file.url,
"extension" => (jpf.journal_file.url.split(".").last rescue "")
}
end
{
"id" => j.id.to_s,
"edit_url" => "/#{I18n.locale.to_s}/admin/journal_papers/#{j.to_param}/edit",
"delete_url" => "/#{I18n.locale.to_s}/admin/journal_papers/#{j.id.to_s}",
"paper_title" => j.paper_title,
"journal_title" => j.journal_title,
"keywords" => j.keywords,
"abstract" => j.abstract,
"files" => files
}
end
journals
end
end end

View File

@ -6,4 +6,31 @@ module Admin::JournalPapersHelper
journal_paper_page = pages.first if journal_paper_page.nil? journal_paper_page = pages.first if journal_paper_page.nil?
request.protocol+(request.host_with_port+journal_paper_page.url+'/'+journal_paper_object.to_param).gsub('//','/') rescue "/" request.protocol+(request.host_with_port+journal_paper_page.url+'/'+journal_paper_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
journals = JournalPaper.where(:member_profile_id => user_profile.id)
journals = journals.collect do |j|
files = j.journal_paper_files.collect do |jpf|
{
"title" => jpf.title,
"description" => jpf.description,
"link" => jpf.journal_file.url,
"extension" => (jpf.journal_file.url.split(".").last rescue "")
}
end
{
"id" => j.id.to_s,
"edit_url" => "/#{I18n.locale.to_s}/admin/journal_papers/#{j.to_param}/edit",
"delete_url" => "/#{I18n.locale.to_s}/admin/journal_papers/#{j.id.to_s}",
"paper_title" => j.paper_title,
"journal_title" => j.journal_title,
"keywords" => j.keywords,
"abstract" => j.abstract,
"files" => files
}
end
journals
end
end end