personal_writing/app/helpers/admin/personal_writings_helper.rb

93 lines
2.3 KiB
Ruby

module Admin::PersonalWritingsHelper
def get_paper_list
user = current_user.nil? ? OrbitHelper.current_user : current_user
user_profile = user.member_profile
writings = Writing.where(:member_profile_id => user_profile.id)
writings = writings.collect do |l|
files = l.writing_files.collect do |lf|
{
"title" => lf.title,
"description" => lf.description,
"link" => lf.file.url,
"extension" => (lf.file.url.split(".").last rescue "")
}
end
{
"id" => l.id.to_s,
"edit_url" => "/#{I18n.locale.to_s}/admin/members/#{user_profile.to_param}/writings/#{l.to_param}/edit",
"delete_url" => "/#{I18n.locale.to_s}/admin/writings/#{l.id.to_s}",
"paper_title" => l.writing_title,
"keywords" => l.keywords,
"files" => files
}
end
writings
end
def import_this_writing(row, mp)
value = nil
writing = Writing.new
row.cells.each_with_index do |cell,index|
next if index < 2
next if cell.nil?
val = cell.value
next if val.nil? || val == ""
case index
when 2
value = {"en" => val}
when 3
begin
value["zh_tw"] = val
rescue
value = {"zh_tw" => val}
end
writing.writing_title_translations = value
when 4
value = {"en" => val}
when 5
begin
value["zh_tw"] = val
rescue
value = {"zh_tw" => val}
end
writing.location_translations = value
when 6
value = {"en" => val}
when 7
begin
value["zh_tw"] = val
rescue
value = {"zh_tw" => val}
end
writing.participating_professor_translations = value
when 8
value = {"en" => val}
when 9
begin
value["zh_tw"] = val
rescue
value = {"zh_tw" => val}
end
writing.participating_student_translations = value
when 10
writing.year = val
when 11
writing.extension_no = val
when 12
writing.research_direction = val
when 13
writing.facility = val
when 14
writing.url = val
when 15
writing.keywords = val
when 16
writing.note = val
end
end
writing.member_profile = mp
writing.save
end
end