mirror of
https://forge.murkfall.net/bluesaxman/librePECS.git
synced 2026-03-13 02:04:20 -06:00
added ability to have multipul boards
This commit is contained in:
50
main.js
50
main.js
@@ -87,6 +87,55 @@ function setPec(pecTemplate=null, targetIndex=null) {
|
||||
targetPec.appendChild(pecTemplate.DOM);
|
||||
}
|
||||
|
||||
function repopBoards (current=0) {
|
||||
//app.boards;
|
||||
//app.currentBoards;
|
||||
//app.menu;
|
||||
// Normally we only want <, but we want an extra
|
||||
// iteration here for the "add new board" element
|
||||
for (var i = 0; i <= app.boards.length; i++) {
|
||||
var boardTab = document.getElementById("board"+i);
|
||||
if (null == boardTab) {
|
||||
boardTab = document.createElement("span");
|
||||
boardTab.setAttribute("id", "board"+i);
|
||||
boardTab.classList.add("board_tab");
|
||||
app.gui.menu.appendChild(boardTab);
|
||||
}
|
||||
// Clear event listeners
|
||||
var oldTab = boardTab;
|
||||
boardTab = oldTab.cloneNode(true);
|
||||
oldTab.parentNode.replaceChild(boardTab, oldTab);
|
||||
// not sure how memory safe the above lines are
|
||||
var name = "Board "+i;
|
||||
if (i == app.boards.length) {
|
||||
name = "+";
|
||||
boardTab.addEventListener("click",(e)=>{
|
||||
var current = app.boards.findIndex(i=>i==app.currentBoard);
|
||||
app.boards.push(new pecBoard());
|
||||
repopBoards(current);
|
||||
repopGrid(app.currentBoard);
|
||||
});
|
||||
} else {
|
||||
if (current != i) {
|
||||
boardTab.classList.remove("active_board");
|
||||
boardTab.addEventListener("click", (e)=>{
|
||||
var sourceID = ((e.currentTarget.getAttribute("id")).split("board"))[1];
|
||||
app.currentBoard = app.boards[sourceID];
|
||||
repopBoards(sourceID);
|
||||
repopGrid(app.currentBoard);
|
||||
});
|
||||
} else {
|
||||
boardTab.classList.add("active_board");
|
||||
}
|
||||
if (undefined != app.boards[i].name) {
|
||||
name = app.boards[i].name;
|
||||
}
|
||||
}
|
||||
boardTab.innerText = name;
|
||||
console.log(boardTab);
|
||||
}
|
||||
}
|
||||
|
||||
function repopGrid (board=null) {
|
||||
if (null == board) { return systemMsg("repopGrid was not provided data",2); }
|
||||
if (!(board instanceof pecBoard)) { return systemMsg("repopGrid was not provided data of type pecBoard",2); }
|
||||
@@ -146,6 +195,7 @@ for (var x = 0; x < 16; x++) {
|
||||
app.boards = [];
|
||||
app.boards.push(new pecBoard());
|
||||
app.currentBoard = app.boards[0];
|
||||
repopBoards(0);
|
||||
repopGrid(app.currentBoard);
|
||||
|
||||
// Populate Library
|
||||
|
||||
Reference in New Issue
Block a user