| 4 | */ |
| 5 | |
| 6 | function setBomHandlers() { |
| 7 | |
| 8 | const bom = document.getElementById('bomtable'); |
| 9 | |
| 10 | let dragName; |
| 11 | let placeHolderElements; |
| 12 | let draggingElement; |
| 13 | let forcePopulation; |
| 14 | let xOffset; |
| 15 | let yOffset; |
| 16 | let wasDragged; |
| 17 | |
| 18 | const mouseUpHandler = function(e) { |
| 19 | // Delete dragging element |
| 20 | draggingElement.remove(); |
| 21 | |
| 22 | // Make BOM selectable again |
| 23 | bom.style.removeProperty("user-select"); |
| 24 | |
| 25 | // Remove listeners |
| 26 | document.removeEventListener('mousemove', mouseMoveHandler); |
| 27 | document.removeEventListener('mouseup', mouseUpHandler); |
| 28 | |
| 29 | if (wasDragged) { |
| 30 | // Redraw whole BOM |
| 31 | populateBomTable(); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | const mouseMoveHandler = function(e) { |
| 36 | // Notice the dragging |
| 37 | wasDragged = true; |
| 38 | |
| 39 | // Make the dragged element visible |
| 40 | draggingElement.style.removeProperty("display"); |
| 41 | |
| 42 | // Set elements position to mouse position |
| 43 | draggingElement.style.left = `${e.screenX - xOffset}px`; |
| 44 | draggingElement.style.top = `${e.screenY - yOffset}px`; |
| 45 | |
| 46 | // Forced redrawing of BOM table |
| 47 | if (forcePopulation) { |
| 48 | forcePopulation = false; |
| 49 | // Copy array |
| 50 | phe = Array.from(placeHolderElements); |
| 51 | // populate BOM table again |
| 52 | populateBomHeader(dragName, phe); |
| 53 | populateBomBody(dragName, phe); |
| 54 | } |
| 55 | |
| 56 | // Set up array of hidden columns |
| 57 | var hiddenColumns = Array.from(settings.hiddenColumns); |
| 58 | // In the ungrouped mode, quantity don't exist |
| 59 | if (settings.bommode === "ungrouped") |
| 60 | hiddenColumns.push("Quantity"); |
| 61 | // If no checkbox fields can be found, we consider them hidden |
| 62 | if (settings.checkboxes.length == 0) |
| 63 | hiddenColumns.push("checkboxes"); |