Employer table broken up and new idcard module setup
This commit is contained in:
@@ -1,43 +1,43 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ["dependentField"]
|
||||
|
||||
connect() {
|
||||
}
|
||||
|
||||
toggleFields() {
|
||||
console.log("--- in toggle --- ")
|
||||
const selector = this.element.querySelector('[data-action*="change->general-form#toggleFields"]');
|
||||
if (selector) {
|
||||
const selectedValue = selector.value
|
||||
this.field_match = false;
|
||||
this.dependentFieldTargets.forEach((field) => {
|
||||
// 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.classList.remove("hidden");
|
||||
} else {
|
||||
field.parentElement.classList.remove("hidden");
|
||||
}
|
||||
this.field_match = true;
|
||||
console.log("- ", selectedValue)
|
||||
console.log("-- ", this.field_match)
|
||||
} else {
|
||||
if (field.dataset.parentValue == "network_logo") {
|
||||
field.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");
|
||||
}
|
||||
}
|
||||
}
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ["dependentField"]
|
||||
|
||||
connect() {
|
||||
}
|
||||
|
||||
toggleFields() {
|
||||
console.log("--- in toggle --- ")
|
||||
const selector = this.element.querySelector('[data-action*="change->general-form#toggleFields"]');
|
||||
if (selector) {
|
||||
const selectedValue = selector.value
|
||||
this.field_match = false;
|
||||
this.dependentFieldTargets.forEach((field) => {
|
||||
// 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.classList.remove("hidden");
|
||||
} else {
|
||||
field.parentElement.classList.remove("hidden");
|
||||
}
|
||||
this.field_match = true;
|
||||
console.log("- ", selectedValue)
|
||||
console.log("-- ", this.field_match)
|
||||
} else {
|
||||
if (field.dataset.parentValue == "network_logo") {
|
||||
field.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,16 +1,16 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = [ "name", "output" ]
|
||||
|
||||
connect() {
|
||||
// this.element.textContent = "Hello World!"
|
||||
console.log('Hello World hello_controller.js');
|
||||
}
|
||||
|
||||
greet() {
|
||||
console.log('greet');
|
||||
this.outputTarget.textContent =
|
||||
`Hello, ${this.nameTarget.value}!`
|
||||
}
|
||||
}
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = [ "name", "output" ]
|
||||
|
||||
connect() {
|
||||
// this.element.textContent = "Hello World!"
|
||||
console.log('Hello World hello_controller.js');
|
||||
}
|
||||
|
||||
greet() {
|
||||
console.log('greet');
|
||||
this.outputTarget.textContent =
|
||||
`Hello, ${this.nameTarget.value}!`
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,12 @@ export default class extends Controller {
|
||||
static values = {
|
||||
logoType: String,
|
||||
employerName: String
|
||||
}
|
||||
static targets = ["preview", "previewContainer", "logoSelect", "logofield", "initialLogoFile"];
|
||||
}
|
||||
static targets = ["preview", "previewContainer", "logoSelect", "logoField", "initialLogoFile"];
|
||||
|
||||
async connect() {
|
||||
console.log('in connect');
|
||||
const initValue = this.logofieldTarget.value
|
||||
const initValue = this.logoFieldTarget.value
|
||||
console.log(initValue)
|
||||
if (initValue) {
|
||||
const response = await fetch(`/id_card/${this.logoTypeValue}_logos/${initValue}/image`); // Fetch the binary data
|
||||
@@ -25,41 +25,49 @@ export default class extends Controller {
|
||||
uploadLogo(event) {
|
||||
console.log('in uploadLogo');
|
||||
event.preventDefault()
|
||||
const file = event.target.files[0];
|
||||
if (!file) return;
|
||||
let logoFile = event.target.files[0];
|
||||
if (!logoFile) return;
|
||||
|
||||
const logoType = this.logoTypeValue
|
||||
|
||||
let newFileName = file.name
|
||||
let newFileName = logoFile.name
|
||||
if (logoType == "network") {
|
||||
console.log("n " + newFileName);
|
||||
newFileName = this.determineNetworkFilename(file)
|
||||
newFileName = this.determineNetworkFilename(logoFile)
|
||||
this.addOptionToSelect(newFileName)
|
||||
logoFile = new File([logoFile], newFileName)
|
||||
} else if (logoType == "employer") {
|
||||
newFileName = this.determineEmployerFilename(file)
|
||||
file.name = newFileName
|
||||
newFileName = this.determineEmployerFilename(logoFile)
|
||||
logoFile = new File([logoFile], newFileName)
|
||||
}
|
||||
|
||||
this.previewFile(file);
|
||||
this.uploadLogoToServer(file);
|
||||
|
||||
this.logofieldTarget.value = newFileName;
|
||||
|
||||
this.uploadLogoToServer(logoFile)
|
||||
.then((result) => {
|
||||
console.log(result);
|
||||
const logoId = result.id
|
||||
this.previewFile(logoFile);
|
||||
this.logoFieldTarget.value = logoId;
|
||||
})
|
||||
.catch((error) => {
|
||||
// Handle any errors that occurred
|
||||
console.error(error);
|
||||
});
|
||||
}
|
||||
|
||||
previewFile(file) {
|
||||
previewFile(logoFile) {
|
||||
console.log('in previewFile');
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
this.previewTarget.src = e.target.result;
|
||||
this.previewContainerTarget.classList.remove("hidden");
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
reader.readAsDataURL(logoFile);
|
||||
}
|
||||
|
||||
async uploadLogoToServer(file) {
|
||||
async uploadLogoToServer(logoFile) {
|
||||
console.log('in uploadLogoToServer');
|
||||
const formData = new FormData();
|
||||
formData.append(`id_card_${this.logoTypeValue}_logo[logo_file]`, file);
|
||||
formData.append(`id_card_${this.logoTypeValue}_logo[logo_file]`, logoFile);
|
||||
|
||||
const csrfToken = document.querySelector("meta[name='csrf-token']").content;
|
||||
|
||||
@@ -74,11 +82,14 @@ export default class extends Controller {
|
||||
|
||||
if (response.ok) {
|
||||
console.log('Upload successful!')
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} else {
|
||||
console.error("Failed to track event.");
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Network error:", error);
|
||||
throw new Error("Network error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,17 +97,17 @@ export default class extends Controller {
|
||||
const blankOptionIndex = 0;
|
||||
const newOption = new Option(name, name, true, true)
|
||||
|
||||
if (this.logofieldTarget.options.length > blankOptionIndex + 1) {
|
||||
this.logofieldTarget.insertBefore(newOption, this.logofieldTarget.options[blankOptionIndex + 1]);
|
||||
if (this.logoFieldTarget.options.length > blankOptionIndex + 1) {
|
||||
this.logoFieldTarget.insertBefore(newOption, this.logoFieldTarget.options[blankOptionIndex + 1]);
|
||||
} else {
|
||||
this.logofieldTarget.appendChild(newOption);
|
||||
this.logoFieldTarget.appendChild(newOption);
|
||||
}
|
||||
|
||||
this.logofieldTarget.value = name;
|
||||
this.logoFieldTarget.value = name;
|
||||
}
|
||||
|
||||
determineNetworkFilename(file) {
|
||||
const fileExtension = file.name.split('.').pop();
|
||||
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 logoFilename = this.titleizeText(primaryNetworkName).concat(this.titleizeText(secondaryNetworkName)).concat("Logo.").concat(fileExtension).replaceAll(' ', '');
|
||||
@@ -104,8 +115,8 @@ export default class extends Controller {
|
||||
return logoFilename
|
||||
}
|
||||
|
||||
determineEmployerFilename(file) {
|
||||
const fileExtension = file.name.split('.').pop();
|
||||
determineEmployerFilename(logoFile) {
|
||||
const fileExtension = logoFile.name.split('.').pop();
|
||||
const employerName = this.employerNameValue
|
||||
const logoFilename = this.titleizeText(employerName).concat("Logo.").concat(fileExtension).replaceAll(' ', '');
|
||||
|
||||
@@ -120,3 +131,4 @@ export default class extends Controller {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user