2019-03-04 18:17:00 +00:00
|
|
|
const modalSave = new tingle.modal({
|
|
|
|
footer: true,
|
|
|
|
|
|
|
|
});
|
|
|
|
modalSave.setContent('<h3>Dokument speichern</h3><input type="text" id="saveName" placeholder="Bitte gib den Namen des Dokuments ein">');
|
|
|
|
modalSave.addFooterBtn('Schließen', 'btn', () => {
|
|
|
|
document.getElementById('saveName').value = "";
|
|
|
|
modalSave.close();
|
|
|
|
});
|
|
|
|
modalSave.addFooterBtn('Speichern', 'btn', () => {
|
|
|
|
const input = document.getElementById('saveName');
|
|
|
|
const name = input.value;
|
|
|
|
|
2019-04-03 14:15:15 +00:00
|
|
|
if (name.trim().length > 0) {
|
2019-03-04 18:17:00 +00:00
|
|
|
documents[activeDocument].name = name;
|
|
|
|
saveToLocalStorage();
|
|
|
|
modalSave.close();
|
|
|
|
} else {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const modalOpen = new tingle.modal({
|
|
|
|
beforeOpen: () => {
|
|
|
|
const entries = getLocalStorageEntries().sort((a, b) => {
|
|
|
|
return b.document.createdAt - a.document.createdAt
|
|
|
|
});
|
|
|
|
let html = '<h3>Gespeicherte Dokumente</h3><ul class="file-list">';
|
|
|
|
entries.forEach(entry => html += `<li class="file-list-item" data-id="${entry.document.id}">${entry.document.name} (${new Date(entry.document.createdAt).toLocaleString()})</li>`);
|
|
|
|
html += '</ul>';
|
|
|
|
modalOpen.setContent(html);
|
|
|
|
|
2019-04-03 14:15:15 +00:00
|
|
|
for (let element of document.getElementsByClassName('file-list-item')) {
|
2019-03-04 18:17:00 +00:00
|
|
|
element.addEventListener('click', () => {
|
|
|
|
const entry = entries.find(entry => entry.document.id === element.getAttribute('data-id'));
|
|
|
|
addDocument(entry.document);
|
|
|
|
switchDocument(entry.document);
|
|
|
|
modalOpen.close();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const modalExport = new tingle.modal({
|
|
|
|
footer: true,
|
|
|
|
beforeOpen: () => {
|
2019-04-03 14:15:15 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
const el = document.getElementById('previewImage');
|
|
|
|
el.src = canvas.toDataURL('image/png');
|
|
|
|
}, 100);
|
2019-03-04 18:17:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
modalExport.setContent('<h3>Dokument exportieren</h3><img src="" id="previewImage">');
|
|
|
|
modalExport.addFooterBtn('Download .png', 'btn', () => {
|
|
|
|
exportToImageFile();
|
|
|
|
modalExport.close();
|
|
|
|
});
|
|
|
|
modalExport.addFooterBtn('Download .svg', 'btn', () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
modalExport.addFooterBtn('Download .fsm', 'btn', () => {
|
|
|
|
exportToFile();
|
|
|
|
modalExport.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
const modalImport = new tingle.modal({
|
|
|
|
footer: true,
|
|
|
|
});
|
2019-03-05 18:18:21 +00:00
|
|
|
modalImport.setContent('<h3>Dokument importieren</h3><label for="importUpload" class="btn upload-btn"><input type="file" accept=".fsm" class="upload-input" id="importUpload"> <i class="fa fa-upload"></i> Datei auswählen</label>');
|
|
|
|
modalImport.addFooterBtn('Laden', 'btn', () => {
|
|
|
|
const el = document.getElementById('importUpload');
|
|
|
|
const file = el.files[0];
|
|
|
|
|
2019-04-03 14:15:15 +00:00
|
|
|
if (file) {
|
|
|
|
console.log(file.type);
|
2019-03-05 18:18:21 +00:00
|
|
|
const reader = new FileReader();
|
2019-03-05 18:56:42 +00:00
|
|
|
// TODO: Check for file type etc.
|
2019-03-05 18:18:21 +00:00
|
|
|
reader.readAsText(file, 'UTF-8');
|
|
|
|
reader.onload = (evt) => {
|
2019-03-05 18:56:42 +00:00
|
|
|
const json = evt.target.result;
|
|
|
|
// TODO: Add error handling
|
|
|
|
importFromJson(json);
|
|
|
|
modalImport.close();
|
2019-03-05 18:18:21 +00:00
|
|
|
};
|
|
|
|
reader.onerror = (evt) => {
|
2019-03-05 18:56:42 +00:00
|
|
|
alert('Ein Fehler beim Einlesen der Datei ist aufgetreten. Womöglich muss hier ein Bug behoben werden... :(');
|
|
|
|
modalImport.close();
|
2019-03-05 18:18:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2019-03-04 18:17:00 +00:00
|
|
|
|
2019-03-05 19:31:53 +00:00
|
|
|
const modalSimulate = new tingle.modal({
|
|
|
|
footer: true,
|
|
|
|
});
|
2019-04-03 14:15:15 +00:00
|
|
|
modalSimulate.setContent('<h3>Maschine simulieren</h3> <label for="singleCharMode"><input type="checkbox" id="singleCharMode" checked> Eingabe einzelner Buchstaben</label> <br> <label for="simulationInput">Eingabe</label> <input type="text" id="simulationInput">');
|
2019-03-05 19:31:53 +00:00
|
|
|
modalSimulate.addFooterBtn('Simulation starten', 'btn', () => {
|
|
|
|
modalSimulate.close();
|
|
|
|
const input = document.getElementById('simulationInput').value;
|
2019-04-03 14:15:15 +00:00
|
|
|
const singleCharMode = document.getElementById('singleCharMode').checked;
|
|
|
|
simulate(input, singleCharMode);
|
2019-03-05 19:31:53 +00:00
|
|
|
});
|
|
|
|
|
2019-03-04 18:17:00 +00:00
|
|
|
document.getElementById('saveBtn').addEventListener('click', () => {
|
2019-04-03 14:15:15 +00:00
|
|
|
if (activeDocument === null) {
|
2019-03-04 18:17:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-03 14:15:15 +00:00
|
|
|
if (documents[activeDocument].name !== null) {
|
2019-03-04 18:17:00 +00:00
|
|
|
saveToLocalStorage();
|
|
|
|
} else {
|
|
|
|
modalSave.open();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-03-07 15:13:08 +00:00
|
|
|
document.getElementById('addBtn').addEventListener('click', () => {
|
2019-04-03 14:15:15 +00:00
|
|
|
selectedObject = null;
|
|
|
|
currentConnection = null;
|
2019-03-07 15:13:08 +00:00
|
|
|
const doc = new FSMDocument(null);
|
|
|
|
addDocument(doc);
|
|
|
|
switchDocument(doc);
|
|
|
|
});
|
|
|
|
|
2019-03-04 18:17:00 +00:00
|
|
|
document.getElementById('openBtn').addEventListener('click', () => {
|
2019-04-03 14:15:15 +00:00
|
|
|
selectedObject = null;
|
|
|
|
currentConnection = null;
|
2019-03-04 18:17:00 +00:00
|
|
|
modalOpen.open();
|
|
|
|
});
|
|
|
|
|
|
|
|
document.getElementById('importBtn').addEventListener('click', () => {
|
2019-04-03 14:15:15 +00:00
|
|
|
selectedObject = null;
|
|
|
|
currentConnection = null;
|
2019-03-04 18:17:00 +00:00
|
|
|
modalImport.open();
|
|
|
|
});
|
|
|
|
|
|
|
|
document.getElementById('exportBtn').addEventListener('click', () => {
|
2019-04-03 14:15:15 +00:00
|
|
|
selectedObject = null;
|
|
|
|
currentConnection = null;
|
2019-03-04 18:17:00 +00:00
|
|
|
modalExport.open();
|
2019-03-05 18:56:42 +00:00
|
|
|
});
|
2019-03-05 19:31:53 +00:00
|
|
|
|
|
|
|
document.getElementById('simulateBtn').addEventListener('click', () => {
|
2019-04-03 14:15:15 +00:00
|
|
|
selectedObject = null;
|
|
|
|
currentConnection = null;
|
2019-03-05 19:31:53 +00:00
|
|
|
modalSimulate.open();
|
|
|
|
});
|
2019-04-03 14:15:15 +00:00
|
|
|
|
|
|
|
document.addEventListener('dragover', (event) => {
|
|
|
|
elements.dragOverlay.classList.add('visible');
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
|
|
|
|
document.addEventListener('dragexit', (event) => {
|
|
|
|
elements.dragOverlay.classList.remove('visible');
|
|
|
|
});
|
|
|
|
|
|
|
|
document.addEventListener('drop', (event) => {
|
|
|
|
const item = event.dataTransfer.items[0];
|
|
|
|
if (item.kind === 'file') {
|
|
|
|
const file = item.getAsFile();
|
|
|
|
|
|
|
|
const lastDot = file.name.lastIndexOf('.');
|
|
|
|
const ext = file.name.slice(lastDot + 1);
|
|
|
|
|
|
|
|
if (ext === 'fsm') {
|
|
|
|
const reader = new FileReader();
|
|
|
|
reader.readAsText(file, 'UTF-8');
|
|
|
|
reader.onload = (evt) => {
|
|
|
|
const json = evt.target.result;
|
|
|
|
// TODO: Add error handling
|
|
|
|
try {
|
|
|
|
importFromJson(json);
|
|
|
|
} catch (e) {
|
|
|
|
alert('Ein Fehler ist beim Einlesen der Datei aufgetreten. Die Datei scheint nicht im richtigen Format zu sein.')
|
|
|
|
}
|
|
|
|
};
|
|
|
|
reader.onerror = (evt) => {
|
|
|
|
alert('Ein Fehler beim Einlesen der Datei ist aufgetreten. Womöglich muss hier ein Bug behoben werden... :(');
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
alert('Dieses Dateiformat wird nicht unterstützt.')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
elements.dragOverlay.classList.remove('visible');
|
|
|
|
event.preventDefault();
|
|
|
|
return false;
|
|
|
|
});
|