Spaces:
Sleeping
Sleeping
File size: 1,210 Bytes
4450790 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
/**
* File: saveTableData.js
* Project: comfy_mtb
* Author: Mel Massadian
*
* Copyright (c) 2023 Mel Massadian
*
*/
function saveTableData(identifier) {
const table = document.querySelector(
`#style-editor table[data-id='${identifier}']`
)
let currentData = []
const rows = table.querySelectorAll('tr')
const filename = table.getAttribute('data-id')
rows.forEach((row, rowIndex) => {
const rowData = []
const cells =
rowIndex === 0
? row.querySelectorAll('th')
: row.querySelectorAll('td input, td textarea')
cells.forEach((cell) => {
rowData.push(rowIndex === 0 ? cell.textContent : cell.value)
})
currentData.push(rowData)
})
let tablesData = {}
tablesData[filename] = currentData
console.debug('Sending styles to manage endpoint:', tablesData)
fetch('/mtb/actions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'saveStyle',
args: tablesData,
}),
})
.then((response) => response.json())
.then((data) => {
console.debug('Success:', data)
})
.catch((error) => {
console.error('Error:', error)
})
}
|