Skip to content

Commit

Permalink
fix error check, styling fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Amy Chen committed Mar 18, 2024
1 parent bf86dc3 commit ae34c63
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
47 changes: 30 additions & 17 deletions portal/static/js/src/empro.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ emproObj.prototype.initThankyouModal = function (autoShow) {
$("#emproModal").modal(autoShow ? "show" : "hide");
};
emproObj.prototype.populateSelectedOptoutUI = function () {
if (!this.submittedOptOutDomains || this.submittedOptOutDomains.length === 0) {
if (
!this.submittedOptOutDomains ||
this.submittedOptOutDomains.length === 0
) {
return;
}
console.log("submitted opt out domains: ", this.submittedOptOutDomains);
Expand All @@ -92,8 +95,8 @@ emproObj.prototype.populateOptoutInputItems = function () {
<div class="item">
<input type="checkbox" class="ck-input ck-input-${domain}" value="${domain}">
<span class="ck-display" data-domain="${domain}">${this.getDomainDisplay(
domain
)}</span>
domain
)}</span>
</div>
`);
});
Expand All @@ -117,9 +120,12 @@ emproObj.prototype.setOptoutSubmitData = function () {
console.log("Optout data to be submitted: ", submitData);
EmproObj.optOutSubmitData = submitData;
};
emproObj.prototype.setOptoutError = function(text) {
document.querySelector("#emproOptOutModal .error-message").innerText = text;
}
emproObj.prototype.onBeforeSubmitOptoutData = function () {
// reset error
$("#emproOptOutModal .error-message").addClass("hide");
EmproObj.setOptoutError("");
// set data in the correct format for submission to API
EmproObj.setOptoutSubmitData();
// disable buttons
Expand All @@ -136,9 +142,7 @@ emproObj.prototype.onAfterSubmitOptoutData = function (data) {
$("#emproOptOutModal .saving-indicator-container").addClass("hide");
// show error if any
if (data && data.error) {
document.querySelector("#emproOptOutModal .error-message").innerText =
"System error: Unable to save your choices.";
$("#emproOptOutModal .error-message").removeClass("hide");
EmproObj.setOptoutError("System error: Unable to save your choices.");
return false;
}
EmproObj.submittedOptOutDomains = EmproObj.selectedOptOutDomains;
Expand All @@ -150,12 +154,23 @@ emproObj.prototype.onAfterSubmitOptoutData = function (data) {
emproObj.prototype.initObservers = function () {
let errorObserver = new MutationObserver(function (mutations) {
for (let mutation of mutations) {
console.log("mutation? ", mutation);
console.log("error mutation? ", mutation);
if (mutation.type === "childList") {
// do something here if error occurred
document
.querySelector("#emproOptOutModal .continue-container")
.classList.remove("hide");
const errorNode =
mutation.addedNodes && mutation.addedNodes.length
? mutation.addedNodes[0]
: null;
let continueContainerElement = document.querySelector(
"#emproOptOutModal .continue-container"
);
if (continueContainerElement) {
if (errorNode.data) {
continueContainerElement.classList.remove("hide");
} else {
continueContainerElement.classList.add("hide");
}
}
}
}
});
Expand All @@ -176,7 +191,6 @@ emproObj.prototype.initOptOutElementEvents = function () {
}
EmproObj.initObservers();


// submit buttons
$("#emproOptOutModal .btn-submit").on("click", function (e) {
e.preventDefault();
Expand All @@ -186,7 +200,7 @@ emproObj.prototype.initOptOutElementEvents = function () {
EmproObj.userId,
{
data: JSON.stringify(EmproObj.optOutSubmitData),
max_attempts: 1
max_attempts: 1,
},
(data) => {
return EmproObj.onAfterSubmitOptoutData(data);
Expand Down Expand Up @@ -219,11 +233,10 @@ emproObj.prototype.initOptOutElementEvents = function () {
// checkbox display text, clicking on which should check or uncheck the associated checkbox
$("#emproOptOutModal .ck-display").on("click", function () {
var domain = $(this).attr("data-domain");
var associatedCkInput = $("#emproOptOutModal .ck-input-"+domain);
var associatedCkInput = $("#emproOptOutModal .ck-input-" + domain);
if (associatedCkInput.is(":checked"))
associatedCkInput.prop("checked", false);
else
associatedCkInput.prop("checked", true);
else associatedCkInput.prop("checked", true);
});

// continue button that displays when error
Expand Down Expand Up @@ -421,7 +434,7 @@ emproObj.prototype.processTriggerData = function (data) {
q === "_sequential_hard_trigger_count" &&
parseInt(data.triggers.domain[key][q]) > 1
) {
// console.log("domain? ", key, " sequence ", parseInt(data.triggers.domain[key][q]));
// console.log("domain? ", key, " sequence ", parseInt(data.triggers.domain[key][q]));
if (self.optOutDomains.indexOf(key) === -1) {
self.optOutDomains.push(key);
}
Expand Down
7 changes: 6 additions & 1 deletion portal/static/less/eproms.less
Original file line number Diff line number Diff line change
Expand Up @@ -4079,7 +4079,12 @@ section.header {
margin-top: 16px;
}
.no-contact-list-wrapper {
margin-top: 20px;
margin-top: 16px;
margin-bottom: 16px;
&:empty {
margin-top: 0;
margin-bottom: 0;
}
color: @warningColor;
}
}
Expand Down

0 comments on commit ae34c63

Please sign in to comment.