Skip to main content

Example implementation

This is an example of the most common implementation of the project management system. It's based on a file blob download and open file dialog.

function saveProject() {
var project = NetDecor.v3.project.getCurrentProject();
console.log(project);
NetDecor.v3.project.markCurrentProjectClean();
var blob = new File([project.data], project.name, { type: 'application/octet-stream' });
var url = URL.createObjectURL(blob);
window.open(url, "_tab");
}

function handleFiles() {
var file = this.files[0]; /* now you can work with the file list */
var reader = new FileReader();

reader.onload = function (e) {
console.log(e.target.result);
NetDecor.v3.project.openProject({
data: new Uint8Array(e.target.result),
id: null, // generate new ID
name: file.name,
})
}

reader.readAsArrayBuffer(file);
}

var inputElement = document.getElementById("fileInput");
inputElement.addEventListener("change", handleFiles, false);
function openProject() {
inputElement.style.visibility = "visible";
inputElement.focus();
inputElement.click();
inputElement.style.visibility = "hidden";
}

function createNewProject() {
if (NetDecor.v3.project.isCurrentProjectDirty()) {
NetDecor.v3.dialog.show({
title: {
pl: "Niezapisane zmiany w projekcie",
en: "Unsaved changes in project",
},
message: {
pl: "Zapisać zmiany?",
en: "Save changes?"
},
buttons: "YesNoCancel",
onresult: function (result) {
if (result == "Yes")
saveProject();
else if (result == "Cancel")
return;

NetDecor.v3.project.createNewProject({});
}
})
}
else {
NetDecor.v3.project.createNewProject({});
}
}


NetDecor.v3.project.addButton({
label: { pl: "Nowy", en: "New" },
icon: "New",
onclick: createNewProject
});

NetDecor.v3.project.addButton({
label: { pl: "Zapisz", en: "Save" },
icon: "Save",
shortcut:{
flags:["LCtrl"],
key:"S"
},
onclick: saveProject
});

NetDecor.v3.project.addButton({
label: { pl: "Otwórz", en: "Open" },
icon: "Open",
onclick: openProject
});