From c06e87fb05190b2633448e0133a980881fc15b19 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Tue, 20 Jun 2017 15:04:05 +0800 Subject: [PATCH] added external link option --- app/controllers/announcements_controller.rb | 13 ++++++++--- app/models/bulletin.rb | 2 ++ app/views/admin/announcements/_form.html.erb | 23 ++++++++++++++++++++ config/locales/en.yml | 5 ++++- config/locales/zh_tw.yml | 3 +++ 5 files changed, 42 insertions(+), 4 deletions(-) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 96f925e..def60f5 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -65,6 +65,8 @@ class AnnouncementsController < ApplicationController author = User.find(a.create_user_id).member_profile.name rescue "" desc = a.image_description desc = (desc.nil? || desc == "" ? "announcement image" : desc) + link_to_show = a.is_external_link ? a.external_link : OrbitHelper.url_to_show(a.to_param) + target = a.is_external_link ? "_blank" : "_self" anns << { "bulletin_links" => links, "bulletin_files" => files, @@ -78,7 +80,8 @@ class AnnouncementsController < ApplicationController "postdate" => a.postdate, "author" => author, "is_top" => (a.is_top? ? 1 : 0), - "link_to_show" => OrbitHelper.url_to_show(a.to_param), + "link_to_show" => link_to_show, + "target" => target, "img_src" => a.image.thumb.url || "/assets/announcement-default.jpg", "img_description" => desc, "more" => t(:more_plus), @@ -144,6 +147,7 @@ class AnnouncementsController < ApplicationController "source-site-title" => fa["source-site-title"], "source-site-link" => fa["source-site"], "link_to_show" => OrbitHelper.url_to_show(fa["params"]), + "target" => "_self", "img_src" => fa["image"]["thumb"] || "/assets/announcement-default.jpg", "img_description" => fa["image_description_translations"][locale], "more" => t(:more_plus), @@ -201,7 +205,9 @@ class AnnouncementsController < ApplicationController author = User.find(a.create_user_id).member_profile.name rescue "" desc = a.image_description desc = (desc.nil? || desc == "" ? "announcement image" : desc) - anns << { + link_to_show = a.is_external_link ? a.external_link : OrbitHelper.url_to_show(a.to_param) + target = a.is_external_link ? "_blank" : "_self" + anns << { "bulletin_links" => links, "bulletin_files" => files, "title" => a.title, @@ -213,7 +219,8 @@ class AnnouncementsController < ApplicationController "category" => a.category.title, "postdate" => a.postdate, "author" => author, - "link_to_show" => OrbitHelper.widget_item_url(a.to_param), + "link_to_show" => link_to_show, + "target" => target, "img_src" => a.image.thumb.url || "/assets/announcement-default.jpg", "img_description" => desc } diff --git a/app/models/bulletin.rb b/app/models/bulletin.rb index 4f21b4c..6a295f3 100644 --- a/app/models/bulletin.rb +++ b/app/models/bulletin.rb @@ -24,6 +24,8 @@ class Bulletin field :rejected, :type => Boolean, :default => false field :reapproval, :type => Boolean, :default => false field :rejection_reason + field :is_external_link, :type => Boolean, :default => false + field :external_link field :email_id field :email_sent, :type => Boolean, :default => false diff --git a/app/views/admin/announcements/_form.html.erb b/app/views/admin/announcements/_form.html.erb index c8a001b..dec8ea1 100644 --- a/app/views/admin/announcements/_form.html.erb +++ b/app/views/admin/announcements/_form.html.erb @@ -52,6 +52,21 @@ +
+ <%= f.label :is_external_link, t("announcement.is_external_link"), :class => "control-label muted" %> +
+ <%= f.check_box :is_external_link %> +
+
+ + + @@ -441,6 +456,14 @@ },100) }) + $("#bulletin_is_external_link").on("click",function(){ + if($(this).is(":checked")){ + $("#external_link_box").show(); + }else{ + $("#external_link_box").hide(); + } + }) + }); <% end %> \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 5fccf4e..0b979f6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -75,4 +75,7 @@ en: mail_source: Source mail_time: Time image_upload_size_note: The following recommendations %{image_upload_size} upload size - resend_mail: Re-send Email \ No newline at end of file + resend_mail: Re-send Email + is_external_link: Enable External Link + external_link: External Link + external_link_hint: "Make sure URL starts with http://" \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index a179e60..b910925 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -79,3 +79,6 @@ zh_tw: mail_time: 時間 image_upload_size_note: 建議檔案小於%{image_upload_size} resend_mail: 重新寄送提醒 + is_external_link: 開啟內部連結 + external_link: 外部連結 + external_link_hint: "確定連結開頭為http://"