Skip to content

Commit

Permalink
block issuing licences with outstanding approvals
Browse files Browse the repository at this point in the history
closes #98
  • Loading branch information
dangowans committed Jun 9, 2022
1 parent fa3e1d5 commit 548b0fe
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 36 deletions.
32 changes: 19 additions & 13 deletions public-typescript/licence-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
bankInstitutionNumberElement.addEventListener("change", refreshBankName);
bankTransitNumberElement.addEventListener("change", refreshBankName);
}
const licenceCategoryKeyElement = document.querySelector("#licenceEdit--licenceCategoryKey");
const isRenewalElement = document.querySelector("#licenceEdit--isRenewal");
const hasOutstandingRequiredApprovals = () => {
const isRenewal = isRenewalElement.checked;
const approvalCheckboxElements = document.querySelectorAll("#container--licenceApprovals input[type='checkbox']");
for (const approvalCheckboxElement of approvalCheckboxElements) {
if (!approvalCheckboxElement.checked && ((isRenewal && approvalCheckboxElement.dataset.isRequiredForRenewal === "true") ||
(!isRenewal && approvalCheckboxElement.dataset.isRequiredForNew === "true"))) {
return true;
}
}
return false;
};
const licenceCategoryKeyElement = document.querySelector("#licenceEdit--licenceCategoryKey");
const startDateStringElement = document.querySelector("#licenceEdit--startDateString");
const endDateStringElement = document.querySelector("#licenceEdit--endDateString");
const refreshEndDate = () => {
Expand Down Expand Up @@ -391,10 +402,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
inputElement.name = "approval--" + licenceCategoryApproval.licenceApprovalKey;
inputElement.dataset.isRequiredForNew = licenceCategoryApproval.isRequiredForNew ? "true" : "false";
inputElement.dataset.isRequiredForRenewal = licenceCategoryApproval.isRequiredForRenewal ? "true" : "false";
if ((isRenewalElement.checked && licenceCategoryApproval.isRequiredForRenewal) ||
(!isRenewalElement.checked && licenceCategoryApproval.isRequiredForNew)) {
inputElement.required = true;
}
if (licenceCategoryApproval.licenceApprovalDescription !== "") {
const helpElement = document.createElement("p");
helpElement.className = "help";
Expand Down Expand Up @@ -466,14 +473,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
licenceCategory = exports.licenceCategory;
}
isRenewalElement.addEventListener("change", () => {
const approvalInputElements = document.querySelector("#container--licenceApprovals").querySelectorAll("input");
for (const approvalInputElement of approvalInputElements) {
approvalInputElement.required =
(isRenewalElement.checked && approvalInputElement.dataset.isRequiredForRenewal === "true") ||
(!isRenewalElement.checked && approvalInputElement.dataset.isRequiredForNew === "true")
? true
: false;
}
refreshLicenceCategoryFees();
});
let optionalAdditionalFees;
Expand Down Expand Up @@ -781,6 +780,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
contextualColorName: "warning"
});
}
else if (hasOutstandingRequiredApprovals()) {
bulmaJS.alert({
title: licenceAlias + " Has Outstanding Required Approvals",
message: "Please ensure that all requirements have been met.",
contextualColorName: "warning"
});
}
else if (getOutstandingBalance() > 0) {
bulmaJS.confirm({
title: licenceAlias + " Has an Outstanding Balance",
Expand Down
53 changes: 32 additions & 21 deletions public-typescript/licence-edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,37 @@ declare const bulmaJS: BulmaJS;
bankTransitNumberElement.addEventListener("change", refreshBankName);
}

/*
* Licence Approvals
*/

const isRenewalElement = document.querySelector("#licenceEdit--isRenewal") as HTMLInputElement;

const hasOutstandingRequiredApprovals = () => {

const isRenewal = isRenewalElement.checked;

const approvalCheckboxElements = document.querySelectorAll("#container--licenceApprovals input[type='checkbox']") as NodeListOf<HTMLInputElement>;

for (const approvalCheckboxElement of approvalCheckboxElements) {

if (!approvalCheckboxElement.checked && (
(isRenewal && approvalCheckboxElement.dataset.isRequiredForRenewal === "true") ||
(!isRenewal && approvalCheckboxElement.dataset.isRequiredForNew === "true")
)) {
return true;
}
}

return false;
};

/*
* End Date
*/

const licenceCategoryKeyElement = document.querySelector("#licenceEdit--licenceCategoryKey") as HTMLSelectElement;

const isRenewalElement = document.querySelector("#licenceEdit--isRenewal") as HTMLInputElement;

const startDateStringElement = document.querySelector("#licenceEdit--startDateString") as HTMLInputElement;
const endDateStringElement = document.querySelector("#licenceEdit--endDateString") as HTMLInputElement;

Expand Down Expand Up @@ -574,11 +597,6 @@ declare const bulmaJS: BulmaJS;
inputElement.dataset.isRequiredForNew = licenceCategoryApproval.isRequiredForNew ? "true" : "false";
inputElement.dataset.isRequiredForRenewal = licenceCategoryApproval.isRequiredForRenewal ? "true" : "false";

if ((isRenewalElement.checked && licenceCategoryApproval.isRequiredForRenewal) ||
(!isRenewalElement.checked && licenceCategoryApproval.isRequiredForNew)) {
inputElement.required = true;
}

if (licenceCategoryApproval.licenceApprovalDescription !== "") {
const helpElement = document.createElement("p");
helpElement.className = "help";
Expand Down Expand Up @@ -679,21 +697,7 @@ declare const bulmaJS: BulmaJS;

isRenewalElement.addEventListener("change", () => {

// Approvals

const approvalInputElements = document.querySelector("#container--licenceApprovals").querySelectorAll("input");

for (const approvalInputElement of approvalInputElements) {

approvalInputElement.required =
(isRenewalElement.checked && approvalInputElement.dataset.isRequiredForRenewal === "true") ||
(!isRenewalElement.checked && approvalInputElement.dataset.isRequiredForNew === "true")
? true
: false;
}

// Fees

refreshLicenceCategoryFees();
});

Expand Down Expand Up @@ -1137,6 +1141,13 @@ declare const bulmaJS: BulmaJS;
contextualColorName: "warning"
});

} else if (hasOutstandingRequiredApprovals()) {
bulmaJS.alert({
title: licenceAlias + " Has Outstanding Required Approvals",
message: "Please ensure that all requirements have been met.",
contextualColorName: "warning"
});

} else if (getOutstandingBalance() > 0) {

bulmaJS.confirm({
Expand Down
Loading

0 comments on commit 548b0fe

Please sign in to comment.