DB restructure, print page
This commit is contained in:
@@ -4,9 +4,10 @@ export default class extends Controller {
|
||||
static targets = ["exceptionItemTemplate", "exceptionItemContainer", "exceptionItem", "exceptionItemButton"]
|
||||
|
||||
connect() {
|
||||
const content = this.#newExemptionItem()
|
||||
|
||||
this.exceptionItemButtonTarget.insertAdjacentHTML('beforebegin', content);
|
||||
if (this.exceptionItemTargets.length > 0) {
|
||||
const content = this.#newExemptionItem()
|
||||
this.exceptionItemButtonTarget.insertAdjacentHTML('beforebegin', content);
|
||||
}
|
||||
}
|
||||
|
||||
addExemptionItem(event) {
|
||||
@@ -36,6 +37,7 @@ export default class extends Controller {
|
||||
|
||||
#newExemptionItem() {
|
||||
const nextIndex = this.exceptionItemTargets.length
|
||||
console.log(nextIndex)
|
||||
const buttonElement = this.exceptionItemButtonTarget;
|
||||
|
||||
// Get the computed style (returns rgb/rgba value)
|
||||
|
||||
@@ -33,6 +33,7 @@ export default class extends Controller {
|
||||
|
||||
#updateTemplatePlan() {
|
||||
const nextIndex = this.planTargets.length
|
||||
console.log(nextIndex)
|
||||
const num_of_colors = this.formColorValue.length
|
||||
let colorIndex = 0
|
||||
let newSecondaryColor = "copper"
|
||||
|
||||
@@ -14,7 +14,7 @@ export default class extends Controller {
|
||||
return;
|
||||
}
|
||||
|
||||
const url = `/id_card_benefits_templates/get_template_benefits/${templateId}`
|
||||
const url = `/id_card/plans/${templateId}/get_plan_benefits`
|
||||
const response = await fetch(url);
|
||||
const templateBenefitsData = await response.json();
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ["dependentField", "providerField", "selectField"]
|
||||
|
||||
connect() {
|
||||
console.log("--- in toggle connect --- ")
|
||||
const selector = this.selectFieldTarget;
|
||||
if (selector.value) {
|
||||
const selectedValue = selector.value
|
||||
this.dependentFieldTargets.forEach((field) => {
|
||||
if (field.value) {
|
||||
if (selectedValue == "network_logo") {
|
||||
field.parentElement.parentElement.parentElement.classList.remove("hidden");
|
||||
} else {
|
||||
field.parentElement.classList.remove("hidden");
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
toggleFields() {
|
||||
console.log("--- in toggle --- ")
|
||||
const selector = this.selectFieldTarget;
|
||||
if (selector.value) {
|
||||
const selectedValue = selector.value
|
||||
this.field_match = false;
|
||||
this.dependentFieldTargets.forEach((field) => {
|
||||
// console.log("- ", selectedValue)
|
||||
// console.log("-- ", this.field_match)
|
||||
// Check a data attribute on the field to see if it matches the selected value
|
||||
if (field.dataset.parentValue === selectedValue) {
|
||||
if (selectedValue == "network_logo") {
|
||||
field.parentElement.parentElement.parentElement.classList.remove("hidden");
|
||||
} else {
|
||||
field.parentElement.classList.remove("hidden");
|
||||
}
|
||||
this.field_match = true;
|
||||
} else {
|
||||
if (field.dataset.parentValue == "network_logo") {
|
||||
field.parentElement.parentElement.parentElement.classList.add("hidden");
|
||||
} else {
|
||||
field.parentElement.classList.add("hidden");
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!this.field_match) {
|
||||
console.log("--- ", this.field_match)
|
||||
const defaultOption = this.dependentFieldTargets.find(target => {
|
||||
return target.dataset.parentValue === 'default';
|
||||
});
|
||||
defaultOption.parentElement.classList.remove("hidden");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,78 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ["dependentField"]
|
||||
static targets = ["dependentField", "providerField", "selectField"]
|
||||
|
||||
connect() {
|
||||
if (this.selectFieldTarget.value) {
|
||||
this.toggleNewFieldSection();
|
||||
}
|
||||
}
|
||||
|
||||
async initNewFieldSection() {
|
||||
console.log("--- in init async --- ")
|
||||
const selector = this.selectFieldTarget
|
||||
console.log(selector.textContent)
|
||||
console.log(selector.value)
|
||||
if (selector && selector.value && !selector.textContent.includes("Default")) {
|
||||
const sectionId = selector.value
|
||||
|
||||
const response = await fetch(`/id_card/provider_sections/${sectionId}/get_section_data`);
|
||||
const templateSectionData = await response.json();
|
||||
|
||||
this.#updateFields(templateSectionData)
|
||||
|
||||
this.dependentFieldTarget.classList.remove("hidden");
|
||||
}
|
||||
}
|
||||
|
||||
async toggleNewFieldSection() {
|
||||
console.log("--- in new field toggle --- ")
|
||||
const selector = this.selectFieldTarget
|
||||
const selectedOption = selector.options[selector.selectedIndex]
|
||||
const selectedValue = selectedOption.value
|
||||
const selectedLabel = selectedOption.textContent
|
||||
|
||||
if (selectedValue && selectedLabel.includes("Default")) {
|
||||
this.dependentFieldTarget.classList.add("hidden");
|
||||
} else if (selectedValue) {
|
||||
let sectionId = selectedValue
|
||||
if (selectedValue.includes("new")) {
|
||||
sectionId = selectedValue.split('|')[1]
|
||||
}
|
||||
const response = await fetch(`/id_card/provider_sections/${sectionId}/get_section_data`);
|
||||
const sectionData = await response.json();
|
||||
|
||||
this.#updateFields(sectionData)
|
||||
|
||||
this.dependentFieldTarget.classList.remove("hidden");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async #updateFields(templateSectionData) {
|
||||
const providerFieldTargetsList = this.providerFieldTargets
|
||||
console.log(templateSectionData)
|
||||
providerFieldTargetsList.forEach(function(formField) {
|
||||
const dbField = formField.id.replace('id_card_configuration_provider_section_', '')
|
||||
const dbValue = templateSectionData[dbField]
|
||||
formField.value = dbValue;
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
// templateSectionData.forEach(function(data) {
|
||||
// const targetElement = providerFieldTargetsList.find(
|
||||
// (element) => element.dataset.sequence == data.sequence
|
||||
// );
|
||||
// if (targetElement) {
|
||||
// targetElement.value = data.benefit;
|
||||
// } else {
|
||||
// console.error(`Target not found for sequence: ${data.sequence}`);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
toggleFields() {
|
||||
|
||||
@@ -5,21 +5,38 @@ export default class extends Controller {
|
||||
logoType: String,
|
||||
employerName: String
|
||||
}
|
||||
static targets = ["preview", "previewContainer", "logoSelect", "logoField", "initialLogoFile"];
|
||||
static targets = ["preview", "previewContainer", "logoSelect", "logoIdField", "logoNameField", "initialLogoFile"];
|
||||
|
||||
async connect() {
|
||||
console.log('in connect');
|
||||
const initValue = this.logoFieldTarget.value
|
||||
this.setPreviewImage()
|
||||
// Remember to revoke the URL when the controller is disconnected if necessary
|
||||
// this.disconnect = () => URL.revokeObjectURL(objectUrl);
|
||||
}
|
||||
|
||||
async setPreviewImage() {
|
||||
const initValue = this.logoIdFieldTarget.value
|
||||
console.log(initValue)
|
||||
console.log(this.logoTypeValue)
|
||||
if (initValue) {
|
||||
const response = await fetch(`/id_card/${this.logoTypeValue}_logos/${initValue}/image`); // Fetch the binary data
|
||||
const logoType = this.logoTypeValue
|
||||
if (logoType == "employer") {
|
||||
const contentDisposition = response.headers.get('Content-Disposition');
|
||||
const filename = contentDisposition.match(/filename="?([^"]+)"?/)[1];
|
||||
this.logoNameFieldTarget.value = filename;
|
||||
}
|
||||
const blob = await response.blob();
|
||||
const objectUrl = URL.createObjectURL(blob);
|
||||
this.previewTarget.src = objectUrl;
|
||||
this.previewContainerTarget.classList.remove("hidden");
|
||||
} else {
|
||||
this.previewContainerTarget.classList.add("hidden");
|
||||
}
|
||||
// Remember to revoke the URL when the controller is disconnected if necessary
|
||||
// this.disconnect = () => URL.revokeObjectURL(objectUrl);
|
||||
}
|
||||
|
||||
setSelectPreview(event) {
|
||||
this.setPreviewImage()
|
||||
}
|
||||
|
||||
uploadLogo(event) {
|
||||
@@ -34,19 +51,25 @@ export default class extends Controller {
|
||||
if (logoType == "network") {
|
||||
console.log("n " + newFileName);
|
||||
newFileName = this.determineNetworkFilename(logoFile)
|
||||
this.addOptionToSelect(newFileName)
|
||||
logoFile = new File([logoFile], newFileName)
|
||||
} else if (logoType == "employer") {
|
||||
newFileName = this.determineEmployerFilename(logoFile)
|
||||
logoFile = new File([logoFile], newFileName)
|
||||
}
|
||||
logoFile = new File([logoFile], newFileName)
|
||||
|
||||
this.uploadLogoToServer(logoFile)
|
||||
.then((result) => {
|
||||
console.log(result);
|
||||
const logoId = result.id
|
||||
this.previewFile(logoFile);
|
||||
this.logoFieldTarget.value = logoId;
|
||||
if (logoType == "network") {
|
||||
this.addOptionToSelect(newFileName, logoId)
|
||||
} else {
|
||||
this.logoNameFieldTarget.value = newFileName;
|
||||
}
|
||||
|
||||
this.logoIdFieldTarget.value = logoId;
|
||||
|
||||
|
||||
})
|
||||
.catch((error) => {
|
||||
// Handle any errors that occurred
|
||||
@@ -93,23 +116,22 @@ export default class extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
addOptionToSelect(name) {
|
||||
addOptionToSelect(name, id) {
|
||||
const blankOptionIndex = 0;
|
||||
const newOption = new Option(name, name, true, true)
|
||||
const newOption = new Option(name, id, true, true)
|
||||
|
||||
if (this.logoFieldTarget.options.length > blankOptionIndex + 1) {
|
||||
this.logoFieldTarget.insertBefore(newOption, this.logoFieldTarget.options[blankOptionIndex + 1]);
|
||||
if (this.logoIdFieldTarget.options.length > blankOptionIndex + 1) {
|
||||
this.logoIdFieldTarget.insertBefore(newOption, this.logoIdFieldTarget.options[blankOptionIndex + 1]);
|
||||
} else {
|
||||
this.logoFieldTarget.appendChild(newOption);
|
||||
this.logoIdFieldTarget.appendChild(newOption);
|
||||
}
|
||||
|
||||
this.logoFieldTarget.value = name;
|
||||
}
|
||||
|
||||
determineNetworkFilename(logoFile) {
|
||||
const fileExtension = logoFile.name.split('.').pop();
|
||||
const primaryNetworkName = prompt("Enter the name for the primary network (Usually 'Cigna' or 'MedCost':");
|
||||
const secondaryNetworkName = prompt("Enter the name for the primary network (ex: Health Partners):");
|
||||
const secondaryNetworkName = prompt("Enter the name for the partner network (ex: Health Partners):");
|
||||
const logoFilename = this.titleizeText(primaryNetworkName).concat(this.titleizeText(secondaryNetworkName)).concat("Logo.").concat(fileExtension).replaceAll(' ', '');
|
||||
|
||||
return logoFilename
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ["providerNetworkField", "networkLogoField", "providerSectionField"]
|
||||
|
||||
connect() {
|
||||
console.log("---provider update---")
|
||||
}
|
||||
|
||||
syncDefaults() {
|
||||
const pnValue = this.providerNetworkFieldTarget.value
|
||||
if (pnValue == "Cigna") {
|
||||
this.networkLogoFieldTarget.value = 1
|
||||
this.providerSectionFieldTarget.value = 30
|
||||
} else if (pnValue == "Medcost") {
|
||||
this.networkLogoFieldTarget.value = 2
|
||||
this.providerSectionFieldTarget.value = 26
|
||||
} else {
|
||||
this.networkLogoFieldTarget.value = ""
|
||||
this.providerSectionFieldTarget.value = ""
|
||||
}
|
||||
const event = new Event('change', { bubbles: true });
|
||||
this.networkLogoFieldTarget.dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user