From 8c59b6929fac4726b59a31fc2667844bdee69784 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Wed, 26 Nov 2014 19:39:19 +0800 Subject: [PATCH] some changes for desktop --- .../admin/journal_papers_controller.rb | 8 +++++- .../desktop/journal_papers_controller.rb | 27 +------------------ app/helpers/admin/journal_papers_helper.rb | 27 +++++++++++++++++++ 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/app/controllers/admin/journal_papers_controller.rb b/app/controllers/admin/journal_papers_controller.rb index 25d4a1d..e0ae30a 100644 --- a/app/controllers/admin/journal_papers_controller.rb +++ b/app/controllers/admin/journal_papers_controller.rb @@ -47,6 +47,9 @@ class Admin::JournalPapersController < OrbitMemberController @journal_paper = JournalPaper.new(journal_paper_attributes) respond_to do |format| if @journal_paper.save + if params[:desktop] == "true" + format.json { render json: get_paper_list } + end format.html { redirect_to params['referer_url'] } format.json { render action: 'show', status: :created, location: @journal_paper } else @@ -59,6 +62,9 @@ class Admin::JournalPapersController < OrbitMemberController def update respond_to do |format| 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.js { render 'toggle_enable' } format.json { head :no_content } @@ -71,11 +77,11 @@ class Admin::JournalPapersController < OrbitMemberController def destroy @journal_paper.destroy - respond_to do |format| format.html { redirect_to(admin_journal_papers_url) } # format.xml { head :ok } format.js + format.json {render json: {"success" => true}} end end diff --git a/app/controllers/desktop/journal_papers_controller.rb b/app/controllers/desktop/journal_papers_controller.rb index cd63312..4570482 100644 --- a/app/controllers/desktop/journal_papers_controller.rb +++ b/app/controllers/desktop/journal_papers_controller.rb @@ -1,4 +1,5 @@ class Desktop::JournalPapersController < DesktopAdminController + include Admin::JournalPapersHelper def menu user = OrbitHelper.current_user [ @@ -19,32 +20,6 @@ class Desktop::JournalPapersController < DesktopAdminController ] 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 \ No newline at end of file diff --git a/app/helpers/admin/journal_papers_helper.rb b/app/helpers/admin/journal_papers_helper.rb index c072f7b..d3da186 100644 --- a/app/helpers/admin/journal_papers_helper.rb +++ b/app/helpers/admin/journal_papers_helper.rb @@ -6,4 +6,31 @@ module Admin::JournalPapersHelper 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 "/" 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