mirror of
https://gitea.baerentsen.space/FrederikBaerentsen/BrickTracker.git
synced 2025-12-21 08:39:53 -06:00
72 lines
2.4 KiB
JavaScript
72 lines
2.4 KiB
JavaScript
// Add page - handles both sets and individual minifigures
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
// Get template data from data attributes
|
|
const addContainer = document.getElementById('add-set');
|
|
if (!addContainer) return;
|
|
|
|
// Read data from data attributes
|
|
const templateData = {
|
|
path: addContainer.dataset.path,
|
|
namespace: addContainer.dataset.namespace,
|
|
messages: {
|
|
COMPLETE: addContainer.dataset.msgComplete,
|
|
FAIL: addContainer.dataset.msgFail,
|
|
IMPORT_SET: addContainer.dataset.msgImportSet,
|
|
LOAD_SET: addContainer.dataset.msgLoadSet,
|
|
PROGRESS: addContainer.dataset.msgProgress,
|
|
SET_LOADED: addContainer.dataset.msgSetLoaded,
|
|
IMPORT_MINIFIGURE: addContainer.dataset.msgImportMinifigure,
|
|
LOAD_MINIFIGURE: addContainer.dataset.msgLoadMinifigure,
|
|
MINIFIGURE_LOADED: addContainer.dataset.msgMinifigureLoaded,
|
|
}
|
|
};
|
|
|
|
// Default: create set socket
|
|
const setSocket = new BrickSetSocket(
|
|
'add',
|
|
templateData.path,
|
|
templateData.namespace,
|
|
{
|
|
COMPLETE: templateData.messages.COMPLETE,
|
|
FAIL: templateData.messages.FAIL,
|
|
IMPORT_SET: templateData.messages.IMPORT_SET,
|
|
LOAD_SET: templateData.messages.LOAD_SET,
|
|
PROGRESS: templateData.messages.PROGRESS,
|
|
SET_LOADED: templateData.messages.SET_LOADED,
|
|
},
|
|
false,
|
|
false
|
|
);
|
|
|
|
// Override the execute method to check for minifigures
|
|
const originalExecute = setSocket.execute.bind(setSocket);
|
|
let minifigSocket = null;
|
|
|
|
setSocket.execute = function() {
|
|
const inputValue = document.getElementById('add-set').value.trim();
|
|
|
|
if (inputValue.startsWith('fig-') || inputValue.match(/^fig\d/i)) {
|
|
// It's a minifigure - create minifig socket if needed
|
|
if (!minifigSocket) {
|
|
minifigSocket = new BrickMinifigureSocket(
|
|
'add',
|
|
templateData.path,
|
|
templateData.namespace,
|
|
{
|
|
COMPLETE: templateData.messages.COMPLETE,
|
|
FAIL: templateData.messages.FAIL,
|
|
IMPORT_MINIFIGURE: templateData.messages.IMPORT_MINIFIGURE,
|
|
LOAD_MINIFIGURE: templateData.messages.LOAD_MINIFIGURE,
|
|
MINIFIGURE_LOADED: templateData.messages.MINIFIGURE_LOADED,
|
|
PROGRESS: templateData.messages.PROGRESS,
|
|
}
|
|
);
|
|
}
|
|
minifigSocket.execute();
|
|
} else {
|
|
// It's a set - use original execute
|
|
originalExecute();
|
|
}
|
|
};
|
|
});
|