From 8467dd318926a281f65a642b71e89bb39e026d0b Mon Sep 17 00:00:00 2001 From: manson Date: Tue, 5 Aug 2014 14:37:33 +0800 Subject: [PATCH] Add link_to_edit for frontend --- app/controllers/admin/announcements_controller.rb | 10 +++++----- app/controllers/announcements_controller.rb | 6 ++++-- app/views/admin/announcements/_form.html.erb | 1 + 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/announcements_controller.rb b/app/controllers/admin/announcements_controller.rb index 67f2b1d..c1d2a0f 100644 --- a/app/controllers/admin/announcements_controller.rb +++ b/app/controllers/admin/announcements_controller.rb @@ -41,7 +41,7 @@ class Admin::AnnouncementsController < OrbitAdminController bulletin.update_user_id = current_user.id bulletin.save build_email(bulletin) - redirect_to "/admin/announcements" + redirect_to params['referer_url'] end def edit @@ -50,9 +50,9 @@ class Admin::AnnouncementsController < OrbitAdminController @categories = @module_app.categories.enabled @statuses = [] @bulletin.email_sentdate = Time.now if @bulletin.email_sent == false - else - render_401 - end + else + render_401 + end end def update @@ -70,7 +70,7 @@ class Admin::AnnouncementsController < OrbitAdminController bulletin.update_attributes(bulletin_params) bulletin.save build_email(bulletin) - redirect_to "/admin/announcements" + redirect_to params['referer_url'] end def destroy diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 4ab1ac5..9280860 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -60,9 +60,10 @@ class AnnouncementsController < ApplicationController def show params = OrbitHelper.params - announcement = Bulletin.can_display.find_by(:uid=>params[:uid]) + url_to_edit = OrbitHelper.user_can_edit?(announcement) ? "/admin/announcements/#{announcement.id.to_s}/edit" : "" + tags = announcement.tags.map{|tag| { "tag" => tag.name , "url" => OrbitHelper.page_for_tag(tag) @@ -81,7 +82,8 @@ class AnnouncementsController < ApplicationController "body" =>announcement.text, "image" => announcement.image.url }, - "impressionist" => (announcement.is_preview ? nil : announcement) + "impressionist" => (announcement.is_preview ? nil : announcement), + "url_to_edit"=>url_to_edit } end diff --git a/app/views/admin/announcements/_form.html.erb b/app/views/admin/announcements/_form.html.erb index ef4cd52..9623791 100644 --- a/app/views/admin/announcements/_form.html.erb +++ b/app/views/admin/announcements/_form.html.erb @@ -287,6 +287,7 @@
<%= f.submit t('submit'), class: 'btn btn-primary' %> + <%= button_tag t("preview"), id: "button_for_preview", name: "commit", class: 'btn', type: :button %> <%= link_to t('cancel'), admin_announcements_path, :class=>"btn" %>