document.onkeypress = function(evt) {
var evt = evt ? evt : (event ? event : null);
var node = evt.target ? evt.target : (evt.srcElement ? evt.srcElement : null);
if (evt.keyCode == 13 && node.type == "text") {
return false;
}
};
var trackableHeaderActions = {
'subject': 'subject_line',
'fromName': 'from_name',
'fromEmailAddress': 'from_email',
'useFromAsReplyTo': 'reply-to-addr',
'permissionReminderEnabled': 'permission reminder',
'webpageEnabled': 'webpage version',
'webpageVersion': 'webpage cta txt',
'webpageLink': 'webpage link txt',
'socialShareLinksEnabled': 'socialshare',
'overlay_messageOptions_btn_secondary': 'text link Cancel',
'overlay_messageOptions_overlay_close_btn': 'x icon Cancel',
'preheader': 'preheader'
};
jq(document).ready(function() {
enableWizardButtons();
jq("input#subject").keyup(enableWizardButtons);
jq("#preheader").keyup(enableWizardButtons);
jq("input#fromName").keyup(enableWizardButtons);
jq("input#webpageVersion").keyup(enableWizardButtons);
jq("input#webpageLink").keyup(enableWizardButtons);
jq("textarea#permissionReminderValue").keyup(enableWizardButtons);
jq("input#subject").keyup(function(){
if(typeof (distui) != "undefined" && distui) {
distui.dispatchEvent("changesubject", { "subject": jQuery("input#subject").val() }, true);
}
});
jq("#fromNameInfo")
.infoPopup({
useCanvas: true,
content:"What is "From Name"?
The "From Name" is the name that appears in your contact's inbox next to the Subject line of your email. People will often delete mail or report it as spam if they do not instantly recognize who the mail is from. Therefore it is very important to make your "From Name" recognizable and familiar to your contacts. In most cases your contacts are more likely to recognize your business or association name rather than your personal name.
For example, "Joe's Flower Shop" may be more recognizable than "Joe Smith"."
});
jq("#preheaderInfo")
.infoPopup({
useCanvas: true,
content:"What is Preheader
Enter a summary that will show up near the subject line in most email clients. Use this to engage your recipients before they open your email."
});
jq("#useFromAsReplyTo").change(
function() {
if (jq(this).prop('checked')) {
jq("#replyToEmailAddress").parents("li").hide();
jq("#replyToEmailAddress").val(jq("#fromEmailAddress").val());
}
else {
jq("#replyToEmailAddress").parents("li").show();
}
}
);
jq("#fromEmailAddress").change(function(){
if(jq("#useFromAsReplyTo").prop("checked")){
jq("#replyToEmailAddress").val(jq(this).val());
}
});
});
function validatePreheader(){
var $preheader = jq("#preheader"), valid=true;
if($preheader.val().length > 140){
jq("#preheaderErrors").html("");
valid=false;
} else {
jq("#preheaderClientErrors").remove();
}
return valid;
}
function validField(id, connectedChkBoxId) {
var isValid = false;
if ((!connectedChkBoxId || jq("#" + connectedChkBoxId).is(':checked')) && (!jq("#" + id).val() || jq("#" + id).val().replace(/[ n]/g, "") == "")) {
jq("span#" + id + "Errors").html("This field is required.");
}
else {
jq("span#" + id + "ClientErrors").remove();
isValid = true;
}
return isValid;
}
//TODO: Figure out where the heck this gets called from and/or if it's even needed.
function validateSendersEmails(successCallback) {
var form = document.forms.theForm;
if (!form.wizardNavAction) {
FormControl.setWizardAction(form, "wizardNavAction");
}
form.wizardNavAction.value = "_ajaxPost";
if (!form._ajaxPostAction) {
FormControl.createHiddenParam(form, "_ajaxPostAction", "_validate_sender_emails");
} else {
form._ajaxPostAction.value = "_validate_sender_emails";
}
var urlParams = jq(':input[name="settings.header.fromEmail"],:input[name="settings.header.replyEmail"],' +
':input[name="wizardNavAction"],:input[name="_ajaxPostAction"], :input[name="_page"]').serialize();
var url = window.location.href + "&" + urlParams;
enableWizardButton("scheduleButton", false, "btn-primary");
jq('html, body').css('cursor', 'progress');
jq.ajax({
async: true,
cache: false,
dataType: "json",
error: function(request, textStatus, errorThrown) {
handleSendersEmailValidationErrors(["|" + errorThrown]);
},
success: function(data, textStatus) {
if (data.status == "failure") {
handleSendersEmailValidationErrors(data.errors);
} else {
//clear any previous errors
jq("#fromEmailAddress_errors").html("");
jq("#replyToEmailAddress_errors").html("");
successCallback();
}
},
complete: function(jqXHR, textStatus) {
enableWizardButton("scheduleButton", true, "btn-primary");
jq('html, body').css('cursor', 'auto');
},
type: "POST",
url: url
});
}
function handleSendersEmailValidationErrors(errors) {
if (!errors || !errors.length) {
return;
}
jq("#fromEmailAddress_errors").html("");
jq("#replyToEmailAddress_errors").html("");
for (var i = 0; errors && i < errors.length; i++) {
var error = errors[i];
var errTokens = error.split("|",2);
var fieldName = errTokens[0];
var errorMsg = errTokens[1];
switch(fieldName){
case "settings.header.fromEmail":
jq("#fromEmailAddress_errors").append(jq("" + errorMsg + ""));
break;
case "settings.header.replyEmail":
jq("#replyToEmailAddress_errors").append(jq("" + errorMsg + ""));
break;
default:
jq("#generalErrors").append(jq("" + errorMsg + ""));
}
}
}
function enableWizardButtons() {
var validSubject = validField("subject");
var validPreheader = validatePreheader();
var validFromName = validField("fromName");
var validWebpageVersion = validField("webpageVersion", "webpageEnabled");
var validWebpageLink = validField("webpageLink", "webpageEnabled");
var validPermissionReminder = validField("permissionReminderValue", "permissionReminderEnabled");
var enable = validSubject && validPreheader && validFromName && validWebpageVersion && validWebpageLink && validPermissionReminder
&& jq("select#fromEmailAddress").val() &&
jq("select#replyToEmailAddress").val();
enableWizardButton("overlay_messageOptions_btn_primary", enable);
}
function enableWizardButton(id, enable, baseClass) {
jq("#" + id).attr("disabled", !enable);
jq("#" + id).toggleClass ("ui-state-disabled", !enable);
}
var originalMessageOptions = {
subject: "What do Epic users really think? 11 insights | The rise of 'super regional systems' & what it means for healthcare | The 9 CIO executives of the HIMSS Executive Institute | Cyberattack on Maine hospital shakes loose private physician, employee data",
fromName: "Becker's Health IT & CIO Report ",
fromEmailAddress: "editorial@beckershealthcare.com",
replyToEmailAddress: "editorial@beckershealthcare.com",
permissionReminder: {
required: false,
enabled: false,
content: "Hi, just a reminder that you're receiving this email because you have expressed an interest in ASC Communications. Don't forget to add editorial@beckershealthcare.com to your address book so we'll be sure to land in your inbox!"
},
webpage: {
enabled: false,
version: "Having trouble viewing this email?",
link: "Click here"
},
socialShareLinks: { enabled: false },
preheader:""
};
function setupHeaderTracking() {
var inputs = jq('#subject').add('#fromName').add('#webpageVersion').add('#webpageLink').add("#preheader");
inputs
.off('focus.ctctTracking')
.on('focus.ctctTracking', function(){
var $this = jQuery(this);
$this.data('prevVal', $this.val());
})
.off('blur.ctctTracking')
.on('blur.ctctTracking', function(){
var $this = jq(this),
newVal = $this.val(),
prevVal = $this.data('prevVal');
if(prevVal && jQuery.trim(prevVal) !== jQuery.trim(newVal)) {
$this.attr('data-value-changed', true);
}
});
var dropdowns = jq('#fromEmailAddress');
dropdowns
.off('change.ctctTracking')
.on('change.ctctTracking', function(){
jq(this).attr('data-value-changed', true);
});
var checkboxes = jq('#useFromAsReplyTo').add('#permissionReminderEnabled').add('#webpageEnabled').add('#socialShareLinksEnabled');
checkboxes
.off('click.ctctTracking')
.on('click.ctctTracking', function(){
jq(this).attr('data-value-changed', true);
});
if(window.CtctTracking) {
var overlayBtns = jq('#overlay_messageOptions_btn_secondary')
.add('#overlay_messageOptions_overlay_close_btn');
overlayBtns.off('click.ctctTracking').on('click.ctctTracking', function(){
trackHeaderAction(jq(this).attr('id'));
});
}
}
function trackHeaderEvents(elms) {
elms = elms || jq('#overlay_messageOptions').find('[data-value-changed]');
elms.each(function(){
var $this = jq(this),
id = $this.attr('id'),
prefix = '';
if($this.is(':checkbox')){
prefix = (this.checked ? 'ON:' : 'OFF:');
}
$this.removeAttr('data-value-changed');
trackHeaderAction(id, prefix);
});
}
function trackHeaderAction(id, prefix) {
var field = id ? trackableHeaderActions[id] : null,
prefix = prefix || '';
if(window.CtctTracking && field) {
window.CtctTracking.trackAction('Email Edit Header', { 'field' : prefix + field });
}
}
jq(document).ready(function() {
createOptionsOverlay();
setupHeaderTracking();
jq("input[type='checkbox']").click(enableWizardButtons);
jq("#permissionReminderHelpInfo").infoPopup({
useCanvas: true,
content:"This reminder text will be displayed at the top of your email along with an unsubscribe link."
});
jq("#webpageHelpInfo").infoPopup({
useCanvas: true,
content:"Link and link text display together at the top of your email"
});
jq("#socialShareLinksHelpInfo").infoPopup({
useCanvas: true,
content:"Expand your reach by letting subscribers share your email on their social networks."
});
jq("#frm_overlay_messageOptions").submit(submitOptionsOverlay);
});
function webpageTooltipVersionUpdater() {
jq("#webpageTooltipVersion").html(jq("#webpageVersion").val());
}
function webpageTooltipLinkUpdater() {
jq("#webpageTooltipLink").html(jq("#webpageLink").val());
}
function webpageTooltipUpdater() {
webpageTooltipVersionUpdater();
webpageTooltipLinkUpdater();
}
function createOptionsOverlay() {
jq(".enabler").click(function() { showHide.call(jq(this), jq(this).attr("checked")); });
try {
var width = 510,
okClicked = false,
headerContaniner = parent;
jq("#overlay_messageOptions").overlay({
beforeClose: function() {
documentFrame.eve.currentBlock.blockEditor.cancelEditing();
if (typeof evePage != 'undefined' && evePage && evePage.optimize) evePage.optimize.isDirty =true;
jq("#fromNameInfo").infoPopup("hideAll");
jq("#preheaderInfo").infoPopup("hideAll");
if (!okClicked) {
headerContaniner.jQuery('body').trigger('header:cancel');
}
okClicked = false;
},
autoOpen: false,
buttons: [
{
id: "overlay_messageOptions_btn_primary",
text: "OK",
click: function() { okClicked = true; closeOptionsOverlay(true); },
"class": "btn-primary" // NOTE: jQuery.overlay() requires this "class" property, but IE chokes if we use class unquoted
},
{
id: "overlay_messageOptions_btn_secondary",
text: "Cancel",
click: function() { closeOptionsOverlay(false); },
"class": "btn-secondary" // NOTE: jQuery.overlay() requires this "class" property, but IE chokes if we use class unquoted
}
],
title: "Header Options",
usage: "frame",
width: width,
resizeOnScroll : (typeof onIOSDevice === 'undefined' ? true : !onIOSDevice )
});
}
catch (exception) {
}
}
function showOptionsOverlay() {
jq("#overlay_messageOptions").overlay("open");
//set overlay-y hidden if height is auto
var styleAttrOverlay = jq("#overlay_messageOptions").attr("style");
if (styleAttrOverlay.indexOf("height:auto")>0 || styleAttrOverlay.indexOf("height: auto")>0 || styleAttrOverlay.indexOf("height : auto")>0) {
jq("#overlay_messageOptions").css("overflow-y", "hidden");
} else {
jq("#overlay_messageOptions").css("overflow-y", "auto");
}
if (!originalMessageOptions.permissionReminder.required) {
jq("#permissionReminderEnabled").attr("checked", originalMessageOptions.permissionReminder.enabled);
}
jq("#permissionReminderEnabled").attr("checked", originalMessageOptions.permissionReminder.required || originalMessageOptions.permissionReminder.enabled);
jq("#permissionReminderValue").val(originalMessageOptions.permissionReminder.content);
showHide.call(jq("#permissionReminderEnabled"), originalMessageOptions.permissionReminder.required || originalMessageOptions.permissionReminder.enabled);
jq("#webpageEnabled").attr("checked", originalMessageOptions.webpage.enabled);
jq("#webpageVersion").val(originalMessageOptions.webpage.version);
jq("#webpageLink").val(originalMessageOptions.webpage.link);
showHide.call(jq("#webpageEnabled"), originalMessageOptions.webpage.enabled);
webpageTooltipVersionUpdater();
webpageTooltipLinkUpdater();
jq("#socialShareLinksEnabled").attr("checked", originalMessageOptions.socialShareLinks.enabled);
jq("#subject").val(originalMessageOptions.subject);
jq("#preheader").val(originalMessageOptions.preheader);
jq("#fromName").val(originalMessageOptions.fromName);
fromAsReplyTo();
enableWizardButtons();
jq("#socialShareLinksHelpInfo").infoPopup({
useCanvas: true,
content:"Expand your reach by letting subscribers share your email on their social networks."
});
if(navigator.userAgent.match(/(iPad|iPhone|iPod)/g) && document.activeElement) {
//the user must initiate the focus on an ipad, otherwise typing won't work
document.activeElement.blur();
}
}
function submitOptionsOverlay() { //event) {
jq("#generalErrors").html("");
jq("#messageOptionsErrors").html("");
//event.preventDefault();
var permReminder = jq("#permissionReminderValue"),
ajaxURL ="/rnavmap/emcf/email/ajax/create",
form = jq(document.forms.frm_overlay_messageOptions),
url = ajaxURL + window.location.search,
$thisOverlay = jq("#overlay_messageOptions");
// replace new line characters in permission reminder text with ;
permReminder.val(permReminder.val().replace(/n/g,""));
$thisOverlay.pacify();
$thisOverlay.pacify("start");
jq.ajax({
async: false,
cache: false,
data: form.serialize(),
dataType: "json",
error: function(request, textStatus, errorThrown) {
$thisOverlay.pacify("stop");
// Protect against HTML injection
errorThrown = String(errorThrown).replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(//g, ">");
messageOptions_handleAjaxErrors([ errorThrown ? errorThrown : textStatus ]);
},
success: function(data, textStatus) {
$thisOverlay.pacify("stop");
if (data.status == "failure") {
messageOptions_handleAjaxErrors(data.errors);
}
else {
if (!originalMessageOptions.permissionReminder.required) {
originalMessageOptions.permissionReminder.enabled = jq("#permissionReminderEnabled")[0].checked;
}
if (originalMessageOptions.permissionReminder.required || originalMessageOptions.permissionReminder.enabled) {
originalMessageOptions.permissionReminder.content = jq("#permissionReminderValue").val();
}
originalMessageOptions.webpage.enabled = jq("#webpageEnabled")[0].checked;
if (originalMessageOptions.webpage.enabled) {
originalMessageOptions.webpage.version = jq("#webpageVersion").val();
originalMessageOptions.webpage.link = jq("#webpageLink").val();
}
originalMessageOptions.socialShareLinks.enabled = jq("#socialShareLinksEnabled")[0].checked;
originalMessageOptions.subject = jq("#subject").val();
originalMessageOptions.preheader = jq("#preheader").val();
originalMessageOptions.fromName = jq("#fromName").val();
originalMessageOptions.fromEmailAddress = jq("#fromEmailAddress").val();
originalMessageOptions.replyToEmailAddress = jq("#replyToEmailAddress").val();
closeOptionsOverlay(false);
if(evePage && evePage.actionBar){
evePage.toggleContentLoadingIndicator();
evePage.activeView.isDirty=true;
var headerParent = parent;
evePage.viewIframe.one("load", function(){ headerParent.jQuery('body').trigger( 'header:save' ); });
evePage.actionBar.updateFrameSource(evePage.activeView.url);
} else {
wizardSave();
}
}
},
type: "POST",
url: url
});
}
function fromAsReplyTo() {
var jqFrom = jq("#fromEmailAddress"),
jqReply = jq("#replyToEmailAddress"),
jqFromAsReply = jq("#useFromAsReplyTo");
if (jqFrom.val() == jqReply.val()) {
jqFromAsReply.prop("checked", true);
jqReply.parents("li").hide();
}
else {
jqFromAsReply.prop("checked", false);
jqReply.parents("li").show();
}
}
function resetHeaderDefaults() {
var jqFrom = jq("#fromEmailAddress"),
jqReply = jq("#replyToEmailAddress");
jqFrom.val(originalMessageOptions.fromEmailAddress);
jqReply.val(originalMessageOptions.replyToEmailAddress);
}
function closeOptionsOverlay(isOK) {
if (isOK) {
trackHeaderEvents();
submitOptionsOverlay();
return;
}
resetHeaderDefaults();
jq("#messageOptionsErrors").html("");
jQuery("#overlay_messageOptions").overlay("close");
}
function messageOptions_handleAjaxErrors(errors) {
if (!errors || !errors.length) {
return;
}
jq("#messageOptionsErrors").html("");
for (var i = 0; errors && i < errors.length; i++) {
jq("#messageOptionsErrors").append(jq("
" + errors[ i ] + "
"));
}
}
function showHide() {
if (!arguments || !arguments.length) {
jq(this).parent().find(".showHide").toggle();
}
else if (arguments[0]) {
jq(this).parent().find(".showHide").show();
}
else {
jq(this).parent().find(".showHide").hide();
}
}