2014-05-08 07:33:39 +00:00
|
|
|
class FaqsController < ApplicationController
|
2014-08-05 06:39:47 +00:00
|
|
|
def index
|
2024-07-15 13:39:38 +00:00
|
|
|
faqs = Qa.can_display.order_by(:order_position => "asc").filter_by_tags.filter_by_categories
|
2021-11-15 04:35:23 +00:00
|
|
|
locale = I18n.locale.to_s
|
2021-03-23 08:33:56 +00:00
|
|
|
f = faqs.collect do |qa|
|
2014-08-05 06:39:47 +00:00
|
|
|
statuses = qa.statuses_with_classname.collect do |status|
|
2014-06-18 10:03:39 +00:00
|
|
|
{
|
|
|
|
"status" => status["name"],
|
|
|
|
"status-class" => "status-#{status['classname']}"
|
|
|
|
}
|
|
|
|
end
|
2021-03-23 08:33:56 +00:00
|
|
|
qa_files = qa.qa_files.map do |qa_file|
|
2021-11-15 04:35:23 +00:00
|
|
|
next if !qa_file.enabled_for?(locale)
|
2021-11-16 02:14:40 +00:00
|
|
|
file = qa_file.file
|
|
|
|
next if file.path.nil?
|
2021-03-23 08:33:56 +00:00
|
|
|
{
|
2021-11-16 02:14:40 +00:00
|
|
|
"file_url" => file.url + "\" title=\"#{qa_file.file_title}",
|
2021-03-23 08:36:12 +00:00
|
|
|
"file_title" => (qa_file.title.blank? ? File.basename(qa_file["file"]) : qa_file.title)
|
2021-03-23 08:33:56 +00:00
|
|
|
}
|
2021-11-15 04:35:23 +00:00
|
|
|
end.compact
|
2014-08-05 06:39:47 +00:00
|
|
|
{
|
|
|
|
"link_to_show" => OrbitHelper.url_to_show(qa.to_param),
|
|
|
|
"question" => qa.title,
|
2014-11-07 11:00:48 +00:00
|
|
|
"answer" => qa.answer,
|
2021-03-23 08:33:56 +00:00
|
|
|
"statuses" => statuses,
|
|
|
|
"qa_files" => qa_files
|
2014-08-05 06:39:47 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"faqs" => f,
|
|
|
|
"extras" => {"widget-title"=>"Faqs"},
|
|
|
|
"total_pages" => faqs.total_pages
|
|
|
|
}
|
|
|
|
end
|
2014-05-08 07:33:39 +00:00
|
|
|
|
2014-08-05 06:39:47 +00:00
|
|
|
def show
|
|
|
|
params = OrbitHelper.params
|
2022-10-24 08:30:14 +00:00
|
|
|
faq = Qa.can_display.find_by_param(params[:uid].to_s)
|
2014-05-23 06:03:16 +00:00
|
|
|
|
2014-08-05 06:39:47 +00:00
|
|
|
url_to_edit = OrbitHelper.user_can_edit?(faq) ? "/admin/faqs/#{faq.id.to_s}/edit" : ""
|
2014-12-11 09:48:10 +00:00
|
|
|
|
|
|
|
return {} if (faq.category.disable rescue false)
|
2021-11-15 04:35:23 +00:00
|
|
|
locale = I18n.locale.to_s
|
2021-11-15 04:39:30 +00:00
|
|
|
|
2021-11-23 05:27:11 +00:00
|
|
|
faqs_files = faq.qa_files.collect do |qa_file|
|
2021-11-15 04:35:23 +00:00
|
|
|
next if !qa_file.enabled_for?(locale)
|
2021-11-16 02:14:40 +00:00
|
|
|
file = qa_file.file
|
|
|
|
next if file.path.nil?
|
2014-08-05 06:39:47 +00:00
|
|
|
{
|
2021-11-23 05:27:11 +00:00
|
|
|
"file_url" => file.url + "\" title=\"#{qa_file.file_title}",
|
|
|
|
"file_title" => qa_file.title
|
2014-08-05 06:39:47 +00:00
|
|
|
}
|
2021-11-15 04:39:30 +00:00
|
|
|
end.compact
|
2014-08-05 06:39:47 +00:00
|
|
|
faqs_links = faq.qa_links.collect do |f|
|
|
|
|
{
|
|
|
|
"link_url" => f.url,
|
|
|
|
"link_title" => f.title
|
|
|
|
}
|
|
|
|
end
|
|
|
|
tags = faq.tags.map{|tag| { "tag" => tag.name } } rescue []
|
2020-03-20 07:44:21 +00:00
|
|
|
temp_rich_title = Nokogiri::HTML(faq.rich_title).css('body')
|
|
|
|
temp_rich_title.children.each_with_index do |child,i|
|
2020-03-25 03:58:05 +00:00
|
|
|
if !child.attribute('style').nil?
|
|
|
|
temp_rich_title.children[i].attribute('style').value = child.attribute('style').value.gsub(/\b(?:font-size\s*?:\s*([^;>]*?)(?=[;">}]))/,'')
|
|
|
|
end
|
2020-03-20 07:44:21 +00:00
|
|
|
end
|
2014-08-05 06:39:47 +00:00
|
|
|
{
|
2020-03-20 07:44:21 +00:00
|
|
|
"extras" => {"question" => temp_rich_title,"answer" => faq.answer},
|
2014-08-05 06:39:47 +00:00
|
|
|
"faqs_links" => faqs_links,
|
|
|
|
"faqs_files" => faqs_files,
|
|
|
|
"tags" => tags,
|
|
|
|
"url_to_edit" => url_to_edit
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def widget
|
2023-10-18 13:01:51 +00:00
|
|
|
faqs = Qa.can_display.order_by(:order_position => "asc").filter_by_widget_categories.collect do |qa|
|
2014-08-05 06:39:47 +00:00
|
|
|
statuses = qa.statuses_with_classname.collect do |status|
|
|
|
|
{
|
|
|
|
"status" => status["name"],
|
|
|
|
"status-class" => "status-#{status['classname']}"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"link_to_show" => OrbitHelper.widget_item_url(qa.to_param),
|
|
|
|
"title" => qa.title,
|
2023-10-16 13:17:54 +00:00
|
|
|
"answer" => qa.answer,
|
2014-08-05 06:39:47 +00:00
|
|
|
"postdate" => qa.created_at.strftime('%Y-%m-%d %H:%M'),
|
|
|
|
"statuses" => statuses
|
|
|
|
}
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"faqs" => faqs,
|
|
|
|
"extras" => {"widget-title"=>"Faqs","more_url"=>OrbitHelper.widget_more_url}
|
|
|
|
}
|
|
|
|
end
|
2014-05-08 07:33:39 +00:00
|
|
|
end
|