Skip to content

Commit

Permalink
Merge 500460d into f4fe648
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny4381 committed Jun 8, 2021
2 parents f4fe648 + 500460d commit bd5f5a9
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 41 deletions.
9 changes: 0 additions & 9 deletions app/assets/javascripts/cms/lib/editor.js
Expand Up @@ -137,15 +137,6 @@ this.Cms_Editor_CKEditor = (function () {
event.cancel();
}
});

if (js_opts && js_opts.openHref) {
$(ev.editor.document.$).on("click", function (ev2) {
if (typeof ev2.target.href != 'undefined') {
var param = jQuery.param({ ref: ev2.target.href });
window.open(js_opts.openHref + "?" + param);
}
});
}
});
};

Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/sns/_notice.scss
@@ -0,0 +1,4 @@
.ss-notice-wrap {
width: 100%;
height: 400px;
}
2 changes: 2 additions & 0 deletions app/assets/stylesheets/sns/_ss.scss
@@ -1,3 +1,5 @@
@import "sns/notice";

.mypage-box {
width: 50%;
float: left;
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/cms/public_notices_controller.rb
Expand Up @@ -26,4 +26,10 @@ def show
raise "403" unless @model.site(@cur_site).and_public.target_to(@cur_user).find(@item.id)
render
end

def frame_content
set_item
raise "403" unless @model.site(@cur_site).and_public.target_to(@cur_user).find(@item.id)
render file: "sns/public_notices/frame_content", layout: false
end
end
5 changes: 5 additions & 0 deletions app/controllers/concerns/sns/public_notice_filter.rb
Expand Up @@ -9,4 +9,9 @@ def show
raise "403" unless @item = @model.and_public.find(params[:id])
render
end

def frame_content
raise "403" unless @item = @model.and_public.find(params[:id])
render file: "frame_content", layout: false
end
end
2 changes: 1 addition & 1 deletion app/controllers/sns/public_notices_controller.rb
Expand Up @@ -3,7 +3,7 @@ class Sns::PublicNoticesController < ApplicationController
include Sys::CrudFilter
include Sns::PublicNoticeFilter

skip_before_action :logged_in?, only: [:index, :show]
skip_before_action :logged_in?, only: [:index, :show, :frame_content]

layout "ss/login"
navi_view nil
Expand Down
10 changes: 7 additions & 3 deletions app/views/cms/public_notices/show.html.erb
@@ -1,5 +1,9 @@
<section class="main-box">
<header><h2><%= @item.send :name %></h2></header>
<%= html_editor "#notice-body", { height: "400px", readonly: true }, { openHref: sns_redirect_path } %>
<%= text_area_tag "notice-body", sanitize(@item.html), style: "height: 400px;" %>
<header><h2><%= @item.name %></h2></header>
<% if false %>
<iframe src="<%= url_for(action: :frame_content) %>" frameborder="0" class="ss-notice-frame" title="<%= @item.name %>" tabindex="0" allowtransparency="true"></iframe>
<% end %>
<div class="ss-notice-wrap">
<%= sanitize(@item.html) %>
</div>
</section>
31 changes: 31 additions & 0 deletions app/views/sns/public_notices/frame_content.html.erb
@@ -0,0 +1,31 @@
<!doctype html>
<html lang="ja">
<head>
<title><%= @item.name %></title>
<link type="text/css" rel="stylesheet" href="/assets/js/ckeditor/contents.css">
<link type="text/css" rel="stylesheet" href="/assets/js/ckeditor/plugins/tableselection/styles/tableselection.css">
</head>
<body contenteditable="false" class="cke_editable cke_editable_themed cke_contents_ltr cke_show_borders" spellcheck="false">
<%= sanitize(@item.html) %>
</body>

<%= javascript_tag(defer: true) do %>
var linkTemplate = <%== sns_redirect_path(ref: "_ref_").to_json %>
var viaSnsRedirect = function(ev) {
var href = encodeURIComponent(this.href);
href = linkTemplate.replace("_ref_", href);
window.open(href);

ev.preventDefault();
return false;
};

document.addEventListener('DOMContentLoaded', function() {
var anchors = document.querySelectorAll("a[href]");
for (var i = 0; i < anchors.length; i++) {
var anchor = anchors.item(i);
anchor.addEventListener("click", viaSnsRedirect);
}
}, false);
<% end %>
</html>
9 changes: 7 additions & 2 deletions app/views/sns/public_notices/show.html.erb
@@ -1,5 +1,10 @@
<section class="main-box">
<header><h2><%= @item.name %></h2></header>
<%= html_editor "#notice-body", { height: "400px", readonly: true, templates: false }, { openHref: sns_redirect_path } %>
<%= text_area_tag "notice-body", sanitize(@item.html), style: "height: 400px;" %>

<% if false %>
<iframe src="<%= url_for(action: :frame_content) %>" frameborder="0" class="ss-notice-frame" title="<%= @item.name %>" tabindex="0" allowtransparency="true"></iframe>
<% end %>
<div class="ss-notice-wrap">
<%= sanitize(@item.html) %>
</div>
</section>
8 changes: 6 additions & 2 deletions config/routes.rb
Expand Up @@ -55,8 +55,12 @@ def part(ns, &block)
match "login" => "login#login", as: :login, via: [:get, :post]
match "remote_login" => "login#remote_login", as: :remote_login, via: [:get, :post]
get "redirect" => "login#redirect", as: :redirect
resources :public_notices, only: [:index, :show]
resources :sys_notices, only: [:index, :show]
resources :public_notices, only: [:index, :show] do
get :frame_content, on: :member
end
resources :sys_notices, only: [:index, :show] do
get :frame_content, on: :member
end
get "status" => "login#status", as: :login_status
get "auth_token" => "auth_token#index", as: :auth_token
get "cms" => "mypage#cms"
Expand Down
8 changes: 6 additions & 2 deletions config/routes/cms/routes_end.rb
Expand Up @@ -116,8 +116,12 @@
resources :columns, concerns: [:deletion]
end
resources :notices, concerns: [:deletion, :copy]
resources :public_notices, concerns: [:deletion, :copy]
resources :sys_notices, only: [:index, :show]
resources :public_notices, concerns: [:deletion, :copy] do
get :frame_content, on: :member
end
resources :sys_notices, only: [:index, :show] do
get :frame_content, on: :member
end

resources :files, concerns: [:deletion, :template] do
get :view, on: :member
Expand Down
4 changes: 3 additions & 1 deletion config/routes/gws/routes.rb
Expand Up @@ -45,7 +45,9 @@
match :import, on: :collection, via: %i[get post]
end
resources :roles, concerns: [:deletion, :download, :import]
resources :sys_notices, only: [:index, :show]
resources :sys_notices, only: [:index, :show] do
get :frame_content, on: :member
end
resources :links, concerns: [:deletion]
resources :public_links, only: [:index, :show]
resources :histories, only: [:index]
Expand Down
4 changes: 3 additions & 1 deletion config/routes/webmail/routes.rb
Expand Up @@ -122,7 +122,9 @@
get :start_export, on: :collection
end

resources :sys_notices, only: [:index, :show]
resources :sys_notices, only: [:index, :show] do
get :frame_content, on: :member
end

namespace "apis" do
get ":webmail_mode-:account/recent" => "imap#recent",
Expand Down
2 changes: 1 addition & 1 deletion spec/features/cms/notice/link_click_spec.rb
Expand Up @@ -16,7 +16,7 @@
visit cms_public_notice_path(site: site, id: item)

new_window = nil
within_frame find("iframe.cke_wysiwyg_frame") do
within_frame find("iframe.ss-notice-frame") do
new_window = window_opened_by { click_on file.humanized_name }
end

Expand Down
16 changes: 8 additions & 8 deletions spec/features/sys/notice/link_click_spec.rb
Expand Up @@ -31,14 +31,14 @@
click_on notice.name

new_window = nil
within_frame find("iframe.cke_wysiwyg_frame") do
within_frame find("iframe.ss-notice-frame") do
new_window = window_opened_by { click_on notice0.name }
end

# new window (tab) is opened and pdf is show
expect(new_window).to be_present
within_window new_window do
within_frame find("iframe.cke_wysiwyg_frame") do
within_frame find("iframe.ss-notice-frame") do
expect(page).to have_css(".heading", text: heading)
end
end
Expand All @@ -56,14 +56,14 @@
click_on notice.name

new_window = nil
within_frame find("iframe.cke_wysiwyg_frame") do
within_frame find("iframe.ss-notice-frame") do
new_window = window_opened_by { click_on notice0.name }
end

# new window (tab) is opened and pdf is show
expect(new_window).to be_present
within_window new_window do
within_frame find("iframe.cke_wysiwyg_frame") do
within_frame find("iframe.ss-notice-frame") do
expect(page).to have_css(".heading", text: heading)
end
end
Expand All @@ -83,14 +83,14 @@
click_on notice.name

new_window = nil
within_frame find("iframe.cke_wysiwyg_frame") do
within_frame find("iframe.ss-notice-frame") do
new_window = window_opened_by { click_on notice0.name }
end

# new window (tab) is opened and pdf is show
expect(new_window).to be_present
within_window new_window do
within_frame find("iframe.cke_wysiwyg_frame") do
within_frame find("iframe.ss-notice-frame") do
expect(page).to have_css(".heading", text: heading)
end
end
Expand All @@ -110,14 +110,14 @@
click_on notice.name

new_window = nil
within_frame find("iframe.cke_wysiwyg_frame") do
within_frame find("iframe.ss-notice-frame") do
new_window = window_opened_by { click_on notice0.name }
end

# new window (tab) is opened and pdf is show
expect(new_window).to be_present
within_window new_window do
within_frame find("iframe.cke_wysiwyg_frame") do
within_frame find("iframe.ss-notice-frame") do
expect(page).to have_css(".heading", text: heading)
end
end
Expand Down
32 changes: 21 additions & 11 deletions spec/features/sys/notice/posting_place_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe "sys_notice", type: :feature, dbscope: :example do
describe "sys_notice", type: :feature, dbscope: :example, js: true do
let!(:notice0) do
create(:sys_notice, notice_severity: "high", notice_target: %w(login_view cms_admin gw_admin webmail_admin sys_admin))
end
Expand All @@ -24,8 +24,10 @@

click_on notice0.name
end
within ".main-box" do
expect(page).to have_content(ApplicationController.helpers.sanitize(notice0.html, tags: []))
within_frame(first(".main-box .ss-notice-frame")) do
within ".cke_editable" do
expect(page).to have_content(ApplicationController.helpers.sanitize(notice0.html, tags: []))
end
end
end
end
Expand All @@ -46,8 +48,10 @@

click_on notice0.name
end
within ".main-box" do
expect(page).to have_content(ApplicationController.helpers.sanitize(notice0.html, tags: []))
within_frame(first(".main-box .ss-notice-frame")) do
within ".cke_editable" do
expect(page).to have_content(ApplicationController.helpers.sanitize(notice0.html, tags: []))
end
end
end
end
Expand All @@ -70,8 +74,10 @@

click_on notice0.name
end
within ".main-box" do
expect(page).to have_content(ApplicationController.helpers.sanitize(notice0.html, tags: []))
within_frame(first(".main-box .ss-notice-frame")) do
within ".cke_editable" do
expect(page).to have_content(ApplicationController.helpers.sanitize(notice0.html, tags: []))
end
end
end
end
Expand All @@ -94,8 +100,10 @@

click_on notice0.name
end
within ".main-box" do
expect(page).to have_content(ApplicationController.helpers.sanitize(notice0.html, tags: []))
within_frame(first(".main-box .ss-notice-frame")) do
within ".cke_editable" do
expect(page).to have_content(ApplicationController.helpers.sanitize(notice0.html, tags: []))
end
end
end
end
Expand All @@ -118,8 +126,10 @@

click_on notice0.name
end
within ".main-box" do
expect(page).to have_content(ApplicationController.helpers.sanitize(notice0.html, tags: []))
within_frame(first(".main-box .ss-notice-frame")) do
within ".cke_editable" do
expect(page).to have_content(ApplicationController.helpers.sanitize(notice0.html, tags: []))
end
end
end
end
Expand Down

0 comments on commit bd5f5a9

Please sign in to comment.