From f45ea1249066ebb8c10e163e841c7bd76e0e851f Mon Sep 17 00:00:00 2001 From: manson Date: Tue, 5 Aug 2014 14:39:47 +0800 Subject: [PATCH] Add link_to_edit for frontend --- app/controllers/admin/faqs_controller.rb | 4 +- app/controllers/faqs_controller.rb | 122 ++++++++++++----------- app/views/admin/faqs/_form.html.erb | 5 +- 3 files changed, 67 insertions(+), 64 deletions(-) diff --git a/app/controllers/admin/faqs_controller.rb b/app/controllers/admin/faqs_controller.rb index 58168e0..d93acf9 100644 --- a/app/controllers/admin/faqs_controller.rb +++ b/app/controllers/admin/faqs_controller.rb @@ -58,7 +58,7 @@ class Admin::FaqsController < OrbitAdminController @qa.create_user_id = current_user.id @qa.update_user_id = current_user.id @qa.save - redirect_to admin_faqs_path + redirect_to params['referer_url'] end def edit @@ -76,7 +76,7 @@ class Admin::FaqsController < OrbitAdminController @qa.update_attributes(create_params) @qa.update_user_id = current_user.id @qa.save - redirect_to admin_faqs_path + redirect_to params['referer_url'] end def destroy diff --git a/app/controllers/faqs_controller.rb b/app/controllers/faqs_controller.rb index ef96f44..e3bdbfe 100644 --- a/app/controllers/faqs_controller.rb +++ b/app/controllers/faqs_controller.rb @@ -1,68 +1,72 @@ class FaqsController < ApplicationController - def index - faqs = Qa.can_display.order_by(:created_at=>'desc').filter_by_categories - f = faqs.collect do |qa| - statuses = qa.statuses_with_classname.collect do |status| + def index + faqs = Qa.can_display.order_by(:created_at=>'desc').filter_by_categories + f = faqs.collect do |qa| + statuses = qa.statuses_with_classname.collect do |status| { "status" => status["name"], "status-class" => "status-#{status['classname']}" } end - { - "link_to_show" => OrbitHelper.url_to_show(qa.to_param), - "question" => qa.title, - "statuses" => statuses - } - end - { - "faqs" => f, - "extras" => {"widget-title"=>"Faqs"}, - "total_pages" => faqs.total_pages - } - end + { + "link_to_show" => OrbitHelper.url_to_show(qa.to_param), + "question" => qa.title, + "statuses" => statuses + } + end + { + "faqs" => f, + "extras" => {"widget-title"=>"Faqs"}, + "total_pages" => faqs.total_pages + } + end - def show - params = OrbitHelper.params - 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 show + params = OrbitHelper.params + faq = Qa.can_display.find_by_param(params[:uid]) - 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 + url_to_edit = OrbitHelper.user_can_edit?(faq) ? "/admin/faqs/#{faq.id.to_s}/edit" : "" + + 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, + "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 \ No newline at end of file diff --git a/app/views/admin/faqs/_form.html.erb b/app/views/admin/faqs/_form.html.erb index e9b62aa..3f3e6c2 100644 --- a/app/views/admin/faqs/_form.html.erb +++ b/app/views/admin/faqs/_form.html.erb @@ -170,9 +170,8 @@
- <%= f.submit t('submit'), class: 'btn btn-primary' %> - <%#= button_tag t("preview"), id: "button_for_preview", name: "commit", class: 'btn post_preview', type: :button, url: preview_panel_announcement_back_end_bulletins_path %> - <%#= link_to t('cancel'), get_go_back, :class=>"btn" %> + + <%= f.submit t('submit'), class: 'btn btn-primary' %>