Skip to content

Commit

Permalink
Merge pull request #968 from uclibs/lisa3711-new2-contactform
Browse files Browse the repository at this point in the history
New Contact Form- Iframe embed
  • Loading branch information
hortongn authored Feb 9, 2022
2 parents dfa9156 + 418cced commit cbc27c1
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 321 deletions.
4 changes: 0 additions & 4 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ SCHOLAR_ANALYTICS_PRIVKEY_PATH=analytics_privkey_path
SCHOLAR_ANALYTICS_PRIVKEY_SECRET=analytics_privkey_secret
SCHOLAR_ANALYTICS_CLIENT_EMAIL=analytics_client_email

# Google Re-captcha
SCHOLAR_CAPTCHA_SITE_KEY=captcha_site_key
SCHOLAR_CAPTCHA_SECRET_KEY=captcha_secret_key

# ORCID
ORCID_AUTHORIZE_URL=change_me
ORCID_APP_ID=change_me
Expand Down
6 changes: 1 addition & 5 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ SCHOLAR_ANALYTICS_PRIVKEY_PATH=analytics_privkey_path
SCHOLAR_ANALYTICS_PRIVKEY_SECRET=analytics_privkey_secret
SCHOLAR_ANALYTICS_CLIENT_EMAIL=analytics_client_email

# Google Re-captcha
SCHOLAR_CAPTCHA_SITE_KEY=captcha_site_key
SCHOLAR_CAPTCHA_SECRET_KEY=captcha_secret_key

# ORCID
ORCID_AUTHORIZE_URL=change_me
ORCID_APP_ID=change_me
Expand Down Expand Up @@ -77,4 +73,4 @@ SCHOLAR_DOI_URL=https://api.test.datacite.org/dois
API_KEY={ :development => 'testKey'}

# XRay max log size in MB, must be an integer value
SCHOLAR_XRAY_MAX_LOG_SIZE=10
SCHOLAR_XRAY_MAX_LOG_SIZE=10
5 changes: 0 additions & 5 deletions app/assets/stylesheets/hyrax.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@
padding-bottom: 10px;
}

.g-recaptcha {
margin-bottom: 20px;
}


div.profile a.btn-primary {
margin-bottom: 20px;
}
Expand Down
60 changes: 0 additions & 60 deletions app/controllers/hyrax/contact_form_controller.rb

This file was deleted.

36 changes: 0 additions & 36 deletions app/models/hyrax/contact_form.rb

This file was deleted.

1 change: 0 additions & 1 deletion app/views/hyrax/contact_form/_directions.html.erb

This file was deleted.

142 changes: 96 additions & 46 deletions app/views/hyrax/contact_form/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,47 +1,97 @@
<script src='https://www.google.com/recaptcha/api.js'></script>
<div class="alert alert-info">
<%= render 'directions' %>
</div>

<h1>
<%= t('hyrax.contact_form.header') %>
</h1>

<% if user_signed_in? %>
<% nm = current_user.name %>
<% em = current_user.email %>
<% else %>
<% nm = '' %>
<% em = '' %>
<% end %>

<%= form_for @contact_form, url: hyrax.contact_form_index_path,
html: { class: 'form-horizontal' } do |f| %>
<%= f.text_field :contact_method, class: 'hide' %>

<div class="form-group">
<%= f.label :name, t('hyrax.contact_form.name_label'), class: "col-sm-2 control-label" %>
<div class="col-sm-10"><%= f.text_field :name, value: nm, class: 'form-control', required: true %></div>
</div>

<div class="form-group">
<%= f.label :email, t('hyrax.contact_form.email_label'), class: "col-sm-2 control-label" %>
<div class="col-sm-10"><%= f.text_field :email, value: em, class: 'form-control', required: true %></div>
</div>

<div class="form-group">
<%= f.label :subject, t('hyrax.contact_form.subject_label'), class: "col-sm-2 control-label" %>
<div class="col-sm-10"><%= f.text_field :subject, class: 'form-control', required: true %></div>
</div>

<div class="form-group">
<%= f.label :message, t('hyrax.contact_form.message_label'), class: "col-sm-2 control-label" %>
<div class="col-sm-10"><%= f.text_area :message, rows: 4, class: 'form-control', required: true %></div>
</div>

<% if current_user.blank? %>
<div class="g-recaptcha" data-sitekey= "<%=CAPTCHA_SERVER['site_key']%>"></div>
<% end %>

<%= f.submit value: t('hyrax.contact_form.button_label'), class: "btn btn-primary" %>
<% end %>
<iframe
id="JotFormIFrame-220205071955146"
title="Scholar at UC Contact Form"
onload="window.parent.scrollTo(0,0)"
allowtransparency="true"
allowfullscreen="true"
allow="geolocation; microphone; camera"
src="https://form.jotform.com/220205071955146"
frameborder="0"
style="
min-width: 100%;
height:539px;
border:none;"
scrolling="no"
>
</iframe>
<script type="text/javascript">
var ifr = document.getElementById("JotFormIFrame-220205071955146");
if (ifr) {
var src = ifr.src;
var iframeParams = [];
if (window.location.href && window.location.href.indexOf("?") > -1) {
iframeParams = iframeParams.concat(window.location.href.substr(window.location.href.indexOf("?") + 1).split('&'));
}
if (src && src.indexOf("?") > -1) {
iframeParams = iframeParams.concat(src.substr(src.indexOf("?") + 1).split("&"));
src = src.substr(0, src.indexOf("?"))
}
iframeParams.push("isIframeEmbed=1");
ifr.src = src + "?" + iframeParams.join('&');
}
window.handleIFrameMessage = function(e) {
if (typeof e.data === 'object') { return; }
var args = e.data.split(":");
if (args.length > 2) { iframe = document.getElementById("JotFormIFrame-" + args[(args.length - 1)]); } else { iframe = document.getElementById("JotFormIFrame"); }
if (!iframe) { return; }
switch (args[0]) {
case "scrollIntoView":
iframe.scrollIntoView();
break;
case "setHeight":
iframe.style.height = args[1] + "px";
break;
case "collapseErrorPage":
if (iframe.clientHeight > window.innerHeight) {
iframe.style.height = window.innerHeight + "px";
}
break;
case "reloadPage":
window.location.reload();
break;
case "loadScript":
if( !window.isPermitted(e.origin, ['jotform.com', 'jotform.pro']) ) { break; }
var src = args[1];
if (args.length > 3) {
src = args[1] + ':' + args[2];
}
var script = document.createElement('script');
script.src = src;
script.type = 'text/javascript';
document.body.appendChild(script);
break;
case "exitFullscreen":
if (window.document.exitFullscreen) window.document.exitFullscreen();
else if (window.document.mozCancelFullScreen) window.document.mozCancelFullScreen();
else if (window.document.mozCancelFullscreen) window.document.mozCancelFullScreen();
else if (window.document.webkitExitFullscreen) window.document.webkitExitFullscreen();
else if (window.document.msExitFullscreen) window.document.msExitFullscreen();
break;
}
var isJotForm = (e.origin.indexOf("jotform") > -1) ? true : false;
if(isJotForm && "contentWindow" in iframe && "postMessage" in iframe.contentWindow) {
var urls = {"docurl":encodeURIComponent(document.URL),"referrer":encodeURIComponent(document.referrer)};
iframe.contentWindow.postMessage(JSON.stringify({"type":"urls","value":urls}), "*");
}
};
window.isPermitted = function(originUrl, whitelisted_domains) {
var url = document.createElement('a');
url.href = originUrl;
var hostname = url.hostname;
var result = false;
if( typeof hostname !== 'undefined' ) {
whitelisted_domains.forEach(function(element) {
if( hostname.slice((-1 * element.length - 1)) === '.'.concat(element) || hostname === element ) {
result = true;
}
});
return result;
}
};
if (window.addEventListener) {
window.addEventListener("message", handleIFrameMessage, false);
} else if (window.attachEvent) {
window.attachEvent("onmessage", handleIFrameMessage);
}
</script>
4 changes: 2 additions & 2 deletions config/initializers/hyrax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
# config.admin_set_predicate = ::RDF::DC.isPartOf

# Email recipient of messages sent via the contact form
config.contact_email = "[email protected]"
# config.contact_email = "[email protected]"

# Text prefacing the subject entered in the contact form
config.subject_prefix = "Scholar@UC Contact form:"
# config.subject_prefix = "Scholar@UC Contact form:"

# How many notifications should be displayed on the dashboard
# config.max_notifications_for_dashboard = 5
Expand Down
3 changes: 0 additions & 3 deletions config/initializers/load_captcha_configs.rb

This file was deleted.

4 changes: 0 additions & 4 deletions config/locales/hyrax.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ en:
results_per_page: Results per page
sort_by: Sort by
works_in_collection: Items in this Collection
contact_form:
header: Contact the Scholar@UC Team
notice_html: 'Please us this form to send questions, feedback, or report a problem to the Scholar@UC team. You can also check %{href} for more information'
help_resources_href: 'Help Resources'
file_sets:
show_details:
fixity_check: Fixity Check
Expand Down
11 changes: 0 additions & 11 deletions config/recaptcha.yml

This file was deleted.

Loading

0 comments on commit cbc27c1

Please sign in to comment.