Add link_to_edit for frontend

This commit is contained in:
manson 2014-08-05 14:39:47 +08:00
parent 951be509e5
commit f45ea12490
3 changed files with 67 additions and 64 deletions

View File

@ -58,7 +58,7 @@ class Admin::FaqsController < OrbitAdminController
@qa.create_user_id = current_user.id @qa.create_user_id = current_user.id
@qa.update_user_id = current_user.id @qa.update_user_id = current_user.id
@qa.save @qa.save
redirect_to admin_faqs_path redirect_to params['referer_url']
end end
def edit def edit
@ -76,7 +76,7 @@ class Admin::FaqsController < OrbitAdminController
@qa.update_attributes(create_params) @qa.update_attributes(create_params)
@qa.update_user_id = current_user.id @qa.update_user_id = current_user.id
@qa.save @qa.save
redirect_to admin_faqs_path redirect_to params['referer_url']
end end
def destroy def destroy

View File

@ -1,68 +1,72 @@
class FaqsController < ApplicationController class FaqsController < ApplicationController
def index def index
faqs = Qa.can_display.order_by(:created_at=>'desc').filter_by_categories faqs = Qa.can_display.order_by(:created_at=>'desc').filter_by_categories
f = faqs.collect do |qa| f = faqs.collect do |qa|
statuses = qa.statuses_with_classname.collect do |status| statuses = qa.statuses_with_classname.collect do |status|
{ {
"status" => status["name"], "status" => status["name"],
"status-class" => "status-#{status['classname']}" "status-class" => "status-#{status['classname']}"
} }
end end
{ {
"link_to_show" => OrbitHelper.url_to_show(qa.to_param), "link_to_show" => OrbitHelper.url_to_show(qa.to_param),
"question" => qa.title, "question" => qa.title,
"statuses" => statuses "statuses" => statuses
} }
end end
{ {
"faqs" => f, "faqs" => f,
"extras" => {"widget-title"=>"Faqs"}, "extras" => {"widget-title"=>"Faqs"},
"total_pages" => faqs.total_pages "total_pages" => faqs.total_pages
} }
end end
def show def show
params = OrbitHelper.params params = OrbitHelper.params
faq = Qa.can_display.find_by_param(params[:uid]) faq = Qa.can_display.find_by_param(params[:uid])
faqs_files = faq.qa_files.collect do |f|
{
"file_url" => f.file.url,
"file_title" => f.title
}
end
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 []
{
"extras" => {"question" => faq.title,"answer" => faq.answer},
"faqs_links" => faqs_links,
"faqs_files" => faqs_files,
"tags" => tags
}
end
def widget url_to_edit = OrbitHelper.user_can_edit?(faq) ? "/admin/faqs/#{faq.id.to_s}/edit" : ""
faqs = Qa.filter_by_widget_categories.collect do |qa|
statuses = qa.statuses_with_classname.collect do |status| faqs_files = faq.qa_files.collect do |f|
{ {
"status" => status["name"], "file_url" => f.file.url,
"status-class" => "status-#{status['classname']}" "file_title" => f.title
} }
end end
{ faqs_links = faq.qa_links.collect do |f|
"link_to_show" => OrbitHelper.widget_item_url(qa.to_param), {
"title" => qa.title, "link_url" => f.url,
"postdate" => qa.created_at.strftime('%Y-%m-%d %H:%M'), "link_title" => f.title
"statuses" => statuses }
} end
end tags = faq.tags.map{|tag| { "tag" => tag.name } } rescue []
{ {
"faqs" => faqs, "extras" => {"question" => faq.title,"answer" => faq.answer},
"extras" => {"widget-title"=>"Faqs","more_url"=>OrbitHelper.widget_more_url} "faqs_links" => faqs_links,
} "faqs_files" => faqs_files,
end "tags" => tags,
"url_to_edit" => url_to_edit
}
end
def widget
faqs = Qa.filter_by_widget_categories.collect do |qa|
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,
"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
end end

View File

@ -170,9 +170,8 @@
</div> </div>
<!-- Form Actions --> <!-- Form Actions -->
<div class="form-actions"> <div class="form-actions">
<%= f.submit t('submit'), class: 'btn btn-primary' %> <input type="hidden" name="referer_url" value="<%= request.referer %>">
<%#= button_tag t("preview"), id: "button_for_preview", name: "commit", class: 'btn post_preview', type: :button, url: preview_panel_announcement_back_end_bulletins_path %> <%= f.submit t('submit'), class: 'btn btn-primary' %>
<%#= link_to t('cancel'), get_go_back, :class=>"btn" %>
</div> </div>
</fieldset> </fieldset>