Skip to content

Commit

Permalink
Finalize ESL mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
megastary committed Oct 6, 2024
1 parent b9da27a commit 300507b
Show file tree
Hide file tree
Showing 5 changed files with 431 additions and 252 deletions.
88 changes: 61 additions & 27 deletions public/javascripts/esl_mapping.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,76 @@
/*global bootstrap, $*/
/*global bootstrap, $, json_data*/

const myModal = new bootstrap.Modal('#confirm-modal')
const unlinkModal = new bootstrap.Modal('#unlink-modal')
const linkModal = new bootstrap.Modal('#link-modal')

// Change settings when checkbox state changes
const checkboxes = document.getElementsByClassName('realtime-checkbox')
// Display dialog to unlink product from label
// eslint-disable-next-line no-unused-vars
async function showUnlinkConfirm(id) {
const submit = document.getElementById('modal_unlink')
submit.dataset.submit_id = 'unlink_' + id
unlinkModal.show()
}

// Display dialog to link product to label
// eslint-disable-next-line no-unused-vars
const _checkboxesEvent = [...checkboxes].forEach((element) => {
element.addEventListener('change', async function () {
await fetch('/admin_users', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
user: this.dataset.user,
name: this.dataset.property,
value: this.checked,
_csrf: document.getElementsByName('_csrf')[0].value
})
})
})
})
async function showLinkConfirm(id) {
const submit = document.getElementById('modal_link')
submit.dataset.submit_id = 'link_' + id
submit.dataset.product_id = 'product_id_' + id
linkModal.show()
}

// Display confirmation dialog
// Submit form from modal to confirm product unlink from label
// eslint-disable-next-line no-unused-vars
async function showUnlinkConfirm(id) {
const submit = document.getElementById('modal_confirm')
submit.dataset.submit_id = 'unlink_' + id
myModal.show()
function submitUnlinkFromModal(ctx) {
document.getElementById(ctx.dataset.submit_id).submit()
}

// Submit form from modal to confirm deactivation
// Submit form from modal to confirm product link to label
// eslint-disable-next-line no-unused-vars
function submitFromModal(ctx) {
function submitLinkFromModal(ctx) {
console.log(document.getElementById(ctx.dataset.product_id))
console.log(document.getElementById('product_id').value)

document.getElementById(ctx.dataset.product_id).value =
document.getElementById('product_id').value

document.getElementById(ctx.dataset.submit_id).submit()
}

function loadProductInfo() {
var productId = document.getElementById('product_id').value
var productStockId = document.getElementById('product_stock')
var productPriceId = document.getElementById('product_price')
var newImg = new Image()
newImg.onload = function () {
document.getElementById('product_img').src = this.src
}
if (productId === '') {
newImg.src = '/static_images/preview.png'
} else {
newImg.src = json_data[productId].product_image
}

if (productStockId === '') {
productStockId.value = null
} else {
productStockId.value = json_data[productId].product_stock
}

if (productPriceId === '') {
productPriceId.value = null
} else {
productPriceId.value = json_data[productId].product_price
}
}

document.addEventListener('DOMContentLoaded', function () {
if (document.getElementById('product_id').value) {
loadProductInfo()
}
})

// Initialize DataTables
// dom customizes header paging, search and export
// columndefs makes id unsortable, sortabledate hidden, date linked for filtering and displays currency next to price
Expand Down
Loading

0 comments on commit 300507b

Please sign in to comment.